AgIsoStack++
A control-function-focused implementation of the major ISOBUS and J1939 protocols
Loading...
Searching...
No Matches
libusb.h
1/*
2 * Public libusb header file
3 * Copyright © 2001 Johannes Erdfelt <[email protected]>
4 * Copyright © 2007-2008 Daniel Drake <[email protected]>
5 * Copyright © 2012 Pete Batard <[email protected]>
6 * Copyright © 2012 Nathan Hjelm <[email protected]>
7 * For more information, please visit: http://libusb.info
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24// clang-format off
26
27#ifndef LIBUSB_H
28#define LIBUSB_H
29
30#ifdef _MSC_VER
31/* on MS environments, the inline keyword is available in C++ only */
32#if !defined(__cplusplus)
33#define inline __inline
34#endif
35/* ssize_t is also not available (copy/paste from MinGW) */
36#ifndef _SSIZE_T_DEFINED
37#define _SSIZE_T_DEFINED
38#undef ssize_t
39#ifdef _WIN64
40 typedef __int64 ssize_t;
41#else
42 typedef int ssize_t;
43#endif /* _WIN64 */
44#endif /* _SSIZE_T_DEFINED */
45#endif /* _MSC_VER */
46
47/* stdint.h is not available on older MSVC */
48#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
49typedef unsigned __int8 uint8_t;
50typedef unsigned __int16 uint16_t;
51typedef unsigned __int32 uint32_t;
52#else
53#include <stdint.h>
54#endif
55
56#if !defined(_WIN32_WCE)
57#include <sys/types.h>
58#endif
59
60#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__)
61#include <sys/time.h>
62#endif
63
64#include <time.h>
65#include <limits.h>
66
67#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
68#define ZERO_SIZED_ARRAY /* [] - valid C99 code */
69#else
70#define ZERO_SIZED_ARRAY 0 /* [0] - non-standard, but usually working code */
71#endif
72
73/* 'interface' might be defined as a macro on Windows, so we need to
74 * undefine it so as not to break the current libusb API, because
75 * libusb_config_descriptor has an 'interface' member
76 * As this can be problematic if you include windows.h after libusb.h
77 * in your sources, we force windows.h to be included first. */
78#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
79#include <windows.h>
80#if defined(interface)
81#undef interface
82#endif
83#if !defined(__CYGWIN__)
84#include <winsock.h>
85#endif
86#endif
87
88#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
89#define LIBUSB_DEPRECATED_FOR(f) \
90 __attribute__((deprecated("Use " #f " instead")))
91#elif __GNUC__ >= 3
92#define LIBUSB_DEPRECATED_FOR(f) __attribute__((deprecated))
93#else
94#define LIBUSB_DEPRECATED_FOR(f)
95#endif /* __GNUC__ */
96
122/* LIBUSB_CALL must be defined on both definition and declaration of libusb
123 * functions. You'd think that declaration would be enough, but cygwin will
124 * complain about conflicting types unless both are marked this way.
125 * The placement of this macro is important too; it must appear after the
126 * return type, before the function name. See internal documentation for
127 * API_EXPORTED.
128 */
129#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
130#define LIBUSB_CALL WINAPI
131#else
132#define LIBUSB_CALL
133#endif
134
155#define LIBUSB_API_VERSION 0x01000106
156
157/* The following is kept for compatibility, but will be deprecated in the future */
158#define LIBUSBX_API_VERSION LIBUSB_API_VERSION
159
160#ifdef __cplusplus
161extern "C" {
162#endif
163
172static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
173{
174 union {
175 uint8_t b8[2];
176 uint16_t b16;
177 } _tmp;
178 _tmp.b8[1] = (uint8_t) (x >> 8);
179 _tmp.b8[0] = (uint8_t) (x & 0xff);
180 return _tmp.b16;
181}
182
191#define libusb_le16_to_cpu libusb_cpu_to_le16
192
193/* standard USB stuff */
194
197enum libusb_class_code {
202 LIBUSB_CLASS_PER_INTERFACE = 0,
203
205 LIBUSB_CLASS_AUDIO = 1,
206
208 LIBUSB_CLASS_COMM = 2,
209
211 LIBUSB_CLASS_HID = 3,
212
214 LIBUSB_CLASS_PHYSICAL = 5,
215
217 LIBUSB_CLASS_PRINTER = 7,
218
220 LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
221 LIBUSB_CLASS_IMAGE = 6,
222
224 LIBUSB_CLASS_MASS_STORAGE = 8,
225
227 LIBUSB_CLASS_HUB = 9,
228
230 LIBUSB_CLASS_DATA = 10,
231
233 LIBUSB_CLASS_SMART_CARD = 0x0b,
234
236 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
237
239 LIBUSB_CLASS_VIDEO = 0x0e,
240
242 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
243
245 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
246
248 LIBUSB_CLASS_WIRELESS = 0xe0,
249
251 LIBUSB_CLASS_APPLICATION = 0xfe,
252
254 LIBUSB_CLASS_VENDOR_SPEC = 0xff
255};
256
259enum libusb_descriptor_type {
261 LIBUSB_DT_DEVICE = 0x01,
262
264 LIBUSB_DT_CONFIG = 0x02,
265
267 LIBUSB_DT_STRING = 0x03,
268
270 LIBUSB_DT_INTERFACE = 0x04,
271
273 LIBUSB_DT_ENDPOINT = 0x05,
274
276 LIBUSB_DT_BOS = 0x0f,
277
279 LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
280
282 LIBUSB_DT_HID = 0x21,
283
285 LIBUSB_DT_REPORT = 0x22,
286
288 LIBUSB_DT_PHYSICAL = 0x23,
289
291 LIBUSB_DT_HUB = 0x29,
292
294 LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
295
297 LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
298};
299
300/* Descriptor sizes per descriptor type */
301#define LIBUSB_DT_DEVICE_SIZE 18
302#define LIBUSB_DT_CONFIG_SIZE 9
303#define LIBUSB_DT_INTERFACE_SIZE 9
304#define LIBUSB_DT_ENDPOINT_SIZE 7
305#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
306#define LIBUSB_DT_HUB_NONVAR_SIZE 7
307#define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
308#define LIBUSB_DT_BOS_SIZE 5
309#define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3
310
311/* BOS descriptor sizes */
312#define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7
313#define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10
314#define LIBUSB_BT_CONTAINER_ID_SIZE 20
315
316/* We unwrap the BOS => define its max size */
317#define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\
318 (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\
319 (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\
320 (LIBUSB_BT_CONTAINER_ID_SIZE))
321
322#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
323#define LIBUSB_ENDPOINT_DIR_MASK 0x80
324
329enum libusb_endpoint_direction {
331 LIBUSB_ENDPOINT_IN = 0x80,
332
334 LIBUSB_ENDPOINT_OUT = 0x00
335};
336
337#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
338
343enum libusb_transfer_type {
345 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
346
348 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
349
351 LIBUSB_TRANSFER_TYPE_BULK = 2,
352
354 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
355
357 LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4,
358};
359
362enum libusb_standard_request {
364 LIBUSB_REQUEST_GET_STATUS = 0x00,
365
367 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
368
369 /* 0x02 is reserved */
370
372 LIBUSB_REQUEST_SET_FEATURE = 0x03,
373
374 /* 0x04 is reserved */
375
377 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
378
380 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
381
383 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
384
386 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
387
389 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
390
392 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
393
395 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
396
398 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
399
401 LIBUSB_REQUEST_SET_SEL = 0x30,
402
405 LIBUSB_SET_ISOCH_DELAY = 0x31,
406};
407
412enum libusb_request_type {
414 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
415
417 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
418
420 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
421
423 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
424};
425
430enum libusb_request_recipient {
432 LIBUSB_RECIPIENT_DEVICE = 0x00,
433
435 LIBUSB_RECIPIENT_INTERFACE = 0x01,
436
438 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
439
441 LIBUSB_RECIPIENT_OTHER = 0x03,
442};
443
444#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
445
451enum libusb_iso_sync_type {
453 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
454
456 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
457
459 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
460
462 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
463};
464
465#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
466
472enum libusb_iso_usage_type {
474 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
475
477 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
478
480 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
481};
482
488struct libusb_device_descriptor {
490 uint8_t bLength;
491
495 uint8_t bDescriptorType;
496
499 uint16_t bcdUSB;
500
502 uint8_t bDeviceClass;
503
506 uint8_t bDeviceSubClass;
507
510 uint8_t bDeviceProtocol;
511
513 uint8_t bMaxPacketSize0;
514
516 uint16_t idVendor;
517
519 uint16_t idProduct;
520
522 uint16_t bcdDevice;
523
525 uint8_t iManufacturer;
526
528 uint8_t iProduct;
529
531 uint8_t iSerialNumber;
532
534 uint8_t bNumConfigurations;
535};
536
542struct libusb_endpoint_descriptor {
544 uint8_t bLength;
545
549 uint8_t bDescriptorType;
550
555 uint8_t bEndpointAddress;
556
564 uint8_t bmAttributes;
565
567 uint16_t wMaxPacketSize;
568
570 uint8_t bInterval;
571
574 uint8_t bRefresh;
575
577 uint8_t bSynchAddress;
578
581 const unsigned char *extra;
582
584 int extra_length;
585};
586
592struct libusb_interface_descriptor {
594 uint8_t bLength;
595
599 uint8_t bDescriptorType;
600
602 uint8_t bInterfaceNumber;
603
605 uint8_t bAlternateSetting;
606
609 uint8_t bNumEndpoints;
610
612 uint8_t bInterfaceClass;
613
616 uint8_t bInterfaceSubClass;
617
620 uint8_t bInterfaceProtocol;
621
623 uint8_t iInterface;
624
627 const struct libusb_endpoint_descriptor *endpoint;
628
631 const unsigned char *extra;
632
634 int extra_length;
635};
636
640struct libusb_interface {
643 const struct libusb_interface_descriptor *altsetting;
644
646 int num_altsetting;
647};
648
654struct libusb_config_descriptor {
656 uint8_t bLength;
657
661 uint8_t bDescriptorType;
662
664 uint16_t wTotalLength;
665
667 uint8_t bNumInterfaces;
668
670 uint8_t bConfigurationValue;
671
673 uint8_t iConfiguration;
674
676 uint8_t bmAttributes;
677
682 uint8_t MaxPower;
683
686 const struct libusb_interface *interface;
687
690 const unsigned char *extra;
691
693 int extra_length;
694};
695
702struct libusb_ss_endpoint_companion_descriptor {
703
705 uint8_t bLength;
706
710 uint8_t bDescriptorType;
711
712
715 uint8_t bMaxBurst;
716
721 uint8_t bmAttributes;
722
725 uint16_t wBytesPerInterval;
726};
727
733struct libusb_bos_dev_capability_descriptor {
735 uint8_t bLength;
739 uint8_t bDescriptorType;
741 uint8_t bDevCapabilityType;
743 uint8_t dev_capability_data[ZERO_SIZED_ARRAY];
744};
745
751struct libusb_bos_descriptor {
753 uint8_t bLength;
754
758 uint8_t bDescriptorType;
759
761 uint16_t wTotalLength;
762
765 uint8_t bNumDeviceCaps;
766
768 struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY];
769};
770
776struct libusb_usb_2_0_extension_descriptor {
778 uint8_t bLength;
779
783 uint8_t bDescriptorType;
784
788 uint8_t bDevCapabilityType;
789
794 uint32_t bmAttributes;
795};
796
802struct libusb_ss_usb_device_capability_descriptor {
804 uint8_t bLength;
805
809 uint8_t bDescriptorType;
810
814 uint8_t bDevCapabilityType;
815
820 uint8_t bmAttributes;
821
824 uint16_t wSpeedSupported;
825
830 uint8_t bFunctionalitySupport;
831
833 uint8_t bU1DevExitLat;
834
836 uint16_t bU2DevExitLat;
837};
838
844struct libusb_container_id_descriptor {
846 uint8_t bLength;
847
851 uint8_t bDescriptorType;
852
856 uint8_t bDevCapabilityType;
857
859 uint8_t bReserved;
860
862 uint8_t ContainerID[16];
863};
864
867struct libusb_control_setup {
873 uint8_t bmRequestType;
874
880 uint8_t bRequest;
881
883 uint16_t wValue;
884
887 uint16_t wIndex;
888
890 uint16_t wLength;
891};
892
893#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
894
895/* libusb */
896
897struct libusb_context;
898struct libusb_device;
899struct libusb_device_handle;
900
904struct libusb_version {
906 const uint16_t major;
907
909 const uint16_t minor;
910
912 const uint16_t micro;
913
915 const uint16_t nano;
916
918 const char *rc;
919
921 const char* describe;
922};
923
941typedef struct libusb_context libusb_context;
942
958typedef struct libusb_device libusb_device;
959
960
969typedef struct libusb_device_handle libusb_device_handle;
970
974enum libusb_speed {
976 LIBUSB_SPEED_UNKNOWN = 0,
977
979 LIBUSB_SPEED_LOW = 1,
980
982 LIBUSB_SPEED_FULL = 2,
983
985 LIBUSB_SPEED_HIGH = 3,
986
988 LIBUSB_SPEED_SUPER = 4,
989
991 LIBUSB_SPEED_SUPER_PLUS = 5,
992};
993
998enum libusb_supported_speed {
1000 LIBUSB_LOW_SPEED_OPERATION = 1,
1001
1003 LIBUSB_FULL_SPEED_OPERATION = 2,
1004
1006 LIBUSB_HIGH_SPEED_OPERATION = 4,
1007
1009 LIBUSB_SUPER_SPEED_OPERATION = 8,
1010};
1011
1017enum libusb_usb_2_0_extension_attributes {
1019 LIBUSB_BM_LPM_SUPPORT = 2,
1020};
1021
1027enum libusb_ss_usb_device_capability_attributes {
1029 LIBUSB_BM_LTM_SUPPORT = 2,
1030};
1031
1035enum libusb_bos_type {
1037 LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
1038
1040 LIBUSB_BT_USB_2_0_EXTENSION = 2,
1041
1043 LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
1044
1046 LIBUSB_BT_CONTAINER_ID = 4,
1047};
1048
1056enum libusb_error {
1058 LIBUSB_SUCCESS = 0,
1059
1061 LIBUSB_ERROR_IO = -1,
1062
1064 LIBUSB_ERROR_INVALID_PARAM = -2,
1065
1067 LIBUSB_ERROR_ACCESS = -3,
1068
1070 LIBUSB_ERROR_NO_DEVICE = -4,
1071
1073 LIBUSB_ERROR_NOT_FOUND = -5,
1074
1076 LIBUSB_ERROR_BUSY = -6,
1077
1079 LIBUSB_ERROR_TIMEOUT = -7,
1080
1082 LIBUSB_ERROR_OVERFLOW = -8,
1083
1085 LIBUSB_ERROR_PIPE = -9,
1086
1088 LIBUSB_ERROR_INTERRUPTED = -10,
1089
1091 LIBUSB_ERROR_NO_MEM = -11,
1092
1094 LIBUSB_ERROR_NOT_SUPPORTED = -12,
1095
1096 /* NB: Remember to update LIBUSB_ERROR_COUNT below as well as the
1097 message strings in strerror.c when adding new error codes here. */
1098
1100 LIBUSB_ERROR_OTHER = -99,
1101};
1102
1103/* Total number of error codes in enum libusb_error */
1104#define LIBUSB_ERROR_COUNT 14
1105
1108enum libusb_transfer_status {
1111 LIBUSB_TRANSFER_COMPLETED,
1112
1114 LIBUSB_TRANSFER_ERROR,
1115
1117 LIBUSB_TRANSFER_TIMED_OUT,
1118
1120 LIBUSB_TRANSFER_CANCELLED,
1121
1124 LIBUSB_TRANSFER_STALL,
1125
1127 LIBUSB_TRANSFER_NO_DEVICE,
1128
1130 LIBUSB_TRANSFER_OVERFLOW,
1131
1132 /* NB! Remember to update libusb_error_name()
1133 when adding new status codes here. */
1134};
1135
1138enum libusb_transfer_flags {
1140 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
1141
1146 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
1147
1152 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
1153
1177 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
1178};
1179
1182struct libusb_iso_packet_descriptor {
1184 unsigned int length;
1185
1187 unsigned int actual_length;
1188
1190 enum libusb_transfer_status status;
1191};
1192
1193struct libusb_transfer;
1194
1204typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
1205
1212struct libusb_transfer {
1214 libusb_device_handle *dev_handle;
1215
1217 uint8_t flags;
1218
1220 unsigned char endpoint;
1221
1223 unsigned char type;
1224
1227 unsigned int timeout;
1228
1236 enum libusb_transfer_status status;
1237
1239 int length;
1240
1244 int actual_length;
1245
1248 libusb_transfer_cb_fn callback;
1249
1251 void *user_data;
1252
1254 unsigned char *buffer;
1255
1258 int num_iso_packets;
1259
1261 struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY];
1262};
1263
1269enum libusb_capability {
1271 LIBUSB_CAP_HAS_CAPABILITY = 0x0000,
1273 LIBUSB_CAP_HAS_HOTPLUG = 0x0001,
1278 LIBUSB_CAP_HAS_HID_ACCESS = 0x0100,
1281 LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101
1282};
1283
1292enum libusb_log_level {
1293 LIBUSB_LOG_LEVEL_NONE = 0,
1294 LIBUSB_LOG_LEVEL_ERROR = 1,
1295 LIBUSB_LOG_LEVEL_WARNING = 2,
1296 LIBUSB_LOG_LEVEL_INFO = 3,
1297 LIBUSB_LOG_LEVEL_DEBUG = 4,
1298};
1299
1300int LIBUSB_CALL libusb_init(libusb_context **ctx);
1301void LIBUSB_CALL libusb_exit(libusb_context *ctx);
1302LIBUSB_DEPRECATED_FOR(libusb_set_option)
1303void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
1304const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
1305int LIBUSB_CALL libusb_has_capability(uint32_t capability);
1306const char * LIBUSB_CALL libusb_error_name(int errcode);
1307int LIBUSB_CALL libusb_setlocale(const char *locale);
1308const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
1309
1310ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
1311 libusb_device ***list);
1312void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
1313 int unref_devices);
1314libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
1315void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
1316
1317int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
1318 int *config);
1319int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
1320 struct libusb_device_descriptor *desc);
1321int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
1322 struct libusb_config_descriptor **config);
1323int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
1324 uint8_t config_index, struct libusb_config_descriptor **config);
1325int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
1326 uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
1327void LIBUSB_CALL libusb_free_config_descriptor(
1328 struct libusb_config_descriptor *config);
1329int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor(
1330 struct libusb_context *ctx,
1331 const struct libusb_endpoint_descriptor *endpoint,
1332 struct libusb_ss_endpoint_companion_descriptor **ep_comp);
1333void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor(
1334 struct libusb_ss_endpoint_companion_descriptor *ep_comp);
1335int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
1336 struct libusb_bos_descriptor **bos);
1337void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
1338int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor(
1339 struct libusb_context *ctx,
1340 struct libusb_bos_dev_capability_descriptor *dev_cap,
1341 struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
1342void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor(
1343 struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
1344int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor(
1345 struct libusb_context *ctx,
1346 struct libusb_bos_dev_capability_descriptor *dev_cap,
1347 struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap);
1348void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor(
1349 struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap);
1350int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx,
1351 struct libusb_bos_dev_capability_descriptor *dev_cap,
1352 struct libusb_container_id_descriptor **container_id);
1353void LIBUSB_CALL libusb_free_container_id_descriptor(
1354 struct libusb_container_id_descriptor *container_id);
1355uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
1356uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
1357int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
1358LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
1359int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
1360libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
1361uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
1362int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
1363int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
1364 unsigned char endpoint);
1365int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
1366 unsigned char endpoint);
1367
1368int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **dev_handle);
1369void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
1370libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
1371
1372int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev_handle,
1373 int configuration);
1374int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev_handle,
1375 int interface_number);
1376int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev_handle,
1377 int interface_number);
1378
1379libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
1380 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
1381
1382int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev_handle,
1383 int interface_number, int alternate_setting);
1384int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev_handle,
1385 unsigned char endpoint);
1386int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev_handle);
1387
1388int LIBUSB_CALL libusb_alloc_streams(libusb_device_handle *dev_handle,
1389 uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
1390int LIBUSB_CALL libusb_free_streams(libusb_device_handle *dev_handle,
1391 unsigned char *endpoints, int num_endpoints);
1392
1393unsigned char * LIBUSB_CALL libusb_dev_mem_alloc(libusb_device_handle *dev_handle,
1394 size_t length);
1395int LIBUSB_CALL libusb_dev_mem_free(libusb_device_handle *dev_handle,
1396 unsigned char *buffer, size_t length);
1397
1398int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev_handle,
1399 int interface_number);
1400int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev_handle,
1401 int interface_number);
1402int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev_handle,
1403 int interface_number);
1404int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
1405 libusb_device_handle *dev_handle, int enable);
1406
1407/* async I/O */
1408
1421static inline unsigned char *libusb_control_transfer_get_data(
1422 struct libusb_transfer *transfer)
1423{
1424 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
1425}
1426
1439static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
1440 struct libusb_transfer *transfer)
1441{
1442 return (struct libusb_control_setup *)(void *) transfer->buffer;
1443}
1444
1468static inline void libusb_fill_control_setup(unsigned char *buffer,
1469 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1470 uint16_t wLength)
1471{
1472 struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
1473 setup->bmRequestType = bmRequestType;
1474 setup->bRequest = bRequest;
1475 setup->wValue = libusb_cpu_to_le16(wValue);
1476 setup->wIndex = libusb_cpu_to_le16(wIndex);
1477 setup->wLength = libusb_cpu_to_le16(wLength);
1478}
1479
1480struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
1481int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
1482int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
1483void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
1484void LIBUSB_CALL libusb_transfer_set_stream_id(
1485 struct libusb_transfer *transfer, uint32_t stream_id);
1486uint32_t LIBUSB_CALL libusb_transfer_get_stream_id(
1487 struct libusb_transfer *transfer);
1488
1517static inline void libusb_fill_control_transfer(
1518 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1519 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
1520 unsigned int timeout)
1521{
1522 struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
1523 transfer->dev_handle = dev_handle;
1524 transfer->endpoint = 0;
1525 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
1526 transfer->timeout = timeout;
1527 transfer->buffer = buffer;
1528 if (setup)
1529 transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE
1530 + libusb_le16_to_cpu(setup->wLength));
1531 transfer->user_data = user_data;
1532 transfer->callback = callback;
1533}
1534
1548static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
1549 libusb_device_handle *dev_handle, unsigned char endpoint,
1550 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
1551 void *user_data, unsigned int timeout)
1552{
1553 transfer->dev_handle = dev_handle;
1554 transfer->endpoint = endpoint;
1555 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
1556 transfer->timeout = timeout;
1557 transfer->buffer = buffer;
1558 transfer->length = length;
1559 transfer->user_data = user_data;
1560 transfer->callback = callback;
1561}
1562
1579static inline void libusb_fill_bulk_stream_transfer(
1580 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1581 unsigned char endpoint, uint32_t stream_id,
1582 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
1583 void *user_data, unsigned int timeout)
1584{
1585 libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer,
1586 length, callback, user_data, timeout);
1587 transfer->type = LIBUSB_TRANSFER_TYPE_BULK_STREAM;
1588 libusb_transfer_set_stream_id(transfer, stream_id);
1589}
1590
1604static inline void libusb_fill_interrupt_transfer(
1605 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
1606 unsigned char endpoint, unsigned char *buffer, int length,
1607 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1608{
1609 transfer->dev_handle = dev_handle;
1610 transfer->endpoint = endpoint;
1611 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
1612 transfer->timeout = timeout;
1613 transfer->buffer = buffer;
1614 transfer->length = length;
1615 transfer->user_data = user_data;
1616 transfer->callback = callback;
1617}
1618
1633static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
1634 libusb_device_handle *dev_handle, unsigned char endpoint,
1635 unsigned char *buffer, int length, int num_iso_packets,
1636 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
1637{
1638 transfer->dev_handle = dev_handle;
1639 transfer->endpoint = endpoint;
1640 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
1641 transfer->timeout = timeout;
1642 transfer->buffer = buffer;
1643 transfer->length = length;
1644 transfer->num_iso_packets = num_iso_packets;
1645 transfer->user_data = user_data;
1646 transfer->callback = callback;
1647}
1648
1657static inline void libusb_set_iso_packet_lengths(
1658 struct libusb_transfer *transfer, unsigned int length)
1659{
1660 int i;
1661 for (i = 0; i < transfer->num_iso_packets; i++)
1662 transfer->iso_packet_desc[i].length = length;
1663}
1664
1681static inline unsigned char *libusb_get_iso_packet_buffer(
1682 struct libusb_transfer *transfer, unsigned int packet)
1683{
1684 int i;
1685 size_t offset = 0;
1686 int _packet;
1687
1688 /* oops..slight bug in the API. packet is an unsigned int, but we use
1689 * signed integers almost everywhere else. range-check and convert to
1690 * signed to avoid compiler warnings. FIXME for libusb-2. */
1691 if (packet > INT_MAX)
1692 return NULL;
1693 _packet = (int) packet;
1694
1695 if (_packet >= transfer->num_iso_packets)
1696 return NULL;
1697
1698 for (i = 0; i < _packet; i++)
1699 offset += transfer->iso_packet_desc[i].length;
1700
1701 return transfer->buffer + offset;
1702}
1703
1723static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1724 struct libusb_transfer *transfer, unsigned int packet)
1725{
1726 int _packet;
1727
1728 /* oops..slight bug in the API. packet is an unsigned int, but we use
1729 * signed integers almost everywhere else. range-check and convert to
1730 * signed to avoid compiler warnings. FIXME for libusb-2. */
1731 if (packet > INT_MAX)
1732 return NULL;
1733 _packet = (int) packet;
1734
1735 if (_packet >= transfer->num_iso_packets)
1736 return NULL;
1737
1738 return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet);
1739}
1740
1741/* sync I/O */
1742
1743int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
1744 uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
1745 unsigned char *data, uint16_t wLength, unsigned int timeout);
1746
1747int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
1748 unsigned char endpoint, unsigned char *data, int length,
1749 int *actual_length, unsigned int timeout);
1750
1751int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
1752 unsigned char endpoint, unsigned char *data, int length,
1753 int *actual_length, unsigned int timeout);
1754
1767static inline int libusb_get_descriptor(libusb_device_handle *dev_handle,
1768 uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
1769{
1770 return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN,
1771 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index),
1772 0, data, (uint16_t) length, 1000);
1773}
1774
1789static inline int libusb_get_string_descriptor(libusb_device_handle *dev_handle,
1790 uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
1791{
1792 return libusb_control_transfer(dev_handle, LIBUSB_ENDPOINT_IN,
1793 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
1794 langid, data, (uint16_t) length, 1000);
1795}
1796
1797int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle,
1798 uint8_t desc_index, unsigned char *data, int length);
1799
1800/* polling and timeouts */
1801
1802int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
1803void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
1804void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
1805int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
1806int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
1807void LIBUSB_CALL libusb_interrupt_event_handler(libusb_context *ctx);
1808void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
1809void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
1810int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
1811
1812int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
1813 struct timeval *tv);
1814int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
1815 struct timeval *tv, int *completed);
1816int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
1817int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
1818int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
1819 struct timeval *tv);
1820int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
1821int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
1822 struct timeval *tv);
1823
1827struct libusb_pollfd {
1829 int fd;
1830
1835 short events;
1836};
1837
1848typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
1849 void *user_data);
1850
1860typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
1861
1862const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
1863 libusb_context *ctx);
1864void LIBUSB_CALL libusb_free_pollfds(const struct libusb_pollfd **pollfds);
1865void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
1866 libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
1867 void *user_data);
1868
1881typedef int libusb_hotplug_callback_handle;
1882
1888typedef enum {
1890 LIBUSB_HOTPLUG_NO_FLAGS = 0,
1891
1893 LIBUSB_HOTPLUG_ENUMERATE = 1<<0,
1894} libusb_hotplug_flag;
1895
1901typedef enum {
1903 LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
1904
1908 LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
1909} libusb_hotplug_event;
1910
1913#define LIBUSB_HOTPLUG_MATCH_ANY -1
1914
1937typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
1938 libusb_device *device,
1939 libusb_hotplug_event event,
1940 void *user_data);
1941
1976int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
1977 libusb_hotplug_event events,
1978 libusb_hotplug_flag flags,
1979 int vendor_id, int product_id,
1980 int dev_class,
1981 libusb_hotplug_callback_fn cb_fn,
1982 void *user_data,
1983 libusb_hotplug_callback_handle *callback_handle);
1984
1996void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
1997 libusb_hotplug_callback_handle callback_handle);
1998
2002enum libusb_option {
2024 LIBUSB_OPTION_LOG_LEVEL,
2025
2033 LIBUSB_OPTION_USE_USBDK,
2034};
2035
2036int LIBUSB_CALL libusb_set_option(libusb_context *ctx, enum libusb_option option, ...);
2037
2038#ifdef __cplusplus
2039}
2040#endif
2041
2042#endif
2043
2044// clang-format on