2 * Public libusbx header file
3 * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
4 * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 /* on MS environments, the inline keyword is available in C++ only */
26 #define inline __inline
27 /* ssize_t is also not available (copy/paste from MinGW) */
28 #ifndef _SSIZE_T_DEFINED
29 #define _SSIZE_T_DEFINED
32 typedef __int64 ssize_t
;
36 #endif /* _SSIZE_T_DEFINED */
39 /* stdint.h is also not usually available on MS */
40 #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
41 typedef unsigned __int8
uint8_t;
42 typedef unsigned __int16
uint16_t;
43 typedef unsigned __int32
uint32_t;
48 #include <sys/types.h>
52 #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
56 /* 'interface' might be defined as a macro on Windows, so we need to
57 * undefine it so as not to break the current libusbx API, because
58 * libusb_config_descriptor has an 'interface' member
59 * As this can be problematic if you include windows.h after libusb.h
60 * in your sources, we force windows.h to be included first. */
61 #if defined(_WIN32) || defined(__CYGWIN__)
63 #if defined(interface)
70 * libusbx's Windows calling convention.
72 * Under Windows, the selection of available compilers and configurations
73 * means that, unlike other platforms, there is not <em>one true calling
74 * convention</em> (calling convention: the manner in which parameters are
75 * passed to funcions in the generated assembly code).
77 * Matching the Windows API itself, libusbx uses the WINAPI convention (which
78 * translates to the <tt>stdcall</tt> convention) and guarantees that the
79 * library is compiled in this way. The public header file also includes
80 * appropriate annotations so that your own software will use the right
81 * convention, even if another convention is being used by default within
84 * The one consideration that you must apply in your software is to mark
85 * all functions which you use as libusbx callbacks with this LIBUSB_CALL
86 * annotation, so that they too get compiled for the correct calling
89 * On non-Windows operating systems, this macro is defined as nothing. This
90 * means that you can apply it to your code without worrying about
91 * cross-platform compatibility.
93 /* LIBUSB_CALL must be defined on both definition and declaration of libusbx
94 * functions. You'd think that declaration would be enough, but cygwin will
95 * complain about conflicting types unless both are marked this way.
96 * The placement of this macro is important too; it must appear after the
97 * return type, before the function name. See internal documentation for
100 #if defined(_WIN32) || defined(__CYGWIN__)
101 #define LIBUSB_CALL WINAPI
110 /** \def libusb_cpu_to_le16
112 * Convert a 16-bit value from host-endian to little-endian format. On
113 * little endian systems, this function does nothing. On big endian systems,
114 * the bytes are swapped.
115 * \param x the host-endian value to convert
116 * \returns the value in little-endian byte order
118 static inline uint16_t libusb_cpu_to_le16(const uint16_t x
)
125 _tmp
.b8
[0] = x
& 0xff;
129 /** \def libusb_le16_to_cpu
131 * Convert a 16-bit value from little-endian to host-endian format. On
132 * little endian systems, this function does nothing. On big endian systems,
133 * the bytes are swapped.
134 * \param x the little-endian value to convert
135 * \returns the value in host-endian byte order
137 #define libusb_le16_to_cpu libusb_cpu_to_le16
139 /* standard USB stuff */
142 * Device and/or Interface Class codes */
143 enum libusb_class_code
{
144 /** In the context of a \ref libusb_device_descriptor "device descriptor",
145 * this bDeviceClass value indicates that each interface specifies its
146 * own class information and all interfaces operate independently.
148 LIBUSB_CLASS_PER_INTERFACE
= 0,
151 LIBUSB_CLASS_AUDIO
= 1,
153 /** Communications class */
154 LIBUSB_CLASS_COMM
= 2,
156 /** Human Interface Device class */
157 LIBUSB_CLASS_HID
= 3,
160 LIBUSB_CLASS_PHYSICAL
= 5,
163 LIBUSB_CLASS_PRINTER
= 7,
166 LIBUSB_CLASS_PTP
= 6, /* legacy name from libusb-0.1 usb.h */
167 LIBUSB_CLASS_IMAGE
= 6,
169 /** Mass storage class */
170 LIBUSB_CLASS_MASS_STORAGE
= 8,
173 LIBUSB_CLASS_HUB
= 9,
176 LIBUSB_CLASS_DATA
= 10,
179 LIBUSB_CLASS_SMART_CARD
= 0x0b,
181 /** Content Security */
182 LIBUSB_CLASS_CONTENT_SECURITY
= 0x0d,
185 LIBUSB_CLASS_VIDEO
= 0x0e,
187 /** Personal Healthcare */
188 LIBUSB_CLASS_PERSONAL_HEALTHCARE
= 0x0f,
190 /** Diagnostic Device */
191 LIBUSB_CLASS_DIAGNOSTIC_DEVICE
= 0xdc,
193 /** Wireless class */
194 LIBUSB_CLASS_WIRELESS
= 0xe0,
196 /** Application class */
197 LIBUSB_CLASS_APPLICATION
= 0xfe,
199 /** Class is vendor-specific */
200 LIBUSB_CLASS_VENDOR_SPEC
= 0xff
204 * Descriptor types as defined by the USB specification. */
205 enum libusb_descriptor_type
{
206 /** Device descriptor. See libusb_device_descriptor. */
207 LIBUSB_DT_DEVICE
= 0x01,
209 /** Configuration descriptor. See libusb_config_descriptor. */
210 LIBUSB_DT_CONFIG
= 0x02,
212 /** String descriptor */
213 LIBUSB_DT_STRING
= 0x03,
215 /** Interface descriptor. See libusb_interface_descriptor. */
216 LIBUSB_DT_INTERFACE
= 0x04,
218 /** Endpoint descriptor. See libusb_endpoint_descriptor. */
219 LIBUSB_DT_ENDPOINT
= 0x05,
221 /** HID descriptor */
222 LIBUSB_DT_HID
= 0x21,
224 /** HID report descriptor */
225 LIBUSB_DT_REPORT
= 0x22,
227 /** Physical descriptor */
228 LIBUSB_DT_PHYSICAL
= 0x23,
230 /** Hub descriptor */
231 LIBUSB_DT_HUB
= 0x29,
234 /* Descriptor sizes per descriptor type */
235 #define LIBUSB_DT_DEVICE_SIZE 18
236 #define LIBUSB_DT_CONFIG_SIZE 9
237 #define LIBUSB_DT_INTERFACE_SIZE 9
238 #define LIBUSB_DT_ENDPOINT_SIZE 7
239 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
240 #define LIBUSB_DT_HUB_NONVAR_SIZE 7
242 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
243 #define LIBUSB_ENDPOINT_DIR_MASK 0x80
246 * Endpoint direction. Values for bit 7 of the
247 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
249 enum libusb_endpoint_direction
{
250 /** In: device-to-host */
251 LIBUSB_ENDPOINT_IN
= 0x80,
253 /** Out: host-to-device */
254 LIBUSB_ENDPOINT_OUT
= 0x00
257 #define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
260 * Endpoint transfer type. Values for bits 0:1 of the
261 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
263 enum libusb_transfer_type
{
264 /** Control endpoint */
265 LIBUSB_TRANSFER_TYPE_CONTROL
= 0,
267 /** Isochronous endpoint */
268 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
= 1,
271 LIBUSB_TRANSFER_TYPE_BULK
= 2,
273 /** Interrupt endpoint */
274 LIBUSB_TRANSFER_TYPE_INTERRUPT
= 3
278 * Standard requests, as defined in table 9-3 of the USB2 specifications */
279 enum libusb_standard_request
{
280 /** Request status of the specific recipient */
281 LIBUSB_REQUEST_GET_STATUS
= 0x00,
283 /** Clear or disable a specific feature */
284 LIBUSB_REQUEST_CLEAR_FEATURE
= 0x01,
286 /* 0x02 is reserved */
288 /** Set or enable a specific feature */
289 LIBUSB_REQUEST_SET_FEATURE
= 0x03,
291 /* 0x04 is reserved */
293 /** Set device address for all future accesses */
294 LIBUSB_REQUEST_SET_ADDRESS
= 0x05,
296 /** Get the specified descriptor */
297 LIBUSB_REQUEST_GET_DESCRIPTOR
= 0x06,
299 /** Used to update existing descriptors or add new descriptors */
300 LIBUSB_REQUEST_SET_DESCRIPTOR
= 0x07,
302 /** Get the current device configuration value */
303 LIBUSB_REQUEST_GET_CONFIGURATION
= 0x08,
305 /** Set device configuration */
306 LIBUSB_REQUEST_SET_CONFIGURATION
= 0x09,
308 /** Return the selected alternate setting for the specified interface */
309 LIBUSB_REQUEST_GET_INTERFACE
= 0x0A,
311 /** Select an alternate interface for the specified interface */
312 LIBUSB_REQUEST_SET_INTERFACE
= 0x0B,
314 /** Set then report an endpoint's synchronization frame */
315 LIBUSB_REQUEST_SYNCH_FRAME
= 0x0C,
319 * Request type bits of the
320 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
322 enum libusb_request_type
{
324 LIBUSB_REQUEST_TYPE_STANDARD
= (0x00 << 5),
327 LIBUSB_REQUEST_TYPE_CLASS
= (0x01 << 5),
330 LIBUSB_REQUEST_TYPE_VENDOR
= (0x02 << 5),
333 LIBUSB_REQUEST_TYPE_RESERVED
= (0x03 << 5)
337 * Recipient bits of the
338 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
339 * transfers. Values 4 through 31 are reserved. */
340 enum libusb_request_recipient
{
342 LIBUSB_RECIPIENT_DEVICE
= 0x00,
345 LIBUSB_RECIPIENT_INTERFACE
= 0x01,
348 LIBUSB_RECIPIENT_ENDPOINT
= 0x02,
351 LIBUSB_RECIPIENT_OTHER
= 0x03,
354 #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
357 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
358 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
359 * libusb_endpoint_descriptor.
361 enum libusb_iso_sync_type
{
362 /** No synchronization */
363 LIBUSB_ISO_SYNC_TYPE_NONE
= 0,
366 LIBUSB_ISO_SYNC_TYPE_ASYNC
= 1,
369 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE
= 2,
372 LIBUSB_ISO_SYNC_TYPE_SYNC
= 3
375 #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
378 * Usage type for isochronous endpoints. Values for bits 4:5 of the
379 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
380 * libusb_endpoint_descriptor.
382 enum libusb_iso_usage_type
{
384 LIBUSB_ISO_USAGE_TYPE_DATA
= 0,
386 /** Feedback endpoint */
387 LIBUSB_ISO_USAGE_TYPE_FEEDBACK
= 1,
389 /** Implicit feedback Data endpoint */
390 LIBUSB_ISO_USAGE_TYPE_IMPLICIT
= 2,
394 * A structure representing the standard USB device descriptor. This
395 * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
396 * All multiple-byte fields are represented in host-endian format.
398 struct libusb_device_descriptor
{
399 /** Size of this descriptor (in bytes) */
402 /** Descriptor type. Will have value
403 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
405 uint8_t bDescriptorType
;
407 /** USB specification release number in binary-coded decimal. A value of
408 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
411 /** USB-IF class code for the device. See \ref libusb_class_code. */
412 uint8_t bDeviceClass
;
414 /** USB-IF subclass code for the device, qualified by the bDeviceClass
416 uint8_t bDeviceSubClass
;
418 /** USB-IF protocol code for the device, qualified by the bDeviceClass and
419 * bDeviceSubClass values */
420 uint8_t bDeviceProtocol
;
422 /** Maximum packet size for endpoint 0 */
423 uint8_t bMaxPacketSize0
;
425 /** USB-IF vendor ID */
428 /** USB-IF product ID */
431 /** Device release number in binary-coded decimal */
434 /** Index of string descriptor describing manufacturer */
435 uint8_t iManufacturer
;
437 /** Index of string descriptor describing product */
440 /** Index of string descriptor containing device serial number */
441 uint8_t iSerialNumber
;
443 /** Number of possible configurations */
444 uint8_t bNumConfigurations
;
448 * A structure representing the standard USB endpoint descriptor. This
449 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
450 * All multiple-byte fields are represented in host-endian format.
452 struct libusb_endpoint_descriptor
{
453 /** Size of this descriptor (in bytes) */
456 /** Descriptor type. Will have value
457 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
459 uint8_t bDescriptorType
;
461 /** The address of the endpoint described by this descriptor. Bits 0:3 are
462 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
463 * see \ref libusb_endpoint_direction.
465 uint8_t bEndpointAddress
;
467 /** Attributes which apply to the endpoint when it is configured using
468 * the bConfigurationValue. Bits 0:1 determine the transfer type and
469 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
470 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
471 * Bits 4:5 are also only used for isochronous endpoints and correspond to
472 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
474 uint8_t bmAttributes
;
476 /** Maximum packet size this endpoint is capable of sending/receiving. */
477 uint16_t wMaxPacketSize
;
479 /** Interval for polling endpoint for data transfers. */
482 /** For audio devices only: the rate at which synchronization feedback
486 /** For audio devices only: the address if the synch endpoint */
487 uint8_t bSynchAddress
;
489 /** Extra descriptors. If libusbx encounters unknown endpoint descriptors,
490 * it will store them here, should you wish to parse them. */
491 const unsigned char *extra
;
493 /** Length of the extra descriptors, in bytes. */
498 * A structure representing the standard USB interface descriptor. This
499 * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
500 * All multiple-byte fields are represented in host-endian format.
502 struct libusb_interface_descriptor
{
503 /** Size of this descriptor (in bytes) */
506 /** Descriptor type. Will have value
507 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
508 * in this context. */
509 uint8_t bDescriptorType
;
511 /** Number of this interface */
512 uint8_t bInterfaceNumber
;
514 /** Value used to select this alternate setting for this interface */
515 uint8_t bAlternateSetting
;
517 /** Number of endpoints used by this interface (excluding the control
519 uint8_t bNumEndpoints
;
521 /** USB-IF class code for this interface. See \ref libusb_class_code. */
522 uint8_t bInterfaceClass
;
524 /** USB-IF subclass code for this interface, qualified by the
525 * bInterfaceClass value */
526 uint8_t bInterfaceSubClass
;
528 /** USB-IF protocol code for this interface, qualified by the
529 * bInterfaceClass and bInterfaceSubClass values */
530 uint8_t bInterfaceProtocol
;
532 /** Index of string descriptor describing this interface */
535 /** Array of endpoint descriptors. This length of this array is determined
536 * by the bNumEndpoints field. */
537 const struct libusb_endpoint_descriptor
*endpoint
;
539 /** Extra descriptors. If libusbx encounters unknown interface descriptors,
540 * it will store them here, should you wish to parse them. */
541 const unsigned char *extra
;
543 /** Length of the extra descriptors, in bytes. */
548 * A collection of alternate settings for a particular USB interface.
550 struct libusb_interface
{
551 /** Array of interface descriptors. The length of this array is determined
552 * by the num_altsetting field. */
553 const struct libusb_interface_descriptor
*altsetting
;
555 /** The number of alternate settings that belong to this interface */
560 * A structure representing the standard USB configuration descriptor. This
561 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
562 * All multiple-byte fields are represented in host-endian format.
564 struct libusb_config_descriptor
{
565 /** Size of this descriptor (in bytes) */
568 /** Descriptor type. Will have value
569 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
570 * in this context. */
571 uint8_t bDescriptorType
;
573 /** Total length of data returned for this configuration */
574 uint16_t wTotalLength
;
576 /** Number of interfaces supported by this configuration */
577 uint8_t bNumInterfaces
;
579 /** Identifier value for this configuration */
580 uint8_t bConfigurationValue
;
582 /** Index of string descriptor describing this configuration */
583 uint8_t iConfiguration
;
585 /** Configuration characteristics */
586 uint8_t bmAttributes
;
588 /** Maximum power consumption of the USB device from this bus in this
589 * configuration when the device is fully opreation. Expressed in units
593 /** Array of interfaces supported by this configuration. The length of
594 * this array is determined by the bNumInterfaces field. */
595 const struct libusb_interface
*interface
;
597 /** Extra descriptors. If libusbx encounters unknown configuration
598 * descriptors, it will store them here, should you wish to parse them. */
599 const unsigned char *extra
;
601 /** Length of the extra descriptors, in bytes. */
606 * Setup packet for control transfers. */
607 struct libusb_control_setup
{
608 /** Request type. Bits 0:4 determine recipient, see
609 * \ref libusb_request_recipient. Bits 5:6 determine type, see
610 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
611 * \ref libusb_endpoint_direction.
613 uint8_t bmRequestType
;
615 /** Request. If the type bits of bmRequestType are equal to
616 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
617 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
618 * \ref libusb_standard_request. For other cases, use of this field is
619 * application-specific. */
622 /** Value. Varies according to request */
625 /** Index. Varies according to request, typically used to pass an index
629 /** Number of bytes to transfer */
633 #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
637 struct libusb_context
;
638 struct libusb_device
;
639 struct libusb_device_handle
;
642 * Structure providing the version of the libusbx runtime
644 struct libusb_version
{
645 /** Library major version. */
646 const uint16_t major
;
648 /** Library minor version. */
649 const uint16_t minor
;
651 /** Library micro version. */
652 const uint16_t micro
;
654 /** Library nano version. */
657 /** Library release candidate suffix string, e.g. "-rc4". */
660 /** For ABI compatibility only. */
661 const char* describe
;
665 * Structure representing a libusbx session. The concept of individual libusbx
666 * sessions allows for your program to use two libraries (or dynamically
667 * load two modules) which both independently use libusb. This will prevent
668 * interference between the individual libusbx users - for example
669 * libusb_set_debug() will not affect the other user of the library, and
670 * libusb_exit() will not destroy resources that the other user is still
673 * Sessions are created by libusb_init() and destroyed through libusb_exit().
674 * If your application is guaranteed to only ever include a single libusbx
675 * user (i.e. you), you do not have to worry about contexts: pass NULL in
676 * every function call where a context is required. The default context
679 * For more information, see \ref contexts.
681 typedef struct libusb_context libusb_context
;
684 * Structure representing a USB device detected on the system. This is an
685 * opaque type for which you are only ever provided with a pointer, usually
686 * originating from libusb_get_device_list().
688 * Certain operations can be performed on a device, but in order to do any
689 * I/O you will have to first obtain a device handle using libusb_open().
691 * Devices are reference counted with libusb_device_ref() and
692 * libusb_device_unref(), and are freed when the reference count reaches 0.
693 * New devices presented by libusb_get_device_list() have a reference count of
694 * 1, and libusb_free_device_list() can optionally decrease the reference count
695 * on all devices in the list. libusb_open() adds another reference which is
696 * later destroyed by libusb_close().
698 typedef struct libusb_device libusb_device
;
702 * Structure representing a handle on a USB device. This is an opaque type for
703 * which you are only ever provided with a pointer, usually originating from
706 * A device handle is used to perform I/O and other operations. When finished
707 * with a device handle, you should call libusb_close().
709 typedef struct libusb_device_handle libusb_device_handle
;
712 * Speed codes. Indicates the speed at which the device is operating.
715 /** The OS doesn't report or know the device speed. */
716 LIBUSB_SPEED_UNKNOWN
= 0,
718 /** The device is operating at low speed (1.5MBit/s). */
719 LIBUSB_SPEED_LOW
= 1,
721 /** The device is operating at full speed (12MBit/s). */
722 LIBUSB_SPEED_FULL
= 2,
724 /** The device is operating at high speed (480MBit/s). */
725 LIBUSB_SPEED_HIGH
= 3,
727 /** The device is operating at super speed (5000MBit/s). */
728 LIBUSB_SPEED_SUPER
= 4,
732 * Error codes. Most libusbx functions return 0 on success or one of these
734 * You can call \ref libusb_error_name() to retrieve a string representation
738 /** Success (no error) */
741 /** Input/output error */
742 LIBUSB_ERROR_IO
= -1,
744 /** Invalid parameter */
745 LIBUSB_ERROR_INVALID_PARAM
= -2,
747 /** Access denied (insufficient permissions) */
748 LIBUSB_ERROR_ACCESS
= -3,
750 /** No such device (it may have been disconnected) */
751 LIBUSB_ERROR_NO_DEVICE
= -4,
753 /** Entity not found */
754 LIBUSB_ERROR_NOT_FOUND
= -5,
757 LIBUSB_ERROR_BUSY
= -6,
759 /** Operation timed out */
760 LIBUSB_ERROR_TIMEOUT
= -7,
763 LIBUSB_ERROR_OVERFLOW
= -8,
766 LIBUSB_ERROR_PIPE
= -9,
768 /** System call interrupted (perhaps due to signal) */
769 LIBUSB_ERROR_INTERRUPTED
= -10,
771 /** Insufficient memory */
772 LIBUSB_ERROR_NO_MEM
= -11,
774 /** Operation not supported or unimplemented on this platform */
775 LIBUSB_ERROR_NOT_SUPPORTED
= -12,
777 /* NB! Remember to update libusb_error_name()
778 when adding new error codes here. */
781 LIBUSB_ERROR_OTHER
= -99,
785 * Transfer status codes */
786 enum libusb_transfer_status
{
787 /** Transfer completed without error. Note that this does not indicate
788 * that the entire amount of requested data was transferred. */
789 LIBUSB_TRANSFER_COMPLETED
,
791 /** Transfer failed */
792 LIBUSB_TRANSFER_ERROR
,
794 /** Transfer timed out */
795 LIBUSB_TRANSFER_TIMED_OUT
,
797 /** Transfer was cancelled */
798 LIBUSB_TRANSFER_CANCELLED
,
800 /** For bulk/interrupt endpoints: halt condition detected (endpoint
801 * stalled). For control endpoints: control request not supported. */
802 LIBUSB_TRANSFER_STALL
,
804 /** Device was disconnected */
805 LIBUSB_TRANSFER_NO_DEVICE
,
807 /** Device sent more data than requested */
808 LIBUSB_TRANSFER_OVERFLOW
,
812 * libusb_transfer.flags values */
813 enum libusb_transfer_flags
{
814 /** Report short frames as errors */
815 LIBUSB_TRANSFER_SHORT_NOT_OK
= 1<<0,
817 /** Automatically free() transfer buffer during libusb_free_transfer() */
818 LIBUSB_TRANSFER_FREE_BUFFER
= 1<<1,
820 /** Automatically call libusb_free_transfer() after callback returns.
821 * If this flag is set, it is illegal to call libusb_free_transfer()
822 * from your transfer callback, as this will result in a double-free
823 * when this flag is acted upon. */
824 LIBUSB_TRANSFER_FREE_TRANSFER
= 1<<2,
826 /** Terminate transfers that are a multiple of the endpoint's
827 * wMaxPacketSize with an extra zero length packet. This is useful
828 * when a device protocol mandates that each logical request is
829 * terminated by an incomplete packet (i.e. the logical requests are
830 * not separated by other means).
832 * This flag only affects host-to-device transfers to bulk and interrupt
833 * endpoints. In other situations, it is ignored.
835 * This flag only affects transfers with a length that is a multiple of
836 * the endpoint's wMaxPacketSize. On transfers of other lengths, this
837 * flag has no effect. Therefore, if you are working with a device that
838 * needs a ZLP whenever the end of the logical request falls on a packet
839 * boundary, then it is sensible to set this flag on <em>every</em>
840 * transfer (you do not have to worry about only setting it on transfers
841 * that end on the boundary).
843 * This flag is currently only supported on Linux.
844 * On other systems, libusb_submit_transfer() will return
845 * LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
847 * Available since libusb-1.0.9.
849 LIBUSB_TRANSFER_ADD_ZERO_PACKET
= 1 << 3,
853 * Isochronous packet descriptor. */
854 struct libusb_iso_packet_descriptor
{
855 /** Length of data to request in this packet */
858 /** Amount of data that was actually transferred */
859 unsigned int actual_length
;
861 /** Status code for this packet */
862 enum libusb_transfer_status status
;
865 struct libusb_transfer
;
868 * Asynchronous transfer callback function type. When submitting asynchronous
869 * transfers, you pass a pointer to a callback function of this type via the
870 * \ref libusb_transfer::callback "callback" member of the libusb_transfer
871 * structure. libusbx will call this function later, when the transfer has
872 * completed or failed. See \ref asyncio for more information.
873 * \param transfer The libusb_transfer struct the callback function is being
876 typedef void (LIBUSB_CALL
*libusb_transfer_cb_fn
)(struct libusb_transfer
*transfer
);
879 * The generic USB transfer structure. The user populates this structure and
880 * then submits it in order to request a transfer. After the transfer has
881 * completed, the library populates the transfer with the results and passes
882 * it back to the user.
884 struct libusb_transfer
{
885 /** Handle of the device that this transfer will be submitted to */
886 libusb_device_handle
*dev_handle
;
888 /** A bitwise OR combination of \ref libusb_transfer_flags. */
891 /** Address of the endpoint where this transfer will be sent. */
892 unsigned char endpoint
;
894 /** Type of the endpoint from \ref libusb_transfer_type */
897 /** Timeout for this transfer in millseconds. A value of 0 indicates no
899 unsigned int timeout
;
901 /** The status of the transfer. Read-only, and only for use within
902 * transfer callback function.
904 * If this is an isochronous transfer, this field may read COMPLETED even
905 * if there were errors in the frames. Use the
906 * \ref libusb_iso_packet_descriptor::status "status" field in each packet
907 * to determine if errors occurred. */
908 enum libusb_transfer_status status
;
910 /** Length of the data buffer */
913 /** Actual length of data that was transferred. Read-only, and only for
914 * use within transfer callback function. Not valid for isochronous
915 * endpoint transfers. */
918 /** Callback function. This will be invoked when the transfer completes,
919 * fails, or is cancelled. */
920 libusb_transfer_cb_fn callback
;
922 /** User context data to pass to the callback function. */
926 unsigned char *buffer
;
928 /** Number of isochronous packets. Only used for I/O with isochronous
932 /** Isochronous packet descriptors, for isochronous transfers only. */
933 struct libusb_iso_packet_descriptor iso_packet_desc
934 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
935 [] /* valid C99 code */
937 [0] /* non-standard, but usually working code */
943 * Capabilities supported by this instance of libusb. Test if the loaded
944 * library supports a given capability by calling
945 * \ref libusb_has_capability().
947 enum libusb_capability
{
948 /** The libusb_has_capability() API is available. */
949 LIBUSB_CAP_HAS_CAPABILITY
= 0,
952 int LIBUSB_CALL
libusb_init(libusb_context
**ctx
);
953 void LIBUSB_CALL
libusb_exit(libusb_context
*ctx
);
954 void LIBUSB_CALL
libusb_set_debug(libusb_context
*ctx
, int level
);
955 const struct libusb_version
* LIBUSB_CALL
libusb_get_version(void);
956 int LIBUSB_CALL
libusb_has_capability(uint32_t capability
);
957 const char * LIBUSB_CALL
libusb_error_name(int errcode
);
959 ssize_t LIBUSB_CALL
libusb_get_device_list(libusb_context
*ctx
,
960 libusb_device
***list
);
961 void LIBUSB_CALL
libusb_free_device_list(libusb_device
**list
,
963 libusb_device
* LIBUSB_CALL
libusb_ref_device(libusb_device
*dev
);
964 void LIBUSB_CALL
libusb_unref_device(libusb_device
*dev
);
966 int LIBUSB_CALL
libusb_get_configuration(libusb_device_handle
*dev
,
968 int LIBUSB_CALL
libusb_get_device_descriptor(libusb_device
*dev
,
969 struct libusb_device_descriptor
*desc
);
970 int LIBUSB_CALL
libusb_get_active_config_descriptor(libusb_device
*dev
,
971 struct libusb_config_descriptor
**config
);
972 int LIBUSB_CALL
libusb_get_config_descriptor(libusb_device
*dev
,
973 uint8_t config_index
, struct libusb_config_descriptor
**config
);
974 int LIBUSB_CALL
libusb_get_config_descriptor_by_value(libusb_device
*dev
,
975 uint8_t bConfigurationValue
, struct libusb_config_descriptor
**config
);
976 void LIBUSB_CALL
libusb_free_config_descriptor(
977 struct libusb_config_descriptor
*config
);
978 uint8_t LIBUSB_CALL
libusb_get_bus_number(libusb_device
*dev
);
979 uint8_t LIBUSB_CALL
libusb_get_port_number(libusb_device
*dev
);
980 libusb_device
* LIBUSB_CALL
libusb_get_parent(libusb_device
*dev
);
981 int LIBUSB_CALL
libusb_get_port_path(libusb_context
*ctx
, libusb_device
*dev
, uint8_t* path
, uint8_t path_length
);
982 uint8_t LIBUSB_CALL
libusb_get_device_address(libusb_device
*dev
);
983 int LIBUSB_CALL
libusb_get_device_speed(libusb_device
*dev
);
984 int LIBUSB_CALL
libusb_get_max_packet_size(libusb_device
*dev
,
985 unsigned char endpoint
);
986 int LIBUSB_CALL
libusb_get_max_iso_packet_size(libusb_device
*dev
,
987 unsigned char endpoint
);
989 int LIBUSB_CALL
libusb_open(libusb_device
*dev
, libusb_device_handle
**handle
);
990 void LIBUSB_CALL
libusb_close(libusb_device_handle
*dev_handle
);
991 libusb_device
* LIBUSB_CALL
libusb_get_device(libusb_device_handle
*dev_handle
);
993 int LIBUSB_CALL
libusb_set_configuration(libusb_device_handle
*dev
,
995 int LIBUSB_CALL
libusb_claim_interface(libusb_device_handle
*dev
,
996 int interface_number
);
997 int LIBUSB_CALL
libusb_release_interface(libusb_device_handle
*dev
,
998 int interface_number
);
1000 libusb_device_handle
* LIBUSB_CALL
libusb_open_device_with_vid_pid(
1001 libusb_context
*ctx
, uint16_t vendor_id
, uint16_t product_id
);
1003 int LIBUSB_CALL
libusb_set_interface_alt_setting(libusb_device_handle
*dev
,
1004 int interface_number
, int alternate_setting
);
1005 int LIBUSB_CALL
libusb_clear_halt(libusb_device_handle
*dev
,
1006 unsigned char endpoint
);
1007 int LIBUSB_CALL
libusb_reset_device(libusb_device_handle
*dev
);
1009 int LIBUSB_CALL
libusb_kernel_driver_active(libusb_device_handle
*dev
,
1010 int interface_number
);
1011 int LIBUSB_CALL
libusb_detach_kernel_driver(libusb_device_handle
*dev
,
1012 int interface_number
);
1013 int LIBUSB_CALL
libusb_attach_kernel_driver(libusb_device_handle
*dev
,
1014 int interface_number
);
1018 /** \ingroup asyncio
1019 * Get the data section of a control transfer. This convenience function is here
1020 * to remind you that the data does not start until 8 bytes into the actual
1021 * buffer, as the setup packet comes first.
1023 * Calling this function only makes sense from a transfer callback function,
1024 * or situations where you have already allocated a suitably sized buffer at
1027 * \param transfer a transfer
1028 * \returns pointer to the first byte of the data section
1030 static inline unsigned char *libusb_control_transfer_get_data(
1031 struct libusb_transfer
*transfer
)
1033 return transfer
->buffer
+ LIBUSB_CONTROL_SETUP_SIZE
;
1036 /** \ingroup asyncio
1037 * Get the control setup packet of a control transfer. This convenience
1038 * function is here to remind you that the control setup occupies the first
1039 * 8 bytes of the transfer data buffer.
1041 * Calling this function only makes sense from a transfer callback function,
1042 * or situations where you have already allocated a suitably sized buffer at
1045 * \param transfer a transfer
1046 * \returns a casted pointer to the start of the transfer data buffer
1048 static inline struct libusb_control_setup
*libusb_control_transfer_get_setup(
1049 struct libusb_transfer
*transfer
)
1051 return (struct libusb_control_setup
*) transfer
->buffer
;
1054 /** \ingroup asyncio
1055 * Helper function to populate the setup packet (first 8 bytes of the data
1056 * buffer) for a control transfer. The wIndex, wValue and wLength values should
1057 * be given in host-endian byte order.
1059 * \param buffer buffer to output the setup packet into
1060 * \param bmRequestType see the
1061 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
1062 * \ref libusb_control_setup
1063 * \param bRequest see the
1064 * \ref libusb_control_setup::bRequest "bRequest" field of
1065 * \ref libusb_control_setup
1066 * \param wValue see the
1067 * \ref libusb_control_setup::wValue "wValue" field of
1068 * \ref libusb_control_setup
1069 * \param wIndex see the
1070 * \ref libusb_control_setup::wIndex "wIndex" field of
1071 * \ref libusb_control_setup
1072 * \param wLength see the
1073 * \ref libusb_control_setup::wLength "wLength" field of
1074 * \ref libusb_control_setup
1076 static inline void libusb_fill_control_setup(unsigned char *buffer
,
1077 uint8_t bmRequestType
, uint8_t bRequest
, uint16_t wValue
, uint16_t wIndex
,
1080 struct libusb_control_setup
*setup
= (struct libusb_control_setup
*) buffer
;
1081 setup
->bmRequestType
= bmRequestType
;
1082 setup
->bRequest
= bRequest
;
1083 setup
->wValue
= libusb_cpu_to_le16(wValue
);
1084 setup
->wIndex
= libusb_cpu_to_le16(wIndex
);
1085 setup
->wLength
= libusb_cpu_to_le16(wLength
);
1088 struct libusb_transfer
* LIBUSB_CALL
libusb_alloc_transfer(int iso_packets
);
1089 int LIBUSB_CALL
libusb_submit_transfer(struct libusb_transfer
*transfer
);
1090 int LIBUSB_CALL
libusb_cancel_transfer(struct libusb_transfer
*transfer
);
1091 void LIBUSB_CALL
libusb_free_transfer(struct libusb_transfer
*transfer
);
1093 /** \ingroup asyncio
1094 * Helper function to populate the required \ref libusb_transfer fields
1095 * for a control transfer.
1097 * If you pass a transfer buffer to this function, the first 8 bytes will
1098 * be interpreted as a control setup packet, and the wLength field will be
1099 * used to automatically populate the \ref libusb_transfer::length "length"
1100 * field of the transfer. Therefore the recommended approach is:
1101 * -# Allocate a suitably sized data buffer (including space for control setup)
1102 * -# Call libusb_fill_control_setup()
1103 * -# If this is a host-to-device transfer with a data stage, put the data
1104 * in place after the setup packet
1105 * -# Call this function
1106 * -# Call libusb_submit_transfer()
1108 * It is also legal to pass a NULL buffer to this function, in which case this
1109 * function will not attempt to populate the length field. Remember that you
1110 * must then populate the buffer and length fields later.
1112 * \param transfer the transfer to populate
1113 * \param dev_handle handle of the device that will handle the transfer
1114 * \param buffer data buffer. If provided, this function will interpret the
1115 * first 8 bytes as a setup packet and infer the transfer length from that.
1116 * \param callback callback function to be invoked on transfer completion
1117 * \param user_data user data to pass to callback function
1118 * \param timeout timeout for the transfer in milliseconds
1120 static inline void libusb_fill_control_transfer(
1121 struct libusb_transfer
*transfer
, libusb_device_handle
*dev_handle
,
1122 unsigned char *buffer
, libusb_transfer_cb_fn callback
, void *user_data
,
1123 unsigned int timeout
)
1125 struct libusb_control_setup
*setup
= (struct libusb_control_setup
*) buffer
;
1126 transfer
->dev_handle
= dev_handle
;
1127 transfer
->endpoint
= 0;
1128 transfer
->type
= LIBUSB_TRANSFER_TYPE_CONTROL
;
1129 transfer
->timeout
= timeout
;
1130 transfer
->buffer
= buffer
;
1132 transfer
->length
= LIBUSB_CONTROL_SETUP_SIZE
1133 + libusb_le16_to_cpu(setup
->wLength
);
1134 transfer
->user_data
= user_data
;
1135 transfer
->callback
= callback
;
1138 /** \ingroup asyncio
1139 * Helper function to populate the required \ref libusb_transfer fields
1140 * for a bulk transfer.
1142 * \param transfer the transfer to populate
1143 * \param dev_handle handle of the device that will handle the transfer
1144 * \param endpoint address of the endpoint where this transfer will be sent
1145 * \param buffer data buffer
1146 * \param length length of data buffer
1147 * \param callback callback function to be invoked on transfer completion
1148 * \param user_data user data to pass to callback function
1149 * \param timeout timeout for the transfer in milliseconds
1151 static inline void libusb_fill_bulk_transfer(struct libusb_transfer
*transfer
,
1152 libusb_device_handle
*dev_handle
, unsigned char endpoint
,
1153 unsigned char *buffer
, int length
, libusb_transfer_cb_fn callback
,
1154 void *user_data
, unsigned int timeout
)
1156 transfer
->dev_handle
= dev_handle
;
1157 transfer
->endpoint
= endpoint
;
1158 transfer
->type
= LIBUSB_TRANSFER_TYPE_BULK
;
1159 transfer
->timeout
= timeout
;
1160 transfer
->buffer
= buffer
;
1161 transfer
->length
= length
;
1162 transfer
->user_data
= user_data
;
1163 transfer
->callback
= callback
;
1166 /** \ingroup asyncio
1167 * Helper function to populate the required \ref libusb_transfer fields
1168 * for an interrupt transfer.
1170 * \param transfer the transfer to populate
1171 * \param dev_handle handle of the device that will handle the transfer
1172 * \param endpoint address of the endpoint where this transfer will be sent
1173 * \param buffer data buffer
1174 * \param length length of data buffer
1175 * \param callback callback function to be invoked on transfer completion
1176 * \param user_data user data to pass to callback function
1177 * \param timeout timeout for the transfer in milliseconds
1179 static inline void libusb_fill_interrupt_transfer(
1180 struct libusb_transfer
*transfer
, libusb_device_handle
*dev_handle
,
1181 unsigned char endpoint
, unsigned char *buffer
, int length
,
1182 libusb_transfer_cb_fn callback
, void *user_data
, unsigned int timeout
)
1184 transfer
->dev_handle
= dev_handle
;
1185 transfer
->endpoint
= endpoint
;
1186 transfer
->type
= LIBUSB_TRANSFER_TYPE_INTERRUPT
;
1187 transfer
->timeout
= timeout
;
1188 transfer
->buffer
= buffer
;
1189 transfer
->length
= length
;
1190 transfer
->user_data
= user_data
;
1191 transfer
->callback
= callback
;
1194 /** \ingroup asyncio
1195 * Helper function to populate the required \ref libusb_transfer fields
1196 * for an isochronous transfer.
1198 * \param transfer the transfer to populate
1199 * \param dev_handle handle of the device that will handle the transfer
1200 * \param endpoint address of the endpoint where this transfer will be sent
1201 * \param buffer data buffer
1202 * \param length length of data buffer
1203 * \param num_iso_packets the number of isochronous packets
1204 * \param callback callback function to be invoked on transfer completion
1205 * \param user_data user data to pass to callback function
1206 * \param timeout timeout for the transfer in milliseconds
1208 static inline void libusb_fill_iso_transfer(struct libusb_transfer
*transfer
,
1209 libusb_device_handle
*dev_handle
, unsigned char endpoint
,
1210 unsigned char *buffer
, int length
, int num_iso_packets
,
1211 libusb_transfer_cb_fn callback
, void *user_data
, unsigned int timeout
)
1213 transfer
->dev_handle
= dev_handle
;
1214 transfer
->endpoint
= endpoint
;
1215 transfer
->type
= LIBUSB_TRANSFER_TYPE_ISOCHRONOUS
;
1216 transfer
->timeout
= timeout
;
1217 transfer
->buffer
= buffer
;
1218 transfer
->length
= length
;
1219 transfer
->num_iso_packets
= num_iso_packets
;
1220 transfer
->user_data
= user_data
;
1221 transfer
->callback
= callback
;
1224 /** \ingroup asyncio
1225 * Convenience function to set the length of all packets in an isochronous
1226 * transfer, based on the num_iso_packets field in the transfer structure.
1228 * \param transfer a transfer
1229 * \param length the length to set in each isochronous packet descriptor
1230 * \see libusb_get_max_packet_size()
1232 static inline void libusb_set_iso_packet_lengths(
1233 struct libusb_transfer
*transfer
, unsigned int length
)
1236 for (i
= 0; i
< transfer
->num_iso_packets
; i
++)
1237 transfer
->iso_packet_desc
[i
].length
= length
;
1240 /** \ingroup asyncio
1241 * Convenience function to locate the position of an isochronous packet
1242 * within the buffer of an isochronous transfer.
1244 * This is a thorough function which loops through all preceding packets,
1245 * accumulating their lengths to find the position of the specified packet.
1246 * Typically you will assign equal lengths to each packet in the transfer,
1247 * and hence the above method is sub-optimal. You may wish to use
1248 * libusb_get_iso_packet_buffer_simple() instead.
1250 * \param transfer a transfer
1251 * \param packet the packet to return the address of
1252 * \returns the base address of the packet buffer inside the transfer buffer,
1253 * or NULL if the packet does not exist.
1254 * \see libusb_get_iso_packet_buffer_simple()
1256 static inline unsigned char *libusb_get_iso_packet_buffer(
1257 struct libusb_transfer
*transfer
, unsigned int packet
)
1263 /* oops..slight bug in the API. packet is an unsigned int, but we use
1264 * signed integers almost everywhere else. range-check and convert to
1265 * signed to avoid compiler warnings. FIXME for libusb-2. */
1266 if (packet
> INT_MAX
)
1270 if (_packet
>= transfer
->num_iso_packets
)
1273 for (i
= 0; i
< _packet
; i
++)
1274 offset
+= transfer
->iso_packet_desc
[i
].length
;
1276 return transfer
->buffer
+ offset
;
1279 /** \ingroup asyncio
1280 * Convenience function to locate the position of an isochronous packet
1281 * within the buffer of an isochronous transfer, for transfers where each
1282 * packet is of identical size.
1284 * This function relies on the assumption that every packet within the transfer
1285 * is of identical size to the first packet. Calculating the location of
1286 * the packet buffer is then just a simple calculation:
1287 * <tt>buffer + (packet_size * packet)</tt>
1289 * Do not use this function on transfers other than those that have identical
1290 * packet lengths for each packet.
1292 * \param transfer a transfer
1293 * \param packet the packet to return the address of
1294 * \returns the base address of the packet buffer inside the transfer buffer,
1295 * or NULL if the packet does not exist.
1296 * \see libusb_get_iso_packet_buffer()
1298 static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1299 struct libusb_transfer
*transfer
, unsigned int packet
)
1303 /* oops..slight bug in the API. packet is an unsigned int, but we use
1304 * signed integers almost everywhere else. range-check and convert to
1305 * signed to avoid compiler warnings. FIXME for libusb-2. */
1306 if (packet
> INT_MAX
)
1310 if (_packet
>= transfer
->num_iso_packets
)
1313 return transfer
->buffer
+ (transfer
->iso_packet_desc
[0].length
* _packet
);
1318 int LIBUSB_CALL
libusb_control_transfer(libusb_device_handle
*dev_handle
,
1319 uint8_t request_type
, uint8_t bRequest
, uint16_t wValue
, uint16_t wIndex
,
1320 unsigned char *data
, uint16_t wLength
, unsigned int timeout
);
1322 int LIBUSB_CALL
libusb_bulk_transfer(libusb_device_handle
*dev_handle
,
1323 unsigned char endpoint
, unsigned char *data
, int length
,
1324 int *actual_length
, unsigned int timeout
);
1326 int LIBUSB_CALL
libusb_interrupt_transfer(libusb_device_handle
*dev_handle
,
1327 unsigned char endpoint
, unsigned char *data
, int length
,
1328 int *actual_length
, unsigned int timeout
);
1331 * Retrieve a descriptor from the default control pipe.
1332 * This is a convenience function which formulates the appropriate control
1333 * message to retrieve the descriptor.
1335 * \param dev a device handle
1336 * \param desc_type the descriptor type, see \ref libusb_descriptor_type
1337 * \param desc_index the index of the descriptor to retrieve
1338 * \param data output buffer for descriptor
1339 * \param length size of data buffer
1340 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1342 static inline int libusb_get_descriptor(libusb_device_handle
*dev
,
1343 uint8_t desc_type
, uint8_t desc_index
, unsigned char *data
, int length
)
1345 return libusb_control_transfer(dev
, LIBUSB_ENDPOINT_IN
,
1346 LIBUSB_REQUEST_GET_DESCRIPTOR
, (desc_type
<< 8) | desc_index
, 0, data
,
1347 (uint16_t) length
, 1000);
1351 * Retrieve a descriptor from a device.
1352 * This is a convenience function which formulates the appropriate control
1353 * message to retrieve the descriptor. The string returned is Unicode, as
1354 * detailed in the USB specifications.
1356 * \param dev a device handle
1357 * \param desc_index the index of the descriptor to retrieve
1358 * \param langid the language ID for the string descriptor
1359 * \param data output buffer for descriptor
1360 * \param length size of data buffer
1361 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1362 * \see libusb_get_string_descriptor_ascii()
1364 static inline int libusb_get_string_descriptor(libusb_device_handle
*dev
,
1365 uint8_t desc_index
, uint16_t langid
, unsigned char *data
, int length
)
1367 return libusb_control_transfer(dev
, LIBUSB_ENDPOINT_IN
,
1368 LIBUSB_REQUEST_GET_DESCRIPTOR
, (uint16_t)((LIBUSB_DT_STRING
<< 8) | desc_index
),
1369 langid
, data
, (uint16_t) length
, 1000);
1372 int LIBUSB_CALL
libusb_get_string_descriptor_ascii(libusb_device_handle
*dev
,
1373 uint8_t desc_index
, unsigned char *data
, int length
);
1375 /* polling and timeouts */
1377 int LIBUSB_CALL
libusb_try_lock_events(libusb_context
*ctx
);
1378 void LIBUSB_CALL
libusb_lock_events(libusb_context
*ctx
);
1379 void LIBUSB_CALL
libusb_unlock_events(libusb_context
*ctx
);
1380 int LIBUSB_CALL
libusb_event_handling_ok(libusb_context
*ctx
);
1381 int LIBUSB_CALL
libusb_event_handler_active(libusb_context
*ctx
);
1382 void LIBUSB_CALL
libusb_lock_event_waiters(libusb_context
*ctx
);
1383 void LIBUSB_CALL
libusb_unlock_event_waiters(libusb_context
*ctx
);
1384 int LIBUSB_CALL
libusb_wait_for_event(libusb_context
*ctx
, struct timeval
*tv
);
1386 int LIBUSB_CALL
libusb_handle_events_timeout(libusb_context
*ctx
,
1387 struct timeval
*tv
);
1388 int LIBUSB_CALL
libusb_handle_events_timeout_completed(libusb_context
*ctx
,
1389 struct timeval
*tv
, int *completed
);
1390 int LIBUSB_CALL
libusb_handle_events(libusb_context
*ctx
);
1391 int LIBUSB_CALL
libusb_handle_events_completed(libusb_context
*ctx
, int *completed
);
1392 int LIBUSB_CALL
libusb_handle_events_locked(libusb_context
*ctx
,
1393 struct timeval
*tv
);
1394 int LIBUSB_CALL
libusb_pollfds_handle_timeouts(libusb_context
*ctx
);
1395 int LIBUSB_CALL
libusb_get_next_timeout(libusb_context
*ctx
,
1396 struct timeval
*tv
);
1399 * File descriptor for polling
1401 struct libusb_pollfd
{
1402 /** Numeric file descriptor */
1405 /** Event flags to poll for from <poll.h>. POLLIN indicates that you
1406 * should monitor this file descriptor for becoming ready to read from,
1407 * and POLLOUT indicates that you should monitor this file descriptor for
1408 * nonblocking write readiness. */
1413 * Callback function, invoked when a new file descriptor should be added
1414 * to the set of file descriptors monitored for events.
1415 * \param fd the new file descriptor
1416 * \param events events to monitor for, see \ref libusb_pollfd for a
1418 * \param user_data User data pointer specified in
1419 * libusb_set_pollfd_notifiers() call
1420 * \see libusb_set_pollfd_notifiers()
1422 typedef void (LIBUSB_CALL
*libusb_pollfd_added_cb
)(int fd
, short events
,
1426 * Callback function, invoked when a file descriptor should be removed from
1427 * the set of file descriptors being monitored for events. After returning
1428 * from this callback, do not use that file descriptor again.
1429 * \param fd the file descriptor to stop monitoring
1430 * \param user_data User data pointer specified in
1431 * libusb_set_pollfd_notifiers() call
1432 * \see libusb_set_pollfd_notifiers()
1434 typedef void (LIBUSB_CALL
*libusb_pollfd_removed_cb
)(int fd
, void *user_data
);
1436 const struct libusb_pollfd
** LIBUSB_CALL
libusb_get_pollfds(
1437 libusb_context
*ctx
);
1438 void LIBUSB_CALL
libusb_set_pollfd_notifiers(libusb_context
*ctx
,
1439 libusb_pollfd_added_cb added_cb
, libusb_pollfd_removed_cb removed_cb
,