32#if !defined(__cplusplus)
33#define inline __inline
36#ifndef _SSIZE_T_DEFINED
37#define _SSIZE_T_DEFINED
40 typedef __int64 ssize_t;
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;
56#if !defined(_WIN32_WCE)
60#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__HAIKU__)
67#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
68#define ZERO_SIZED_ARRAY
70#define ZERO_SIZED_ARRAY 0
78#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
83#if !defined(__CYGWIN__)
88#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
89#define LIBUSB_DEPRECATED_FOR(f) \
90 __attribute__((deprecated("Use " #f " instead")))
92#define LIBUSB_DEPRECATED_FOR(f) __attribute__((deprecated))
94#define LIBUSB_DEPRECATED_FOR(f)
129#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
130#define LIBUSB_CALL WINAPI
155#define LIBUSB_API_VERSION 0x01000106
158#define LIBUSBX_API_VERSION LIBUSB_API_VERSION
172static inline uint16_t libusb_cpu_to_le16(
const uint16_t x)
178 _tmp.b8[1] = (uint8_t) (x >> 8);
179 _tmp.b8[0] = (uint8_t) (x & 0xff);
191#define libusb_le16_to_cpu libusb_cpu_to_le16
197enum libusb_class_code {
202 LIBUSB_CLASS_PER_INTERFACE = 0,
205 LIBUSB_CLASS_AUDIO = 1,
208 LIBUSB_CLASS_COMM = 2,
211 LIBUSB_CLASS_HID = 3,
214 LIBUSB_CLASS_PHYSICAL = 5,
217 LIBUSB_CLASS_PRINTER = 7,
220 LIBUSB_CLASS_PTP = 6,
221 LIBUSB_CLASS_IMAGE = 6,
224 LIBUSB_CLASS_MASS_STORAGE = 8,
227 LIBUSB_CLASS_HUB = 9,
230 LIBUSB_CLASS_DATA = 10,
233 LIBUSB_CLASS_SMART_CARD = 0x0b,
236 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
239 LIBUSB_CLASS_VIDEO = 0x0e,
242 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
245 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
248 LIBUSB_CLASS_WIRELESS = 0xe0,
251 LIBUSB_CLASS_APPLICATION = 0xfe,
254 LIBUSB_CLASS_VENDOR_SPEC = 0xff
259enum libusb_descriptor_type {
261 LIBUSB_DT_DEVICE = 0x01,
264 LIBUSB_DT_CONFIG = 0x02,
267 LIBUSB_DT_STRING = 0x03,
270 LIBUSB_DT_INTERFACE = 0x04,
273 LIBUSB_DT_ENDPOINT = 0x05,
276 LIBUSB_DT_BOS = 0x0f,
279 LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
282 LIBUSB_DT_HID = 0x21,
285 LIBUSB_DT_REPORT = 0x22,
288 LIBUSB_DT_PHYSICAL = 0x23,
291 LIBUSB_DT_HUB = 0x29,
294 LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
297 LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
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
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
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
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))
322#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f
323#define LIBUSB_ENDPOINT_DIR_MASK 0x80
329enum libusb_endpoint_direction {
331 LIBUSB_ENDPOINT_IN = 0x80,
334 LIBUSB_ENDPOINT_OUT = 0x00
337#define LIBUSB_TRANSFER_TYPE_MASK 0x03
343enum libusb_transfer_type {
345 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
348 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
351 LIBUSB_TRANSFER_TYPE_BULK = 2,
354 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3,
357 LIBUSB_TRANSFER_TYPE_BULK_STREAM = 4,
362enum libusb_standard_request {
364 LIBUSB_REQUEST_GET_STATUS = 0x00,
367 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
372 LIBUSB_REQUEST_SET_FEATURE = 0x03,
377 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
380 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
383 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
386 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
389 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
392 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
395 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
398 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
401 LIBUSB_REQUEST_SET_SEL = 0x30,
405 LIBUSB_SET_ISOCH_DELAY = 0x31,
412enum libusb_request_type {
414 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
417 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
420 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
423 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
430enum libusb_request_recipient {
432 LIBUSB_RECIPIENT_DEVICE = 0x00,
435 LIBUSB_RECIPIENT_INTERFACE = 0x01,
438 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
441 LIBUSB_RECIPIENT_OTHER = 0x03,
444#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
451enum libusb_iso_sync_type {
453 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
456 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
459 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
462 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
465#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
472enum libusb_iso_usage_type {
474 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
477 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
480 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
488struct libusb_device_descriptor {
495 uint8_t bDescriptorType;
502 uint8_t bDeviceClass;
506 uint8_t bDeviceSubClass;
510 uint8_t bDeviceProtocol;
513 uint8_t bMaxPacketSize0;
525 uint8_t iManufacturer;
531 uint8_t iSerialNumber;
534 uint8_t bNumConfigurations;
542struct libusb_endpoint_descriptor {
549 uint8_t bDescriptorType;
555 uint8_t bEndpointAddress;
564 uint8_t bmAttributes;
567 uint16_t wMaxPacketSize;
577 uint8_t bSynchAddress;
581 const unsigned char *extra;
592struct libusb_interface_descriptor {
599 uint8_t bDescriptorType;
602 uint8_t bInterfaceNumber;
605 uint8_t bAlternateSetting;
609 uint8_t bNumEndpoints;
612 uint8_t bInterfaceClass;
616 uint8_t bInterfaceSubClass;
620 uint8_t bInterfaceProtocol;
627 const struct libusb_endpoint_descriptor *endpoint;
631 const unsigned char *extra;
640struct libusb_interface {
643 const struct libusb_interface_descriptor *altsetting;
654struct libusb_config_descriptor {
661 uint8_t bDescriptorType;
664 uint16_t wTotalLength;
667 uint8_t bNumInterfaces;
670 uint8_t bConfigurationValue;
673 uint8_t iConfiguration;
676 uint8_t bmAttributes;
686 const struct libusb_interface *interface;
690 const unsigned char *extra;
702struct libusb_ss_endpoint_companion_descriptor {
710 uint8_t bDescriptorType;
721 uint8_t bmAttributes;
725 uint16_t wBytesPerInterval;
733struct libusb_bos_dev_capability_descriptor {
739 uint8_t bDescriptorType;
741 uint8_t bDevCapabilityType;
743 uint8_t dev_capability_data[ZERO_SIZED_ARRAY];
751struct libusb_bos_descriptor {
758 uint8_t bDescriptorType;
761 uint16_t wTotalLength;
765 uint8_t bNumDeviceCaps;
768 struct libusb_bos_dev_capability_descriptor *dev_capability[ZERO_SIZED_ARRAY];
776struct libusb_usb_2_0_extension_descriptor {
783 uint8_t bDescriptorType;
788 uint8_t bDevCapabilityType;
794 uint32_t bmAttributes;
802struct libusb_ss_usb_device_capability_descriptor {
809 uint8_t bDescriptorType;
814 uint8_t bDevCapabilityType;
820 uint8_t bmAttributes;
824 uint16_t wSpeedSupported;
830 uint8_t bFunctionalitySupport;
833 uint8_t bU1DevExitLat;
836 uint16_t bU2DevExitLat;
844struct libusb_container_id_descriptor {
851 uint8_t bDescriptorType;
856 uint8_t bDevCapabilityType;
862 uint8_t ContainerID[16];
867struct libusb_control_setup {
873 uint8_t bmRequestType;
893#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
897struct libusb_context;
899struct libusb_device_handle;
904struct libusb_version {
906 const uint16_t major;
909 const uint16_t minor;
912 const uint16_t micro;
921 const char* describe;
941typedef struct libusb_context libusb_context;
958typedef struct libusb_device libusb_device;
969typedef struct libusb_device_handle libusb_device_handle;
976 LIBUSB_SPEED_UNKNOWN = 0,
979 LIBUSB_SPEED_LOW = 1,
982 LIBUSB_SPEED_FULL = 2,
985 LIBUSB_SPEED_HIGH = 3,
988 LIBUSB_SPEED_SUPER = 4,
991 LIBUSB_SPEED_SUPER_PLUS = 5,
998enum libusb_supported_speed {
1000 LIBUSB_LOW_SPEED_OPERATION = 1,
1003 LIBUSB_FULL_SPEED_OPERATION = 2,
1006 LIBUSB_HIGH_SPEED_OPERATION = 4,
1009 LIBUSB_SUPER_SPEED_OPERATION = 8,
1017enum libusb_usb_2_0_extension_attributes {
1019 LIBUSB_BM_LPM_SUPPORT = 2,
1027enum libusb_ss_usb_device_capability_attributes {
1029 LIBUSB_BM_LTM_SUPPORT = 2,
1035enum libusb_bos_type {
1037 LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
1040 LIBUSB_BT_USB_2_0_EXTENSION = 2,
1043 LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
1046 LIBUSB_BT_CONTAINER_ID = 4,
1061 LIBUSB_ERROR_IO = -1,
1064 LIBUSB_ERROR_INVALID_PARAM = -2,
1067 LIBUSB_ERROR_ACCESS = -3,
1070 LIBUSB_ERROR_NO_DEVICE = -4,
1073 LIBUSB_ERROR_NOT_FOUND = -5,
1076 LIBUSB_ERROR_BUSY = -6,
1079 LIBUSB_ERROR_TIMEOUT = -7,
1082 LIBUSB_ERROR_OVERFLOW = -8,
1085 LIBUSB_ERROR_PIPE = -9,
1088 LIBUSB_ERROR_INTERRUPTED = -10,
1091 LIBUSB_ERROR_NO_MEM = -11,
1094 LIBUSB_ERROR_NOT_SUPPORTED = -12,
1100 LIBUSB_ERROR_OTHER = -99,
1104#define LIBUSB_ERROR_COUNT 14
1108enum libusb_transfer_status {
1111 LIBUSB_TRANSFER_COMPLETED,
1114 LIBUSB_TRANSFER_ERROR,
1117 LIBUSB_TRANSFER_TIMED_OUT,
1120 LIBUSB_TRANSFER_CANCELLED,
1124 LIBUSB_TRANSFER_STALL,
1127 LIBUSB_TRANSFER_NO_DEVICE,
1130 LIBUSB_TRANSFER_OVERFLOW,
1138enum libusb_transfer_flags {
1140 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
1146 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
1152 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
1177 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
1182struct libusb_iso_packet_descriptor {
1184 unsigned int length;
1187 unsigned int actual_length;
1190 enum libusb_transfer_status status;
1193struct libusb_transfer;
1204typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(
struct libusb_transfer *transfer);
1212struct libusb_transfer {
1214 libusb_device_handle *dev_handle;
1220 unsigned char endpoint;
1227 unsigned int timeout;
1236 enum libusb_transfer_status status;
1248 libusb_transfer_cb_fn callback;
1254 unsigned char *buffer;
1258 int num_iso_packets;
1261 struct libusb_iso_packet_descriptor iso_packet_desc[ZERO_SIZED_ARRAY];
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
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,
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);
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,
1314libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
1315void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
1317int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
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);
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);
1372int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev_handle,
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);
1379libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
1380 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
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);
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);
1393unsigned char * LIBUSB_CALL libusb_dev_mem_alloc(libusb_device_handle *dev_handle,
1395int LIBUSB_CALL libusb_dev_mem_free(libusb_device_handle *dev_handle,
1396 unsigned char *buffer,
size_t length);
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);
1421static inline unsigned char *libusb_control_transfer_get_data(
1422 struct libusb_transfer *transfer)
1424 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
1439static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
1440 struct libusb_transfer *transfer)
1442 return (
struct libusb_control_setup *)(
void *) transfer->buffer;
1468static inline void libusb_fill_control_setup(
unsigned char *buffer,
1469 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
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);
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);
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)
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;
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;
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)
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;
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)
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);
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)
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;
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)
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;
1657static inline void libusb_set_iso_packet_lengths(
1658 struct libusb_transfer *transfer,
unsigned int length)
1661 for (i = 0; i < transfer->num_iso_packets; i++)
1662 transfer->iso_packet_desc[i].length = length;
1681static inline unsigned char *libusb_get_iso_packet_buffer(
1682 struct libusb_transfer *transfer,
unsigned int packet)
1691 if (packet > INT_MAX)
1693 _packet = (int) packet;
1695 if (_packet >= transfer->num_iso_packets)
1698 for (i = 0; i < _packet; i++)
1699 offset += transfer->iso_packet_desc[i].length;
1701 return transfer->buffer + offset;
1723static inline unsigned char *libusb_get_iso_packet_buffer_simple(
1724 struct libusb_transfer *transfer,
unsigned int packet)
1731 if (packet > INT_MAX)
1733 _packet = (int) packet;
1735 if (_packet >= transfer->num_iso_packets)
1738 return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet);
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);
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);
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);
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)
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);
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)
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);
1797int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle,
1798 uint8_t desc_index,
unsigned char *data,
int length);
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);
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);
1827struct libusb_pollfd {
1848typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(
int fd,
short events,
1860typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(
int fd,
void *user_data);
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,
1881typedef int libusb_hotplug_callback_handle;
1890 LIBUSB_HOTPLUG_NO_FLAGS = 0,
1893 LIBUSB_HOTPLUG_ENUMERATE = 1<<0,
1894} libusb_hotplug_flag;
1903 LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
1908 LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
1909} libusb_hotplug_event;
1913#define LIBUSB_HOTPLUG_MATCH_ANY -1
1937typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
1938 libusb_device *device,
1939 libusb_hotplug_event event,
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,
1981 libusb_hotplug_callback_fn cb_fn,
1983 libusb_hotplug_callback_handle *callback_handle);
1996void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
1997 libusb_hotplug_callback_handle callback_handle);
2024 LIBUSB_OPTION_LOG_LEVEL,
2033 LIBUSB_OPTION_USE_USBDK,
2036int LIBUSB_CALL libusb_set_option(libusb_context *ctx,
enum libusb_option option, ...);