17b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij/** 27cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij * \file libusb-glue.h 37b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Low-level USB interface glue towards libusb. 47b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * 57b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Copyright (C) 2005-2007 Richard A. Low <richard@wentnet.com> 615d18e31458be5006eb229df68869df2fff93495Linus Walleij * Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se> 7fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij * Copyright (C) 2006-2011 Marcus Meissner 87b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Copyright (C) 2007 Ted Bullock 92f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleij * Copyright (C) 2008 Chris Bagwell <chris@cnpbagwell.com> 107b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * 117b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * This library is free software; you can redistribute it and/or 127b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * modify it under the terms of the GNU Lesser General Public 137b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * License as published by the Free Software Foundation; either 147b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * version 2 of the License, or (at your option) any later version. 157b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * 167b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * This library is distributed in the hope that it will be useful, 177b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * but WITHOUT ANY WARRANTY; without even the implied warranty of 187b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 197b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Lesser General Public License for more details. 207b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * 217b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * You should have received a copy of the GNU Lesser General Public 227b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * License along with this library; if not, write to the 237b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 247b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Boston, MA 02111-1307, USA. 25eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij * 267b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Created by Richard Low on 24/12/2005. 277b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Modified by Linus Walleij 28eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij * 29eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij */ 307cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#ifndef LIBUSB_GLUE_H 317cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#define LIBUSB_GLUE_H 32eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 33b02a066363ab3c9b4f8f48b227c9b7b71cf7705eLinus Walleij#include "ptp.h" 34fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB1 350976e94f7cba09f62f876f8a4cb86c78a3baa2a6Linus Walleij#include <libusb.h> 36fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 37fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 387cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#include <usb.h> 39fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 4011082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#ifdef HAVE_LIBOPENUSB 4111082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#include <openusb.h> 4211082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#endif 4315e344f57021b532da574b73aa74d1de3d6cdc73Linus Walleij#include "libmtp.h" 44fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#include "device-flags.h" 45eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 46d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij/* Make functions available for C++ */ 47d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus 48d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleijextern "C" { 49d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */ 50d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 51daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas/** 52daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas * Debug macro 53daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas */ 54daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DEBUG(format, args...) \ 55daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas do { \ 560358408fe9faa91c1c6737a785771dfaf691e101nicklas if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \ 57daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ 58daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas } while (0) 59daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas 60daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DATA(buffer, length, base) \ 61daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas do { \ 620358408fe9faa91c1c6737a785771dfaf691e101nicklas if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \ 63daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas data_dump_ascii (stdout, buffer, length, base); \ 64daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas } while (0) 65daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas 66fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB1 67fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#define USB_BULK_READ libusb_bulk_transfer 68fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#define USB_BULK_WRITE libusb_bulk_transfer 69fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 70fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 717cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#define USB_BULK_READ usb_bulk_read 727cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#define USB_BULK_WRITE usb_bulk_write 73fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 7411082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#ifdef HAVE_LIBOPENUSB 7511082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#define USB_BULK_READ openusb_bulk_xfer 7611082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#define USB_BULK_WRITE openusb_bulk_xfer 7711082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#endif 78eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 792d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij/** 800558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij * Internal USB struct. 812d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij */ 822d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijtypedef struct _PTP_USB PTP_USB; 832d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijstruct _PTP_USB { 843e418e20db3fa3ec60d069478314238b47e71354Linus Walleij PTPParams *params; 85fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB1 86fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij libusb_device_handle* handle; 87fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 88fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 897cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij usb_dev_handle* handle; 90fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 9111082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#ifdef HAVE_LIBOPENUSB 9211082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew openusb_dev_handle_t* handle; 9311082d39bc800f7eba9a29484e8139445de41329Darran Kartaschew#endif 9415d18e31458be5006eb229df68869df2fff93495Linus Walleij uint8_t config; 95b0ab548319faa7bd1b8fb3cb6371d6d9ec98ce50Linus Walleij uint8_t interface; 9615d18e31458be5006eb229df68869df2fff93495Linus Walleij uint8_t altsetting; 97c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int inep; 98c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int inep_maxpacket; 99c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int outep; 100c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int outep_maxpacket; 101c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int intep; 102d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij /** File transfer callbacks and counters */ 103d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij int callback_active; 104e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij int timeout; 105e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij uint16_t bcdusb; 106d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij uint64_t current_transfer_total; 107d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij uint64_t current_transfer_complete; 108d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij LIBMTP_progressfunc_t current_transfer_callback; 109ee73ef2300dae31ead0bf9dd755192207b18df53Linus Walleij void const * current_transfer_callback_data; 1100558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij /** Any special device flags, only used internally */ 111fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij LIBMTP_raw_device_t rawdevice; 1122d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij}; 113eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 114c6210fb655cbf972efe722328e504434dc4d171cLinus Walleijvoid dump_usbinfo(PTP_USB *ptp_usb); 115e029ebaaf63ea59609023de908d89ffe63074bddRichard Lowconst char *get_playlist_extension(PTP_USB *ptp_usb); 1163c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleijvoid close_device(PTP_USB *ptp_usb, PTPParams *params); 117549f49a7966b55adde29133d8b97ab9a10a9ab25Linus WalleijLIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, 1183c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleij PTPParams *params, 119a700d220088b2042e3a4198ee78baf5691330db2Linus Walleij void **usbinfo); 1202f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid set_usb_device_timeout(PTP_USB *ptp_usb, int timeout); 1212f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout); 122e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleijint guess_usb_speed(PTP_USB *ptp_usb); 123eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 124fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij/* Flag check macros */ 125fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \ 126fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL) 127fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_UNLOAD_DRIVER(a) \ 128fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER) 129fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \ 130fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST) 131fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_ZERO_READS(a) \ 132fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS) 133fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IRIVER_OGG_ALZHEIMER(a) \ 134fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER) 135fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_ONLY_7BIT_FILENAMES(a) \ 136fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES) 137fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_RELEASE_INTERFACE(a) \ 138fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE) 139fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IGNORE_HEADER_ERRORS(a) \ 140fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS) 141fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \ 142fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST) 143fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_OGG_IS_UNKNOWN(a) \ 144fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN) 145fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \ 146fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS) 147335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij#define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \ 148335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR) 149f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V1(a) \ 150f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1) 151f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V2(a) \ 152f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2) 153f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL(a) \ 154f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2)) 155cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij#define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \ 156cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED) 157f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij#define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \ 158f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST) 1594096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij#define FLAG_BROKEN_BATTERY_LEVEL(a) \ 1604096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL) 16189bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij#define FLAG_FLAC_IS_UNKNOWN(a) \ 16289bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN) 163094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij#define FLAG_UNIQUE_FILENAMES(a) \ 164094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES) 165fea4f53595425274263166b92797e3bb2349b549Linus Walleij#define FLAG_SWITCH_MODE_BLACKBERRY(a) \ 166fea4f53595425274263166b92797e3bb2349b549Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY) 167e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij#define FLAG_LONG_TIMEOUT(a) \ 168e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT) 169f691317b6e4c37b22f5f1b3e3b94a717031db695Linus Walleij#define FLAG_FORCE_RESET_ON_CLOSE(a) \ 170f691317b6e4c37b22f5f1b3e3b94a717031db695Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE) 1716ccbe96fef92215cc02548b99c1d7d75140c05eaLinus Walleij#define FLAG_BROKEN_GET_OBJECT_PROPVAL(a) \ 1726ccbe96fef92215cc02548b99c1d7d75140c05eaLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_GET_OBJECT_PROPVAL) 173fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij 174eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij/* connect_first_device return codes */ 175eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_CONNECTED 0 176eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_NO_DEVICES 1 177eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_ERROR_CONNECTING 2 178d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 179d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus 180d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij} 181d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */ 182d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 1837cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#endif // LIBUSB-GLUE_H 184