2 * Public libusbx header file
3 * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
4 * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
5 * Copyright © 2012 Pete Batard <pete@akeo.ie>
6 * For more information, please visit: http://libusbx.org
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 /* on MS environments, the inline keyword is available in C++ only */
28 #if !defined(__cplusplus)
29 #define inline __inline
31 /* ssize_t is also not available (copy/paste from MinGW) */
32 #ifndef _SSIZE_T_DEFINED
33 #define _SSIZE_T_DEFINED
36 typedef __int64 ssize_t;
40 #endif /* _SSIZE_T_DEFINED */
43 /* stdint.h is also not usually available on MS */
44 #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
45 typedef unsigned __int8 uint8_t;
46 typedef unsigned __int16 uint16_t;
47 typedef unsigned __int32 uint32_t;
52 #include <sys/types.h>
56 #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
60 /* 'interface' might be defined as a macro on Windows, so we need to
61 * undefine it so as not to break the current libusbx API, because
62 * libusb_config_descriptor has an 'interface' member
63 * As this can be problematic if you include windows.h after libusb.h
64 * in your sources, we force windows.h to be included first. */
65 #if defined(_WIN32) || defined(__CYGWIN__)
67 #if defined(interface)
74 * libusbx's Windows calling convention.
76 * Under Windows, the selection of available compilers and configurations
77 * means that, unlike other platforms, there is not <em>one true calling
78 * convention</em> (calling convention: the manner in which parameters are
79 * passed to funcions in the generated assembly code).
81 * Matching the Windows API itself, libusbx uses the WINAPI convention (which
82 * translates to the <tt>stdcall</tt> convention) and guarantees that the
83 * library is compiled in this way. The public header file also includes
84 * appropriate annotations so that your own software will use the right
85 * convention, even if another convention is being used by default within
88 * The one consideration that you must apply in your software is to mark
89 * all functions which you use as libusbx callbacks with this LIBUSB_CALL
90 * annotation, so that they too get compiled for the correct calling
93 * On non-Windows operating systems, this macro is defined as nothing. This
94 * means that you can apply it to your code without worrying about
95 * cross-platform compatibility.
97 /* LIBUSB_CALL must be defined on both definition and declaration of libusbx
98 * functions. You'd think that declaration would be enough, but cygwin will
99 * complain about conflicting types unless both are marked this way.
100 * The placement of this macro is important too; it must appear after the
101 * return type, before the function name. See internal documentation for
104 #if defined(_WIN32) || defined(__CYGWIN__)
105 #define LIBUSB_CALL WINAPI
114 /** \def libusb_cpu_to_le16
116 * Convert a 16-bit value from host-endian to little-endian format. On
117 * little endian systems, this function does nothing. On big endian systems,
118 * the bytes are swapped.
119 * \param x the host-endian value to convert
120 * \returns the value in little-endian byte order
122 static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
129 _tmp.b8[0] = x & 0xff;
133 /** \def libusb_le16_to_cpu
135 * Convert a 16-bit value from little-endian to host-endian format. On
136 * little endian systems, this function does nothing. On big endian systems,
137 * the bytes are swapped.
138 * \param x the little-endian value to convert
139 * \returns the value in host-endian byte order
141 #define libusb_le16_to_cpu libusb_cpu_to_le16
143 /* standard USB stuff */
146 * Device and/or Interface Class codes */
147 enum libusb_class_code {
148 /** In the context of a \ref libusb_device_descriptor "device descriptor",
149 * this bDeviceClass value indicates that each interface specifies its
150 * own class information and all interfaces operate independently.
152 LIBUSB_CLASS_PER_INTERFACE = 0,
155 LIBUSB_CLASS_AUDIO = 1,
157 /** Communications class */
158 LIBUSB_CLASS_COMM = 2,
160 /** Human Interface Device class */
161 LIBUSB_CLASS_HID = 3,
164 LIBUSB_CLASS_PHYSICAL = 5,
167 LIBUSB_CLASS_PRINTER = 7,
170 LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
171 LIBUSB_CLASS_IMAGE = 6,
173 /** Mass storage class */
174 LIBUSB_CLASS_MASS_STORAGE = 8,
177 LIBUSB_CLASS_HUB = 9,
180 LIBUSB_CLASS_DATA = 10,
183 LIBUSB_CLASS_SMART_CARD = 0x0b,
185 /** Content Security */
186 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
189 LIBUSB_CLASS_VIDEO = 0x0e,
191 /** Personal Healthcare */
192 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
194 /** Diagnostic Device */
195 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
197 /** Wireless class */
198 LIBUSB_CLASS_WIRELESS = 0xe0,
200 /** Application class */
201 LIBUSB_CLASS_APPLICATION = 0xfe,
203 /** Class is vendor-specific */
204 LIBUSB_CLASS_VENDOR_SPEC = 0xff
208 * Descriptor types as defined by the USB specification. */
209 enum libusb_descriptor_type {
210 /** Device descriptor. See libusb_device_descriptor. */
211 LIBUSB_DT_DEVICE = 0x01,
213 /** Configuration descriptor. See libusb_config_descriptor. */
214 LIBUSB_DT_CONFIG = 0x02,
216 /** String descriptor */
217 LIBUSB_DT_STRING = 0x03,
219 /** Interface descriptor. See libusb_interface_descriptor. */
220 LIBUSB_DT_INTERFACE = 0x04,
222 /** Endpoint descriptor. See libusb_endpoint_descriptor. */
223 LIBUSB_DT_ENDPOINT = 0x05,
225 /** HID descriptor */
226 LIBUSB_DT_HID = 0x21,
228 /** HID report descriptor */
229 LIBUSB_DT_REPORT = 0x22,
231 /** Physical descriptor */
232 LIBUSB_DT_PHYSICAL = 0x23,
234 /** Hub descriptor */
235 LIBUSB_DT_HUB = 0x29,
237 /** SuperSpeed Hub descriptor */
238 LIBUSB_DT_SUPERSPEED_HUB = 0x2A,
241 /* Descriptor sizes per descriptor type */
242 #define LIBUSB_DT_DEVICE_SIZE 18
243 #define LIBUSB_DT_CONFIG_SIZE 9
244 #define LIBUSB_DT_INTERFACE_SIZE 9
245 #define LIBUSB_DT_ENDPOINT_SIZE 7
246 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
247 #define LIBUSB_DT_HUB_NONVAR_SIZE 7
249 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
250 #define LIBUSB_ENDPOINT_DIR_MASK 0x80
253 * Endpoint direction. Values for bit 7 of the
254 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
256 enum libusb_endpoint_direction {
257 /** In: device-to-host */
258 LIBUSB_ENDPOINT_IN = 0x80,
260 /** Out: host-to-device */
261 LIBUSB_ENDPOINT_OUT = 0x00
264 #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
267 * Endpoint transfer type. Values for bits 0:1 of the
268 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
270 enum libusb_transfer_type {
271 /** Control endpoint */
272 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
274 /** Isochronous endpoint */
275 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
278 LIBUSB_TRANSFER_TYPE_BULK = 2,
280 /** Interrupt endpoint */
281 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
285 * Standard requests, as defined in table 9-5 of the USB 3.0 specifications */
286 enum libusb_standard_request {
287 /** Request status of the specific recipient */
288 LIBUSB_REQUEST_GET_STATUS = 0x00,
290 /** Clear or disable a specific feature */
291 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
293 /* 0x02 is reserved */
295 /** Set or enable a specific feature */
296 LIBUSB_REQUEST_SET_FEATURE = 0x03,
298 /* 0x04 is reserved */
300 /** Set device address for all future accesses */
301 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
303 /** Get the specified descriptor */
304 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
306 /** Used to update existing descriptors or add new descriptors */
307 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
309 /** Get the current device configuration value */
310 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
312 /** Set device configuration */
313 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
315 /** Return the selected alternate setting for the specified interface */
316 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
318 /** Select an alternate interface for the specified interface */
319 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
321 /** Set then report an endpoint's synchronization frame */
322 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
324 /** Sets both the U1 and U2 Exit Latency */
325 LIBUSB_REQUEST_SET_SEL = 0x30,
327 /** Delay from the time a host transmits a packet to the time it is
328 * received by the device. */
329 LIBUSB_SET_ISOCH_DELAY = 0x31,
333 * Request type bits of the
334 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
336 enum libusb_request_type {
338 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
341 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
344 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
347 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
351 * Recipient bits of the
352 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
353 * transfers. Values 4 through 31 are reserved. */
354 enum libusb_request_recipient {
356 LIBUSB_RECIPIENT_DEVICE = 0x00,
359 LIBUSB_RECIPIENT_INTERFACE = 0x01,
362 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
365 LIBUSB_RECIPIENT_OTHER = 0x03,
368 #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
371 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
372 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
373 * libusb_endpoint_descriptor.
375 enum libusb_iso_sync_type {
376 /** No synchronization */
377 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
380 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
383 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
386 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
389 #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
392 * Usage type for isochronous endpoints. Values for bits 4:5 of the
393 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
394 * libusb_endpoint_descriptor.
396 enum libusb_iso_usage_type {
398 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
400 /** Feedback endpoint */
401 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
403 /** Implicit feedback Data endpoint */
404 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
408 * A structure representing the standard USB device descriptor. This
409 * descriptor is documented in section 9.6.1 of the USB 3.0 specification.
410 * All multiple-byte fields are represented in host-endian format.
412 struct libusb_device_descriptor {
413 /** Size of this descriptor (in bytes) */
416 /** Descriptor type. Will have value
417 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
419 uint8_t bDescriptorType;
421 /** USB specification release number in binary-coded decimal. A value of
422 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
425 /** USB-IF class code for the device. See \ref libusb_class_code. */
426 uint8_t bDeviceClass;
428 /** USB-IF subclass code for the device, qualified by the bDeviceClass
430 uint8_t bDeviceSubClass;
432 /** USB-IF protocol code for the device, qualified by the bDeviceClass and
433 * bDeviceSubClass values */
434 uint8_t bDeviceProtocol;
436 /** Maximum packet size for endpoint 0 */
437 uint8_t bMaxPacketSize0;
439 /** USB-IF vendor ID */
442 /** USB-IF product ID */
445 /** Device release number in binary-coded decimal */
448 /** Index of string descriptor describing manufacturer */
449 uint8_t iManufacturer;
451 /** Index of string descriptor describing product */
454 /** Index of string descriptor containing device serial number */
455 uint8_t iSerialNumber;
457 /** Number of possible configurations */
458 uint8_t bNumConfigurations;
462 * A structure representing the standard USB endpoint descriptor. This
463 * descriptor is documented in section 9.6.6 of the USB 3.0 specification.
464 * All multiple-byte fields are represented in host-endian format.
466 struct libusb_endpoint_descriptor {
467 /** Size of this descriptor (in bytes) */
470 /** Descriptor type. Will have value
471 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
473 uint8_t bDescriptorType;
475 /** The address of the endpoint described by this descriptor. Bits 0:3 are
476 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
477 * see \ref libusb_endpoint_direction.
479 uint8_t bEndpointAddress;
481 /** Attributes which apply to the endpoint when it is configured using
482 * the bConfigurationValue. Bits 0:1 determine the transfer type and
483 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
484 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
485 * Bits 4:5 are also only used for isochronous endpoints and correspond to
486 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
488 uint8_t bmAttributes;
490 /** Maximum packet size this endpoint is capable of sending/receiving. */
491 uint16_t wMaxPacketSize;
493 /** Interval for polling endpoint for data transfers. */
496 /** For audio devices only: the rate at which synchronization feedback
500 /** For audio devices only: the address if the synch endpoint */
501 uint8_t bSynchAddress;
503 /** Extra descriptors. If libusbx encounters unknown endpoint descriptors,
504 * it will store them here, should you wish to parse them. */
505 const unsigned char *extra;
507 /** Length of the extra descriptors, in bytes. */
512 * A structure representing the standard USB interface descriptor. This
513 * descriptor is documented in section 9.6.5 of the USB 3.0 specification.
514 * All multiple-byte fields are represented in host-endian format.
516 struct libusb_interface_descriptor {
517 /** Size of this descriptor (in bytes) */
520 /** Descriptor type. Will have value
521 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
522 * in this context. */
523 uint8_t bDescriptorType;
525 /** Number of this interface */
526 uint8_t bInterfaceNumber;
528 /** Value used to select this alternate setting for this interface */
529 uint8_t bAlternateSetting;
531 /** Number of endpoints used by this interface (excluding the control
533 uint8_t bNumEndpoints;
535 /** USB-IF class code for this interface. See \ref libusb_class_code. */
536 uint8_t bInterfaceClass;
538 /** USB-IF subclass code for this interface, qualified by the
539 * bInterfaceClass value */
540 uint8_t bInterfaceSubClass;
542 /** USB-IF protocol code for this interface, qualified by the
543 * bInterfaceClass and bInterfaceSubClass values */
544 uint8_t bInterfaceProtocol;
546 /** Index of string descriptor describing this interface */
549 /** Array of endpoint descriptors. This length of this array is determined
550 * by the bNumEndpoints field. */
551 const struct libusb_endpoint_descriptor *endpoint;
553 /** Extra descriptors. If libusbx encounters unknown interface descriptors,
554 * it will store them here, should you wish to parse them. */
555 const unsigned char *extra;
557 /** Length of the extra descriptors, in bytes. */
562 * A collection of alternate settings for a particular USB interface.
564 struct libusb_interface {
565 /** Array of interface descriptors. The length of this array is determined
566 * by the num_altsetting field. */
567 const struct libusb_interface_descriptor *altsetting;
569 /** The number of alternate settings that belong to this interface */
574 * A structure representing the standard USB configuration descriptor. This
575 * descriptor is documented in section 9.6.3 of the USB 3.0 specification.
576 * All multiple-byte fields are represented in host-endian format.
578 struct libusb_config_descriptor {
579 /** Size of this descriptor (in bytes) */
582 /** Descriptor type. Will have value
583 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
584 * in this context. */
585 uint8_t bDescriptorType;
587 /** Total length of data returned for this configuration */
588 uint16_t wTotalLength;
590 /** Number of interfaces supported by this configuration */
591 uint8_t bNumInterfaces;
593 /** Identifier value for this configuration */
594 uint8_t bConfigurationValue;
596 /** Index of string descriptor describing this configuration */
597 uint8_t iConfiguration;
599 /** Configuration characteristics */
600 uint8_t bmAttributes;
602 /** Maximum power consumption of the USB device from this bus in this
603 * configuration when the device is fully opreation. Expressed in units
607 /** Array of interfaces supported by this configuration. The length of
608 * this array is determined by the bNumInterfaces field. */
609 const struct libusb_interface *interface;
611 /** Extra descriptors. If libusbx encounters unknown configuration
612 * descriptors, it will store them here, should you wish to parse them. */
613 const unsigned char *extra;
615 /** Length of the extra descriptors, in bytes. */
620 * Setup packet for control transfers. */
621 struct libusb_control_setup {
622 /** Request type. Bits 0:4 determine recipient, see
623 * \ref libusb_request_recipient. Bits 5:6 determine type, see
624 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
625 * \ref libusb_endpoint_direction.
627 uint8_t bmRequestType;
629 /** Request. If the type bits of bmRequestType are equal to
630 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
631 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
632 * \ref libusb_standard_request. For other cases, use of this field is
633 * application-specific. */
636 /** Value. Varies according to request */
639 /** Index. Varies according to request, typically used to pass an index
643 /** Number of bytes to transfer */
647 #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
651 struct libusb_context;
652 struct libusb_device;
653 struct libusb_device_handle;
656 * Structure providing the version of the libusbx runtime
658 struct libusb_version {
659 /** Library major version. */
660 const uint16_t major;
662 /** Library minor version. */
663 const uint16_t minor;
665 /** Library micro version. */
666 const uint16_t micro;
668 /** Library nano version. */
671 /** Library release candidate suffix string, e.g. "-rc4". */
674 /** For ABI compatibility only. */
675 const char* describe;
679 * Structure representing a libusbx session. The concept of individual libusbx
680 * sessions allows for your program to use two libraries (or dynamically
681 * load two modules) which both independently use libusb. This will prevent
682 * interference between the individual libusbx users - for example
683 * libusb_set_debug() will not affect the other user of the library, and
684 * libusb_exit() will not destroy resources that the other user is still
687 * Sessions are created by libusb_init() and destroyed through libusb_exit().
688 * If your application is guaranteed to only ever include a single libusbx
689 * user (i.e. you), you do not have to worry about contexts: pass NULL in
690 * every function call where a context is required. The default context
693 * For more information, see \ref contexts.
695 typedef struct libusb_context libusb_context;
698 * Structure representing a USB device detected on the system. This is an
699 * opaque type for which you are only ever provided with a pointer, usually
700 * originating from libusb_get_device_list().
702 * Certain operations can be performed on a device, but in order to do any
703 * I/O you will have to first obtain a device handle using libusb_open().
705 * Devices are reference counted with libusb_device_ref() and
706 * libusb_device_unref(), and are freed when the reference count reaches 0.
707 * New devices presented by libusb_get_device_list() have a reference count of
708 * 1, and libusb_free_device_list() can optionally decrease the reference count
709 * on all devices in the list. libusb_open() adds another reference which is
710 * later destroyed by libusb_close().
712 typedef struct libusb_device libusb_device;
716 * Structure representing a handle on a USB device. This is an opaque type for
717 * which you are only ever provided with a pointer, usually originating from
720 * A device handle is used to perform I/O and other operations. When finished
721 * with a device handle, you should call libusb_close().
723 typedef struct libusb_device_handle libusb_device_handle;
726 * Speed codes. Indicates the speed at which the device is operating.
729 /** The OS doesn't report or know the device speed. */
730 LIBUSB_SPEED_UNKNOWN = 0,
732 /** The device is operating at low speed (1.5MBit/s). */
733 LIBUSB_SPEED_LOW = 1,
735 /** The device is operating at full speed (12MBit/s). */
736 LIBUSB_SPEED_FULL = 2,
738 /** The device is operating at high speed (480MBit/s). */
739 LIBUSB_SPEED_HIGH = 3,
741 /** The device is operating at super speed (5000MBit/s). */
742 LIBUSB_SPEED_SUPER = 4,
746 * Error codes. Most libusbx functions return 0 on success or one of these
748 * You can call \ref libusb_error_name() to retrieve a string representation
752 /** Success (no error) */
755 /** Input/output error */
756 LIBUSB_ERROR_IO = -1,
758 /** Invalid parameter */
759 LIBUSB_ERROR_INVALID_PARAM = -2,
761 /** Access denied (insufficient permissions) */
762 LIBUSB_ERROR_ACCESS = -3,
764 /** No such device (it may have been disconnected) */
765 LIBUSB_ERROR_NO_DEVICE = -4,
767 /** Entity not found */
768 LIBUSB_ERROR_NOT_FOUND = -5,
771 LIBUSB_ERROR_BUSY = -6,
773 /** Operation timed out */
774 LIBUSB_ERROR_TIMEOUT = -7,
777 LIBUSB_ERROR_OVERFLOW = -8,
780 LIBUSB_ERROR_PIPE = -9,
782 /** System call interrupted (perhaps due to signal) */
783 LIBUSB_ERROR_INTERRUPTED = -10,
785 /** Insufficient memory */
786 LIBUSB_ERROR_NO_MEM = -11,
788 /** Operation not supported or unimplemented on this platform */
789 LIBUSB_ERROR_NOT_SUPPORTED = -12,
791 /* NB! Remember to update libusb_error_name()
792 when adding new error codes here. */
795 LIBUSB_ERROR_OTHER = -99,
799 * Transfer status codes */
800 enum libusb_transfer_status {
801 /** Transfer completed without error. Note that this does not indicate
802 * that the entire amount of requested data was transferred. */
803 LIBUSB_TRANSFER_COMPLETED,
805 /** Transfer failed */
806 LIBUSB_TRANSFER_ERROR,
808 /** Transfer timed out */
809 LIBUSB_TRANSFER_TIMED_OUT,
811 /** Transfer was cancelled */
812 LIBUSB_TRANSFER_CANCELLED,
814 /** For bulk/interrupt endpoints: halt condition detected (endpoint
815 * stalled). For control endpoints: control request not supported. */
816 LIBUSB_TRANSFER_STALL,
818 /** Device was disconnected */
819 LIBUSB_TRANSFER_NO_DEVICE,
821 /** Device sent more data than requested */
822 LIBUSB_TRANSFER_OVERFLOW,
824 /* NB! Remember to update libusb_error_name()
825 when adding new status codes here. */
829 * libusb_transfer.flags values */
830 enum libusb_transfer_flags {
831 /** Report short frames as errors */
832 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
834 /** Automatically free() transfer buffer during libusb_free_transfer() */
835 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
837 /** Automatically call libusb_free_transfer() after callback returns.
838 * If this flag is set, it is illegal to call libusb_free_transfer()
839 * from your transfer callback, as this will result in a double-free
840 * when this flag is acted upon. */
841 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
843 /** Terminate transfers that are a multiple of the endpoint's
844 * wMaxPacketSize with an extra zero length packet. This is useful
845 * when a device protocol mandates that each logical request is
846 * terminated by an incomplete packet (i.e. the logical requests are
847 * not separated by other means).
849 * This flag only affects host-to-device transfers to bulk and interrupt
850 * endpoints. In other situations, it is ignored.
852 * This flag only affects transfers with a length that is a multiple of
853 * the endpoint's wMaxPacketSize. On transfers of other lengths, this
854 * flag has no effect. Therefore, if you are working with a device that
855 * needs a ZLP whenever the end of the logical request falls on a packet
856 * boundary, then it is sensible to set this flag on <em>every</em>
857 * transfer (you do not have to worry about only setting it on transfers
858 * that end on the boundary).
860 * This flag is currently only supported on Linux.
861 * On other systems, libusb_submit_transfer() will return
862 * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
864 * Available since libusb-1.0.9.
866 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
870 * Isochronous packet descriptor. */
871 struct libusb_iso_packet_descriptor {
872 /** Length of data to request in this packet */
875 /** Amount of data that was actually transferred */
876 unsigned int actual_length;
878 /** Status code for this packet */
879 enum libusb_transfer_status status;
882 struct libusb_transfer;
885 * Asynchronous transfer callback function type. When submitting asynchronous
886 * transfers, you pass a pointer to a callback function of this type via the
887 * \ref libusb_transfer::callback "callback" member of the libusb_transfer
888 * structure. libusbx will call this function later, when the transfer has
889 * completed or failed. See \ref asyncio for more information.
890 * \param transfer The libusb_transfer struct the callback function is being
893 typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
896 * The generic USB transfer structure. The user populates this structure and
897 * then submits it in order to request a transfer. After the transfer has
898 * completed, the library populates the transfer with the results and passes
899 * it back to the user.
901 struct libusb_transfer {
902 /** Handle of the device that this transfer will be submitted to */
903 libusb_device_handle *dev_handle;
905 /** A bitwise OR combination of \ref libusb_transfer_flags. */
908 /** Address of the endpoint where this transfer will be sent. */
909 unsigned char endpoint;
911 /** Type of the endpoint from \ref libusb_transfer_type */
914 /** Timeout for this transfer in millseconds. A value of 0 indicates no
916 unsigned int timeout;
918 /** The status of the transfer. Read-only, and only for use within
919 * transfer callback function.
921 * If this is an isochronous transfer, this field may read COMPLETED even
922 * if there were errors in the frames. Use the
923 * \ref libusb_iso_packet_descriptor::status "status" field in each packet
924 * to determine if errors occurred. */
925 enum libusb_transfer_status status;
927 /** Length of the data buffer */
930 /** Actual length of data that was transferred. Read-only, and only for
931 * use within transfer callback function. Not valid for isochronous
932 * endpoint transfers. */
935 /** Callback function. This will be invoked when the transfer completes,
936 * fails, or is cancelled. */
937 libusb_transfer_cb_fn callback;
939 /** User context data to pass to the callback function. */
943 unsigned char *buffer;
945 /** Number of isochronous packets. Only used for I/O with isochronous
949 /** Isochronous packet descriptors, for isochronous transfers only. */
950 struct libusb_iso_packet_descriptor iso_packet_desc
951 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
952 [] /* valid C99 code */
954 [0] /* non-standard, but usually working code */
960 * Capabilities supported by this instance of libusb. Test if the loaded
961 * library supports a given capability by calling
962 * \ref libusb_has_capability().
964 enum libusb_capability {
965 /** The libusb_has_capability() API is available. */
966 LIBUSB_CAP_HAS_CAPABILITY = 0,
970 * Log message levels.
971 * - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
972 * - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
973 * - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
974 * - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning
975 * and error messages are printed to stderr
976 * - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout,
977 * warnings and errors to stderr
979 enum libusb_log_level {
980 LIBUSB_LOG_LEVEL_NONE = 0,
981 LIBUSB_LOG_LEVEL_ERROR,
982 LIBUSB_LOG_LEVEL_WARNING,
983 LIBUSB_LOG_LEVEL_INFO,
984 LIBUSB_LOG_LEVEL_DEBUG,
987 int LIBUSB_CALL libusb_init(libusb_context **ctx);
988 void LIBUSB_CALL libusb_exit(libusb_context *ctx);
989 void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
990 const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
991 int LIBUSB_CALL libusb_has_capability(uint32_t capability);
992 const char * LIBUSB_CALL libusb_error_name(int errcode);
994 ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
995 libusb_device ***list);
996 void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
998 libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
999 void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
1001 int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
1003 int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
1004 struct libusb_device_descriptor *desc);
1005 int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
1006 struct libusb_config_descriptor **config);
1007 int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
1008 uint8_t config_index, struct libusb_config_descriptor **config);
1009 int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
1010 uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
1011 void LIBUSB_CALL libusb_free_config_descriptor(
1012 struct libusb_config_descriptor *config);
1013 uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
1014 uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
1015 libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
1016 int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
1017 uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
1018 int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
1019 int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
1020 unsigned char endpoint);
1021 int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
1022 unsigned char endpoint);
1024 int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
1025 void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
1026 libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
1028 int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
1030 int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
1031 int interface_number);
1032 int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
1033 int interface_number);
1035 libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
1036 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
1038 int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
1039 int interface_number, int alternate_setting);
1040 int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
1041 unsigned char endpoint);
1042 int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
1044 int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
1045 int interface_number);
1046 int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
1047 int interface_number);
1048 int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
1049 int interface_number);
1053 /** \ingroup asyncio
1054 * Get the data section of a control transfer. This convenience function is here
1055 * to remind you that the data does not start until 8 bytes into the actual
1056 * buffer, as the setup packet comes first.
1058 * Calling this function only makes sense from a transfer callback function,
1059 * or situations where you have already allocated a suitably sized buffer at
1062 * \param transfer a transfer
1063 * \returns pointer to the first byte of the data section
1065 static inline unsigned char *libusb_control_transfer_get_data(
1066 struct libusb_transfer *transfer)
1068 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
1071 /** \ingroup asyncio
1072 * Get the control setup packet of a control transfer. This convenience
1073 * function is here to remind you that the control setup occupies the first
1074 * 8 bytes of the transfer data buffer.
1076 * Calling this function only makes sense from a transfer callback function,
1077 * or situations where you have already allocated a suitably sized buffer at
1080 * \param transfer a transfer
1081 * \returns a casted pointer to the start of the transfer data buffer
1083 static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
1084 struct libusb_transfer *transfer)
1086 return (struct libusb_control_setup *) transfer->buffer;
1089 /** \ingroup asyncio
1090 * Helper function to populate the setup packet (first 8 bytes of the data
1091 * buffer) for a control transfer. The wIndex, wValue and wLength values should
1092 * be given in host-endian byte order.
1094 * \param buffer buffer to output the setup packet into
1095 * \param bmRequestType see the
1096 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
1097 * \ref libusb_control_setup
1098 * \param bRequest see the
1099 * \ref libusb_control_setup::bRequest "bRequest" field of
1100 * \ref libusb_control_setup
1101 * \param wValue see the
1102 * \ref libusb_control_setup::wValue "wValue" field of
1103 * \ref libusb_control_setup
1104 * \param wIndex see the
1105 * \ref libusb_control_setup::wIndex "wIndex" field of
1106 * \ref libusb_control_setup
1107 * \param wLength see the
1108 * \ref libusb_control_setup::wLength "wLength" field of
1109 * \ref libusb_control_setup
1111 static inline void libusb_fill_control_setup(unsigned char *buffer,
1112 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1115 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
1116 setup->bmRequestType = bmRequestType;
1117 setup->bRequest = bRequest;
1118 setup->wValue = libusb_cpu_to_le16(wValue);
1119 setup->wIndex = libusb_cpu_to_le16(wIndex);
1120 setup->wLength = libusb_cpu_to_le16(wLength);
1123 struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
1124 int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
1125 int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
1126 void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
1128 /** \ingroup asyncio
1129 * Helper function to populate the required \ref libusb_transfer fields
1130 * for a control transfer.
1132 * If you pass a transfer buffer to this function, the first 8 bytes will
1133 * be interpreted as a control setup packet, and the wLength field will be
1134 * used to automatically populate the \ref libusb_transfer::length "length"
1135 * field of the transfer. Therefore the recommended approach is:
1136 * -# Allocate a suitably sized data buffer (including space for control setup)
1137 * -# Call libusb_fill_control_setup()
1138 * -# If this is a host-to-device transfer with a data stage, put the data
1139 * in place after the setup packet
1140 * -# Call this function
1141 * -# Call libusb_submit_transfer()
1143 * It is also legal to pass a NULL buffer to this function, in which case this
1144 * function will not attempt to populate the length field. Remember that you
1145 * must then populate the buffer and length fields later.
1147 * \param transfer the transfer to populate
1148 * \param dev_handle handle of the device that will handle the transfer
1149 * \param buffer data buffer. If provided, this function will interpret the
1150 * first 8 bytes as a setup packet and infer the transfer length from that.
1151 * \param callback callback function to be invoked on transfer completion
1152 * \param user_data user data to pass to callback function
1153 * \param timeout timeout for the transfer in milliseconds
1155 static inline void libusb_fill_control_transfer(
1156 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1157 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
1158 unsigned int timeout)
1160 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
1161 transfer->dev_handle = dev_handle;
1162 transfer->endpoint = 0;
1163 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
1164 transfer->timeout = timeout;
1165 transfer->buffer = buffer;
1167 transfer->length = LIBUSB_CONTROL_SETUP_SIZE
1168 + libusb_le16_to_cpu(setup->wLength);
1169 transfer->user_data = user_data;
1170 transfer->callback = callback;
1173 /** \ingroup asyncio
1174 * Helper function to populate the required \ref libusb_transfer fields
1175 * for a bulk transfer.
1177 * \param transfer the transfer to populate
1178 * \param dev_handle handle of the device that will handle the transfer
1179 * \param endpoint address of the endpoint where this transfer will be sent
1180 * \param buffer data buffer
1181 * \param length length of data buffer
1182 * \param callback callback function to be invoked on transfer completion
1183 * \param user_data user data to pass to callback function
1184 * \param timeout timeout for the transfer in milliseconds
1186 static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
1187 libusb_device_handle *dev_handle, unsigned char endpoint,
1188 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
1189 void *user_data, unsigned int timeout)
1191 transfer->dev_handle = dev_handle;
1192 transfer->endpoint = endpoint;
1193 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
1194 transfer->timeout = timeout;
1195 transfer->buffer = buffer;
1196 transfer->length = length;
1197 transfer->user_data = user_data;
1198 transfer->callback = callback;
1201 /** \ingroup asyncio
1202 * Helper function to populate the required \ref libusb_transfer fields
1203 * for an interrupt transfer.
1205 * \param transfer the transfer to populate
1206 * \param dev_handle handle of the device that will handle the transfer
1207 * \param endpoint address of the endpoint where this transfer will be sent
1208 * \param buffer data buffer
1209 * \param length length of data buffer
1210 * \param callback callback function to be invoked on transfer completion
1211 * \param user_data user data to pass to callback function
1212 * \param timeout timeout for the transfer in milliseconds
1214 static inline void libusb_fill_interrupt_transfer(
1215 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1216 unsigned char endpoint, unsigned char *buffer, int length,
1217 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1219 transfer->dev_handle = dev_handle;
1220 transfer->endpoint = endpoint;
1221 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
1222 transfer->timeout = timeout;
1223 transfer->buffer = buffer;
1224 transfer->length = length;
1225 transfer->user_data = user_data;
1226 transfer->callback = callback;
1229 /** \ingroup asyncio
1230 * Helper function to populate the required \ref libusb_transfer fields
1231 * for an isochronous transfer.
1233 * \param transfer the transfer to populate
1234 * \param dev_handle handle of the device that will handle the transfer
1235 * \param endpoint address of the endpoint where this transfer will be sent
1236 * \param buffer data buffer
1237 * \param length length of data buffer
1238 * \param num_iso_packets the number of isochronous packets
1239 * \param callback callback function to be invoked on transfer completion
1240 * \param user_data user data to pass to callback function
1241 * \param timeout timeout for the transfer in milliseconds
1243 static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
1244 libusb_device_handle *dev_handle, unsigned char endpoint,
1245 unsigned char *buffer, int length, int num_iso_packets,
1246 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1248 transfer->dev_handle = dev_handle;
1249 transfer->endpoint = endpoint;
1250 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
1251 transfer->timeout = timeout;
1252 transfer->buffer = buffer;
1253 transfer->length = length;
1254 transfer->num_iso_packets = num_iso_packets;
1255 transfer->user_data = user_data;
1256 transfer->callback = callback;
1259 /** \ingroup asyncio
1260 * Convenience function to set the length of all packets in an isochronous
1261 * transfer, based on the num_iso_packets field in the transfer structure.
1263 * \param transfer a transfer
1264 * \param length the length to set in each isochronous packet descriptor
1265 * \see libusb_get_max_packet_size()
1267 static inline void libusb_set_iso_packet_lengths(
1268 struct libusb_transfer *transfer, unsigned int length)
1271 for (i = 0; i < transfer->num_iso_packets; i++)
1272 transfer->iso_packet_desc[i].length = length;
1275 /** \ingroup asyncio
1276 * Convenience function to locate the position of an isochronous packet
1277 * within the buffer of an isochronous transfer.
1279 * This is a thorough function which loops through all preceding packets,
1280 * accumulating their lengths to find the position of the specified packet.
1281 * Typically you will assign equal lengths to each packet in the transfer,
1282 * and hence the above method is sub-optimal. You may wish to use
1283 * libusb_get_iso_packet_buffer_simple() instead.
1285 * \param transfer a transfer
1286 * \param packet the packet to return the address of
1287 * \returns the base address of the packet buffer inside the transfer buffer,
1288 * or NULL if the packet does not exist.
1289 * \see libusb_get_iso_packet_buffer_simple()
1291 static inline unsigned char *libusb_get_iso_packet_buffer(
1292 struct libusb_transfer *transfer, unsigned int packet)
1298 /* oops..slight bug in the API. packet is an unsigned int, but we use
1299 * signed integers almost everywhere else. range-check and convert to
1300 * signed to avoid compiler warnings. FIXME for libusb-2. */
1301 if (packet > INT_MAX)
1305 if (_packet >= transfer->num_iso_packets)
1308 for (i = 0; i < _packet; i++)
1309 offset += transfer->iso_packet_desc[i].length;
1311 return transfer->buffer + offset;
1314 /** \ingroup asyncio
1315 * Convenience function to locate the position of an isochronous packet
1316 * within the buffer of an isochronous transfer, for transfers where each
1317 * packet is of identical size.
1319 * This function relies on the assumption that every packet within the transfer
1320 * is of identical size to the first packet. Calculating the location of
1321 * the packet buffer is then just a simple calculation:
1322 * <tt>buffer + (packet_size * packet)</tt>
1324 * Do not use this function on transfers other than those that have identical
1325 * packet lengths for each packet.
1327 * \param transfer a transfer
1328 * \param packet the packet to return the address of
1329 * \returns the base address of the packet buffer inside the transfer buffer,
1330 * or NULL if the packet does not exist.
1331 * \see libusb_get_iso_packet_buffer()
1333 static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1334 struct libusb_transfer *transfer, unsigned int packet)
1338 /* oops..slight bug in the API. packet is an unsigned int, but we use
1339 * signed integers almost everywhere else. range-check and convert to
1340 * signed to avoid compiler warnings. FIXME for libusb-2. */
1341 if (packet > INT_MAX)
1345 if (_packet >= transfer->num_iso_packets)
1348 return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
1353 int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
1354 uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1355 unsigned char *data, uint16_t wLength, unsigned int timeout);
1357 int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
1358 unsigned char endpoint, unsigned char *data, int length,
1359 int *actual_length, unsigned int timeout);
1361 int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
1362 unsigned char endpoint, unsigned char *data, int length,
1363 int *actual_length, unsigned int timeout);
1366 * Retrieve a descriptor from the default control pipe.
1367 * This is a convenience function which formulates the appropriate control
1368 * message to retrieve the descriptor.
1370 * \param dev a device handle
1371 * \param desc_type the descriptor type, see \ref libusb_descriptor_type
1372 * \param desc_index the index of the descriptor to retrieve
1373 * \param data output buffer for descriptor
1374 * \param length size of data buffer
1375 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1377 static inline int libusb_get_descriptor(libusb_device_handle *dev,
1378 uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
1380 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
1381 LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
1382 (uint16_t) length, 1000);
1386 * Retrieve a descriptor from a device.
1387 * This is a convenience function which formulates the appropriate control
1388 * message to retrieve the descriptor. The string returned is Unicode, as
1389 * detailed in the USB specifications.
1391 * \param dev a device handle
1392 * \param desc_index the index of the descriptor to retrieve
1393 * \param langid the language ID for the string descriptor
1394 * \param data output buffer for descriptor
1395 * \param length size of data buffer
1396 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1397 * \see libusb_get_string_descriptor_ascii()
1399 static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
1400 uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
1402 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
1403 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
1404 langid, data, (uint16_t) length, 1000);
1407 int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
1408 uint8_t desc_index, unsigned char *data, int length);
1410 /* polling and timeouts */
1412 int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
1413 void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
1414 void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
1415 int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
1416 int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
1417 void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
1418 void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
1419 int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
1421 int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
1422 struct timeval *tv);
1423 int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
1424 struct timeval *tv, int *completed);
1425 int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
1426 int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
1427 int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
1428 struct timeval *tv);
1429 int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
1430 int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
1431 struct timeval *tv);
1434 * File descriptor for polling
1436 struct libusb_pollfd {
1437 /** Numeric file descriptor */
1440 /** Event flags to poll for from <poll.h>. POLLIN indicates that you
1441 * should monitor this file descriptor for becoming ready to read from,
1442 * and POLLOUT indicates that you should monitor this file descriptor for
1443 * nonblocking write readiness. */
1448 * Callback function, invoked when a new file descriptor should be added
1449 * to the set of file descriptors monitored for events.
1450 * \param fd the new file descriptor
1451 * \param events events to monitor for, see \ref libusb_pollfd for a
1453 * \param user_data User data pointer specified in
1454 * libusb_set_pollfd_notifiers() call
1455 * \see libusb_set_pollfd_notifiers()
1457 typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
1461 * Callback function, invoked when a file descriptor should be removed from
1462 * the set of file descriptors being monitored for events. After returning
1463 * from this callback, do not use that file descriptor again.
1464 * \param fd the file descriptor to stop monitoring
1465 * \param user_data User data pointer specified in
1466 * libusb_set_pollfd_notifiers() call
1467 * \see libusb_set_pollfd_notifiers()
1469 typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
1471 const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
1472 libusb_context *ctx);
1473 void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
1474 libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,