libmtp  1.1.6
libusb-glue.h
Go to the documentation of this file.
1 
30 #ifndef LIBUSB_GLUE_H
31 #define LIBUSB_GLUE_H
32 
33 #include "ptp.h"
34 #ifdef HAVE_LIBUSB1
35 #include <libusb.h>
36 #include <pthread.h>
37 #endif
38 #ifdef HAVE_LIBUSB0
39 #include <usb.h>
40 #endif
41 #ifdef HAVE_LIBOPENUSB
42 #include <openusb.h>
43 #endif
44 #include "libmtp.h"
45 #include "device-flags.h"
46 
47 /* Make functions available for C++ */
48 #ifdef __cplusplus
49 extern "C" {
50 #endif /* __cplusplus */
51 
55 #define LIBMTP_USB_DEBUG(format, args...) \
56  do { \
57  if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \
58  fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \
59  } while (0)
60 
61 #define LIBMTP_USB_DATA(buffer, length, base) \
62  do { \
63  if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \
64  data_dump_ascii (stdout, buffer, length, base); \
65  } while (0)
66 
67 #ifdef HAVE_LIBUSB1
68 #define USB_BULK_READ libusb_bulk_transfer
69 #define USB_BULK_WRITE libusb_bulk_transfer
70 #endif
71 #ifdef HAVE_LIBUSB0
72 #define USB_BULK_READ usb_bulk_read
73 #define USB_BULK_WRITE usb_bulk_write
74 #endif
75 #ifdef HAVE_LIBOPENUSB
76 #define USB_BULK_READ openusb_bulk_xfer
77 #define USB_BULK_WRITE openusb_bulk_xfer
78 #endif
79 
80 #ifdef HAVE_LIBUSB1
81 /*
82  * With libusb1 we use a threaded read/write handler
83  * to speed up transfers.
84  */
85 struct ptp_write_td {
86  struct libusb_transfer *transfer;
87  struct ptp_write_td *next;
88  unsigned char *buffer;
89 };
90 /* Number of async transfer buffers */
91 #define WRITE_TRANSFER_NUM 4
92 #endif
93 
97 typedef struct _PTP_USB PTP_USB;
98 struct _PTP_USB {
99  PTPParams *params;
100 #ifdef HAVE_LIBUSB1
101  /*
102  * With libusb1 we use a threaded read/write handler
103  * to speed up transfers.
104  */
105  libusb_device_handle* handle;
106  int event_thread_run;
107  pthread_t ptp_event_thread_tid;
108  int ptp_read_transfer_done_flag;
109  pthread_cond_t ptp_read_transfer_done_cv;
110  pthread_mutex_t ptp_read_transfer_done_mutex;
111 
112  int ptp_write_transfer_done_flag;
113  pthread_cond_t ptp_write_transfer_cv;
114  pthread_mutex_t ptp_write_transfer_mutex;
115 
116  unsigned char *bytes[WRITE_TRANSFER_NUM];
117  struct ptp_write_td write_td_array[WRITE_TRANSFER_NUM];
118  struct ptp_write_td *p_write_head_td, *p_write_tail_td;
119 #endif
120 #ifdef HAVE_LIBUSB0
121  usb_dev_handle* handle;
122 #endif
123 #ifdef HAVE_LIBOPENUSB
124  openusb_dev_handle_t* handle;
125 #endif
126  uint8_t config;
127  uint8_t interface;
128  uint8_t altsetting;
129  int inep;
130  int inep_maxpacket;
131  int outep;
132  int outep_maxpacket;
133  int intep;
136  int timeout;
137  uint16_t bcdusb;
138  uint64_t current_transfer_total;
139  uint64_t current_transfer_complete;
140  LIBMTP_progressfunc_t current_transfer_callback;
141  void const * current_transfer_callback_data;
144 };
145 
146 void dump_usbinfo(PTP_USB *ptp_usb);
147 const char *get_playlist_extension(PTP_USB *ptp_usb);
148 void close_device(PTP_USB *ptp_usb, PTPParams *params);
150  PTPParams *params,
151  void **usbinfo);
152 void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
153 void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
154 int guess_usb_speed(PTP_USB *ptp_usb);
155 
156 /* Flag check macros */
157 #define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
158  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
159 #define FLAG_UNLOAD_DRIVER(a) \
160  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
161 #define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
162  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
163 #define FLAG_NO_ZERO_READS(a) \
164  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
165 #define FLAG_IRIVER_OGG_ALZHEIMER(a) \
166  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
167 #define FLAG_ONLY_7BIT_FILENAMES(a) \
168  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
169 #define FLAG_NO_RELEASE_INTERFACE(a) \
170  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
171 #define FLAG_IGNORE_HEADER_ERRORS(a) \
172  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
173 #define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
174  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
175 #define FLAG_OGG_IS_UNKNOWN(a) \
176  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
177 #define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
178  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
179 #define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
180  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
181 #define FLAG_PLAYLIST_SPL_V1(a) \
182  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
183 #define FLAG_PLAYLIST_SPL_V2(a) \
184  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
185 #define FLAG_PLAYLIST_SPL(a) \
186  ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
187 #define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
188  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
189 #define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
190  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
191 #define FLAG_BROKEN_BATTERY_LEVEL(a) \
192  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
193 #define FLAG_FLAC_IS_UNKNOWN(a) \
194  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
195 #define FLAG_UNIQUE_FILENAMES(a) \
196  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES)
197 #define FLAG_SWITCH_MODE_BLACKBERRY(a) \
198  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY)
199 #define FLAG_LONG_TIMEOUT(a) \
200  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT)
201 #define FLAG_FORCE_RESET_ON_CLOSE(a) \
202  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE)
203 #define FLAG_BROKEN_GET_OBJECT_PROPVAL(a) \
204  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_GET_OBJECT_PROPVAL)
205 
206 /* connect_first_device return codes */
207 #define PTP_CD_RC_CONNECTED 0
208 #define PTP_CD_RC_NO_DEVICES 1
209 #define PTP_CD_RC_ERROR_CONNECTING 2
210 
211 #ifdef __cplusplus
212 }
213 #endif /* __cplusplus */
214 
215 #endif // LIBUSB-GLUE_H
void dump_usbinfo(PTP_USB *ptp_usb)
Definition: libopenusb1-glue.c:693
int(* LIBMTP_progressfunc_t)(uint64_t const sent, uint64_t const total, void const *const data)
Definition: libmtp.h:470
int callback_active
Definition: libusb-glue.h:135
LIBMTP_error_number_t
Definition: libmtp.h:433
const char * get_playlist_extension(PTP_USB *ptp_usb)
Definition: libopenusb1-glue.c:726
LIBMTP_raw_device_t rawdevice
Definition: libusb-glue.h:143
Definition: ptp.h:2248
LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, PTPParams *params, void **usbinfo)
Definition: libusb-glue.c:1955
Definition: libmtp.h:531
Definition: libusb-glue.h:98