libusb-glue.h revision 549f49a7966b55adde29133d8b97ab9a10a9ab25
17b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij/**
27b7a0e2b9d465dad85dca593693280f1df79a74dLinus 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>
67b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
77b7a0e2b9d465dad85dca593693280f1df79a74dLinus Walleij * Copyright (C) 2006-2007 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 */
30d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifndef LIBUSB_GLUE_H
31d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#define LIBUSB_GLUE_H
32eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij
33b02a066363ab3c9b4f8f48b227c9b7b71cf7705eLinus Walleij#include "ptp.h"
34eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#include <usb.h>
3515e344f57021b532da574b73aa74d1de3d6cdc73Linus Walleij#include "libmtp.h"
36fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#include "device-flags.h"
37eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij
38d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij/* Make functions available for C++ */
39d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus
40d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleijextern "C" {
41d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */
42d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij
43daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas/**
44daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas * Debug macro
45daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas */
46daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DEBUG(format, args...) \
47daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas  do { \
480358408fe9faa91c1c6737a785771dfaf691e101nicklas    if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \
49daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas      fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \
50daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas  } while (0)
51daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas
52daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas#define LIBMTP_USB_DATA(buffer, length, base) \
53daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas  do { \
540358408fe9faa91c1c6737a785771dfaf691e101nicklas    if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \
55daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas      data_dump_ascii (stdout, buffer, length, base); \
56daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas  } while (0)
57daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas
58daadbf2e26eca84c9d250f0e09d9efbe2c70d77anicklas
59eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define USB_BULK_READ usb_bulk_read
60eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define USB_BULK_WRITE usb_bulk_write
61eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij
622d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij/**
630558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij * Internal USB struct.
642d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij */
652d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijtypedef struct _PTP_USB PTP_USB;
662d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleijstruct _PTP_USB {
673e418e20db3fa3ec60d069478314238b47e71354Linus Walleij  PTPParams *params;
68c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  usb_dev_handle* handle;
69b0ab548319faa7bd1b8fb3cb6371d6d9ec98ce50Linus Walleij  uint8_t interface;
70c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  int inep;
71c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  int inep_maxpacket;
72c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  int outep;
73c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  int outep_maxpacket;
74c6210fb655cbf972efe722328e504434dc4d171cLinus Walleij  int intep;
752f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleij  int timeout;
76d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij  /** File transfer callbacks and counters */
77d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij  int callback_active;
78d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij  uint64_t current_transfer_total;
79d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij  uint64_t current_transfer_complete;
80d214b9bae4e9b0c106a21ff3a3c24029982f9d50Linus Walleij  LIBMTP_progressfunc_t current_transfer_callback;
81ee73ef2300dae31ead0bf9dd755192207b18df53Linus Walleij  void const * current_transfer_callback_data;
820558ac5a7223633c592b05c2e10b7591e0b48db4Linus Walleij  /** Any special device flags, only used internally */
83fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  LIBMTP_raw_device_t rawdevice;
842d411dbbac42bec217126c9bf97f6bef9977c484Linus Walleij};
85eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij
86eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleijint open_device (int busn, int devn, short force, PTP_USB *ptp_usb, PTPParams *params, struct usb_device **dev);
87c6210fb655cbf972efe722328e504434dc4d171cLinus Walleijvoid dump_usbinfo(PTP_USB *ptp_usb);
88e029ebaaf63ea59609023de908d89ffe63074bddRichard Lowconst char *get_playlist_extension(PTP_USB *ptp_usb);
893c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleijvoid close_device(PTP_USB *ptp_usb, PTPParams *params);
90549f49a7966b55adde29133d8b97ab9a10a9ab25Linus WalleijLIBMTP_error_number_t configure_usb_device(LIBMTP_raw_device_t *device,
913c643259ce83980ab8b1917fe5bbbb0b5aeeb06eLinus Walleij					   PTPParams *params,
92a700d220088b2042e3a4198ee78baf5691330db2Linus Walleij					   void **usbinfo);
932f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid set_usb_device_timeout(PTP_USB *ptp_usb, int timeout);
942f62281923b4ec12538b47f5d56a5e2b95c45006Linus Walleijvoid get_usb_device_timeout(PTP_USB *ptp_usb, int *timeout);
95eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij
96fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij/* Flag check macros */
97fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST_ALL(a) \
98fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL)
99fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_UNLOAD_DRIVER(a) \
100fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNLOAD_DRIVER)
101fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_MTPGETOBJPROPLIST(a) \
102fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST)
103fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_ZERO_READS(a) \
104fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_ZERO_READS)
105fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IRIVER_OGG_ALZHEIMER(a) \
106fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IRIVER_OGG_ALZHEIMER)
107fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_ONLY_7BIT_FILENAMES(a) \
108fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ONLY_7BIT_FILENAMES)
109fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_NO_RELEASE_INTERFACE(a) \
110fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_NO_RELEASE_INTERFACE)
111fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_IGNORE_HEADER_ERRORS(a) \
112fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_IGNORE_HEADER_ERRORS)
113fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_OBJECT_PROPLIST(a) \
114fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_OBJECT_PROPLIST)
115fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_OGG_IS_UNKNOWN(a) \
116fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_OGG_IS_UNKNOWN)
117fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij#define FLAG_BROKEN_SET_SAMPLE_DIMENSIONS(a) \
118fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SET_SAMPLE_DIMENSIONS)
119335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij#define FLAG_ALWAYS_PROBE_DESCRIPTOR(a) \
120335a81cf1f504d9ba87702181eaa13f8476f3166Linus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_ALWAYS_PROBE_DESCRIPTOR)
121f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V1(a) \
122f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V1)
123f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL_V2(a) \
124f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_PLAYLIST_SPL_V2)
125f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij#define FLAG_PLAYLIST_SPL(a) \
126f3c4405edbf6a9b5c61057c0c2ffbaf067e89cf4Linus Walleij  ((a)->rawdevice.device_entry.device_flags & (DEVICE_FLAG_PLAYLIST_SPL_V1 | DEVICE_FLAG_PLAYLIST_SPL_V2))
127cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij#define FLAG_CANNOT_HANDLE_DATEMODIFIED(a) \
128cf8dc2bb1c3a1f75f4efd0a1a85ddcc66e60341aLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_CANNOT_HANDLE_DATEMODIFIED)
129f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij#define FLAG_BROKEN_SEND_OBJECT_PROPLIST(a) \
130f67c1ada12299062333b7d622509b403ab925e8aLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_SEND_OBJECT_PROPLIST)
1314096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij#define FLAG_BROKEN_BATTERY_LEVEL(a) \
1324096c88324c7199d3bb16ae716be3ddc0a1c66b1Linus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_BROKEN_BATTERY_LEVEL)
13389bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij#define FLAG_FLAC_IS_UNKNOWN(a) \
13489bb1cdbe1d57fe8c43b3993047532024ac453bfLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_FLAC_IS_UNKNOWN)
135094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij#define FLAG_UNIQUE_FILENAMES(a) \
136094b450b7ce920e43eb701d6cdcd9c7d2a61e79eLinus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_UNIQUE_FILENAMES)
137fea4f53595425274263166b92797e3bb2349b549Linus Walleij#define FLAG_SWITCH_MODE_BLACKBERRY(a) \
138fea4f53595425274263166b92797e3bb2349b549Linus Walleij  ((a)->rawdevice.device_entry.device_flags & DEVICE_FLAG_SWITCH_MODE_BLACKBERRY)
139fec4d56d33e839b0d02e4d7f47a8ec16abb3bdcdLinus Walleij
140eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij/* connect_first_device return codes */
141eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_CONNECTED	0
142eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_NO_DEVICES	1
143eb8c6fe031f5ba155cabcbfabcc235acffbc2fbLinus Walleij#define PTP_CD_RC_ERROR_CONNECTING	2
144d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij
145d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#ifdef __cplusplus
146d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij}
147d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif /* __cplusplus */
148d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij
149d866d24d1673ba48ad2397908018b0761bb3beffLinus Walleij#endif //  LIBUSB-GLUE_H
150