3 * Low-level USB interface glue towards libusb.
5 * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com>
6 * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
7 * Copyright (C) 2006-2011 Marcus Meissner
8 * Copyright (C) 2007 Ted Bullock
9 * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
26 * Created by Richard Low on 24/12/2005.
27 * Modified by Linus Walleij
40 #ifdef HAVE_LIBOPENUSB
44 #include "device-flags.h"
46 /* Make functions available for C++ */
49 #endif /* __cplusplus */
54 #define LIBMTP_USB_DEBUG(format, args...) \
56 if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \
57 fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \
60 #define LIBMTP_USB_DATA(buffer, length, base) \
62 if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \
63 data_dump_ascii (stdout, buffer, length, base); \
67 #define USB_BULK_READ libusb_bulk_transfer
68 #define USB_BULK_WRITE libusb_bulk_transfer
71 #define USB_BULK_READ usb_bulk_read
72 #define USB_BULK_WRITE usb_bulk_write
74 #ifdef HAVE_LIBOPENUSB
75 #define USB_BULK_READ openusb_bulk_xfer
76 #define USB_BULK_WRITE openusb_bulk_xfer
80 * Internal USB struct.
82 typedef struct _PTP_USB PTP_USB;
86 libusb_device_handle* handle;
89 usb_dev_handle* handle;
91 #ifdef HAVE_LIBOPENUSB
92 openusb_dev_handle_t* handle;
102 /** File transfer callbacks and counters */
106 uint64_t current_transfer_total;
107 uint64_t current_transfer_complete;
108 LIBMTP_progressfunc_t current_transfer_callback;
109 void const * current_transfer_callback_data;
110 /** Any special device flags, only used internally */
111 LIBMTP_raw_device_t rawdevice;
114 void dump_usbinfo(PTP_USB *ptp_usb);
115 const char *get_playlist_extension(PTP_USB *ptp_usb);
116 void close_device(PTP_USB *ptp_usb, PTPParams *params);
117 LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device,
120 void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
121 void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
122 int guess_usb_speed(PTP_USB *ptp_usb);
124 /* Flag check macros */
125 #define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
126 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
127 #define FLAG_UNLOAD_DRIVER(a) \
128 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
129 #define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
130 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
131 #define FLAG_NO_ZERO_READS(a) \
132 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
133 #define FLAG_IRIVER_OGG_ALZHEIMER(a) \
134 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
135 #define FLAG_ONLY_7BIT_FILENAMES(a) \
136 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
137 #define FLAG_NO_RELEASE_INTERFACE(a) \
138 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
139 #define FLAG_IGNORE_HEADER_ERRORS(a) \
140 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
141 #define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
142 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
143 #define FLAG_OGG_IS_UNKNOWN(a) \
144 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
145 #define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
146 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
147 #define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
148 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
149 #define FLAG_PLAYLIST_SPL_V1(a) \
150 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
151 #define FLAG_PLAYLIST_SPL_V2(a) \
152 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
153 #define FLAG_PLAYLIST_SPL(a) \
154 ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
155 #define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
156 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
157 #define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
158 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
159 #define FLAG_BROKEN_BATTERY_LEVEL(a) \
160 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
161 #define FLAG_FLAC_IS_UNKNOWN(a) \
162 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
163 #define FLAG_UNIQUE_FILENAMES(a) \
164 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES)
165 #define FLAG_SWITCH_MODE_BLACKBERRY(a) \
166 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY)
167 #define FLAG_LONG_TIMEOUT(a) \
168 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT)
169 #define FLAG_FORCE_RESET_ON_CLOSE(a) \
170 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE)
171 #define FLAG_BROKEN_GET_OBJECT_PROPVAL(a) \
172 ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_GET_OBJECT_PROPVAL)
174 /* connect_first_device return codes */
175 #define PTP_CD_RC_CONNECTED 0
176 #define PTP_CD_RC_NO_DEVICES 1
177 #define PTP_CD_RC_ERROR_CONNECTING 2
181 #endif /* __cplusplus */
183 #endif // LIBUSB-GLUE_H