summaryrefslogtreecommitdiffstats
path: root/include/libusb-1.0/os/libusb.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libusb-1.0/os/libusb.h')
-rw-r--r--include/libusb-1.0/os/libusb.h1322
1 files changed, 0 insertions, 1322 deletions
diff --git a/include/libusb-1.0/os/libusb.h b/include/libusb-1.0/os/libusb.h
deleted file mode 100644
index 8dc3362..0000000
--- a/include/libusb-1.0/os/libusb.h
+++ /dev/null
@@ -1,1322 +0,0 @@
1/*
2 * Public libusb header file
3 * Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
4 * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
5 *
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.
10 *
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.
15 *
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
19 */
20
21#ifndef __LIBUSB_H__
22#define __LIBUSB_H__
23
24/* MSVC doesn't like inline, but does accept __inline ?? */
25#ifdef _MSC_VER
26#define inline __inline
27#endif
28
29#include <stdint.h>
30#include <sys/types.h>
31#include <time.h>
32#include <limits.h>
33
34#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
35#include <sys/time.h>
36#endif
37
38/* 'interface' might be defined as a macro on Windows, so we need to
39 * undefine it so as not to break the current libusb API, because
40 * libusb_config_descriptor has an 'interface' member
41 * As this can be problematic if you include windows.h after libusb.h
42 * in your sources, we force windows.h to be included first. */
43#if defined(_WIN32) || defined(__CYGWIN__)
44#include <windows.h>
45#if defined(interface)
46#undef interface
47#endif
48#endif
49
50/** \def LIBUSB_CALL
51 * \ingroup misc
52 * libusb's Windows calling convention.
53 *
54 * Under Windows, the selection of available compilers and configurations
55 * means that, unlike other platforms, there is not <em>one true calling
56 * convention</em> (calling convention: the manner in which parameters are
57 * passed to funcions in the generated assembly code).
58 *
59 * Matching the Windows API itself, libusb uses the WINAPI convention (which
60 * translates to the <tt>stdcall</tt> convention) and guarantees that the
61 * library is compiled in this way. The public header file also includes
62 * appropriate annotations so that your own software will use the right
63 * convention, even if another convention is being used by default within
64 * your codebase.
65 *
66 * The one consideration that you must apply in your software is to mark
67 * all functions which you use as libusb callbacks with this LIBUSB_CALL
68 * annotation, so that they too get compiled for the correct calling
69 * convention.
70 *
71 * On non-Windows operating systems, this macro is defined as nothing. This
72 * means that you can apply it to your code without worrying about
73 * cross-platform compatibility.
74 */
75/* LIBUSB_CALL must be defined on both definition and declaration of libusb
76 * functions. You'd think that declaration would be enough, but cygwin will
77 * complain about conflicting types unless both are marked this way.
78 * The placement of this macro is important too; it must appear after the
79 * return type, before the function name. See internal documentation for
80 * API_EXPORTED.
81 */
82#if defined(_WIN32) || defined(__CYGWIN__)
83#define LIBUSB_CALL WINAPI
84#else
85#define LIBUSB_CALL
86#endif
87
88#ifdef __cplusplus
89extern "C" {
90#endif
91
92/** \def libusb_cpu_to_le16
93 * \ingroup misc
94 * Convert a 16-bit value from host-endian to little-endian format. On
95 * little endian systems, this function does nothing. On big endian systems,
96 * the bytes are swapped.
97 * \param x the host-endian value to convert
98 * \returns the value in little-endian byte order
99 */
100static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
101{
102 union {
103 uint8_t b8[2];
104 uint16_t b16;
105 } _tmp;
106 _tmp.b8[1] = x >> 8;
107 _tmp.b8[0] = x & 0xff;
108 return _tmp.b16;
109}
110
111/** \def libusb_le16_to_cpu
112 * \ingroup misc
113 * Convert a 16-bit value from little-endian to host-endian format. On
114 * little endian systems, this function does nothing. On big endian systems,
115 * the bytes are swapped.
116 * \param x the little-endian value to convert
117 * \returns the value in host-endian byte order
118 */
119#define libusb_le16_to_cpu libusb_cpu_to_le16
120
121/* standard USB stuff */
122
123/** \ingroup desc
124 * Device and/or Interface Class codes */
125enum libusb_class_code {
126 /** In the context of a \ref libusb_device_descriptor "device descriptor",
127 * this bDeviceClass value indicates that each interface specifies its
128 * own class information and all interfaces operate independently.
129 */
130 LIBUSB_CLASS_PER_INTERFACE = 0,
131
132 /** Audio class */
133 LIBUSB_CLASS_AUDIO = 1,
134
135 /** Communications class */
136 LIBUSB_CLASS_COMM = 2,
137
138 /** Human Interface Device class */
139 LIBUSB_CLASS_HID = 3,
140
141 /** Printer dclass */
142 LIBUSB_CLASS_PRINTER = 7,
143
144 /** Picture transfer protocol class */
145 LIBUSB_CLASS_PTP = 6,
146
147 /** Mass storage class */
148 LIBUSB_CLASS_MASS_STORAGE = 8,
149
150 /** Hub class */
151 LIBUSB_CLASS_HUB = 9,
152
153 /** Data class */
154 LIBUSB_CLASS_DATA = 10,
155
156 /** Wireless class */
157 LIBUSB_CLASS_WIRELESS = 0xe0,
158
159 /** Application class */
160 LIBUSB_CLASS_APPLICATION = 0xfe,
161
162 /** Class is vendor-specific */
163 LIBUSB_CLASS_VENDOR_SPEC = 0xff
164};
165
166/** \ingroup desc
167 * Descriptor types as defined by the USB specification. */
168enum libusb_descriptor_type {
169 /** Device descriptor. See libusb_device_descriptor. */
170 LIBUSB_DT_DEVICE = 0x01,
171
172 /** Configuration descriptor. See libusb_config_descriptor. */
173 LIBUSB_DT_CONFIG = 0x02,
174
175 /** String descriptor */
176 LIBUSB_DT_STRING = 0x03,
177
178 /** Interface descriptor. See libusb_interface_descriptor. */
179 LIBUSB_DT_INTERFACE = 0x04,
180
181 /** Endpoint descriptor. See libusb_endpoint_descriptor. */
182 LIBUSB_DT_ENDPOINT = 0x05,
183
184 /** HID descriptor */
185 LIBUSB_DT_HID = 0x21,
186
187 /** HID report descriptor */
188 LIBUSB_DT_REPORT = 0x22,
189
190 /** Physical descriptor */
191 LIBUSB_DT_PHYSICAL = 0x23,
192
193 /** Hub descriptor */
194 LIBUSB_DT_HUB = 0x29
195};
196
197/* Descriptor sizes per descriptor type */
198#define LIBUSB_DT_DEVICE_SIZE 18
199#define LIBUSB_DT_CONFIG_SIZE 9
200#define LIBUSB_DT_INTERFACE_SIZE 9
201#define LIBUSB_DT_ENDPOINT_SIZE 7
202#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
203#define LIBUSB_DT_HUB_NONVAR_SIZE 7
204
205#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
206#define LIBUSB_ENDPOINT_DIR_MASK 0x80
207
208/** \ingroup desc
209 * Endpoint direction. Values for bit 7 of the
210 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
211 */
212enum libusb_endpoint_direction {
213 /** In: device-to-host */
214 LIBUSB_ENDPOINT_IN = 0x80,
215
216 /** Out: host-to-device */
217 LIBUSB_ENDPOINT_OUT = 0x00
218};
219
220#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
221
222/** \ingroup desc
223 * Endpoint transfer type. Values for bits 0:1 of the
224 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
225 */
226enum libusb_transfer_type {
227 /** Control endpoint */
228 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
229
230 /** Isochronous endpoint */
231 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
232
233 /** Bulk endpoint */
234 LIBUSB_TRANSFER_TYPE_BULK = 2,
235
236 /** Interrupt endpoint */
237 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
238};
239
240/** \ingroup misc
241 * Standard requests, as defined in table 9-3 of the USB2 specifications */
242enum libusb_standard_request {
243 /** Request status of the specific recipient */
244 LIBUSB_REQUEST_GET_STATUS = 0x00,
245
246 /** Clear or disable a specific feature */
247 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
248
249 /* 0x02 is reserved */
250
251 /** Set or enable a specific feature */
252 LIBUSB_REQUEST_SET_FEATURE = 0x03,
253
254 /* 0x04 is reserved */
255
256 /** Set device address for all future accesses */
257 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
258
259 /** Get the specified descriptor */
260 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
261
262 /** Used to update existing descriptors or add new descriptors */
263 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
264
265 /** Get the current device configuration value */
266 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
267
268 /** Set device configuration */
269 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
270
271 /** Return the selected alternate setting for the specified interface */
272 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
273
274 /** Select an alternate interface for the specified interface */
275 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
276
277 /** Set then report an endpoint's synchronization frame */
278 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C
279};
280
281/** \ingroup misc
282 * Request type bits of the
283 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
284 * transfers. */
285enum libusb_request_type {
286 /** Standard */
287 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
288
289 /** Class */
290 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
291
292 /** Vendor */
293 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
294
295 /** Reserved */
296 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
297};
298
299/** \ingroup misc
300 * Recipient bits of the
301 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
302 * transfers. Values 4 through 31 are reserved. */
303enum libusb_request_recipient {
304 /** Device */
305 LIBUSB_RECIPIENT_DEVICE = 0x00,
306
307 /** Interface */
308 LIBUSB_RECIPIENT_INTERFACE = 0x01,
309
310 /** Endpoint */
311 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
312
313 /** Other */
314 LIBUSB_RECIPIENT_OTHER = 0x03
315};
316
317#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
318
319/** \ingroup desc
320 * Synchronization type for isochronous endpoints. Values for bits 2:3 of the
321 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
322 * libusb_endpoint_descriptor.
323 */
324enum libusb_iso_sync_type {
325 /** No synchronization */
326 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
327
328 /** Asynchronous */
329 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
330
331 /** Adaptive */
332 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
333
334 /** Synchronous */
335 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
336};
337
338#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
339
340/** \ingroup desc
341 * Usage type for isochronous endpoints. Values for bits 4:5 of the
342 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
343 * libusb_endpoint_descriptor.
344 */
345enum libusb_iso_usage_type {
346 /** Data endpoint */
347 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
348
349 /** Feedback endpoint */
350 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
351
352 /** Implicit feedback Data endpoint */
353 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2
354};
355
356/** \ingroup desc
357 * A structure representing the standard USB device descriptor. This
358 * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
359 * All multiple-byte fields are represented in host-endian format.
360 */
361struct libusb_device_descriptor {
362 /** Size of this descriptor (in bytes) */
363 uint8_t bLength;
364
365 /** Descriptor type. Will have value
366 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
367 * context. */
368 uint8_t bDescriptorType;
369
370 /** USB specification release number in binary-coded decimal. A value of
371 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
372 uint16_t bcdUSB;
373
374 /** USB-IF class code for the device. See \ref libusb_class_code. */
375 uint8_t bDeviceClass;
376
377 /** USB-IF subclass code for the device, qualified by the bDeviceClass
378 * value */
379 uint8_t bDeviceSubClass;
380
381 /** USB-IF protocol code for the device, qualified by the bDeviceClass and
382 * bDeviceSubClass values */
383 uint8_t bDeviceProtocol;
384
385 /** Maximum packet size for endpoint 0 */
386 uint8_t bMaxPacketSize0;
387
388 /** USB-IF vendor ID */
389 uint16_t idVendor;
390
391 /** USB-IF product ID */
392 uint16_t idProduct;
393
394 /** Device release number in binary-coded decimal */
395 uint16_t bcdDevice;
396
397 /** Index of string descriptor describing manufacturer */
398 uint8_t iManufacturer;
399
400 /** Index of string descriptor describing product */
401 uint8_t iProduct;
402
403 /** Index of string descriptor containing device serial number */
404 uint8_t iSerialNumber;
405
406 /** Number of possible configurations */
407 uint8_t bNumConfigurations;
408};
409
410/** \ingroup desc
411 * A structure representing the standard USB endpoint descriptor. This
412 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
413 * All multiple-byte fields are represented in host-endian format.
414 */
415struct libusb_endpoint_descriptor {
416 /** Size of this descriptor (in bytes) */
417 uint8_t bLength;
418
419 /** Descriptor type. Will have value
420 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
421 * this context. */
422 uint8_t bDescriptorType;
423
424 /** The address of the endpoint described by this descriptor. Bits 0:3 are
425 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
426 * see \ref libusb_endpoint_direction.
427 */
428 uint8_t bEndpointAddress;
429
430 /** Attributes which apply to the endpoint when it is configured using
431 * the bConfigurationValue. Bits 0:1 determine the transfer type and
432 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
433 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
434 * Bits 4:5 are also only used for isochronous endpoints and correspond to
435 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
436 */
437 uint8_t bmAttributes;
438
439 /** Maximum packet size this endpoint is capable of sending/receiving. */
440 uint16_t wMaxPacketSize;
441
442 /** Interval for polling endpoint for data transfers. */
443 uint8_t bInterval;
444
445 /** For audio devices only: the rate at which synchronization feedback
446 * is provided. */
447 uint8_t bRefresh;
448
449 /** For audio devices only: the address if the synch endpoint */
450 uint8_t bSynchAddress;
451
452 /** Extra descriptors. If libusb encounters unknown endpoint descriptors,
453 * it will store them here, should you wish to parse them. */
454 const unsigned char *extra;
455
456 /** Length of the extra descriptors, in bytes. */
457 int extra_length;
458};
459
460/** \ingroup desc
461 * A structure representing the standard USB interface descriptor. This
462 * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
463 * All multiple-byte fields are represented in host-endian format.
464 */
465struct libusb_interface_descriptor {
466 /** Size of this descriptor (in bytes) */
467 uint8_t bLength;
468
469 /** Descriptor type. Will have value
470 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
471 * in this context. */
472 uint8_t bDescriptorType;
473
474 /** Number of this interface */
475 uint8_t bInterfaceNumber;
476
477 /** Value used to select this alternate setting for this interface */
478 uint8_t bAlternateSetting;
479
480 /** Number of endpoints used by this interface (excluding the control
481 * endpoint). */
482 uint8_t bNumEndpoints;
483
484 /** USB-IF class code for this interface. See \ref libusb_class_code. */
485 uint8_t bInterfaceClass;
486
487 /** USB-IF subclass code for this interface, qualified by the
488 * bInterfaceClass value */
489 uint8_t bInterfaceSubClass;
490
491 /** USB-IF protocol code for this interface, qualified by the
492 * bInterfaceClass and bInterfaceSubClass values */
493 uint8_t bInterfaceProtocol;
494
495 /** Index of string descriptor describing this interface */
496 uint8_t iInterface;
497
498 /** Array of endpoint descriptors. This length of this array is determined
499 * by the bNumEndpoints field. */
500 const struct libusb_endpoint_descriptor *endpoint;
501
502 /** Extra descriptors. If libusb encounters unknown interface descriptors,
503 * it will store them here, should you wish to parse them. */
504 const unsigned char *extra;
505
506 /** Length of the extra descriptors, in bytes. */
507 int extra_length;
508};
509
510/** \ingroup desc
511 * A collection of alternate settings for a particular USB interface.
512 */
513struct libusb_interface {
514 /** Array of interface descriptors. The length of this array is determined
515 * by the num_altsetting field. */
516 const struct libusb_interface_descriptor *altsetting;
517
518 /** The number of alternate settings that belong to this interface */
519 int num_altsetting;
520};
521
522/** \ingroup desc
523 * A structure representing the standard USB configuration descriptor. This
524 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
525 * All multiple-byte fields are represented in host-endian format.
526 */
527struct libusb_config_descriptor {
528 /** Size of this descriptor (in bytes) */
529 uint8_t bLength;
530
531 /** Descriptor type. Will have value
532 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
533 * in this context. */
534 uint8_t bDescriptorType;
535
536 /** Total length of data returned for this configuration */
537 uint16_t wTotalLength;
538
539 /** Number of interfaces supported by this configuration */
540 uint8_t bNumInterfaces;
541
542 /** Identifier value for this configuration */
543 uint8_t bConfigurationValue;
544
545 /** Index of string descriptor describing this configuration */
546 uint8_t iConfiguration;
547
548 /** Configuration characteristics */
549 uint8_t bmAttributes;
550
551 /** Maximum power consumption of the USB device from this bus in this
552 * configuration when the device is fully opreation. Expressed in units
553 * of 2 mA. */
554 uint8_t MaxPower;
555
556 /** Array of interfaces supported by this configuration. The length of
557 * this array is determined by the bNumInterfaces field. */
558 const struct libusb_interface *interface;
559
560 /** Extra descriptors. If libusb encounters unknown configuration
561 * descriptors, it will store them here, should you wish to parse them. */
562 const unsigned char *extra;
563
564 /** Length of the extra descriptors, in bytes. */
565 int extra_length;
566};
567
568/** \ingroup asyncio
569 * Setup packet for control transfers. */
570struct libusb_control_setup {
571 /** Request type. Bits 0:4 determine recipient, see
572 * \ref libusb_request_recipient. Bits 5:6 determine type, see
573 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
574 * \ref libusb_endpoint_direction.
575 */
576 uint8_t bmRequestType;
577
578 /** Request. If the type bits of bmRequestType are equal to
579 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
580 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
581 * \ref libusb_standard_request. For other cases, use of this field is
582 * application-specific. */
583 uint8_t bRequest;
584
585 /** Value. Varies according to request */
586 uint16_t wValue;
587
588 /** Index. Varies according to request, typically used to pass an index
589 * or offset */
590 uint16_t wIndex;
591
592 /** Number of bytes to transfer */
593 uint16_t wLength;
594};
595
596#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
597
598/* libusb */
599
600struct libusb_context;
601struct libusb_device;
602struct libusb_device_handle;
603
604/** \ingroup lib
605 * Structure representing a libusb session. The concept of individual libusb
606 * sessions allows for your program to use two libraries (or dynamically
607 * load two modules) which both independently use libusb. This will prevent
608 * interference between the individual libusb users - for example
609 * libusb_set_debug() will not affect the other user of the library, and
610 * libusb_exit() will not destroy resources that the other user is still
611 * using.
612 *
613 * Sessions are created by libusb_init() and destroyed through libusb_exit().
614 * If your application is guaranteed to only ever include a single libusb
615 * user (i.e. you), you do not have to worry about contexts: pass NULL in
616 * every function call where a context is required. The default context
617 * will be used.
618 *
619 * For more information, see \ref contexts.
620 */
621typedef struct libusb_context libusb_context;
622
623/** \ingroup dev
624 * Structure representing a USB device detected on the system. This is an
625 * opaque type for which you are only ever provided with a pointer, usually
626 * originating from libusb_get_device_list().
627 *
628 * Certain operations can be performed on a device, but in order to do any
629 * I/O you will have to first obtain a device handle using libusb_open().
630 *
631 * Devices are reference counted with libusb_device_ref() and
632 * libusb_device_unref(), and are freed when the reference count reaches 0.
633 * New devices presented by libusb_get_device_list() have a reference count of
634 * 1, and libusb_free_device_list() can optionally decrease the reference count
635 * on all devices in the list. libusb_open() adds another reference which is
636 * later destroyed by libusb_close().
637 */
638typedef struct libusb_device libusb_device;
639
640
641/** \ingroup dev
642 * Structure representing a handle on a USB device. This is an opaque type for
643 * which you are only ever provided with a pointer, usually originating from
644 * libusb_open().
645 *
646 * A device handle is used to perform I/O and other operations. When finished
647 * with a device handle, you should call libusb_close().
648 */
649typedef struct libusb_device_handle libusb_device_handle;
650
651/** \ingroup misc
652 * Error codes. Most libusb functions return 0 on success or one of these
653 * codes on failure.
654 * You can use libusb_strerror() to retrieve a short string description of
655 * a libusb_error enumeration value.
656 */
657enum libusb_error {
658 /** Success (no error) */
659 LIBUSB_SUCCESS = 0,
660
661 /** Input/output error */
662 LIBUSB_ERROR_IO = -1,
663
664 /** Invalid parameter */
665 LIBUSB_ERROR_INVALID_PARAM = -2,
666
667 /** Access denied (insufficient permissions) */
668 LIBUSB_ERROR_ACCESS = -3,
669
670 /** No such device (it may have been disconnected) */
671 LIBUSB_ERROR_NO_DEVICE = -4,
672
673 /** Entity not found */
674 LIBUSB_ERROR_NOT_FOUND = -5,
675
676 /** Resource busy */
677 LIBUSB_ERROR_BUSY = -6,
678
679 /** Operation timed out */
680 LIBUSB_ERROR_TIMEOUT = -7,
681
682 /** Overflow */
683 LIBUSB_ERROR_OVERFLOW = -8,
684
685 /** Pipe error */
686 LIBUSB_ERROR_PIPE = -9,
687
688 /** System call interrupted (perhaps due to signal) */
689 LIBUSB_ERROR_INTERRUPTED = -10,
690
691 /** Insufficient memory */
692 LIBUSB_ERROR_NO_MEM = -11,
693
694 /** Operation not supported or unimplemented on this platform */
695 LIBUSB_ERROR_NOT_SUPPORTED = -12,
696
697 /** Other error */
698 LIBUSB_ERROR_OTHER = -99
699
700 /* IMPORTANT: when adding new values to this enum, remember to
701 update the libusb_strerror() function implementation! */
702};
703
704/** \ingroup asyncio
705 * Transfer status codes */
706enum libusb_transfer_status {
707 /** Transfer completed without error. Note that this does not indicate
708 * that the entire amount of requested data was transferred. */
709 LIBUSB_TRANSFER_COMPLETED,
710
711 /** Transfer failed */
712 LIBUSB_TRANSFER_ERROR,
713
714 /** Transfer timed out */
715 LIBUSB_TRANSFER_TIMED_OUT,
716
717 /** Transfer was cancelled */
718 LIBUSB_TRANSFER_CANCELLED,
719
720 /** For bulk/interrupt endpoints: halt condition detected (endpoint
721 * stalled). For control endpoints: control request not supported. */
722 LIBUSB_TRANSFER_STALL,
723
724 /** Device was disconnected */
725 LIBUSB_TRANSFER_NO_DEVICE,
726
727 /** Device sent more data than requested */
728 LIBUSB_TRANSFER_OVERFLOW
729};
730
731/** \ingroup asyncio
732 * libusb_transfer.flags values */
733enum libusb_transfer_flags {
734 /** Report short frames as errors */
735 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
736
737 /** Automatically free() transfer buffer during libusb_free_transfer() */
738 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
739
740 /** Automatically call libusb_free_transfer() after callback returns.
741 * If this flag is set, it is illegal to call libusb_free_transfer()
742 * from your transfer callback, as this will result in a double-free
743 * when this flag is acted upon. */
744 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2
745};
746
747/** \ingroup asyncio
748 * Isochronous packet descriptor. */
749struct libusb_iso_packet_descriptor {
750 /** Length of data to request in this packet */
751 unsigned int length;
752
753 /** Amount of data that was actually transferred */
754 unsigned int actual_length;
755
756 /** Status code for this packet */
757 enum libusb_transfer_status status;
758};
759
760struct libusb_transfer;
761
762/** \ingroup asyncio
763 * Asynchronous transfer callback function type. When submitting asynchronous
764 * transfers, you pass a pointer to a callback function of this type via the
765 * \ref libusb_transfer::callback "callback" member of the libusb_transfer
766 * structure. libusb will call this function later, when the transfer has
767 * completed or failed. See \ref asyncio for more information.
768 * \param transfer The libusb_transfer struct the callback function is being
769 * notified about.
770 */
771typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
772
773/** \ingroup asyncio
774 * The generic USB transfer structure. The user populates this structure and
775 * then submits it in order to request a transfer. After the transfer has
776 * completed, the library populates the transfer with the results and passes
777 * it back to the user.
778 */
779struct libusb_transfer {
780 /** Handle of the device that this transfer will be submitted to */
781 libusb_device_handle *dev_handle;
782
783 /** A bitwise OR combination of \ref libusb_transfer_flags. */
784 uint8_t flags;
785
786 /** Address of the endpoint where this transfer will be sent. */
787 unsigned char endpoint;
788
789 /** Type of the endpoint from \ref libusb_transfer_type */
790 unsigned char type;
791
792 /** Timeout for this transfer in millseconds. A value of 0 indicates no
793 * timeout. */
794 unsigned int timeout;
795
796 /** The status of the transfer. Read-only, and only for use within
797 * transfer callback function.
798 *
799 * If this is an isochronous transfer, this field may read COMPLETED even
800 * if there were errors in the frames. Use the
801 * \ref libusb_iso_packet_descriptor::status "status" field in each packet
802 * to determine if errors occurred. */
803 enum libusb_transfer_status status;
804
805 /** Length of the data buffer */
806 int length;
807
808 /** Actual length of data that was transferred. Read-only, and only for
809 * use within transfer callback function. Not valid for isochronous
810 * endpoint transfers. */
811 int actual_length;
812
813 /** Callback function. This will be invoked when the transfer completes,
814 * fails, or is cancelled. */
815 libusb_transfer_cb_fn callback;
816
817 /** User context data to pass to the callback function. */
818 void *user_data;
819
820 /** Data buffer */
821 unsigned char *buffer;
822
823 /** Number of isochronous packets. Only used for I/O with isochronous
824 * endpoints. */
825 int num_iso_packets;
826
827 /** Isochronous packet descriptors, for isochronous transfers only. */
828 struct libusb_iso_packet_descriptor iso_packet_desc
829#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
830 [] /* valid C99 code */
831#else
832 [0] /* non-standard, but usually working code */
833#endif
834 ;
835};
836
837int LIBUSB_CALL libusb_init(libusb_context **ctx);
838void LIBUSB_CALL libusb_exit(libusb_context *ctx);
839void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
840const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
841
842ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
843 libusb_device ***list);
844void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
845 int unref_devices);
846libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
847void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
848
849int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
850 int *config);
851int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
852 struct libusb_device_descriptor *desc);
853int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
854 struct libusb_config_descriptor **config);
855int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
856 uint8_t config_index, struct libusb_config_descriptor **config);
857int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
858 uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
859void LIBUSB_CALL libusb_free_config_descriptor(
860 struct libusb_config_descriptor *config);
861uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
862uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
863int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
864 unsigned char endpoint);
865int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
866 unsigned char endpoint);
867
868int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
869void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
870libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
871
872int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
873 int configuration);
874int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
875 int interface_number);
876int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
877 int interface_number);
878
879libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
880 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
881
882int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
883 int interface_number, int alternate_setting);
884int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
885 unsigned char endpoint);
886int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
887
888int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
889 int interface_number);
890int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
891 int interface_number);
892int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
893 int interface_number);
894
895/* async I/O */
896
897/** \ingroup asyncio
898 * Get the data section of a control transfer. This convenience function is here
899 * to remind you that the data does not start until 8 bytes into the actual
900 * buffer, as the setup packet comes first.
901 *
902 * Calling this function only makes sense from a transfer callback function,
903 * or situations where you have already allocated a suitably sized buffer at
904 * transfer->buffer.
905 *
906 * \param transfer a transfer
907 * \returns pointer to the first byte of the data section
908 */
909static inline unsigned char *libusb_control_transfer_get_data(
910 struct libusb_transfer *transfer)
911{
912 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
913}
914
915/** \ingroup asyncio
916 * Get the control setup packet of a control transfer. This convenience
917 * function is here to remind you that the control setup occupies the first
918 * 8 bytes of the transfer data buffer.
919 *
920 * Calling this function only makes sense from a transfer callback function,
921 * or situations where you have already allocated a suitably sized buffer at
922 * transfer->buffer.
923 *
924 * \param transfer a transfer
925 * \returns a casted pointer to the start of the transfer data buffer
926 */
927static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
928 struct libusb_transfer *transfer)
929{
930 return (struct libusb_control_setup *) transfer->buffer;
931}
932
933/** \ingroup asyncio
934 * Helper function to populate the setup packet (first 8 bytes of the data
935 * buffer) for a control transfer. The wIndex, wValue and wLength values should
936 * be given in host-endian byte order.
937 *
938 * \param buffer buffer to output the setup packet into
939 * \param bmRequestType see the
940 * \ref libusb_control_setup::bmRequestType "bmRequestType" field of
941 * \ref libusb_control_setup
942 * \param bRequest see the
943 * \ref libusb_control_setup::bRequest "bRequest" field of
944 * \ref libusb_control_setup
945 * \param wValue see the
946 * \ref libusb_control_setup::wValue "wValue" field of
947 * \ref libusb_control_setup
948 * \param wIndex see the
949 * \ref libusb_control_setup::wIndex "wIndex" field of
950 * \ref libusb_control_setup
951 * \param wLength see the
952 * \ref libusb_control_setup::wLength "wLength" field of
953 * \ref libusb_control_setup
954 */
955static inline void libusb_fill_control_setup(unsigned char *buffer,
956 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
957 uint16_t wLength)
958{
959 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
960 setup->bmRequestType = bmRequestType;
961 setup->bRequest = bRequest;
962 setup->wValue = libusb_cpu_to_le16(wValue);
963 setup->wIndex = libusb_cpu_to_le16(wIndex);
964 setup->wLength = libusb_cpu_to_le16(wLength);
965}
966
967struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
968int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
969int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
970void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
971
972/** \ingroup asyncio
973 * Helper function to populate the required \ref libusb_transfer fields
974 * for a control transfer.
975 *
976 * If you pass a transfer buffer to this function, the first 8 bytes will
977 * be interpreted as a control setup packet, and the wLength field will be
978 * used to automatically populate the \ref libusb_transfer::length "length"
979 * field of the transfer. Therefore the recommended approach is:
980 * -# Allocate a suitably sized data buffer (including space for control setup)
981 * -# Call libusb_fill_control_setup()
982 * -# If this is a host-to-device transfer with a data stage, put the data
983 * in place after the setup packet
984 * -# Call this function
985 * -# Call libusb_submit_transfer()
986 *
987 * It is also legal to pass a NULL buffer to this function, in which case this
988 * function will not attempt to populate the length field. Remember that you
989 * must then populate the buffer and length fields later.
990 *
991 * \param transfer the transfer to populate
992 * \param dev_handle handle of the device that will handle the transfer
993 * \param buffer data buffer. If provided, this function will interpret the
994 * first 8 bytes as a setup packet and infer the transfer length from that.
995 * \param callback callback function to be invoked on transfer completion
996 * \param user_data user data to pass to callback function
997 * \param timeout timeout for the transfer in milliseconds
998 */
999static inline void libusb_fill_control_transfer(
1000 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1001 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
1002 unsigned int timeout)
1003{
1004 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
1005 transfer->dev_handle = dev_handle;
1006 transfer->endpoint = 0;
1007 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
1008 transfer->timeout = timeout;
1009 transfer->buffer = buffer;
1010 if (setup)
1011 transfer->length = LIBUSB_CONTROL_SETUP_SIZE
1012 + libusb_le16_to_cpu(setup->wLength);
1013 transfer->user_data = user_data;
1014 transfer->callback = callback;
1015}
1016
1017/** \ingroup asyncio
1018 * Helper function to populate the required \ref libusb_transfer fields
1019 * for a bulk transfer.
1020 *
1021 * \param transfer the transfer to populate
1022 * \param dev_handle handle of the device that will handle the transfer
1023 * \param endpoint address of the endpoint where this transfer will be sent
1024 * \param buffer data buffer
1025 * \param length length of data buffer
1026 * \param callback callback function to be invoked on transfer completion
1027 * \param user_data user data to pass to callback function
1028 * \param timeout timeout for the transfer in milliseconds
1029 */
1030static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
1031 libusb_device_handle *dev_handle, unsigned char endpoint,
1032 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
1033 void *user_data, unsigned int timeout)
1034{
1035 transfer->dev_handle = dev_handle;
1036 transfer->endpoint = endpoint;
1037 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
1038 transfer->timeout = timeout;
1039 transfer->buffer = buffer;
1040 transfer->length = length;
1041 transfer->user_data = user_data;
1042 transfer->callback = callback;
1043}
1044
1045/** \ingroup asyncio
1046 * Helper function to populate the required \ref libusb_transfer fields
1047 * for an interrupt transfer.
1048 *
1049 * \param transfer the transfer to populate
1050 * \param dev_handle handle of the device that will handle the transfer
1051 * \param endpoint address of the endpoint where this transfer will be sent
1052 * \param buffer data buffer
1053 * \param length length of data buffer
1054 * \param callback callback function to be invoked on transfer completion
1055 * \param user_data user data to pass to callback function
1056 * \param timeout timeout for the transfer in milliseconds
1057 */
1058static inline void libusb_fill_interrupt_transfer(
1059 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1060 unsigned char endpoint, unsigned char *buffer, int length,
1061 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1062{
1063 transfer->dev_handle = dev_handle;
1064 transfer->endpoint = endpoint;
1065 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
1066 transfer->timeout = timeout;
1067 transfer->buffer = buffer;
1068 transfer->length = length;
1069 transfer->user_data = user_data;
1070 transfer->callback = callback;
1071}
1072
1073/** \ingroup asyncio
1074 * Helper function to populate the required \ref libusb_transfer fields
1075 * for an isochronous transfer.
1076 *
1077 * \param transfer the transfer to populate
1078 * \param dev_handle handle of the device that will handle the transfer
1079 * \param endpoint address of the endpoint where this transfer will be sent
1080 * \param buffer data buffer
1081 * \param length length of data buffer
1082 * \param num_iso_packets the number of isochronous packets
1083 * \param callback callback function to be invoked on transfer completion
1084 * \param user_data user data to pass to callback function
1085 * \param timeout timeout for the transfer in milliseconds
1086 */
1087static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
1088 libusb_device_handle *dev_handle, unsigned char endpoint,
1089 unsigned char *buffer, int length, int num_iso_packets,
1090 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1091{
1092 transfer->dev_handle = dev_handle;
1093 transfer->endpoint = endpoint;
1094 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
1095 transfer->timeout = timeout;
1096 transfer->buffer = buffer;
1097 transfer->length = length;
1098 transfer->num_iso_packets = num_iso_packets;
1099 transfer->user_data = user_data;
1100 transfer->callback = callback;
1101}
1102
1103/** \ingroup asyncio
1104 * Convenience function to set the length of all packets in an isochronous
1105 * transfer, based on the num_iso_packets field in the transfer structure.
1106 *
1107 * \param transfer a transfer
1108 * \param length the length to set in each isochronous packet descriptor
1109 * \see libusb_get_max_packet_size()
1110 */
1111static inline void libusb_set_iso_packet_lengths(
1112 struct libusb_transfer *transfer, unsigned int length)
1113{
1114 int i;
1115 for (i = 0; i < transfer->num_iso_packets; i++)
1116 transfer->iso_packet_desc[i].length = length;
1117}
1118
1119/** \ingroup asyncio
1120 * Convenience function to locate the position of an isochronous packet
1121 * within the buffer of an isochronous transfer.
1122 *
1123 * This is a thorough function which loops through all preceding packets,
1124 * accumulating their lengths to find the position of the specified packet.
1125 * Typically you will assign equal lengths to each packet in the transfer,
1126 * and hence the above method is sub-optimal. You may wish to use
1127 * libusb_get_iso_packet_buffer_simple() instead.
1128 *
1129 * \param transfer a transfer
1130 * \param packet the packet to return the address of
1131 * \returns the base address of the packet buffer inside the transfer buffer,
1132 * or NULL if the packet does not exist.
1133 * \see libusb_get_iso_packet_buffer_simple()
1134 */
1135static inline unsigned char *libusb_get_iso_packet_buffer(
1136 struct libusb_transfer *transfer, unsigned int packet)
1137{
1138 int i;
1139 size_t offset = 0;
1140 int _packet;
1141
1142 /* oops..slight bug in the API. packet is an unsigned int, but we use
1143 * signed integers almost everywhere else. range-check and convert to
1144 * signed to avoid compiler warnings. FIXME for libusb-2. */
1145 if (packet > INT_MAX)
1146 return NULL;
1147 _packet = packet;
1148
1149 if (_packet >= transfer->num_iso_packets)
1150 return NULL;
1151
1152 for (i = 0; i < _packet; i++)
1153 offset += transfer->iso_packet_desc[i].length;
1154
1155 return transfer->buffer + offset;
1156}
1157
1158/** \ingroup asyncio
1159 * Convenience function to locate the position of an isochronous packet
1160 * within the buffer of an isochronous transfer, for transfers where each
1161 * packet is of identical size.
1162 *
1163 * This function relies on the assumption that every packet within the transfer
1164 * is of identical size to the first packet. Calculating the location of
1165 * the packet buffer is then just a simple calculation:
1166 * <tt>buffer + (packet_size * packet)</tt>
1167 *
1168 * Do not use this function on transfers other than those that have identical
1169 * packet lengths for each packet.
1170 *
1171 * \param transfer a transfer
1172 * \param packet the packet to return the address of
1173 * \returns the base address of the packet buffer inside the transfer buffer,
1174 * or NULL if the packet does not exist.
1175 * \see libusb_get_iso_packet_buffer()
1176 */
1177static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1178 struct libusb_transfer *transfer, unsigned int packet)
1179{
1180 int _packet;
1181
1182 /* oops..slight bug in the API. packet is an unsigned int, but we use
1183 * signed integers almost everywhere else. range-check and convert to
1184 * signed to avoid compiler warnings. FIXME for libusb-2. */
1185 if (packet > INT_MAX)
1186 return NULL;
1187 _packet = packet;
1188
1189 if (_packet >= transfer->num_iso_packets)
1190 return NULL;
1191
1192 return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
1193}
1194
1195/* sync I/O */
1196
1197int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
1198 uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1199 unsigned char *data, uint16_t wLength, unsigned int timeout);
1200
1201int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
1202 unsigned char endpoint, unsigned char *data, int length,
1203 int *actual_length, unsigned int timeout);
1204
1205int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
1206 unsigned char endpoint, unsigned char *data, int length,
1207 int *actual_length, unsigned int timeout);
1208
1209/** \ingroup desc
1210 * Retrieve a descriptor from the default control pipe.
1211 * This is a convenience function which formulates the appropriate control
1212 * message to retrieve the descriptor.
1213 *
1214 * \param dev a device handle
1215 * \param desc_type the descriptor type, see \ref libusb_descriptor_type
1216 * \param desc_index the index of the descriptor to retrieve
1217 * \param data output buffer for descriptor
1218 * \param length size of data buffer
1219 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1220 */
1221static inline int libusb_get_descriptor(libusb_device_handle *dev,
1222 uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
1223{
1224 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
1225 LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
1226 (uint16_t) length, 1000);
1227}
1228
1229/** \ingroup desc
1230 * Retrieve a descriptor from a device.
1231 * This is a convenience function which formulates the appropriate control
1232 * message to retrieve the descriptor. The string returned is Unicode, as
1233 * detailed in the USB specifications.
1234 *
1235 * \param dev a device handle
1236 * \param desc_index the index of the descriptor to retrieve
1237 * \param langid the language ID for the string descriptor
1238 * \param data output buffer for descriptor
1239 * \param length size of data buffer
1240 * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1241 * \see libusb_get_string_descriptor_ascii()
1242 */
1243static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
1244 uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
1245{
1246 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
1247 LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | desc_index,
1248 langid, data, (uint16_t) length, 1000);
1249}
1250
1251int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
1252 uint8_t desc_index, unsigned char *data, int length);
1253
1254/* polling and timeouts */
1255
1256int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
1257void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
1258void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
1259int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
1260int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
1261void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
1262void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
1263int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
1264
1265int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
1266 struct timeval *tv);
1267int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
1268int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
1269 struct timeval *tv);
1270int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
1271int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
1272 struct timeval *tv);
1273
1274/** \ingroup poll
1275 * File descriptor for polling
1276 */
1277struct libusb_pollfd {
1278 /** Numeric file descriptor */
1279 int fd;
1280
1281 /** Event flags to poll for from <poll.h>. POLLIN indicates that you
1282 * should monitor this file descriptor for becoming ready to read from,
1283 * and POLLOUT indicates that you should monitor this file descriptor for
1284 * nonblocking write readiness. */
1285 short events;
1286};
1287
1288/** \ingroup poll
1289 * Callback function, invoked when a new file descriptor should be added
1290 * to the set of file descriptors monitored for events.
1291 * \param fd the new file descriptor
1292 * \param events events to monitor for, see \ref libusb_pollfd for a
1293 * description
1294 * \param user_data User data pointer specified in
1295 * libusb_set_pollfd_notifiers() call
1296 * \see libusb_set_pollfd_notifiers()
1297 */
1298typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
1299 void *user_data);
1300
1301/** \ingroup poll
1302 * Callback function, invoked when a file descriptor should be removed from
1303 * the set of file descriptors being monitored for events. After returning
1304 * from this callback, do not use that file descriptor again.
1305 * \param fd the file descriptor to stop monitoring
1306 * \param user_data User data pointer specified in
1307 * libusb_set_pollfd_notifiers() call
1308 * \see libusb_set_pollfd_notifiers()
1309 */
1310typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
1311
1312const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
1313 libusb_context *ctx);
1314void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
1315 libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
1316 void *user_data);
1317
1318#ifdef __cplusplus
1319}
1320#endif
1321
1322#endif