![]() |
libusb 1.0.30-rc1
A cross-platform user library to access USB devices
|
This page details how to examine the various standard USB descriptors for detected devices. More...
Data Structures | |
| struct | libusb_device_descriptor |
| A structure representing the standard USB device descriptor. More... | |
| struct | libusb_endpoint_descriptor |
| A structure representing the standard USB endpoint descriptor. More... | |
| struct | libusb_interface_association_descriptor |
| A structure representing the standard USB interface association descriptor. More... | |
| struct | libusb_interface_association_descriptor_array |
| Structure containing an array of 0 or more interface association descriptors. More... | |
| struct | libusb_interface_descriptor |
| A structure representing the standard USB interface descriptor. More... | |
| struct | libusb_interface |
| A collection of alternate settings for a particular USB interface. More... | |
| struct | libusb_config_descriptor |
| A structure representing the standard USB configuration descriptor. More... | |
| struct | libusb_ss_endpoint_companion_descriptor |
| A structure representing the superspeed endpoint companion descriptor. More... | |
| struct | libusb_bos_dev_capability_descriptor |
| A generic representation of a BOS Device Capability descriptor. More... | |
| struct | libusb_bos_descriptor |
| A structure representing the Binary Device Object Store (BOS) descriptor. More... | |
| struct | libusb_usb_2_0_extension_descriptor |
| A structure representing the USB 2.0 Extension descriptor This descriptor is documented in section 9.6.2.1 of the USB 3.0 specification. More... | |
| struct | libusb_ss_usb_device_capability_descriptor |
| A structure representing the SuperSpeed USB Device Capability descriptor This descriptor is documented in section 9.6.2.2 of the USB 3.0 specification. More... | |
| struct | libusb_ssplus_sublink_attribute |
| Expose libusb_ssplus_usb_device_capability_descriptor::sublinkSpeedAttributes. More... | |
| struct | libusb_ssplus_usb_device_capability_descriptor |
| A structure representing the SuperSpeedPlus descriptor This descriptor is documented in section 9.6.2.5 of the USB 3.1 specification. More... | |
| struct | libusb_container_id_descriptor |
| A structure representing the Container ID descriptor. More... | |
| struct | libusb_platform_descriptor |
| A structure representing a Platform descriptor. More... | |
Macros | |
| #define | LIBUSB_DEVICE_STRING_BYTES_MAX (384U) |
| The maximum length for a device string descriptor in UTF-8. | |
Functions | |
| int | libusb_get_device_descriptor (libusb_device *dev, struct libusb_device_descriptor *desc) |
| Get the USB device descriptor for a given device. | |
| int | libusb_get_active_config_descriptor (libusb_device *dev, struct libusb_config_descriptor **config) |
| Get the USB configuration descriptor for the currently active configuration. | |
| int | libusb_get_config_descriptor (libusb_device *dev, uint8_t config_index, struct libusb_config_descriptor **config) |
| Get a USB configuration descriptor based on its index. | |
| int | libusb_get_config_descriptor_by_value (libusb_device *dev, uint8_t bConfigurationValue, struct libusb_config_descriptor **config) |
| Get a USB configuration descriptor with a specific bConfigurationValue. | |
| void | libusb_free_config_descriptor (struct libusb_config_descriptor *config) |
| Free a configuration descriptor obtained from libusb_get_active_config_descriptor() or libusb_get_config_descriptor(). | |
| int | libusb_get_ss_endpoint_companion_descriptor (libusb_context *ctx, const struct libusb_endpoint_descriptor *endpoint, struct libusb_ss_endpoint_companion_descriptor **ep_comp) |
| Get an endpoints superspeed endpoint companion descriptor (if any). | |
| void | libusb_free_ss_endpoint_companion_descriptor (struct libusb_ss_endpoint_companion_descriptor *ep_comp) |
| Free a superspeed endpoint companion descriptor obtained from libusb_get_ss_endpoint_companion_descriptor(). | |
| int | libusb_get_bos_descriptor (libusb_device_handle *dev_handle, struct libusb_bos_descriptor **bos) |
| Get a Binary Object Store (BOS) descriptor This is a BLOCKING function, which will send requests to the device. | |
| void | libusb_free_bos_descriptor (struct libusb_bos_descriptor *bos) |
| Free a BOS descriptor obtained from libusb_get_bos_descriptor(). | |
| int | libusb_get_usb_2_0_extension_descriptor (libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension) |
| Get an USB 2.0 Extension descriptor. | |
| void | libusb_free_usb_2_0_extension_descriptor (struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension) |
| Free a USB 2.0 Extension descriptor obtained from libusb_get_usb_2_0_extension_descriptor(). | |
| int | libusb_get_ss_usb_device_capability_descriptor (libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap) |
| Get a SuperSpeed USB Device Capability descriptor. | |
| int | libusb_get_ssplus_usb_device_capability_descriptor (libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_ssplus_usb_device_capability_descriptor **ssplus_usb_device_cap) |
| Get a SuperSpeedPlus USB Device Capability descriptor. | |
| void | libusb_free_ssplus_usb_device_capability_descriptor (struct libusb_ssplus_usb_device_capability_descriptor *ssplus_usb_device_cap) |
| Free a SuperSpeedPlus USB Device Capability descriptor obtained from libusb_get_ssplus_usb_device_capability_descriptor(). | |
| void | libusb_free_ss_usb_device_capability_descriptor (struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap) |
| Free a SuperSpeed USB Device Capability descriptor obtained from libusb_get_ss_usb_device_capability_descriptor(). | |
| int | libusb_get_container_id_descriptor (libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_container_id_descriptor **container_id) |
| Get a Container ID descriptor. | |
| void | libusb_free_container_id_descriptor (struct libusb_container_id_descriptor *container_id) |
| Free a Container ID descriptor obtained from libusb_get_container_id_descriptor(). | |
| int | libusb_get_platform_descriptor (libusb_context *ctx, struct libusb_bos_dev_capability_descriptor *dev_cap, struct libusb_platform_descriptor **platform_descriptor) |
| Get a platform descriptor. | |
| void | libusb_free_platform_descriptor (struct libusb_platform_descriptor *platform_descriptor) |
| Free a platform descriptor obtained from libusb_get_platform_descriptor(). | |
| int | libusb_get_string_descriptor_ascii (libusb_device_handle *dev_handle, uint8_t desc_index, unsigned char *data, int length) |
| Retrieve a string descriptor in C style ASCII. | |
| int | libusb_get_interface_association_descriptors (libusb_device *dev, uint8_t config_index, struct libusb_interface_association_descriptor_array **iad_array) |
| Get an array of interface association descriptors (IAD) for a given configuration. | |
| int | libusb_get_active_interface_association_descriptors (libusb_device *dev, struct libusb_interface_association_descriptor_array **iad_array) |
| Get an array of interface association descriptors (IAD) for the currently active configuration. | |
| void | libusb_free_interface_association_descriptors (struct libusb_interface_association_descriptor_array *iad_array) |
| Free an array of interface association descriptors (IADs) obtained from libusb_get_interface_association_descriptors() or libusb_get_active_interface_association_descriptors(). | |
| int | libusb_get_device_string (libusb_device *dev, enum libusb_device_string_type string_type, char *data, int length) |
| Retrieve a device string without needing to open the device. | |
| static int | libusb_get_descriptor (libusb_device_handle *dev_handle, uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length) |
| Retrieve a descriptor from the default control pipe. | |
| static int | libusb_get_string_descriptor (libusb_device_handle *dev_handle, uint8_t desc_index, uint16_t langid, unsigned char *data, int length) |
| Retrieve a descriptor from a device. | |
This page details how to examine the various standard USB descriptors for detected devices.
| #define LIBUSB_DEVICE_STRING_BYTES_MAX (384U) |
The maximum length for a device string descriptor in UTF-8.
255 max descriptor length with 2 byte header => 253 bytes UTF-16LE, no null termination (USB 2.0 9.6.7) => 126.5 codepoints => 126 * 3 + 1 => 382 bytes
Stay with 256 * 2/3 = 384 to be safe.
| enum libusb_class_code |
Device and/or Interface Class codes.
| Enumerator | |
|---|---|
| LIBUSB_CLASS_PER_INTERFACE | In the context of a device descriptor, this bDeviceClass value indicates that each interface specifies its own class information and all interfaces operate independently. |
| LIBUSB_CLASS_AUDIO | Audio class. |
| LIBUSB_CLASS_COMM | Communications class. |
| LIBUSB_CLASS_HID | Human Interface Device class. |
| LIBUSB_CLASS_PHYSICAL | Physical. |
| LIBUSB_CLASS_IMAGE | Image class. |
| LIBUSB_CLASS_PRINTER | Printer class. |
| LIBUSB_CLASS_MASS_STORAGE | Mass storage class. |
| LIBUSB_CLASS_HUB | Hub class. |
| LIBUSB_CLASS_DATA | Data class. |
| LIBUSB_CLASS_SMART_CARD | Smart Card. |
| LIBUSB_CLASS_CONTENT_SECURITY | Content Security. |
| LIBUSB_CLASS_VIDEO | Video. |
| LIBUSB_CLASS_PERSONAL_HEALTHCARE | Personal Healthcare. |
| LIBUSB_CLASS_AUDIO_VIDEO | Audio & Video. |
| LIBUSB_CLASS_BILLBOARD | Billboard. |
| LIBUSB_CLASS_TYPE_C_BRIDGE | Interface class. |
| LIBUSB_CLASS_BULK_DISPLAY_PROTOCOL | Bulk display. |
| LIBUSB_CLASS_MCTP | MCTP. |
| LIBUSB_CLASS_I3C | I3C. |
| LIBUSB_CLASS_DIAGNOSTIC_DEVICE | Diagnostic Device. |
| LIBUSB_CLASS_WIRELESS | Wireless class. |
| LIBUSB_CLASS_MISCELLANEOUS | Miscellaneous class. |
| LIBUSB_CLASS_APPLICATION | Application class. |
| LIBUSB_CLASS_VENDOR_SPEC | Class is vendor-specific. |
Descriptor types as defined by the USB specification.
Endpoint direction.
Values for bit 7 of the endpoint address scheme.
| Enumerator | |
|---|---|
| LIBUSB_ENDPOINT_OUT | Out: host-to-device. |
| LIBUSB_ENDPOINT_IN | In: device-to-host. |
Endpoint transfer type.
Values for bits 0:1 of the endpoint attributes field.
| enum libusb_iso_sync_type |
Synchronization type for isochronous endpoints.
Values for bits 2:3 of the bmAttributes field in libusb_endpoint_descriptor.
| Enumerator | |
|---|---|
| LIBUSB_ISO_SYNC_TYPE_NONE | No synchronization. |
| LIBUSB_ISO_SYNC_TYPE_ASYNC | Asynchronous. |
| LIBUSB_ISO_SYNC_TYPE_ADAPTIVE | Adaptive. |
| LIBUSB_ISO_SYNC_TYPE_SYNC | Synchronous. |
Usage type for isochronous endpoints.
Values for bits 4:5 of the bmAttributes field in libusb_endpoint_descriptor.
| Enumerator | |
|---|---|
| LIBUSB_ISO_USAGE_TYPE_DATA | Data endpoint. |
| LIBUSB_ISO_USAGE_TYPE_FEEDBACK | Feedback endpoint. |
| LIBUSB_ISO_USAGE_TYPE_IMPLICIT | Implicit feedback Data endpoint. |
Supported speeds (wSpeedSupported) bitfield.
Indicates what speeds the device supports.
Masks for the bits of the bmAttributes field of the USB 2.0 Extension descriptor.
| Enumerator | |
|---|---|
| LIBUSB_BM_LPM_SUPPORT | Supports Link Power Management (LPM). |
Masks for the bits of the bmAttributes field field of the SuperSpeed USB Device Capability descriptor.
| Enumerator | |
|---|---|
| LIBUSB_BM_LTM_SUPPORT | Supports Latency Tolerance Messages (LTM). |
| enum libusb_bos_type |
USB capability types.
| int libusb_get_device_descriptor | ( | libusb_device * | dev, |
| struct libusb_device_descriptor * | desc ) |
Get the USB device descriptor for a given device.
This is a non-blocking function; the device descriptor is cached in memory.
Note since libusb-1.0.16, LIBUSBX_API_VERSION >= 0x01000102, this function always succeeds.
| dev | the device |
| desc | output location for the descriptor data |
| int libusb_get_active_config_descriptor | ( | libusb_device * | dev, |
| struct libusb_config_descriptor ** | config ) |
Get the USB configuration descriptor for the currently active configuration.
This is a non-blocking function which does not involve any requests being sent to the device.
| dev | a device |
| config | output location for the USB configuration descriptor. Only valid if 0 was returned. Must be freed with libusb_free_config_descriptor() after use. |
| int libusb_get_config_descriptor | ( | libusb_device * | dev, |
| uint8_t | config_index, | ||
| struct libusb_config_descriptor ** | config ) |
Get a USB configuration descriptor based on its index.
This is a non-blocking function which does not involve any requests being sent to the device.
| dev | a device |
| config_index | the index of the configuration you wish to retrieve |
| config | output location for the USB configuration descriptor. Only valid if 0 was returned. Must be freed with libusb_free_config_descriptor() after use. |
| int libusb_get_config_descriptor_by_value | ( | libusb_device * | dev, |
| uint8_t | bConfigurationValue, | ||
| struct libusb_config_descriptor ** | config ) |
Get a USB configuration descriptor with a specific bConfigurationValue.
This is a non-blocking function which does not involve any requests being sent to the device.
| dev | a device |
| bConfigurationValue | the bConfigurationValue of the configuration you wish to retrieve |
| config | output location for the USB configuration descriptor. Only valid if 0 was returned. Must be freed with libusb_free_config_descriptor() after use. |
| void libusb_free_config_descriptor | ( | struct libusb_config_descriptor * | config | ) |
Free a configuration descriptor obtained from libusb_get_active_config_descriptor() or libusb_get_config_descriptor().
It is safe to call this function with a NULL config parameter, in which case the function simply returns.
| config | the configuration descriptor to free |
| int libusb_get_ss_endpoint_companion_descriptor | ( | libusb_context * | ctx, |
| const struct libusb_endpoint_descriptor * | endpoint, | ||
| struct libusb_ss_endpoint_companion_descriptor ** | ep_comp ) |
Get an endpoints superspeed endpoint companion descriptor (if any).
| ctx | the context to operate on, or NULL for the default context |
| endpoint | endpoint descriptor from which to get the superspeed endpoint companion descriptor |
| ep_comp | output location for the superspeed endpoint companion descriptor. Only valid if 0 was returned. Must be freed with libusb_free_ss_endpoint_companion_descriptor() after use. |
| void libusb_free_ss_endpoint_companion_descriptor | ( | struct libusb_ss_endpoint_companion_descriptor * | ep_comp | ) |
Free a superspeed endpoint companion descriptor obtained from libusb_get_ss_endpoint_companion_descriptor().
It is safe to call this function with a NULL ep_comp parameter, in which case the function simply returns.
| ep_comp | the superspeed endpoint companion descriptor to free |
| int libusb_get_bos_descriptor | ( | libusb_device_handle * | dev_handle, |
| struct libusb_bos_descriptor ** | bos ) |
Get a Binary Object Store (BOS) descriptor This is a BLOCKING function, which will send requests to the device.
| dev_handle | the handle of an open libusb device |
| bos | output location for the BOS descriptor. Only valid if 0 was returned. Must be freed with libusb_free_bos_descriptor() after use. |
| void libusb_free_bos_descriptor | ( | struct libusb_bos_descriptor * | bos | ) |
Free a BOS descriptor obtained from libusb_get_bos_descriptor().
It is safe to call this function with a NULL bos parameter, in which case the function simply returns.
| bos | the BOS descriptor to free |
| int libusb_get_usb_2_0_extension_descriptor | ( | libusb_context * | ctx, |
| struct libusb_bos_dev_capability_descriptor * | dev_cap, | ||
| struct libusb_usb_2_0_extension_descriptor ** | usb_2_0_extension ) |
Get an USB 2.0 Extension descriptor.
| ctx | the context to operate on, or NULL for the default context |
| dev_cap | Device Capability descriptor with a bDevCapabilityType of libusb_bos_type::LIBUSB_BT_USB_2_0_EXTENSION LIBUSB_BT_USB_2_0_EXTENSION |
| usb_2_0_extension | output location for the USB 2.0 Extension descriptor. Only valid if 0 was returned. Must be freed with libusb_free_usb_2_0_extension_descriptor() after use. |
| void libusb_free_usb_2_0_extension_descriptor | ( | struct libusb_usb_2_0_extension_descriptor * | usb_2_0_extension | ) |
Free a USB 2.0 Extension descriptor obtained from libusb_get_usb_2_0_extension_descriptor().
It is safe to call this function with a NULL usb_2_0_extension parameter, in which case the function simply returns.
| usb_2_0_extension | the USB 2.0 Extension descriptor to free |
| int libusb_get_ss_usb_device_capability_descriptor | ( | libusb_context * | ctx, |
| struct libusb_bos_dev_capability_descriptor * | dev_cap, | ||
| struct libusb_ss_usb_device_capability_descriptor ** | ss_usb_device_cap ) |
Get a SuperSpeed USB Device Capability descriptor.
| ctx | the context to operate on, or NULL for the default context |
| dev_cap | Device Capability descriptor with a bDevCapabilityType of libusb_bos_type::LIBUSB_BT_SS_USB_DEVICE_CAPABILITY LIBUSB_BT_SS_USB_DEVICE_CAPABILITY |
| ss_usb_device_cap | output location for the SuperSpeed USB Device Capability descriptor. Only valid if 0 was returned. Must be freed with libusb_free_ss_usb_device_capability_descriptor() after use. |
| int libusb_get_ssplus_usb_device_capability_descriptor | ( | libusb_context * | ctx, |
| struct libusb_bos_dev_capability_descriptor * | dev_cap, | ||
| struct libusb_ssplus_usb_device_capability_descriptor ** | ssplus_usb_device_cap ) |
Get a SuperSpeedPlus USB Device Capability descriptor.
Since version 1.0.28, LIBUSB_API_VERSION >= 0x0100010B
| ctx | the context to operate on, or NULL for the default context |
| dev_cap | Device Capability descriptor with a bDevCapabilityType of libusb_bos_type::LIBUSB_BT_SUPERSPEED_PLUS_CAPABILITY LIBUSB_BT_SUPERSPEED_PLUS_CAPABILITY |
| ssplus_usb_device_cap | output location for the SuperSpeedPlus USB Device Capability descriptor. Only valid if 0 was returned. Must be freed with libusb_free_ssplus_usb_device_capability_descriptor() after use. |
| void libusb_free_ssplus_usb_device_capability_descriptor | ( | struct libusb_ssplus_usb_device_capability_descriptor * | ssplus_usb_device_cap | ) |
Free a SuperSpeedPlus USB Device Capability descriptor obtained from libusb_get_ssplus_usb_device_capability_descriptor().
It is safe to call this function with a NULL ssplus_usb_device_cap parameter, in which case the function simply returns.
Since version 1.0.28, LIBUSB_API_VERSION >= 0x0100010B
| ssplus_usb_device_cap | the SuperSpeedPlus USB Device Capability descriptor to free |
| void libusb_free_ss_usb_device_capability_descriptor | ( | struct libusb_ss_usb_device_capability_descriptor * | ss_usb_device_cap | ) |
Free a SuperSpeed USB Device Capability descriptor obtained from libusb_get_ss_usb_device_capability_descriptor().
It is safe to call this function with a NULL ss_usb_device_cap parameter, in which case the function simply returns.
| ss_usb_device_cap | the SuperSpeed USB Device Capability descriptor to free |
| int libusb_get_container_id_descriptor | ( | libusb_context * | ctx, |
| struct libusb_bos_dev_capability_descriptor * | dev_cap, | ||
| struct libusb_container_id_descriptor ** | container_id ) |
Get a Container ID descriptor.
| ctx | the context to operate on, or NULL for the default context |
| dev_cap | Device Capability descriptor with a bDevCapabilityType of libusb_bos_type::LIBUSB_BT_CONTAINER_ID LIBUSB_BT_CONTAINER_ID |
| container_id | output location for the Container ID descriptor. Only valid if 0 was returned. Must be freed with libusb_free_container_id_descriptor() after use. |
| void libusb_free_container_id_descriptor | ( | struct libusb_container_id_descriptor * | container_id | ) |
Free a Container ID descriptor obtained from libusb_get_container_id_descriptor().
It is safe to call this function with a NULL container_id parameter, in which case the function simply returns.
| container_id | the Container ID descriptor to free |
| int libusb_get_platform_descriptor | ( | libusb_context * | ctx, |
| struct libusb_bos_dev_capability_descriptor * | dev_cap, | ||
| struct libusb_platform_descriptor ** | platform_descriptor ) |
Get a platform descriptor.
Since version 1.0.27, LIBUSB_API_VERSION >= 0x0100010A
| ctx | the context to operate on, or NULL for the default context |
| dev_cap | Device Capability descriptor with a bDevCapabilityType of libusb_bos_type::LIBUSB_BT_PLATFORM_DESCRIPTOR LIBUSB_BT_PLATFORM_DESCRIPTOR |
| platform_descriptor | output location for the Platform descriptor. Only valid if 0 was returned. Must be freed with libusb_free_platform_descriptor() after use. |
| void libusb_free_platform_descriptor | ( | struct libusb_platform_descriptor * | platform_descriptor | ) |
Free a platform descriptor obtained from libusb_get_platform_descriptor().
It is safe to call this function with a NULL platform_descriptor parameter, in which case the function simply returns.
| platform_descriptor | the Platform descriptor to free |
| int libusb_get_string_descriptor_ascii | ( | libusb_device_handle * | dev_handle, |
| uint8_t | desc_index, | ||
| unsigned char * | data, | ||
| int | length ) |
Retrieve a string descriptor in C style ASCII.
Wrapper around libusb_get_string_descriptor(). Uses the first language supported by the device.
| dev_handle | a device handle |
| desc_index | the index of the descriptor to retrieve |
| data | output buffer for ASCII string descriptor |
| length | size of data buffer |
| int libusb_get_interface_association_descriptors | ( | libusb_device * | dev, |
| uint8_t | config_index, | ||
| struct libusb_interface_association_descriptor_array ** | iad_array ) |
Get an array of interface association descriptors (IAD) for a given configuration.
This is a non-blocking function which does not involve any requests being sent to the device.
| dev | a device |
| config_index | the index of the configuration you wish to retrieve the IADs for. |
| iad_array | output location for the array of IADs. Only valid if 0 was returned. Must be freed with libusb_free_interface_association_descriptors() after use. It's possible that a given configuration contains no IADs. In this case the iad_array is still output, but will have 'length' field set to 0, and iad field set to NULL. |
| int libusb_get_active_interface_association_descriptors | ( | libusb_device * | dev, |
| struct libusb_interface_association_descriptor_array ** | iad_array ) |
Get an array of interface association descriptors (IAD) for the currently active configuration.
This is a non-blocking function which does not involve any requests being sent to the device.
| dev | a device |
| iad_array | output location for the array of IADs. Only valid if 0 was returned. Must be freed with libusb_free_interface_association_descriptors() after use. It's possible that a given configuration contains no IADs. In this case the iad_array is still output, but will have 'length' field set to 0, and iad field set to NULL. |
| void libusb_free_interface_association_descriptors | ( | struct libusb_interface_association_descriptor_array * | iad_array | ) |
Free an array of interface association descriptors (IADs) obtained from libusb_get_interface_association_descriptors() or libusb_get_active_interface_association_descriptors().
It is safe to call this function with a NULL iad_array parameter, in which case the function simply returns.
| iad_array | the IAD array to free |
| int libusb_get_device_string | ( | libusb_device * | dev, |
| enum libusb_device_string_type | string_type, | ||
| char * | data, | ||
| int | length ) |
Retrieve a device string without needing to open the device.
Since version v1.0.30 LIBUSB_API_VERSION >= 0x0100010C
| dev | the target device |
| string_type | the string type to retrieve |
| data | the data buffer for the UTF-8 encoded string. |
| length | the size of the data buffer in bytes. USB string descriptors cannot be longer than LIBUSB_DEVICE_STRING_BYTES_MAX. |
This function works when the device is still closed since it relies on the operating system to provide the string. The operating system normally reads and caches the common string descriptors during USB enumeration.
Since the USB string descriptor could be processed by the OS, this function returns a UTF-8 encoded string.
The string will be returned untranslated or in the default OS language when supported by the OS and USB device.
One way to call this function is using a buffer on the stack:
char buffer[LIBUSB_DEVICE_STRING_BYTES_MAX];
int ret = libusb_get_device_string(dev, LIBUSB_DEVICE_STRING_SERIAL_NUMBER, buffer, sizeof(buffer));
if (ret < 0) {
// handle error
}
This function is commonly used to get the serial number to allow for device selection before opening the selected device.
|
inlinestatic |
Retrieve a descriptor from the default control pipe.
This is a convenience function which formulates the appropriate control message to retrieve the descriptor.
| dev_handle | a device handle |
| desc_type | the descriptor type, see libusb_descriptor_type |
| desc_index | the index of the descriptor to retrieve |
| data | output buffer for descriptor |
| length | size of data buffer |
|
inlinestatic |
Retrieve a descriptor from a device.
This is a convenience function which formulates the appropriate control message to retrieve the descriptor. The string returned is Unicode, as detailed in the USB specifications.
| dev_handle | a device handle |
| desc_index | the index of the descriptor to retrieve |
| langid | the language ID for the string descriptor |
| data | output buffer for descriptor |
| length | size of data buffer |