libusb-glue.h revision fbbef8b16876568f760986e4ff8f4921b8373fd5
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> 6e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij * Copyright (C) 2005-2011 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 35fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#include <libusb-1.0/libusb.h> 36fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 37fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 387cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#include <usb.h> 39fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 4015e344f57021b532da574b73aa74d1de3d6cdc73Linus Walleij#include "libmtp.h" 41fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#include "device-flags.h" 42eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 43d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij/* Make functions available for C++ */ 44d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus 45d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleijextern "C" { 46d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */ 47d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 48daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas/** 49daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas * Debug macro 50daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas */ 51daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DEBUG(format, args...) \ 52daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas do { \ 530358408fe9faa91c1c6737a785771dfaf691e101nicklas if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \ 54daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ 55daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas } while (0) 56daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas 57daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DATA(buffer, length, base) \ 58daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas do { \ 590358408fe9faa91c1c6737a785771dfaf691e101nicklas if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \ 60daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas data_dump_ascii (stdout, buffer, length, base); \ 61daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas } while (0) 62daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas 63fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB1 64fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#define USB_BULK_READ libusb_bulk_transfer 65fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#define USB_BULK_WRITE libusb_bulk_transfer 66fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 67fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 687cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#define USB_BULK_READ usb_bulk_read 697cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#define USB_BULK_WRITE usb_bulk_write 70fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 71eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 722d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij/** 730558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij * Internal USB struct. 742d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij */ 752d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijtypedef struct _PTP_USB PTP_USB; 762d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijstruct _PTP_USB { 773e418e20db3fa3ec60d069478314238b47e71354Linus Walleij PTPParams *params; 78fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB1 79fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij libusb_device_handle* handle; 80fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 81fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#ifdef HAVE_LIBUSB0 827cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij usb_dev_handle* handle; 83fbbef8b16876568f760986e4ff8f4921b8373fd5Linus Walleij#endif 84b0ab548319faa7bd1b8fb3cb6371d6d9ec98ce50Linus Walleij uint8_t interface; 85c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int inep; 86c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int inep_maxpacket; 87c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int outep; 88c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int outep_maxpacket; 89c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij int intep; 90d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij /** File transfer callbacks and counters */ 91d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij int callback_active; 92e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij int timeout; 93e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij uint16_t bcdusb; 94d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij uint64_t current_transfer_total; 95d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij uint64_t current_transfer_complete; 96d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij LIBMTP_progressfunc_t current_transfer_callback; 97ee73ef2300dae31ead0bf9dd755192207b18df53Linus Walleij void const * current_transfer_callback_data; 980558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij /** Any special device flags, only used internally */ 99fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij LIBMTP_raw_device_t rawdevice; 1002d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij}; 101eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 1027cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleijint open_device (int busn, int devn, short force, PTP_USB *ptp_usb, PTPParams *params, struct usb_device **dev); 103c6210fb655cbf972efe722328e504434dc4d171cLinus Walleijvoid dump_usbinfo(PTP_USB *ptp_usb); 104e029ebaaf63ea59609023de908d89ffe63074bddRichard Lowconst char *get_playlist_extension(PTP_USB *ptp_usb); 1053c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleijvoid close_device(PTP_USB *ptp_usb, PTPParams *params); 106549f49a7966b55adde29133d8b97ab9a10a9ab25Linus WalleijLIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device, 1073c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleij PTPParams *params, 108a700d220088b2042e3a4198ee78baf5691330db2Linus Walleij void **usbinfo); 1092f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid set_usb_device_timeout(PTP_USB *ptp_usb, int timeout); 1102f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout); 111e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleijint guess_usb_speed(PTP_USB *ptp_usb); 112eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij 113fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij/* Flag check macros */ 114fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \ 115fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL) 116fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_UNLOAD_DRIVER(a) \ 117fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER) 118fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \ 119fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST) 120fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_ZERO_READS(a) \ 121fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS) 122fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IRIVER_OGG_ALZHEIMER(a) \ 123fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER) 124fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_ONLY_7BIT_FILENAMES(a) \ 125fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES) 126fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_RELEASE_INTERFACE(a) \ 127fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE) 128fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IGNORE_HEADER_ERRORS(a) \ 129fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS) 130fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \ 131fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST) 132fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_OGG_IS_UNKNOWN(a) \ 133fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN) 134fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \ 135fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS) 136335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij#define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \ 137335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR) 138f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V1(a) \ 139f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1) 140f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V2(a) \ 141f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2) 142f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL(a) \ 143f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2)) 144cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij#define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \ 145cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED) 146f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij#define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \ 147f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST) 1484096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij#define FLAG_BROKEN_BATTERY_LEVEL(a) \ 1494096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL) 15089bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij#define FLAG_FLAC_IS_UNKNOWN(a) \ 15189bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN) 152094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij#define FLAG_UNIQUE_FILENAMES(a) \ 153094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES) 154fea4f53595425274263166b92797e3bb2349b549Linus Walleij#define FLAG_SWITCH_MODE_BLACKBERRY(a) \ 155fea4f53595425274263166b92797e3bb2349b549Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY) 156e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij#define FLAG_LONG_TIMEOUT(a) \ 157e04a1b943a8cab73dc03b14382e1803fcf7eaf3fLinus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_LONG_TIMEOUT) 158f691317b6e4c37b22f5f1b3e3b94a717031db695Linus Walleij#define FLAG_FORCE_RESET_ON_CLOSE(a) \ 159f691317b6e4c37b22f5f1b3e3b94a717031db695Linus Walleij ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FORCE_RESET_ON_CLOSE) 160fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij 161eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij/* connect_first_device return codes */ 162eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_CONNECTED 0 163eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_NO_DEVICES 1 164eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_ERROR_CONNECTING 2 165d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 166d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus 167d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij} 168d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */ 169d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij 1707cf02643117f11ab3c7d11dd49c1fc9d1776ba4eLinus Walleij#endif // LIBUSB-GLUE_H 171