libusb-glue.h
Go to the documentation of this file.00001
00030 #ifndef LIBUSB_GLUE_H
00031 #define LIBUSB_GLUE_H
00032
00033 #include "ptp.h"
00034 #ifdef HAVE_LIBUSB1
00035 #include <libusb.h>
00036 #endif
00037 #ifdef HAVE_LIBUSB0
00038 #include <usb.h>
00039 #endif
00040 #ifdef HAVE_LIBOPENUSB
00041 #include <openusb.h>
00042 #endif
00043 #include "libmtp.h"
00044 #include "device-flags.h"
00045
00046
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050
00054 #define LIBMTP_USB_DEBUG(format, args...) \
00055 do { \
00056 if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \
00057 fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \
00058 } while (0)
00059
00060 #define LIBMTP_USB_DATA(buffer, length, base) \
00061 do { \
00062 if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \
00063 data_dump_ascii (stdout, buffer, length, base); \
00064 } while (0)
00065
00066 #ifdef HAVE_LIBUSB1
00067 #define USB_BULK_READ libusb_bulk_transfer
00068 #define USB_BULK_WRITE libusb_bulk_transfer
00069 #endif
00070 #ifdef HAVE_LIBUSB0
00071 #define USB_BULK_READ usb_bulk_read
00072 #define USB_BULK_WRITE usb_bulk_write
00073 #endif
00074 #ifdef HAVE_LIBOPENUSB
00075 #define USB_BULK_READ openusb_bulk_xfer
00076 #define USB_BULK_WRITE openusb_bulk_xfer
00077 #endif
00078
00082 typedef struct _PTP_USB PTP_USB;
00083 struct _PTP_USB {
00084 PTPParams *params;
00085 #ifdef HAVE_LIBUSB1
00086 libusb_device_handle* handle;
00087 #endif
00088 #ifdef HAVE_LIBUSB0
00089 usb_dev_handle* handle;
00090 #endif
00091 #ifdef HAVE_LIBOPENUSB
00092 openusb_dev_handle_t* handle;
00093 #endif
00094 uint8_t config;
00095 uint8_t interface;
00096 uint8_t altsetting;
00097 int inep;
00098 int inep_maxpacket;
00099 int outep;
00100 int outep_maxpacket;
00101 int intep;
00103 int callback_active;
00104 int timeout;
00105 uint16_t bcdusb;
00106 uint64_t current_transfer_total;
00107 uint64_t current_transfer_complete;
00108 LIBMTP_progressfunc_t current_transfer_callback;
00109 void const * current_transfer_callback_data;
00111 LIBMTP_raw_device_t rawdevice;
00112 };
00113
00114 void dump_usbinfo(PTP_USB *ptp_usb);
00115 const char *get_playlist_extension(PTP_USB *ptp_usb);
00116 void close_device(PTP_USB *ptp_usb, PTPParams *params);
00117 LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device,
00118 PTPParams *params,
00119 void **usbinfo);
00120 void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
00121 void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
00122 int guess_usb_speed(PTP_USB *ptp_usb);
00123
00124
00125 #define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
00126 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
00127 #define FLAG_UNLOAD_DRIVER(a) \
00128 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
00129 #define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
00130 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
00131 #define FLAG_NO_ZERO_READS(a) \
00132 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
00133 #define FLAG_IRIVER_OGG_ALZHEIMER(a) \
00134 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
00135 #define FLAG_ONLY_7BIT_FILENAMES(a) \
00136 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
00137 #define FLAG_NO_RELEASE_INTERFACE(a) \
00138 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
00139 #define FLAG_IGNORE_HEADER_ERRORS(a) \
00140 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
00141 #define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
00142 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
00143 #define FLAG_OGG_IS_UNKNOWN(a) \
00144 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
00145 #define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
00146 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
00147 #define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
00148 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
00149 #define FLAG_PLAYLIST_SPL_V1(a) \
00150 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
00151 #define FLAG_PLAYLIST_SPL_V2(a) \
00152 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
00153 #define FLAG_PLAYLIST_SPL(a) \
00154 ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
00155 #define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
00156 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
00157 #define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
00158 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
00159 #define FLAG_BROKEN_BATTERY_LEVEL(a) \
00160 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
00161 #define FLAG_FLAC_IS_UNKNOWN(a) \
00162 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
00163 #define FLAG_UNIQUE_FILENAMES(a) \
00164 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES)
00165 #define FLAG_SWITCH_MODE_BLACKBERRY(a) \
00166 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY)
00167 #define FLAG_LONG_TIMEOUT(a) \
00168 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT)
00169 #define FLAG_FORCE_RESET_ON_CLOSE(a) \
00170 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE)
00171 #define FLAG_BROKEN_GET_OBJECT_PROPVAL(a) \
00172 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_GET_OBJECT_PROPVAL)
00173
00174
00175 #define PTP_CD_RC_CONNECTED 0
00176 #define PTP_CD_RC_NO_DEVICES 1
00177 #define PTP_CD_RC_ERROR_CONNECTING 2
00178
00179 #ifdef __cplusplus
00180 }
00181 #endif
00182
00183 #endif // LIBUSB-GLUE_H