00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef LIBUSB_H
00025 #define LIBUSB_H
00026
00027 #ifdef _MSC_VER
00028
00029 #if !defined(__cplusplus)
00030 #define inline __inline
00031 #endif
00032
00033 #ifndef _SSIZE_T_DEFINED
00034 #define _SSIZE_T_DEFINED
00035 #undef ssize_t
00036 #ifdef _WIN64
00037 typedef __int64 ssize_t;
00038 #else
00039 typedef int ssize_t;
00040 #endif
00041 #endif
00042 #endif
00043
00044
00045 #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
00046 typedef unsigned __int8 uint8_t;
00047 typedef unsigned __int16 uint16_t;
00048 typedef unsigned __int32 uint32_t;
00049 #else
00050 #include <stdint.h>
00051 #endif
00052
00053 #if !defined(_WIN32_WCE)
00054 #include <sys/types.h>
00055 #endif
00056
00057 #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
00058 #include <sys/time.h>
00059 #endif
00060
00061 #include <time.h>
00062 #include <limits.h>
00063
00064
00065
00066
00067
00068
00069 #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
00070 #include <windows.h>
00071 #if defined(interface)
00072 #undef interface
00073 #endif
00074 #if !defined(__CYGWIN__)
00075 #include <winsock.h>
00076 #endif
00077 #endif
00078
00079 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
00080 #define LIBUSB_DEPRECATED_FOR(f) \
00081 __attribute__((deprecated("Use " #f " instead")))
00082 #else
00083 #define LIBUSB_DEPRECATED_FOR(f)
00084 #endif
00085
00111
00112
00113
00114
00115
00116
00117
00118 #if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN32_WCE)
00119 #define LIBUSB_CALL WINAPI
00120 #else
00121 #define LIBUSB_CALL
00122 #endif
00123
00147 #define LIBUSB_API_VERSION 0x01000102
00148
00149
00150 #define LIBUSBX_API_VERSION LIBUSB_API_VERSION
00151
00152 #ifdef __cplusplus
00153 extern "C" {
00154 #endif
00155
00164 static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
00165 {
00166 union {
00167 uint8_t b8[2];
00168 uint16_t b16;
00169 } _tmp;
00170 _tmp.b8[1] = (uint8_t) (x >> 8);
00171 _tmp.b8[0] = (uint8_t) (x & 0xff);
00172 return _tmp.b16;
00173 }
00174
00183 #define libusb_le16_to_cpu libusb_cpu_to_le16
00184
00185
00186
00189 enum libusb_class_code {
00194 LIBUSB_CLASS_PER_INTERFACE = 0,
00195
00197 LIBUSB_CLASS_AUDIO = 1,
00198
00200 LIBUSB_CLASS_COMM = 2,
00201
00203 LIBUSB_CLASS_HID = 3,
00204
00206 LIBUSB_CLASS_PHYSICAL = 5,
00207
00209 LIBUSB_CLASS_PRINTER = 7,
00210
00212 LIBUSB_CLASS_PTP = 6,
00213 LIBUSB_CLASS_IMAGE = 6,
00214
00216 LIBUSB_CLASS_MASS_STORAGE = 8,
00217
00219 LIBUSB_CLASS_HUB = 9,
00220
00222 LIBUSB_CLASS_DATA = 10,
00223
00225 LIBUSB_CLASS_SMART_CARD = 0x0b,
00226
00228 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
00229
00231 LIBUSB_CLASS_VIDEO = 0x0e,
00232
00234 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
00235
00237 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
00238
00240 LIBUSB_CLASS_WIRELESS = 0xe0,
00241
00243 LIBUSB_CLASS_APPLICATION = 0xfe,
00244
00246 LIBUSB_CLASS_VENDOR_SPEC = 0xff
00247 };
00248
00251 enum libusb_descriptor_type {
00253 LIBUSB_DT_DEVICE = 0x01,
00254
00256 LIBUSB_DT_CONFIG = 0x02,
00257
00259 LIBUSB_DT_STRING = 0x03,
00260
00262 LIBUSB_DT_INTERFACE = 0x04,
00263
00265 LIBUSB_DT_ENDPOINT = 0x05,
00266
00268 LIBUSB_DT_BOS = 0x0f,
00269
00271 LIBUSB_DT_DEVICE_CAPABILITY = 0x10,
00272
00274 LIBUSB_DT_HID = 0x21,
00275
00277 LIBUSB_DT_REPORT = 0x22,
00278
00280 LIBUSB_DT_PHYSICAL = 0x23,
00281
00283 LIBUSB_DT_HUB = 0x29,
00284
00286 LIBUSB_DT_SUPERSPEED_HUB = 0x2a,
00287
00289 LIBUSB_DT_SS_ENDPOINT_COMPANION = 0x30
00290 };
00291
00292
00293 #define LIBUSB_DT_DEVICE_SIZE 18
00294 #define LIBUSB_DT_CONFIG_SIZE 9
00295 #define LIBUSB_DT_INTERFACE_SIZE 9
00296 #define LIBUSB_DT_ENDPOINT_SIZE 7
00297 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9
00298 #define LIBUSB_DT_HUB_NONVAR_SIZE 7
00299 #define LIBUSB_DT_SS_ENDPOINT_COMPANION_SIZE 6
00300 #define LIBUSB_DT_BOS_SIZE 5
00301 #define LIBUSB_DT_DEVICE_CAPABILITY_SIZE 3
00302
00303
00304 #define LIBUSB_BT_USB_2_0_EXTENSION_SIZE 7
00305 #define LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE 10
00306 #define LIBUSB_BT_CONTAINER_ID_SIZE 20
00307
00308
00309 #define LIBUSB_DT_BOS_MAX_SIZE ((LIBUSB_DT_BOS_SIZE) +\
00310 (LIBUSB_BT_USB_2_0_EXTENSION_SIZE) +\
00311 (LIBUSB_BT_SS_USB_DEVICE_CAPABILITY_SIZE) +\
00312 (LIBUSB_BT_CONTAINER_ID_SIZE))
00313
00314 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f
00315 #define LIBUSB_ENDPOINT_DIR_MASK 0x80
00316
00321 enum libusb_endpoint_direction {
00323 LIBUSB_ENDPOINT_IN = 0x80,
00324
00326 LIBUSB_ENDPOINT_OUT = 0x00
00327 };
00328
00329 #define LIBUSB_TRANSFER_TYPE_MASK 0x03
00330
00335 enum libusb_transfer_type {
00337 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
00338
00340 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
00341
00343 LIBUSB_TRANSFER_TYPE_BULK = 2,
00344
00346 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
00347 };
00348
00351 enum libusb_standard_request {
00353 LIBUSB_REQUEST_GET_STATUS = 0x00,
00354
00356 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
00357
00358
00359
00361 LIBUSB_REQUEST_SET_FEATURE = 0x03,
00362
00363
00364
00366 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
00367
00369 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
00370
00372 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
00373
00375 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
00376
00378 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
00379
00381 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
00382
00384 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
00385
00387 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
00388
00390 LIBUSB_REQUEST_SET_SEL = 0x30,
00391
00394 LIBUSB_SET_ISOCH_DELAY = 0x31,
00395 };
00396
00401 enum libusb_request_type {
00403 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
00404
00406 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
00407
00409 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
00410
00412 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
00413 };
00414
00419 enum libusb_request_recipient {
00421 LIBUSB_RECIPIENT_DEVICE = 0x00,
00422
00424 LIBUSB_RECIPIENT_INTERFACE = 0x01,
00425
00427 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
00428
00430 LIBUSB_RECIPIENT_OTHER = 0x03,
00431 };
00432
00433 #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
00434
00440 enum libusb_iso_sync_type {
00442 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
00443
00445 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
00446
00448 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
00449
00451 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
00452 };
00453
00454 #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
00455
00461 enum libusb_iso_usage_type {
00463 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
00464
00466 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
00467
00469 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
00470 };
00471
00477 struct libusb_device_descriptor {
00479 uint8_t bLength;
00480
00484 uint8_t bDescriptorType;
00485
00488 uint16_t bcdUSB;
00489
00491 uint8_t bDeviceClass;
00492
00495 uint8_t bDeviceSubClass;
00496
00499 uint8_t bDeviceProtocol;
00500
00502 uint8_t bMaxPacketSize0;
00503
00505 uint16_t idVendor;
00506
00508 uint16_t idProduct;
00509
00511 uint16_t bcdDevice;
00512
00514 uint8_t iManufacturer;
00515
00517 uint8_t iProduct;
00518
00520 uint8_t iSerialNumber;
00521
00523 uint8_t bNumConfigurations;
00524 };
00525
00531 struct libusb_endpoint_descriptor {
00533 uint8_t bLength;
00534
00538 uint8_t bDescriptorType;
00539
00544 uint8_t bEndpointAddress;
00545
00553 uint8_t bmAttributes;
00554
00556 uint16_t wMaxPacketSize;
00557
00559 uint8_t bInterval;
00560
00563 uint8_t bRefresh;
00564
00566 uint8_t bSynchAddress;
00567
00570 const unsigned char *extra;
00571
00573 int extra_length;
00574 };
00575
00581 struct libusb_interface_descriptor {
00583 uint8_t bLength;
00584
00588 uint8_t bDescriptorType;
00589
00591 uint8_t bInterfaceNumber;
00592
00594 uint8_t bAlternateSetting;
00595
00598 uint8_t bNumEndpoints;
00599
00601 uint8_t bInterfaceClass;
00602
00605 uint8_t bInterfaceSubClass;
00606
00609 uint8_t bInterfaceProtocol;
00610
00612 uint8_t iInterface;
00613
00616 const struct libusb_endpoint_descriptor *endpoint;
00617
00620 const unsigned char *extra;
00621
00623 int extra_length;
00624 };
00625
00629 struct libusb_interface {
00632 const struct libusb_interface_descriptor *altsetting;
00633
00635 int num_altsetting;
00636 };
00637
00643 struct libusb_config_descriptor {
00645 uint8_t bLength;
00646
00650 uint8_t bDescriptorType;
00651
00653 uint16_t wTotalLength;
00654
00656 uint8_t bNumInterfaces;
00657
00659 uint8_t bConfigurationValue;
00660
00662 uint8_t iConfiguration;
00663
00665 uint8_t bmAttributes;
00666
00670 uint8_t MaxPower;
00671
00674 const struct libusb_interface *interface;
00675
00678 const unsigned char *extra;
00679
00681 int extra_length;
00682 };
00683
00690 struct libusb_ss_endpoint_companion_descriptor {
00691
00693 uint8_t bLength;
00694
00698 uint8_t bDescriptorType;
00699
00700
00703 uint8_t bMaxBurst;
00704
00709 uint8_t bmAttributes;
00710
00713 uint16_t wBytesPerInterval;
00714 };
00715
00721 struct libusb_bos_dev_capability_descriptor {
00723 uint8_t bLength;
00727 uint8_t bDescriptorType;
00729 uint8_t bDevCapabilityType;
00731 uint8_t dev_capability_data
00732 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00733 []
00734 #else
00735 [0]
00736 #endif
00737 ;
00738 };
00739
00745 struct libusb_bos_descriptor {
00747 uint8_t bLength;
00748
00752 uint8_t bDescriptorType;
00753
00755 uint16_t wTotalLength;
00756
00759 uint8_t bNumDeviceCaps;
00760
00762 struct libusb_bos_dev_capability_descriptor *dev_capability
00763 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00764 []
00765 #else
00766 [0]
00767 #endif
00768 ;
00769 };
00770
00776 struct libusb_usb_2_0_extension_descriptor {
00778 uint8_t bLength;
00779
00783 uint8_t bDescriptorType;
00784
00788 uint8_t bDevCapabilityType;
00789
00794 uint32_t bmAttributes;
00795 };
00796
00802 struct libusb_ss_usb_device_capability_descriptor {
00804 uint8_t bLength;
00805
00809 uint8_t bDescriptorType;
00810
00814 uint8_t bDevCapabilityType;
00815
00820 uint8_t bmAttributes;
00821
00824 uint16_t wSpeedSupported;
00825
00830 uint8_t bFunctionalitySupport;
00831
00833 uint8_t bU1DevExitLat;
00834
00836 uint16_t bU2DevExitLat;
00837 };
00838
00844 struct libusb_container_id_descriptor {
00846 uint8_t bLength;
00847
00851 uint8_t bDescriptorType;
00852
00856 uint8_t bDevCapabilityType;
00857
00859 uint8_t bReserved;
00860
00862 uint8_t ContainerID[16];
00863 };
00864
00867 struct libusb_control_setup {
00873 uint8_t bmRequestType;
00874
00880 uint8_t bRequest;
00881
00883 uint16_t wValue;
00884
00887 uint16_t wIndex;
00888
00890 uint16_t wLength;
00891 };
00892
00893 #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
00894
00895
00896
00897 struct libusb_context;
00898 struct libusb_device;
00899 struct libusb_device_handle;
00900 struct libusb_hotplug_callback;
00901
00905 struct libusb_version {
00907 const uint16_t major;
00908
00910 const uint16_t minor;
00911
00913 const uint16_t micro;
00914
00916 const uint16_t nano;
00917
00919 const char *rc;
00920
00922 const char* describe;
00923 };
00924
00942 typedef struct libusb_context libusb_context;
00943
00959 typedef struct libusb_device libusb_device;
00960
00961
00970 typedef struct libusb_device_handle libusb_device_handle;
00971
00975 enum libusb_speed {
00977 LIBUSB_SPEED_UNKNOWN = 0,
00978
00980 LIBUSB_SPEED_LOW = 1,
00981
00983 LIBUSB_SPEED_FULL = 2,
00984
00986 LIBUSB_SPEED_HIGH = 3,
00987
00989 LIBUSB_SPEED_SUPER = 4,
00990 };
00991
00996 enum libusb_supported_speed {
00998 LIBUSB_LOW_SPEED_OPERATION = 1,
00999
01001 LIBUSB_FULL_SPEED_OPERATION = 2,
01002
01004 LIBUSB_HIGH_SPEED_OPERATION = 4,
01005
01007 LIBUSB_SUPER_SPEED_OPERATION = 8,
01008 };
01009
01015 enum libusb_usb_2_0_extension_attributes {
01017 LIBUSB_BM_LPM_SUPPORT = 2,
01018 };
01019
01025 enum libusb_ss_usb_device_capability_attributes {
01027 LIBUSB_BM_LTM_SUPPORT = 2,
01028 };
01029
01033 enum libusb_bos_type {
01035 LIBUSB_BT_WIRELESS_USB_DEVICE_CAPABILITY = 1,
01036
01038 LIBUSB_BT_USB_2_0_EXTENSION = 2,
01039
01041 LIBUSB_BT_SS_USB_DEVICE_CAPABILITY = 3,
01042
01044 LIBUSB_BT_CONTAINER_ID = 4,
01045 };
01046
01054 enum libusb_error {
01056 LIBUSB_SUCCESS = 0,
01057
01059 LIBUSB_ERROR_IO = -1,
01060
01062 LIBUSB_ERROR_INVALID_PARAM = -2,
01063
01065 LIBUSB_ERROR_ACCESS = -3,
01066
01068 LIBUSB_ERROR_NO_DEVICE = -4,
01069
01071 LIBUSB_ERROR_NOT_FOUND = -5,
01072
01074 LIBUSB_ERROR_BUSY = -6,
01075
01077 LIBUSB_ERROR_TIMEOUT = -7,
01078
01080 LIBUSB_ERROR_OVERFLOW = -8,
01081
01083 LIBUSB_ERROR_PIPE = -9,
01084
01086 LIBUSB_ERROR_INTERRUPTED = -10,
01087
01089 LIBUSB_ERROR_NO_MEM = -11,
01090
01092 LIBUSB_ERROR_NOT_SUPPORTED = -12,
01093
01094
01095
01096
01098 LIBUSB_ERROR_OTHER = -99,
01099 };
01100
01101
01102 #define LIBUSB_ERROR_COUNT 14
01103
01106 enum libusb_transfer_status {
01109 LIBUSB_TRANSFER_COMPLETED,
01110
01112 LIBUSB_TRANSFER_ERROR,
01113
01115 LIBUSB_TRANSFER_TIMED_OUT,
01116
01118 LIBUSB_TRANSFER_CANCELLED,
01119
01122 LIBUSB_TRANSFER_STALL,
01123
01125 LIBUSB_TRANSFER_NO_DEVICE,
01126
01128 LIBUSB_TRANSFER_OVERFLOW,
01129
01130
01131
01132 };
01133
01136 enum libusb_transfer_flags {
01138 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
01139
01141 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
01142
01147 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
01148
01172 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
01173 };
01174
01177 struct libusb_iso_packet_descriptor {
01179 unsigned int length;
01180
01182 unsigned int actual_length;
01183
01185 enum libusb_transfer_status status;
01186 };
01187
01188 struct libusb_transfer;
01189
01199 typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
01200
01207 struct libusb_transfer {
01209 libusb_device_handle *dev_handle;
01210
01212 uint8_t flags;
01213
01215 unsigned char endpoint;
01216
01218 unsigned char type;
01219
01222 unsigned int timeout;
01223
01231 enum libusb_transfer_status status;
01232
01234 int length;
01235
01239 int actual_length;
01240
01243 libusb_transfer_cb_fn callback;
01244
01246 void *user_data;
01247
01249 unsigned char *buffer;
01250
01253 int num_iso_packets;
01254
01256 struct libusb_iso_packet_descriptor iso_packet_desc
01257 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
01258 []
01259 #else
01260 [0]
01261 #endif
01262 ;
01263 };
01264
01270 enum libusb_capability {
01272 LIBUSB_CAP_HAS_CAPABILITY = 0x0000,
01274 LIBUSB_CAP_HAS_HOTPLUG = 0x0001,
01279 LIBUSB_CAP_HAS_HID_ACCESS = 0x0100,
01282 LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER = 0x0101
01283 };
01284
01295 enum libusb_log_level {
01296 LIBUSB_LOG_LEVEL_NONE = 0,
01297 LIBUSB_LOG_LEVEL_ERROR,
01298 LIBUSB_LOG_LEVEL_WARNING,
01299 LIBUSB_LOG_LEVEL_INFO,
01300 LIBUSB_LOG_LEVEL_DEBUG,
01301 };
01302
01303 int LIBUSB_CALL libusb_init(libusb_context **ctx);
01304 void LIBUSB_CALL libusb_exit(libusb_context *ctx);
01305 void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
01306 const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
01307 int LIBUSB_CALL libusb_has_capability(uint32_t capability);
01308 const char * LIBUSB_CALL libusb_error_name(int errcode);
01309 int LIBUSB_CALL libusb_setlocale(const char *locale);
01310 const char * LIBUSB_CALL libusb_strerror(enum libusb_error errcode);
01311
01312 ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
01313 libusb_device ***list);
01314 void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
01315 int unref_devices);
01316 libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
01317 void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
01318
01319 int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
01320 int *config);
01321 int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
01322 struct libusb_device_descriptor *desc);
01323 int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
01324 struct libusb_config_descriptor **config);
01325 int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
01326 uint8_t config_index, struct libusb_config_descriptor **config);
01327 int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
01328 uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
01329 void LIBUSB_CALL libusb_free_config_descriptor(
01330 struct libusb_config_descriptor *config);
01331 int LIBUSB_CALL libusb_get_ss_endpoint_companion_descriptor(
01332 struct libusb_context *ctx,
01333 const struct libusb_endpoint_descriptor *endpoint,
01334 struct libusb_ss_endpoint_companion_descriptor **ep_comp);
01335 void LIBUSB_CALL libusb_free_ss_endpoint_companion_descriptor(
01336 struct libusb_ss_endpoint_companion_descriptor *ep_comp);
01337 int LIBUSB_CALL libusb_get_bos_descriptor(libusb_device_handle *handle,
01338 struct libusb_bos_descriptor **bos);
01339 void LIBUSB_CALL libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos);
01340 int LIBUSB_CALL libusb_get_usb_2_0_extension_descriptor(
01341 struct libusb_context *ctx,
01342 struct libusb_bos_dev_capability_descriptor *dev_cap,
01343 struct libusb_usb_2_0_extension_descriptor **usb_2_0_extension);
01344 void LIBUSB_CALL libusb_free_usb_2_0_extension_descriptor(
01345 struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension);
01346 int LIBUSB_CALL libusb_get_ss_usb_device_capability_descriptor(
01347 struct libusb_context *ctx,
01348 struct libusb_bos_dev_capability_descriptor *dev_cap,
01349 struct libusb_ss_usb_device_capability_descriptor **ss_usb_device_cap);
01350 void LIBUSB_CALL libusb_free_ss_usb_device_capability_descriptor(
01351 struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap);
01352 int LIBUSB_CALL libusb_get_container_id_descriptor(struct libusb_context *ctx,
01353 struct libusb_bos_dev_capability_descriptor *dev_cap,
01354 struct libusb_container_id_descriptor **container_id);
01355 void LIBUSB_CALL libusb_free_container_id_descriptor(
01356 struct libusb_container_id_descriptor *container_id);
01357 uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
01358 uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
01359 int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t* port_numbers, int port_numbers_len);
01360 LIBUSB_DEPRECATED_FOR(libusb_get_port_numbers)
01361 int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
01362 libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
01363 uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
01364 int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
01365 int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
01366 unsigned char endpoint);
01367 int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
01368 unsigned char endpoint);
01369
01370 int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
01371 void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
01372 libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
01373
01374 int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
01375 int configuration);
01376 int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
01377 int interface_number);
01378 int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
01379 int interface_number);
01380
01381 libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
01382 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
01383
01384 int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
01385 int interface_number, int alternate_setting);
01386 int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
01387 unsigned char endpoint);
01388 int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
01389
01390 int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
01391 int interface_number);
01392 int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
01393 int interface_number);
01394 int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
01395 int interface_number);
01396 int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
01397 libusb_device_handle *dev, int enable);
01398
01399
01400
01413 static inline unsigned char *libusb_control_transfer_get_data(
01414 struct libusb_transfer *transfer)
01415 {
01416 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
01417 }
01418
01431 static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
01432 struct libusb_transfer *transfer)
01433 {
01434 return (struct libusb_control_setup *)(void *) transfer->buffer;
01435 }
01436
01460 static inline void libusb_fill_control_setup(unsigned char *buffer,
01461 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
01462 uint16_t wLength)
01463 {
01464 struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
01465 setup->bmRequestType = bmRequestType;
01466 setup->bRequest = bRequest;
01467 setup->wValue = libusb_cpu_to_le16(wValue);
01468 setup->wIndex = libusb_cpu_to_le16(wIndex);
01469 setup->wLength = libusb_cpu_to_le16(wLength);
01470 }
01471
01472 struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
01473 int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
01474 int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
01475 void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
01476
01505 static inline void libusb_fill_control_transfer(
01506 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
01507 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
01508 unsigned int timeout)
01509 {
01510 struct libusb_control_setup *setup = (struct libusb_control_setup *)(void *) buffer;
01511 transfer->dev_handle = dev_handle;
01512 transfer->endpoint = 0;
01513 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
01514 transfer->timeout = timeout;
01515 transfer->buffer = buffer;
01516 if (setup)
01517 transfer->length = (int) (LIBUSB_CONTROL_SETUP_SIZE
01518 + libusb_le16_to_cpu(setup->wLength));
01519 transfer->user_data = user_data;
01520 transfer->callback = callback;
01521 }
01522
01536 static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
01537 libusb_device_handle *dev_handle, unsigned char endpoint,
01538 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
01539 void *user_data, unsigned int timeout)
01540 {
01541 transfer->dev_handle = dev_handle;
01542 transfer->endpoint = endpoint;
01543 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
01544 transfer->timeout = timeout;
01545 transfer->buffer = buffer;
01546 transfer->length = length;
01547 transfer->user_data = user_data;
01548 transfer->callback = callback;
01549 }
01550
01564 static inline void libusb_fill_interrupt_transfer(
01565 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
01566 unsigned char endpoint, unsigned char *buffer, int length,
01567 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
01568 {
01569 transfer->dev_handle = dev_handle;
01570 transfer->endpoint = endpoint;
01571 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
01572 transfer->timeout = timeout;
01573 transfer->buffer = buffer;
01574 transfer->length = length;
01575 transfer->user_data = user_data;
01576 transfer->callback = callback;
01577 }
01578
01593 static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
01594 libusb_device_handle *dev_handle, unsigned char endpoint,
01595 unsigned char *buffer, int length, int num_iso_packets,
01596 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
01597 {
01598 transfer->dev_handle = dev_handle;
01599 transfer->endpoint = endpoint;
01600 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
01601 transfer->timeout = timeout;
01602 transfer->buffer = buffer;
01603 transfer->length = length;
01604 transfer->num_iso_packets = num_iso_packets;
01605 transfer->user_data = user_data;
01606 transfer->callback = callback;
01607 }
01608
01617 static inline void libusb_set_iso_packet_lengths(
01618 struct libusb_transfer *transfer, unsigned int length)
01619 {
01620 int i;
01621 for (i = 0; i < transfer->num_iso_packets; i++)
01622 transfer->iso_packet_desc[i].length = length;
01623 }
01624
01641 static inline unsigned char *libusb_get_iso_packet_buffer(
01642 struct libusb_transfer *transfer, unsigned int packet)
01643 {
01644 int i;
01645 size_t offset = 0;
01646 int _packet;
01647
01648
01649
01650
01651 if (packet > INT_MAX)
01652 return NULL;
01653 _packet = (int) packet;
01654
01655 if (_packet >= transfer->num_iso_packets)
01656 return NULL;
01657
01658 for (i = 0; i < _packet; i++)
01659 offset += transfer->iso_packet_desc[i].length;
01660
01661 return transfer->buffer + offset;
01662 }
01663
01683 static inline unsigned char *libusb_get_iso_packet_buffer_simple(
01684 struct libusb_transfer *transfer, unsigned int packet)
01685 {
01686 int _packet;
01687
01688
01689
01690
01691 if (packet > INT_MAX)
01692 return NULL;
01693 _packet = (int) packet;
01694
01695 if (_packet >= transfer->num_iso_packets)
01696 return NULL;
01697
01698 return transfer->buffer + ((int) transfer->iso_packet_desc[0].length * _packet);
01699 }
01700
01701
01702
01703 int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
01704 uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
01705 unsigned char *data, uint16_t wLength, unsigned int timeout);
01706
01707 int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
01708 unsigned char endpoint, unsigned char *data, int length,
01709 int *actual_length, unsigned int timeout);
01710
01711 int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
01712 unsigned char endpoint, unsigned char *data, int length,
01713 int *actual_length, unsigned int timeout);
01714
01727 static inline int libusb_get_descriptor(libusb_device_handle *dev,
01728 uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
01729 {
01730 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
01731 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t) ((desc_type << 8) | desc_index),
01732 0, data, (uint16_t) length, 1000);
01733 }
01734
01749 static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
01750 uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
01751 {
01752 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
01753 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
01754 langid, data, (uint16_t) length, 1000);
01755 }
01756
01757 int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
01758 uint8_t desc_index, unsigned char *data, int length);
01759
01760
01761
01762 int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
01763 void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
01764 void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
01765 int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
01766 int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
01767 void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
01768 void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
01769 int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
01770
01771 int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
01772 struct timeval *tv);
01773 int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
01774 struct timeval *tv, int *completed);
01775 int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
01776 int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
01777 int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
01778 struct timeval *tv);
01779 int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
01780 int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
01781 struct timeval *tv);
01782
01786 struct libusb_pollfd {
01788 int fd;
01789
01794 short events;
01795 };
01796
01807 typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
01808 void *user_data);
01809
01819 typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
01820
01821 const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
01822 libusb_context *ctx);
01823 void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
01824 libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
01825 void *user_data);
01826
01839 typedef int libusb_hotplug_callback_handle;
01840
01846 typedef enum {
01848 LIBUSB_HOTPLUG_ENUMERATE = 1,
01849 } libusb_hotplug_flag;
01850
01856 typedef enum {
01858 LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED = 0x01,
01859
01863 LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT = 0x02,
01864 } libusb_hotplug_event;
01865
01868 #define LIBUSB_HOTPLUG_MATCH_ANY -1
01869
01892 typedef int (LIBUSB_CALL *libusb_hotplug_callback_fn)(libusb_context *ctx,
01893 libusb_device *device,
01894 libusb_hotplug_event event,
01895 void *user_data);
01896
01931 int LIBUSB_CALL libusb_hotplug_register_callback(libusb_context *ctx,
01932 libusb_hotplug_event events,
01933 libusb_hotplug_flag flags,
01934 int vendor_id, int product_id,
01935 int dev_class,
01936 libusb_hotplug_callback_fn cb_fn,
01937 void *user_data,
01938 libusb_hotplug_callback_handle *handle);
01939
01951 void LIBUSB_CALL libusb_hotplug_deregister_callback(libusb_context *ctx,
01952 libusb_hotplug_callback_handle handle);
01953
01954 #ifdef __cplusplus
01955 }
01956 #endif
01957
01958 #endif