Linus Walleij | 7b7a0e2 | 2007-02-05 18:22:27 +0000 | [diff] [blame] | 1 | /** |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 2 | * \file libusb-glue.h |
Linus Walleij | 7b7a0e2 | 2007-02-05 18:22:27 +0000 | [diff] [blame] | 3 | * Low-level USB interface glue towards libusb. |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 4 | * |
Linus Walleij | 7b7a0e2 | 2007-02-05 18:22:27 +0000 | [diff] [blame] | 5 | * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com> |
Linus Walleij | 15d18e3 | 2012-08-20 02:00:34 +0200 | [diff] [blame] | 6 | * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 7 | * Copyright (C) 2006-2011 Marcus Meissner |
Linus Walleij | 7b7a0e2 | 2007-02-05 18:22:27 +0000 | [diff] [blame] | 8 | * Copyright (C) 2007 Ted Bullock |
Linus Walleij | 2f62281 | 2008-08-30 22:06:58 +0000 | [diff] [blame] | 9 | * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com> |
Linus Walleij | 7b7a0e2 | 2007-02-05 18:22:27 +0000 | [diff] [blame] | 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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. |
| 25 | * |
| 26 | * Created by Richard Low on 24/12/2005. |
| 27 | * Modified by Linus Walleij |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 28 | * |
| 29 | */ |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 30 | #ifndef LIBUSB_GLUE_H |
| 31 | #define LIBUSB_GLUE_H |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 32 | |
Linus Walleij | b02a066 | 2006-04-25 08:05:09 +0000 | [diff] [blame] | 33 | #include "ptp.h" |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 34 | #ifdef HAVE_LIBUSB1 |
Linus Walleij | 0976e94 | 2013-11-06 04:44:23 +0100 | [diff] [blame] | 35 | #include <libusb.h> |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 36 | #endif |
| 37 | #ifdef HAVE_LIBUSB0 |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 38 | #include <usb.h> |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 39 | #endif |
Darran Kartaschew | 11082d3 | 2011-12-13 00:42:01 +0100 | [diff] [blame] | 40 | #ifdef HAVE_LIBOPENUSB |
| 41 | #include <openusb.h> |
| 42 | #endif |
Linus Walleij | 15e344f | 2006-03-06 15:15:00 +0000 | [diff] [blame] | 43 | #include "libmtp.h" |
Linus Walleij | fec4d56 | 2008-06-01 22:30:36 +0000 | [diff] [blame] | 44 | #include "device-flags.h" |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 45 | |
Linus Walleij | d866d24 | 2009-08-23 21:50:39 +0000 | [diff] [blame] | 46 | /* Make functions available for C++ */ |
| 47 | #ifdef __cplusplus |
| 48 | extern "C" { |
| 49 | #endif /* __cplusplus */ |
| 50 | |
nicklas79 | daadbf2 | 2009-09-28 18:19:34 +0000 | [diff] [blame] | 51 | /** |
| 52 | * Debug macro |
| 53 | */ |
| 54 | #define LIBMTP_USB_DEBUG(format, args...) \ |
| 55 | do { \ |
nicklas79 | 0358408 | 2009-09-28 18:20:16 +0000 | [diff] [blame] | 56 | if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \ |
nicklas79 | daadbf2 | 2009-09-28 18:19:34 +0000 | [diff] [blame] | 57 | fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ |
| 58 | } while (0) |
| 59 | |
| 60 | #define LIBMTP_USB_DATA(buffer, length, base) \ |
| 61 | do { \ |
nicklas79 | 0358408 | 2009-09-28 18:20:16 +0000 | [diff] [blame] | 62 | if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \ |
nicklas79 | daadbf2 | 2009-09-28 18:19:34 +0000 | [diff] [blame] | 63 | data_dump_ascii (stdout, buffer, length, base); \ |
| 64 | } while (0) |
| 65 | |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 66 | #ifdef HAVE_LIBUSB1 |
| 67 | #define USB_BULK_READ libusb_bulk_transfer |
| 68 | #define USB_BULK_WRITE libusb_bulk_transfer |
| 69 | #endif |
| 70 | #ifdef HAVE_LIBUSB0 |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 71 | #define USB_BULK_READ usb_bulk_read |
| 72 | #define USB_BULK_WRITE usb_bulk_write |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 73 | #endif |
Darran Kartaschew | 11082d3 | 2011-12-13 00:42:01 +0100 | [diff] [blame] | 74 | #ifdef HAVE_LIBOPENUSB |
| 75 | #define USB_BULK_READ openusb_bulk_xfer |
| 76 | #define USB_BULK_WRITE openusb_bulk_xfer |
| 77 | #endif |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 78 | |
Linus Walleij | 2d411db | 2006-03-22 12:13:09 +0000 | [diff] [blame] | 79 | /** |
Linus Walleij | 0558ac5 | 2006-09-07 06:55:03 +0000 | [diff] [blame] | 80 | * Internal USB struct. |
Linus Walleij | 2d411db | 2006-03-22 12:13:09 +0000 | [diff] [blame] | 81 | */ |
| 82 | typedef struct _PTP_USB PTP_USB; |
| 83 | struct _PTP_USB { |
Linus Walleij | 3e418e2 | 2007-09-15 20:30:14 +0000 | [diff] [blame] | 84 | PTPParams *params; |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 85 | #ifdef HAVE_LIBUSB1 |
| 86 | libusb_device_handle* handle; |
| 87 | #endif |
| 88 | #ifdef HAVE_LIBUSB0 |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 89 | usb_dev_handle* handle; |
Linus Walleij | fbbef8b | 2011-11-17 19:19:51 +0100 | [diff] [blame] | 90 | #endif |
Darran Kartaschew | 11082d3 | 2011-12-13 00:42:01 +0100 | [diff] [blame] | 91 | #ifdef HAVE_LIBOPENUSB |
| 92 | openusb_dev_handle_t* handle; |
| 93 | #endif |
Linus Walleij | 15d18e3 | 2012-08-20 02:00:34 +0200 | [diff] [blame] | 94 | uint8_t config; |
Linus Walleij | b0ab548 | 2007-08-29 21:08:54 +0000 | [diff] [blame] | 95 | uint8_t interface; |
Linus Walleij | 15d18e3 | 2012-08-20 02:00:34 +0200 | [diff] [blame] | 96 | uint8_t altsetting; |
Linus Walleij | c6210fb | 2006-05-08 11:11:41 +0000 | [diff] [blame] | 97 | int inep; |
| 98 | int inep_maxpacket; |
| 99 | int outep; |
| 100 | int outep_maxpacket; |
| 101 | int intep; |
Linus Walleij | d214b9b | 2006-08-26 22:08:37 +0000 | [diff] [blame] | 102 | /** File transfer callbacks and counters */ |
| 103 | int callback_active; |
Linus Walleij | e04a1b9 | 2011-03-09 18:00:24 +0100 | [diff] [blame] | 104 | int timeout; |
| 105 | uint16_t bcdusb; |
Linus Walleij | d214b9b | 2006-08-26 22:08:37 +0000 | [diff] [blame] | 106 | uint64_t current_transfer_total; |
| 107 | uint64_t current_transfer_complete; |
| 108 | LIBMTP_progressfunc_t current_transfer_callback; |
Linus Walleij | ee73ef2 | 2006-08-27 19:56:00 +0000 | [diff] [blame] | 109 | void const * current_transfer_callback_data; |
Linus Walleij | 0558ac5 | 2006-09-07 06:55:03 +0000 | [diff] [blame] | 110 | /** Any special device flags, only used internally */ |
Linus Walleij | fec4d56 | 2008-06-01 22:30:36 +0000 | [diff] [blame] | 111 | LIBMTP_raw_device_t rawdevice; |
Linus Walleij | 2d411db | 2006-03-22 12:13:09 +0000 | [diff] [blame] | 112 | }; |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 113 | |
Linus Walleij | c6210fb | 2006-05-08 11:11:41 +0000 | [diff] [blame] | 114 | void dump_usbinfo(PTP_USB *ptp_usb); |
Richard Low | e029eba | 2009-04-11 12:36:25 +0000 | [diff] [blame] | 115 | const char *get_playlist_extension(PTP_USB *ptp_usb); |
Linus Walleij | 3c64325 | 2008-05-31 23:22:28 +0000 | [diff] [blame] | 116 | void close_device(PTP_USB *ptp_usb, PTPParams *params); |
Linus Walleij | 549f49a | 2010-12-05 14:00:34 +0000 | [diff] [blame] | 117 | LIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, |
Linus Walleij | 3c64325 | 2008-05-31 23:22:28 +0000 | [diff] [blame] | 118 | PTPParams *params, |
Linus Walleij | a700d22 | 2008-05-28 23:06:14 +0000 | [diff] [blame] | 119 | void **usbinfo); |
Linus Walleij | 2f62281 | 2008-08-30 22:06:58 +0000 | [diff] [blame] | 120 | void set_usb_device_timeout(PTP_USB *ptp_usb, int timeout); |
| 121 | void get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout); |
Linus Walleij | e04a1b9 | 2011-03-09 18:00:24 +0100 | [diff] [blame] | 122 | int guess_usb_speed(PTP_USB *ptp_usb); |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 123 | |
Linus Walleij | fec4d56 | 2008-06-01 22:30:36 +0000 | [diff] [blame] | 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) |
Linus Walleij | 335a81c | 2008-06-02 23:01:00 +0000 | [diff] [blame] | 147 | #define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \ |
| 148 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR) |
Linus Walleij | f3c4405 | 2008-08-16 21:14:56 +0000 | [diff] [blame] | 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)) |
Linus Walleij | cf8dc2b | 2008-10-21 13:58:36 +0000 | [diff] [blame] | 155 | #define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \ |
| 156 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED) |
Linus Walleij | f67c1ad | 2009-01-14 21:39:50 +0000 | [diff] [blame] | 157 | #define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \ |
| 158 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST) |
Linus Walleij | 4096c88 | 2009-03-16 23:32:34 +0000 | [diff] [blame] | 159 | #define FLAG_BROKEN_BATTERY_LEVEL(a) \ |
| 160 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL) |
Linus Walleij | 89bb1cd | 2009-07-24 21:03:36 +0000 | [diff] [blame] | 161 | #define FLAG_FLAC_IS_UNKNOWN(a) \ |
| 162 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN) |
Linus Walleij | 094b450 | 2009-09-22 22:28:33 +0000 | [diff] [blame] | 163 | #define FLAG_UNIQUE_FILENAMES(a) \ |
| 164 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES) |
Linus Walleij | fea4f53 | 2009-09-22 22:08:35 +0000 | [diff] [blame] | 165 | #define FLAG_SWITCH_MODE_BLACKBERRY(a) \ |
| 166 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY) |
Linus Walleij | e04a1b9 | 2011-03-09 18:00:24 +0100 | [diff] [blame] | 167 | #define FLAG_LONG_TIMEOUT(a) \ |
| 168 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT) |
Linus Walleij | f691317 | 2011-03-10 22:10:26 +0100 | [diff] [blame] | 169 | #define FLAG_FORCE_RESET_ON_CLOSE(a) \ |
| 170 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE) |
Linus Walleij | 6ccbe96 | 2011-11-25 09:40:00 +0100 | [diff] [blame] | 171 | #define FLAG_BROKEN_GET_OBJECT_PROPVAL(a) \ |
| 172 | ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_GET_OBJECT_PROPVAL) |
Linus Walleij | fec4d56 | 2008-06-01 22:30:36 +0000 | [diff] [blame] | 173 | |
Linus Walleij | eb8c6fe | 2006-02-03 09:46:22 +0000 | [diff] [blame] | 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 |
Linus Walleij | d866d24 | 2009-08-23 21:50:39 +0000 | [diff] [blame] | 178 | |
| 179 | #ifdef __cplusplus |
| 180 | } |
| 181 | #endif /* __cplusplus */ |
| 182 | |
Linus Walleij | 7cf0264 | 2011-11-16 23:44:58 +0100 | [diff] [blame] | 183 | #endif // LIBUSB-GLUE_H |