2 * Public libusb header file
3 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
4 * Copyright (c) 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
32 /* standard USB stuff */
35 * Device and/or Interface Class codes */
36 enum libusb_class_code {
37 /** In the context of a \ref libusb_device_descriptor "device descriptor",
38 * this bDeviceClass value indicates that each interface specifies its
39 * own class information and all interfaces operate independently.
41 LIBUSB_CLASS_PER_INTERFACE = 0,
44 LIBUSB_CLASS_AUDIO = 1,
46 /** Communications class */
47 LIBUSB_CLASS_COMM = 2,
49 /** Human Interface Device class */
53 LIBUSB_CLASS_PRINTER = 7,
55 /** Picture transfer protocol class */
58 /** Mass storage class */
59 LIBUSB_CLASS_MASS_STORAGE = 8,
65 LIBUSB_CLASS_DATA = 10,
67 /** Class is vendor-specific */
68 LIBUSB_CLASS_VENDOR_SPEC = 0xff,
72 * Descriptor types as defined by the USB specification. */
73 enum libusb_descriptor_type {
74 /** Device descriptor. See libusb_device_descriptor. */
75 LIBUSB_DT_DEVICE = 0x01,
77 /** Configuration descriptor. See libusb_config_descriptor. */
78 LIBUSB_DT_CONFIG = 0x02,
80 /** String descriptor */
81 LIBUSB_DT_STRING = 0x03,
83 /** Interface descriptor. See libusb_interface_descriptor. */
84 LIBUSB_DT_INTERFACE = 0x04,
86 /** Endpoint descriptor. See libusb_endpoint_descriptor. */
87 LIBUSB_DT_ENDPOINT = 0x05,
92 /** HID report descriptor */
93 LIBUSB_DT_REPORT = 0x22,
95 /** Physical descriptor */
96 LIBUSB_DT_PHYSICAL = 0x23,
102 /* Descriptor sizes per descriptor type */
103 #define LIBUSB_DT_DEVICE_SIZE 18
104 #define LIBUSB_DT_CONFIG_SIZE 9
105 #define LIBUSB_DT_INTERFACE_SIZE 9
106 #define LIBUSB_DT_ENDPOINT_SIZE 7
107 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
108 #define LIBUSB_DT_HUB_NONVAR_SIZE 7
110 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
111 #define LIBUSB_ENDPOINT_DIR_MASK 0x80
114 * Endpoint direction. Values for bit 7 of the
115 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
117 enum libusb_endpoint_direction {
118 /** In: device-to-host */
119 LIBUSB_ENDPOINT_IN = 0x80,
121 /** Out: host-to-device */
122 LIBUSB_ENDPOINT_OUT = 0x00,
125 /* FIXME: 9.6.6 calls these "transfer types", not endpoint types. */
126 #define LIBUSB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
129 * Endpoint transfer type. Values for bits 0:1 of the
130 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
132 enum libusb_endpoint_type {
133 /** Control endpoint */
134 LIBUSB_ENDPOINT_TYPE_CONTROL = 0,
136 /** Isochronous endpoint */
137 LIBUSB_ENDPOINT_TYPE_ISOCHRONOUS = 1,
140 LIBUSB_ENDPOINT_TYPE_BULK = 2,
142 /** Interrupt endpoint */
143 LIBUSB_ENDPOINT_TYPE_INTERRUPT = 3,
146 /** Standard requests, as defined in table 9-3 of the USB2 specifications */
147 enum libusb_standard_request {
148 /** Request status of the specific recipient */
149 LIBUSB_REQUEST_GET_STATUS = 0x00,
151 /** Clear or disable a specific feature */
152 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
154 /* 0x02 is reserved */
156 /** Set or enable a specific feature */
157 LIBUSB_REQUEST_SET_FEATURE = 0x03,
159 /* 0x04 is reserved */
161 /** Set device address for all future accesses */
162 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
164 /** Get the specified descriptor */
165 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
167 /** Used to update existing descriptors or add new descriptors */
168 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
170 /** Get the current device configuration value */
171 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
173 /** Set device configuration */
174 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
176 /** Return the selected alternate setting for the specified interface */
177 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
179 /** Select an alternate interface for the specified interface */
180 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
182 /** Set then report an endpoint's synchronization frame */
183 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
187 * Request type bits of the
188 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
190 enum libusb_request_type {
192 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
195 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
198 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
201 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5),
205 * Recipient bits of the
206 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
207 * transfers. Values 4 through 31 are reserved. */
208 enum libusb_request_recipient {
210 LIBUSB_RECIPIENT_DEVICE = 0x00,
213 LIBUSB_RECIPIENT_INTERFACE = 0x01,
216 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
219 LIBUSB_RECIPIENT_OTHER = 0x03,
222 #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
225 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
226 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
227 * libusb_endpoint_descriptor.
229 enum libusb_iso_sync_type {
230 /** No synchronization */
231 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
234 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
237 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
240 LIBUSB_ISO_SYNC_TYPE_SYNC = 3,
243 #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
246 * Usage type for isochronous endpoints. Values for bits 4:5 of the
247 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
248 * libusb_endpoint_descriptor.
250 enum libusb_iso_usage_type {
252 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
254 /** Feedback endpoint */
255 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
257 /** Implicit feedback Data endpoint */
258 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
262 * A structure representing the standard USB device descriptor. This
263 * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
264 * All multiple-byte fields are represented in host-endian format.
266 struct libusb_device_descriptor {
267 /** Size of this descriptor (in bytes) */
270 /** Descriptor type. Will have value
271 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
273 uint8_t bDescriptorType;
275 /** USB specification release number in binary-coded decimal. A value of
276 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
279 /** USB-IF class code for the device. See \ref libusb_class_code. */
280 uint8_t bDeviceClass;
282 /** USB-IF subclass code for the device, qualified by the bDeviceClass
284 uint8_t bDeviceSubClass;
286 /** USB-IF protocol code for the device, qualified by the bDeviceClass and
287 * bDeviceSubClass values */
288 uint8_t bDeviceProtocol;
290 /** Maximum packet size for endpoint 0 */
291 uint8_t bMaxPacketSize0;
293 /** USB-IF vendor ID */
296 /** USB-IF product ID */
299 /** Device release number in binary-coded decimal */
302 /** Index of string descriptor describing manufacturer */
303 uint8_t iManufacturer;
305 /** Index of string descriptor describing product */
308 /** Index of string descriptor containing device serial number */
309 uint8_t iSerialNumber;
311 /** Number of possible configurations */
312 uint8_t bNumConfigurations;
316 * A structure representing the standard USB endpoint descriptor. This
317 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
318 * All multiple-byte fields are represented in host-endian format.
320 struct libusb_endpoint_descriptor {
321 /** Size of this descriptor (in bytes) */
324 /** Descriptor type. Will have value
325 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
327 uint8_t bDescriptorType;
329 /** The address of the endpoint described by this descriptor. Bits 0:3 are
330 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
331 * see \ref libusb_endpoint_direction.
333 uint8_t bEndpointAddress;
335 /** Attributes which apply to the endpoint when it is configured using
336 * the bConfigurationValue. Bits 0:1 determine the transfer type and
337 * correspond to \ref libusb_endpoint_type. Bits 2:3 are only used for
338 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
339 * Bits 4:5 are also only used for isochronous endpoints and correspond to
340 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
342 uint8_t bmAttributes;
344 /** Maximum packet size this endpoint is capable of sending/receiving. */
345 uint16_t wMaxPacketSize;
347 /** Interval for polling endpoint for data transfers. */
351 uint8_t bSynchAddress;
353 unsigned char *extra; /* Extra descriptors */
358 * A structure representing the standard USB interface descriptor. This
359 * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
360 * All multiple-byte fields are represented in host-endian format.
362 struct libusb_interface_descriptor {
363 /** Size of this descriptor (in bytes) */
366 /** Descriptor type. Will have value
367 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
368 * in this context. */
369 uint8_t bDescriptorType;
371 /** Number of this interface */
372 uint8_t bInterfaceNumber;
374 /** Value used to select this alternate setting for this interface */
375 uint8_t bAlternateSetting;
377 /** Number of endpoints used by this interface (excluding the control
379 uint8_t bNumEndpoints;
381 /** USB-IF class code for this interface. See \ref libusb_class_code. */
382 uint8_t bInterfaceClass;
384 /** USB-IF subclass code for this interface, qualified by the
385 * bInterfaceClass value */
386 uint8_t bInterfaceSubClass;
388 /** USB-IF protocol code for this interface, qualified by the
389 * bInterfaceClass and bInterfaceSubClass values */
390 uint8_t bInterfaceProtocol;
392 /** Index of string descriptor describing this interface */
395 /** Array of endpoint descriptors. This length of this array is determined
396 * by the bNumEndpoints field. */
397 struct libusb_endpoint_descriptor *endpoint;
399 unsigned char *extra; /* Extra descriptors */
404 * A collection of alternate settings for a particular USB interface.
406 struct libusb_interface {
407 /** Array of interface descriptors. The length of this array is determined
408 * by the num_altsetting field. */
409 struct libusb_interface_descriptor *altsetting;
411 /** The number of alternate settings that belong to this interface */
416 * A structure representing the standard USB configuration descriptor. This
417 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
418 * All multiple-byte fields are represented in host-endian format.
420 struct libusb_config_descriptor {
421 /** Size of this descriptor (in bytes) */
424 /** Descriptor type. Will have value
425 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
426 * in this context. */
427 uint8_t bDescriptorType;
429 /** Total length of data returned for this configuration */
430 uint16_t wTotalLength;
432 /** Number of interfaces supported by this configuration */
433 uint8_t bNumInterfaces;
435 /** Identifier value for this configuration */
436 uint8_t bConfigurationValue;
438 /** Index of string descriptor describing this configuration */
439 uint8_t iConfiguration;
441 /** Configuration characteristics */
442 uint8_t bmAttributes;
444 /** Maximum power consumption of the USB device from this bus in this
445 * configuration when the device is fully opreation. Expressed in units
449 /** Array of interfaces supported by this configuration. The length of
450 * this array is determined by the bNumInterfaces field. */
451 struct libusb_interface *interface;
453 unsigned char *extra; /* Extra descriptors */
458 * Setup packet for control transfers. */
459 struct libusb_control_setup {
460 /** Request type. Bits 0:4 determine recipient, see
461 * \ref libusb_request_recipient. Bits 5:6 determine type, see
462 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
463 * \ref libusb_endpoint_direction.
465 uint8_t bmRequestType;
467 /** Request. If the type bits of bmRequestType are equal to
468 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
469 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
470 * \ref libusb_standard_request. For other cases, use of this field is
471 * application-specific. */
474 /** Value. Varies according to request */
477 /** Index. Varies according to request, typically used to pass an index
481 /** Number of bytes to transfer */
483 } __attribute__((packed));
485 #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
489 struct libusb_device;
490 typedef struct libusb_device libusb_device;
492 struct libusb_device_handle;
493 typedef struct libusb_device_handle libusb_device_handle;
496 * Transfer status codes */
497 enum libusb_transfer_status {
498 /* FIXME: make this internal */
499 LIBUSB_TRANSFER_SILENT_COMPLETION = 0,
501 /** Transfer completed without error. Note that this does not indicate
502 * that the entire amount of requested data was transferred. */
503 LIBUSB_TRANSFER_COMPLETED,
505 /** Transfer failed */
506 LIBUSB_TRANSFER_ERROR,
508 /** Transfer timed out */
509 LIBUSB_TRANSFER_TIMED_OUT,
511 /** Transfer was cancelled */
512 LIBUSB_TRANSFER_CANCELLED,
516 * libusb_transfer.flags values */
517 enum libusb_transfer_flags {
518 /** Report short frames as errors */
519 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
521 /** Automatically free() transfer buffer during libusb_free_transfer() */
522 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
524 /** Automatically call libusb_free_transfer() after callback returns.
525 * If this flag is set, it is illegal to call libusb_free_transfer()
526 * from your transfer callback, as this will result in a double-free
527 * when this flag is acted upon. */
528 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
531 struct libusb_transfer;
533 typedef void (*libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
536 * The generic USB transfer structure.
538 struct libusb_transfer {
539 /** Handle of the device that this transfer will be submitted to */
540 libusb_device_handle *dev_handle;
542 /** A bitwise OR combination of \ref libusb_transfer_flags. */
545 /** Address of the endpoint where this transfer will be sent. */
546 unsigned char endpoint;
548 /* FIXME can this be inferred from endpoint address bits? */
549 /** Type of the endpoint from \ref libusb_endpoint_type */
550 unsigned char endpoint_type;
552 /** Timeout for this transfer in millseconds. A value of 0 indicates no
554 unsigned int timeout;
556 /* FIXME: make const? */
557 /** The status of the transfer. Read-only, and only for use within
558 * transfer callback function. */
559 enum libusb_transfer_status status;
561 /** Length of the data buffer */
564 /** Actual length of data that was transferred. Read-only, and only for
565 * use within transfer callback function. */
568 /** Callback function. This will be invoked when the transfer completes,
569 * fails, or is cancelled. */
570 libusb_transfer_cb_fn callback;
572 /** User context data to pass to the callback function. */
576 unsigned char *buffer;
579 int libusb_init(void);
580 void libusb_exit(void);
582 int libusb_get_device_list(libusb_device ***list);
583 void libusb_free_device_list(libusb_device **list, int unref_devices);
584 struct libusb_device_descriptor *libusb_get_device_descriptor(
586 struct libusb_config_descriptor *libusb_get_config_descriptor(
588 libusb_device *libusb_device_ref(libusb_device *dev);
589 void libusb_device_unref(libusb_device *dev);
591 libusb_device_handle *libusb_open(libusb_device *dev);
592 void libusb_close(libusb_device_handle *dev_handle);
593 libusb_device *libusb_get_device(libusb_device_handle *dev_handle);
594 int libusb_claim_interface(libusb_device_handle *dev, int iface);
595 int libusb_release_interface(libusb_device_handle *dev, int iface);
597 libusb_device_handle *libusb_open_device_with_vid_pid(uint16_t vendor_id,
598 uint16_t product_id);
603 * Get the data section of a control transfer. This convenience function is here
604 * to remind you that the data does not start until 8 bytes into the actual
605 * buffer, as the setup packet comes first.
607 * Calling this function only makes sense from a transfer callback function,
608 * or situations where you have already allocated a suitably sized buffer at
611 * \param transfer a transfer
612 * \returns pointer to the first byte of the data section
614 static inline unsigned char *libusb_control_transfer_get_data(
615 struct libusb_transfer *transfer)
617 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
621 * Get the control setup packet of a control transfer. This convenience
622 * function is here to remind you that the control setup occupies the first
623 * 8 bytes of the transfer data buffer.
625 * Calling this function only makes sense from a transfer callback function,
626 * or situations where you have already allocated a suitably sized buffer at
629 * \param transfer a transfer
630 * \returns a casted pointer to the start of the transfer data buffer
632 static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
633 struct libusb_transfer *transfer)
635 return (struct libusb_control_setup *) transfer->buffer;
639 * Helper function to populate the setup packet (first 8 bytes of the data
640 * buffer) for a control transfer.
642 * \param buffer buffer to output the setup packet into
643 * \param bmRequestType see the
644 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
645 * \ref libusb_control_setup
646 * \param bRequest see the
647 * \ref libusb_control_setup::bRequest "bRequest" field of
648 * \ref libusb_control_setup
649 * \param wValue see the
650 * \ref libusb_control_setup::wValue "wValue" field of
651 * \ref libusb_control_setup
652 * \param wIndex see the
653 * \ref libusb_control_setup::wIndex "wIndex" field of
654 * \ref libusb_control_setup
655 * \param wLength see the
656 * \ref libusb_control_setup::wLength "wLength" field of
657 * \ref libusb_control_setup
659 static inline void libusb_fill_control_setup(unsigned char *buffer,
660 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
663 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
664 setup->bmRequestType = bmRequestType;
665 setup->bRequest = bRequest;
666 setup->wValue = wValue;
667 setup->wIndex = wIndex;
668 setup->wLength = wLength;
671 size_t libusb_get_transfer_alloc_size(void);
672 void libusb_init_transfer(struct libusb_transfer *transfer);
674 struct libusb_transfer *libusb_alloc_transfer(void);
675 int libusb_submit_transfer(struct libusb_transfer *transfer);
676 int libusb_cancel_transfer(struct libusb_transfer *transfer);
677 int libusb_cancel_transfer_sync(struct libusb_transfer *transfer);
678 void libusb_free_transfer(struct libusb_transfer *transfer);
681 * Helper function to populate the required \ref libusb_transfer fields
682 * for a control transfer.
684 * If you pass a transfer buffer to this function, the first 8 bytes will
685 * be interpreted as a control setup packet, and the wLength field will be
686 * used to automatically populate the \ref libusb_transfer::length "length"
687 * field of the transfer. Therefore the recommended approach is:
688 * -# Allocate a suitably sized data buffer (including space for control setup)
689 * -# Call libusb_fill_control_setup()
690 * -# If this is a host-to-device transfer with a data stage, put the data
691 * in place after the setup packet
692 * -# Call this function
693 * -# Call libusb_submit_transfer()
695 * It is also legal to pass a NULL buffer to this function, in which case this
696 * function will not attempt to populate the length field. Remember that you
697 * must populate the buffer and length fields later.
699 * \param transfer the transfer to populate
700 * \param dev_handle handle of the device that will handle the transfer
701 * \param buffer data buffer. If provided, this function will interpret the
702 * first 8 bytes as a setup packet and infer the transfer length from that.
703 * \param callback callback function to be invoked on transfer completion
704 * \param user_data user data to pass to callback function
705 * \param timeout timeout for the transfer in milliseconds
707 static inline void libusb_fill_control_transfer(
708 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
709 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
710 unsigned int timeout)
712 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
713 transfer->dev_handle = dev_handle;
714 transfer->endpoint = 0;
715 transfer->endpoint_type = LIBUSB_ENDPOINT_TYPE_CONTROL;
716 transfer->timeout = timeout;
717 transfer->buffer = buffer;
719 transfer->length = LIBUSB_CONTROL_SETUP_SIZE + setup->wLength;
720 transfer->user_data = user_data;
721 transfer->callback = callback;
725 * Helper function to populate the required \ref libusb_transfer fields
726 * for a bulk transfer.
728 * \param transfer the transfer to populate
729 * \param dev_handle handle of the device that will handle the transfer
730 * \param endpoint address of the endpoint where this transfer will be sent
731 * \param buffer data buffer
732 * \param length length of data buffer
733 * \param callback callback function to be invoked on transfer completion
734 * \param user_data user data to pass to callback function
735 * \param timeout timeout for the transfer in milliseconds
737 static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
738 libusb_device_handle *dev_handle, unsigned char endpoint,
739 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
740 void *user_data, unsigned int timeout)
742 transfer->dev_handle = dev_handle;
743 transfer->endpoint = endpoint;
744 transfer->endpoint_type = LIBUSB_ENDPOINT_TYPE_BULK;
745 transfer->timeout = timeout;
746 transfer->buffer = buffer;
747 transfer->length = length;
748 transfer->user_data = user_data;
749 transfer->callback = callback;
753 * Helper function to populate the required \ref libusb_transfer fields
754 * for an interrupt transfer.
756 * \param transfer the transfer to populate
757 * \param dev_handle handle of the device that will handle the transfer
758 * \param endpoint address of the endpoint where this transfer will be sent
759 * \param buffer data buffer
760 * \param length length of data buffer
761 * \param callback callback function to be invoked on transfer completion
762 * \param user_data user data to pass to callback function
763 * \param timeout timeout for the transfer in milliseconds
765 static inline void libusb_fill_interrupt_transfer(
766 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
767 unsigned char endpoint, unsigned char *buffer, int length,
768 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
770 transfer->dev_handle = dev_handle;
771 transfer->endpoint = endpoint;
772 transfer->endpoint_type = LIBUSB_ENDPOINT_TYPE_INTERRUPT;
773 transfer->timeout = timeout;
774 transfer->buffer = buffer;
775 transfer->length = length;
776 transfer->user_data = user_data;
777 transfer->callback = callback;
782 int libusb_control_transfer(libusb_device_handle *dev_handle,
783 uint8_t request_type, uint8_t request, uint16_t value, uint16_t index,
784 unsigned char *data, uint16_t length, unsigned int timeout);
786 int libusb_bulk_transfer(libusb_device_handle *dev_handle,
787 unsigned char endpoint, unsigned char *data, int length,
788 int *actual_length, unsigned int timeout);
790 int libusb_interrupt_transfer(libusb_device_handle *dev_handle,
791 unsigned char endpoint, unsigned char *data, int length,
792 int *actual_length, unsigned int timeout);
794 /* polling and timeouts */
797 * File descriptor for polling
799 struct libusb_pollfd {
800 /** Numeric file descriptor */
803 /** Event flags to poll for from <poll.h>. POLLIN indicates that you
804 * should monitor this file descriptor for becoming ready to read from,
805 * and POLLOUT indicates that you should monitor this file descriptor for
806 * nonblocking write readiness. */
810 int libusb_poll_timeout(struct timeval *tv);
811 int libusb_poll(void);
812 int libusb_get_next_timeout(struct timeval *tv);
813 struct libusb_pollfd **libusb_get_pollfds(void);
815 typedef void (*libusb_pollfd_added_cb)(int fd, short events);
816 typedef void (*libusb_pollfd_removed_cb)(int fd);
817 void libusb_set_pollfd_notifiers(libusb_pollfd_added_cb added_cb,
818 libusb_pollfd_removed_cb removed_cb);