00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef LIBUSB_H
00022 #define LIBUSB_H
00023
00024 #ifdef _MSC_VER
00025
00026 #define inline __inline
00027
00028 #ifndef _SSIZE_T_DEFINED
00029 #define _SSIZE_T_DEFINED
00030 #undef ssize_t
00031 #ifdef _WIN64
00032 typedef __int64 ssize_t;
00033 #else
00034 typedef int ssize_t;
00035 #endif
00036 #endif
00037 #endif
00038
00039
00040 #if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
00041 typedef unsigned __int8 uint8_t;
00042 typedef unsigned __int16 uint16_t;
00043 typedef unsigned __int32 uint32_t;
00044 #else
00045 #include <stdint.h>
00046 #endif
00047
00048 #include <sys/types.h>
00049 #include <time.h>
00050 #include <limits.h>
00051
00052 #if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
00053 #include <sys/time.h>
00054 #endif
00055
00056
00057
00058
00059
00060
00061 #if defined(_WIN32) || defined(__CYGWIN__)
00062 #include <windows.h>
00063 #if defined(interface)
00064 #undef interface
00065 #endif
00066 #endif
00067
00093
00094
00095
00096
00097
00098
00099
00100 #if defined(_WIN32) || defined(__CYGWIN__)
00101 #define LIBUSB_CALL WINAPI
00102 #else
00103 #define LIBUSB_CALL
00104 #endif
00105
00106 #ifdef __cplusplus
00107 extern "C" {
00108 #endif
00109
00118 static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
00119 {
00120 union {
00121 uint8_t b8[2];
00122 uint16_t b16;
00123 } _tmp;
00124 _tmp.b8[1] = x >> 8;
00125 _tmp.b8[0] = x & 0xff;
00126 return _tmp.b16;
00127 }
00128
00137 #define libusb_le16_to_cpu libusb_cpu_to_le16
00138
00139
00140
00143 enum libusb_class_code {
00148 LIBUSB_CLASS_PER_INTERFACE = 0,
00149
00151 LIBUSB_CLASS_AUDIO = 1,
00152
00154 LIBUSB_CLASS_COMM = 2,
00155
00157 LIBUSB_CLASS_HID = 3,
00158
00160 LIBUSB_CLASS_PHYSICAL = 5,
00161
00163 LIBUSB_CLASS_PRINTER = 7,
00164
00166 LIBUSB_CLASS_PTP = 6,
00167 LIBUSB_CLASS_IMAGE = 6,
00168
00170 LIBUSB_CLASS_MASS_STORAGE = 8,
00171
00173 LIBUSB_CLASS_HUB = 9,
00174
00176 LIBUSB_CLASS_DATA = 10,
00177
00179 LIBUSB_CLASS_SMART_CARD = 0x0b,
00180
00182 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
00183
00185 LIBUSB_CLASS_VIDEO = 0x0e,
00186
00188 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
00189
00191 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
00192
00194 LIBUSB_CLASS_WIRELESS = 0xe0,
00195
00197 LIBUSB_CLASS_APPLICATION = 0xfe,
00198
00200 LIBUSB_CLASS_VENDOR_SPEC = 0xff
00201 };
00202
00205 enum libusb_descriptor_type {
00207 LIBUSB_DT_DEVICE = 0x01,
00208
00210 LIBUSB_DT_CONFIG = 0x02,
00211
00213 LIBUSB_DT_STRING = 0x03,
00214
00216 LIBUSB_DT_INTERFACE = 0x04,
00217
00219 LIBUSB_DT_ENDPOINT = 0x05,
00220
00222 LIBUSB_DT_HID = 0x21,
00223
00225 LIBUSB_DT_REPORT = 0x22,
00226
00228 LIBUSB_DT_PHYSICAL = 0x23,
00229
00231 LIBUSB_DT_HUB = 0x29,
00232 };
00233
00234
00235 #define LIBUSB_DT_DEVICE_SIZE 18
00236 #define LIBUSB_DT_CONFIG_SIZE 9
00237 #define LIBUSB_DT_INTERFACE_SIZE 9
00238 #define LIBUSB_DT_ENDPOINT_SIZE 7
00239 #define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9
00240 #define LIBUSB_DT_HUB_NONVAR_SIZE 7
00241
00242 #define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f
00243 #define LIBUSB_ENDPOINT_DIR_MASK 0x80
00244
00249 enum libusb_endpoint_direction {
00251 LIBUSB_ENDPOINT_IN = 0x80,
00252
00254 LIBUSB_ENDPOINT_OUT = 0x00
00255 };
00256
00257 #define LIBUSB_TRANSFER_TYPE_MASK 0x03
00258
00263 enum libusb_transfer_type {
00265 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
00266
00268 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
00269
00271 LIBUSB_TRANSFER_TYPE_BULK = 2,
00272
00274 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
00275 };
00276
00279 enum libusb_standard_request {
00281 LIBUSB_REQUEST_GET_STATUS = 0x00,
00282
00284 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
00285
00286
00287
00289 LIBUSB_REQUEST_SET_FEATURE = 0x03,
00290
00291
00292
00294 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
00295
00297 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
00298
00300 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
00301
00303 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
00304
00306 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
00307
00309 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
00310
00312 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
00313
00315 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
00316 };
00317
00322 enum libusb_request_type {
00324 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
00325
00327 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
00328
00330 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
00331
00333 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
00334 };
00335
00340 enum libusb_request_recipient {
00342 LIBUSB_RECIPIENT_DEVICE = 0x00,
00343
00345 LIBUSB_RECIPIENT_INTERFACE = 0x01,
00346
00348 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
00349
00351 LIBUSB_RECIPIENT_OTHER = 0x03,
00352 };
00353
00354 #define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
00355
00361 enum libusb_iso_sync_type {
00363 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
00364
00366 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
00367
00369 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
00370
00372 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
00373 };
00374
00375 #define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
00376
00382 enum libusb_iso_usage_type {
00384 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
00385
00387 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
00388
00390 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
00391 };
00392
00398 struct libusb_device_descriptor {
00400 uint8_t bLength;
00401
00405 uint8_t bDescriptorType;
00406
00409 uint16_t bcdUSB;
00410
00412 uint8_t bDeviceClass;
00413
00416 uint8_t bDeviceSubClass;
00417
00420 uint8_t bDeviceProtocol;
00421
00423 uint8_t bMaxPacketSize0;
00424
00426 uint16_t idVendor;
00427
00429 uint16_t idProduct;
00430
00432 uint16_t bcdDevice;
00433
00435 uint8_t iManufacturer;
00436
00438 uint8_t iProduct;
00439
00441 uint8_t iSerialNumber;
00442
00444 uint8_t bNumConfigurations;
00445 };
00446
00452 struct libusb_endpoint_descriptor {
00454 uint8_t bLength;
00455
00459 uint8_t bDescriptorType;
00460
00465 uint8_t bEndpointAddress;
00466
00474 uint8_t bmAttributes;
00475
00477 uint16_t wMaxPacketSize;
00478
00480 uint8_t bInterval;
00481
00484 uint8_t bRefresh;
00485
00487 uint8_t bSynchAddress;
00488
00491 const unsigned char *extra;
00492
00494 int extra_length;
00495 };
00496
00502 struct libusb_interface_descriptor {
00504 uint8_t bLength;
00505
00509 uint8_t bDescriptorType;
00510
00512 uint8_t bInterfaceNumber;
00513
00515 uint8_t bAlternateSetting;
00516
00519 uint8_t bNumEndpoints;
00520
00522 uint8_t bInterfaceClass;
00523
00526 uint8_t bInterfaceSubClass;
00527
00530 uint8_t bInterfaceProtocol;
00531
00533 uint8_t iInterface;
00534
00537 const struct libusb_endpoint_descriptor *endpoint;
00538
00541 const unsigned char *extra;
00542
00544 int extra_length;
00545 };
00546
00550 struct libusb_interface {
00553 const struct libusb_interface_descriptor *altsetting;
00554
00556 int num_altsetting;
00557 };
00558
00564 struct libusb_config_descriptor {
00566 uint8_t bLength;
00567
00571 uint8_t bDescriptorType;
00572
00574 uint16_t wTotalLength;
00575
00577 uint8_t bNumInterfaces;
00578
00580 uint8_t bConfigurationValue;
00581
00583 uint8_t iConfiguration;
00584
00586 uint8_t bmAttributes;
00587
00591 uint8_t MaxPower;
00592
00595 const struct libusb_interface *interface;
00596
00599 const unsigned char *extra;
00600
00602 int extra_length;
00603 };
00604
00607 struct libusb_control_setup {
00613 uint8_t bmRequestType;
00614
00620 uint8_t bRequest;
00621
00623 uint16_t wValue;
00624
00627 uint16_t wIndex;
00628
00630 uint16_t wLength;
00631 };
00632
00633 #define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
00634
00635
00636
00637 struct libusb_context;
00638 struct libusb_device;
00639 struct libusb_device_handle;
00640
00644 struct libusb_version {
00646 const uint16_t major;
00647
00649 const uint16_t minor;
00650
00652 const uint16_t micro;
00653
00655 const uint16_t nano;
00656
00658 const char *rc;
00659
00661 const char *describe;
00662 };
00663
00681 typedef struct libusb_context libusb_context;
00682
00698 typedef struct libusb_device libusb_device;
00699
00700
00709 typedef struct libusb_device_handle libusb_device_handle;
00710
00714 enum libusb_speed {
00716 LIBUSB_SPEED_UNKNOWN = 0,
00717
00719 LIBUSB_SPEED_LOW = 1,
00720
00722 LIBUSB_SPEED_FULL = 2,
00723
00725 LIBUSB_SPEED_HIGH = 3,
00726
00728 LIBUSB_SPEED_SUPER = 4,
00729 };
00730
00737 enum libusb_error {
00739 LIBUSB_SUCCESS = 0,
00740
00742 LIBUSB_ERROR_IO = -1,
00743
00745 LIBUSB_ERROR_INVALID_PARAM = -2,
00746
00748 LIBUSB_ERROR_ACCESS = -3,
00749
00751 LIBUSB_ERROR_NO_DEVICE = -4,
00752
00754 LIBUSB_ERROR_NOT_FOUND = -5,
00755
00757 LIBUSB_ERROR_BUSY = -6,
00758
00760 LIBUSB_ERROR_TIMEOUT = -7,
00761
00763 LIBUSB_ERROR_OVERFLOW = -8,
00764
00766 LIBUSB_ERROR_PIPE = -9,
00767
00769 LIBUSB_ERROR_INTERRUPTED = -10,
00770
00772 LIBUSB_ERROR_NO_MEM = -11,
00773
00775 LIBUSB_ERROR_NOT_SUPPORTED = -12,
00776
00777
00778
00779
00781 LIBUSB_ERROR_OTHER = -99,
00782 };
00783
00786 enum libusb_transfer_status {
00789 LIBUSB_TRANSFER_COMPLETED,
00790
00792 LIBUSB_TRANSFER_ERROR,
00793
00795 LIBUSB_TRANSFER_TIMED_OUT,
00796
00798 LIBUSB_TRANSFER_CANCELLED,
00799
00802 LIBUSB_TRANSFER_STALL,
00803
00805 LIBUSB_TRANSFER_NO_DEVICE,
00806
00808 LIBUSB_TRANSFER_OVERFLOW,
00809 };
00810
00813 enum libusb_transfer_flags {
00815 LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
00816
00818 LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
00819
00824 LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
00825
00849 LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
00850 };
00851
00854 struct libusb_iso_packet_descriptor {
00856 unsigned int length;
00857
00859 unsigned int actual_length;
00860
00862 enum libusb_transfer_status status;
00863 };
00864
00865 struct libusb_transfer;
00866
00876 typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
00877
00884 struct libusb_transfer {
00886 libusb_device_handle *dev_handle;
00887
00889 uint8_t flags;
00890
00892 unsigned char endpoint;
00893
00895 unsigned char type;
00896
00899 unsigned int timeout;
00900
00908 enum libusb_transfer_status status;
00909
00911 int length;
00912
00916 int actual_length;
00917
00920 libusb_transfer_cb_fn callback;
00921
00923 void *user_data;
00924
00926 unsigned char *buffer;
00927
00930 int num_iso_packets;
00931
00933 struct libusb_iso_packet_descriptor iso_packet_desc
00934 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
00935 []
00936 #else
00937 [0]
00938 #endif
00939 ;
00940 };
00941
00947 enum libusb_capability {
00949 LIBUSB_CAP_HAS_CAPABILITY = 0,
00950 };
00951
00952 int LIBUSB_CALL libusb_init(libusb_context **ctx);
00953 void LIBUSB_CALL libusb_exit(libusb_context *ctx);
00954 void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
00955 const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
00956 int LIBUSB_CALL libusb_has_capability(uint32_t capability);
00957 const char * LIBUSB_CALL libusb_error_name(int errcode);
00958
00959 ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
00960 libusb_device ***list);
00961 void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
00962 int unref_devices);
00963 libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
00964 void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
00965
00966 int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
00967 int *config);
00968 int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
00969 struct libusb_device_descriptor *desc);
00970 int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
00971 struct libusb_config_descriptor **config);
00972 int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
00973 uint8_t config_index, struct libusb_config_descriptor **config);
00974 int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
00975 uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
00976 void LIBUSB_CALL libusb_free_config_descriptor(
00977 struct libusb_config_descriptor *config);
00978 uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
00979 uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
00980 int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
00981 int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
00982 unsigned char endpoint);
00983 int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
00984 unsigned char endpoint);
00985
00986 int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
00987 void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
00988 libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
00989
00990 int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
00991 int configuration);
00992 int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
00993 int interface_number);
00994 int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
00995 int interface_number);
00996
00997 libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
00998 libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
00999
01000 int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
01001 int interface_number, int alternate_setting);
01002 int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
01003 unsigned char endpoint);
01004 int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
01005
01006 int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
01007 int interface_number);
01008 int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
01009 int interface_number);
01010 int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
01011 int interface_number);
01012
01013
01014
01027 static inline unsigned char *libusb_control_transfer_get_data(
01028 struct libusb_transfer *transfer)
01029 {
01030 return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
01031 }
01032
01045 static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
01046 struct libusb_transfer *transfer)
01047 {
01048 return (struct libusb_control_setup *) transfer->buffer;
01049 }
01050
01073 static inline void libusb_fill_control_setup(unsigned char *buffer,
01074 uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
01075 uint16_t wLength)
01076 {
01077 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
01078 setup->bmRequestType = bmRequestType;
01079 setup->bRequest = bRequest;
01080 setup->wValue = libusb_cpu_to_le16(wValue);
01081 setup->wIndex = libusb_cpu_to_le16(wIndex);
01082 setup->wLength = libusb_cpu_to_le16(wLength);
01083 }
01084
01085 struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
01086 int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
01087 int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
01088 void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
01089
01117 static inline void libusb_fill_control_transfer(
01118 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
01119 unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
01120 unsigned int timeout)
01121 {
01122 struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
01123 transfer->dev_handle = dev_handle;
01124 transfer->endpoint = 0;
01125 transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
01126 transfer->timeout = timeout;
01127 transfer->buffer = buffer;
01128 if (setup)
01129 transfer->length = LIBUSB_CONTROL_SETUP_SIZE
01130 + libusb_le16_to_cpu(setup->wLength);
01131 transfer->user_data = user_data;
01132 transfer->callback = callback;
01133 }
01134
01148 static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
01149 libusb_device_handle *dev_handle, unsigned char endpoint,
01150 unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
01151 void *user_data, unsigned int timeout)
01152 {
01153 transfer->dev_handle = dev_handle;
01154 transfer->endpoint = endpoint;
01155 transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
01156 transfer->timeout = timeout;
01157 transfer->buffer = buffer;
01158 transfer->length = length;
01159 transfer->user_data = user_data;
01160 transfer->callback = callback;
01161 }
01162
01176 static inline void libusb_fill_interrupt_transfer(
01177 struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
01178 unsigned char endpoint, unsigned char *buffer, int length,
01179 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
01180 {
01181 transfer->dev_handle = dev_handle;
01182 transfer->endpoint = endpoint;
01183 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
01184 transfer->timeout = timeout;
01185 transfer->buffer = buffer;
01186 transfer->length = length;
01187 transfer->user_data = user_data;
01188 transfer->callback = callback;
01189 }
01190
01205 static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
01206 libusb_device_handle *dev_handle, unsigned char endpoint,
01207 unsigned char *buffer, int length, int num_iso_packets,
01208 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
01209 {
01210 transfer->dev_handle = dev_handle;
01211 transfer->endpoint = endpoint;
01212 transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
01213 transfer->timeout = timeout;
01214 transfer->buffer = buffer;
01215 transfer->length = length;
01216 transfer->num_iso_packets = num_iso_packets;
01217 transfer->user_data = user_data;
01218 transfer->callback = callback;
01219 }
01220
01229 static inline void libusb_set_iso_packet_lengths(
01230 struct libusb_transfer *transfer, unsigned int length)
01231 {
01232 int i;
01233 for (i = 0; i < transfer->num_iso_packets; i++)
01234 transfer->iso_packet_desc[i].length = length;
01235 }
01236
01253 static inline unsigned char *libusb_get_iso_packet_buffer(
01254 struct libusb_transfer *transfer, unsigned int packet)
01255 {
01256 int i;
01257 size_t offset = 0;
01258 int _packet;
01259
01260
01261
01262
01263 if (packet > INT_MAX)
01264 return NULL;
01265 _packet = packet;
01266
01267 if (_packet >= transfer->num_iso_packets)
01268 return NULL;
01269
01270 for (i = 0; i < _packet; i++)
01271 offset += transfer->iso_packet_desc[i].length;
01272
01273 return transfer->buffer + offset;
01274 }
01275
01295 static inline unsigned char *libusb_get_iso_packet_buffer_simple(
01296 struct libusb_transfer *transfer, unsigned int packet)
01297 {
01298 int _packet;
01299
01300
01301
01302
01303 if (packet > INT_MAX)
01304 return NULL;
01305 _packet = packet;
01306
01307 if (_packet >= transfer->num_iso_packets)
01308 return NULL;
01309
01310 return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
01311 }
01312
01313
01314
01315 int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
01316 uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
01317 unsigned char *data, uint16_t wLength, unsigned int timeout);
01318
01319 int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
01320 unsigned char endpoint, unsigned char *data, int length,
01321 int *actual_length, unsigned int timeout);
01322
01323 int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
01324 unsigned char endpoint, unsigned char *data, int length,
01325 int *actual_length, unsigned int timeout);
01326
01339 static inline int libusb_get_descriptor(libusb_device_handle *dev,
01340 uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
01341 {
01342 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
01343 LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
01344 (uint16_t) length, 1000);
01345 }
01346
01361 static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
01362 uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
01363 {
01364 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
01365 LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
01366 langid, data, (uint16_t) length, 1000);
01367 }
01368
01369 int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
01370 uint8_t desc_index, unsigned char *data, int length);
01371
01372
01373
01374 int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
01375 void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
01376 void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
01377 int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
01378 int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
01379 void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
01380 void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
01381 int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
01382
01383 int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
01384 struct timeval *tv);
01385 int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
01386 struct timeval *tv, int *completed);
01387 int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
01388 int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
01389 int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
01390 struct timeval *tv);
01391 int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
01392 int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
01393 struct timeval *tv);
01394
01398 struct libusb_pollfd {
01400 int fd;
01401
01406 short events;
01407 };
01408
01419 typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
01420 void *user_data);
01421
01431 typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
01432
01433 const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
01434 libusb_context *ctx);
01435 void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
01436 libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
01437 void *user_data);
01438
01439 #ifdef __cplusplus
01440 }
01441 #endif
01442
01443 #endif