├── examples ├── .gitignore ├── util.h ├── pathutils.h ├── common.h ├── connect.h ├── Makefile.am ├── trexist.c ├── util.c ├── newfolder.c ├── reset.c ├── format.c ├── playlists.c ├── getfile.c ├── getplaylist.c ├── sendfile.c ├── delfile.c ├── evolution-sync.sh ├── emptyfolders.c ├── newplaylist.c ├── thumb.c ├── albums.c ├── folders.c ├── files.c ├── filetree.c ├── connect.c ├── albumart.c └── tracks.c ├── doc ├── .gitignore ├── examples.h ├── Makefile.am └── mainpage.h ├── util ├── .gitignore ├── Makefile.am └── mtp-probe.c ├── COPYING ├── src ├── .gitignore ├── README ├── gphoto2-sync.sh ├── playlist-spl.h ├── mtpz.h ├── unicode.h ├── .mtpz-data ├── util.h ├── Makefile.am ├── libmtp.sym ├── util.c ├── unicode.c └── libusb-glue.h ├── m4 └── .gitignore ├── logs ├── mtp-detect-nokia-5700.txt ├── mtp-detect-samsung-x830.txt ├── mtp-detect-toshiba-gigabeat-p20.txt ├── README.TXT ├── mtp-detect-archos-5.txt ├── mtp-detect-gigaware-gx400.txt ├── lsusb-canon-canoscan.txt ├── mtp-detect-toshiba-gigabeat-p10.txt ├── mtp-detect-mymusix-pd6070.txt ├── mtp-detect-thomson-m51.txt ├── mtp-detect-hp-touchpad.txt ├── mtp-detect-medion-lifetab-p9514.txt ├── mtp-detect-maxfield-g-flash-ng-1GB.txt ├── mtp-detect-samsung-sgh-u900.txt ├── mtp-detect-toshiba-gigabeat-v30.txt ├── mtp-detect-lg-gr500.txt ├── mtp-detect-nokia-5800.txt ├── mtp-detect-slacker-pmp.txt ├── mtp-detect-iriver-h10-20GB.txt ├── mtp-detect-sonyericsson-w890i.txt └── mtp-detect-iriver-t60.txt ├── .gitignore ├── libmtp.pc.in ├── sync-usbids.sh ├── .cvsignore ├── Makefile.am ├── libmtp.sh.in ├── AUTHORS ├── autogen.sh ├── README.windows.txt ├── TODO └── hotplug.sh.in /examples/.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs 3 | mtp-* 4 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | Doxyfile 2 | html 3 | latex 4 | man 5 | -------------------------------------------------------------------------------- /util/.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs 3 | mtp-hotplug 4 | mtp-probe 5 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbhomes/libmtp-zune/HEAD/COPYING -------------------------------------------------------------------------------- /src/.gitignore: -------------------------------------------------------------------------------- 1 | .deps 2 | .libs 3 | _stdint.h 4 | gphoto2-endian.h 5 | libmtp.h 6 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | libtool.m4 2 | ltoptions.m4 3 | ltsugar.m4 4 | ltversion.m4 5 | lt~obsolete.m4 6 | -------------------------------------------------------------------------------- /logs/mtp-detect-nokia-5700.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbhomes/libmtp-zune/HEAD/logs/mtp-detect-nokia-5700.txt -------------------------------------------------------------------------------- /logs/mtp-detect-samsung-x830.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbhomes/libmtp-zune/HEAD/logs/mtp-detect-samsung-x830.txt -------------------------------------------------------------------------------- /logs/mtp-detect-toshiba-gigabeat-p20.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kbhomes/libmtp-zune/HEAD/logs/mtp-detect-toshiba-gigabeat-p20.txt -------------------------------------------------------------------------------- /logs/README.TXT: -------------------------------------------------------------------------------- 1 | This directory contains USB packet logs 2 | used for analyzing MTP traffic for interoperability 3 | and device behaviour characteristics. -------------------------------------------------------------------------------- /util/Makefile.am: -------------------------------------------------------------------------------- 1 | if USE_LINUX 2 | bin_PROGRAMS=mtp-hotplug 3 | mtp_hotplug_SOURCES=mtp-hotplug.c 4 | 5 | mtp_probedir=@UDEV@ 6 | mtp_probe_PROGRAMS=mtp-probe 7 | mtp_probe_SOURCES=mtp-probe.c 8 | endif 9 | 10 | AM_CPPFLAGS=-I$(top_builddir)/src 11 | LDADD=../src/libmtp.la 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.patch 2 | *.o 3 | *.a 4 | *.la 5 | *.lo 6 | *~ 7 | *.orig 8 | *.rej 9 | Makefile 10 | Makefile.in 11 | aclocal.m4 12 | autom4te.cache 13 | config.* 14 | depcomp 15 | configure 16 | *.rules 17 | *.fdi 18 | *.pc 19 | *.usermap 20 | hotplug.sh 21 | install-sh 22 | libmtp.sh 23 | libtool 24 | ltmain.sh 25 | missing 26 | stamp-h1 27 | -------------------------------------------------------------------------------- /libmtp.pc.in: -------------------------------------------------------------------------------- 1 | # libmtp pkg-config source file 2 | 3 | prefix=@prefix@ 4 | exec_prefix=@exec_prefix@ 5 | libdir=@libdir@ 6 | includedir=@includedir@ 7 | 8 | Name: libmtp 9 | Description: libmtp is a library for accessing Media Transfer Protocol devices 10 | Version: @VERSION@ 11 | Requires: @LIBUSB_REQUIRES@ 12 | Conflicts: 13 | Libs: -L${libdir} -lmtp 14 | Libs.private: @LIBS@ 15 | Cflags: -I${includedir} @OSFLAGS@ 16 | -------------------------------------------------------------------------------- /sync-usbids.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Script to compare the USB ID list from linux-usb 4 | # with the internal list of libmtp. 5 | 6 | WGET=`which wget` 7 | if [ "x$WGET" != "x" ]; then 8 | wget -O usb.ids http://www.linux-usb.org/usb.ids 9 | examples/hotplug -i > usb.ids-libmtp 10 | echo "OK now compare usb.ids and usb.ids-libmtp..." 11 | else 12 | echo "Could not sync to linux-usb USB ID list. No WGET." 13 | fi 14 | -------------------------------------------------------------------------------- /logs/mtp-detect-archos-5.txt: -------------------------------------------------------------------------------- 1 | Device 0 (VID=0e79 and PID=1333) is UNKNOWN. 2 | Please report this VID/PID and the device model to the libmtp development team 3 | usb_claim_interface(): Device or resource busy 4 | LIBMTP PANIC: Unable to initialize device 5 | Unable to open raw device 0 6 | libmtp version: 0.3.1 7 | 8 | Listing raw device(s) 9 | Found 1 device(s): 10 | 0e79:1333 @ bus 0, dev 20 11 | Attempting to connect device(s) 12 | OK. 13 | -------------------------------------------------------------------------------- /.cvsignore: -------------------------------------------------------------------------------- 1 | *.tar.gz 2 | Makefile 3 | Makefile.in 4 | aclocal.m4 5 | autom4te.cache 6 | build-stamp 7 | config.cache 8 | config.guess 9 | config.h 10 | config.h.in 11 | config.log 12 | config.status 13 | config.sub 14 | configure 15 | configure-stamp 16 | hotplug.sh 17 | libmtp-* 18 | libmtp.pc 19 | libtool 20 | libmtp.sh 21 | stamp-h1 22 | libmtp.rules 23 | libmtp.usermap 24 | libmtp.fdi 25 | ltmain.sh 26 | .cdtproject 27 | .project 28 | depcomp 29 | install-sh 30 | missing -------------------------------------------------------------------------------- /doc/examples.h: -------------------------------------------------------------------------------- 1 | /* 2 | * List examples here... 3 | */ 4 | /** \example delfile.c */ 5 | /** \example detect.c */ 6 | /** \example files.c */ 7 | /** \example folders.c */ 8 | /** \example getfile.c */ 9 | /** \example hotplug.c */ 10 | /** \example newfolder.c */ 11 | /** \example sendfile.c */ 12 | /** \example sendtr.c */ 13 | /** \example tracks.c */ 14 | /** \example trexist.c */ 15 | /** \example playlists.c */ 16 | /** \example getplaylist.c */ 17 | /** \example refactortest.c */ 18 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST=Doxyfile.in examples.h mainpage.h 2 | 3 | if HAVE_DOXYGEN 4 | pkgdocdir=$(datadir)/doc/$(PACKAGE)-$(VERSION) 5 | htmldocdir=$(pkgdocdir)/html 6 | 7 | all-local: 8 | doxygen 9 | 10 | install-data-local: 11 | $(INSTALL) -d $(DESTDIR)$(htmldocdir) 12 | $(INSTALL_DATA) html/* $(DESTDIR)$(htmldocdir) 13 | 14 | uninstall-local: 15 | $(RM) -r $(DESTDIR)$(htmldocdir) 16 | $(RM) -r $(DESTDIR)$(pkgdocdir) 17 | 18 | clean-local: 19 | $(RM) -r html latex man 20 | endif 21 | -------------------------------------------------------------------------------- /doc/mainpage.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \mainpage The official libmtp documentation 3 | * 4 | * \section Introduction 5 | * 6 | * libmtp is a library for the Media Transfer Protocol (MTP) 7 | * under various POSIX operating systems. 8 | * 9 | * \section License 10 | * 11 | * libmtp is available under the GNU Lesser General Public License, 12 | * version 2. You can use libmtp in Free or proprietary software alike as 13 | * long as you publish your modifications to this library in accordance 14 | * with the LGPL license. If you do not follow the LGPL you will be in 15 | * deep, deep trouble. 16 | * 17 | */ 18 | -------------------------------------------------------------------------------- /logs/mtp-detect-gigaware-gx400.txt: -------------------------------------------------------------------------------- 1 | libmtp version: 0.3.7 2 | 3 | Listing raw device(s) 4 | 5 | Potential MTP Device with VendorID:0aa6 and ProductID:9702 responded to control message 2 with a response that was too short. Problems may arrise but continuing 6 | Device 0 (VID=0aa6 and PID=9702) is UNKNOWN. 7 | Please report this VID/PID and the device model to the libmtp development team 8 | Found 1 device(s): 9 | 0aa6:9702 @ bus 0, dev 3 10 | Attempting to connect device(s) 11 | usb_claim_interface(): Device or resource busy 12 | LIBMTP PANIC: Unable to initialize device 13 | Unable to open raw device 0 14 | OK. 15 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS=src examples util doc 2 | ACLOCAL_AMFLAGS=-I m4 3 | 4 | pkgconfigdir=$(libdir)/pkgconfig 5 | pkgconfig_DATA=libmtp.pc 6 | 7 | EXTRA_DIST=libmtp.pc libmtp.sh COPYING README.windows.txt 8 | 9 | # This stuff only makes sense on Linux so only 10 | # build and ship it on Linux. 11 | if USE_LINUX 12 | udevrulesdir=@UDEV@/rules.d 13 | udevrules_DATA=@UDEV_RULES@ 14 | noinst_DATA=libmtp.usermap libmtp.fdi 15 | 16 | libmtp.usermap: util/mtp-hotplug 17 | util/mtp-hotplug > libmtp.usermap 18 | @UDEV_RULES@: util/mtp-hotplug 19 | util/mtp-hotplug -u -p"@UDEV@" @UDEV_GROUP@ @UDEV_MODE@ > @UDEV_RULES@ 20 | libmtp.fdi: util/mtp-hotplug 21 | util/mtp-hotplug -H > libmtp.fdi 22 | 23 | CLEANFILES = libmtp.usermap @UDEV_RULES@ libmtp.fdi 24 | endif 25 | -------------------------------------------------------------------------------- /src/README: -------------------------------------------------------------------------------- 1 | RELATION TO LIBPTP2 2 | ------------------- 3 | 4 | Parts of libptp2 are copied (and modified) from version 1.1.0: 5 | 6 | ptp-pack.c 7 | ptp-pack.h 8 | ptp.c 9 | ptp.h 10 | 11 | These are just copies of the same files from libptp2. 12 | In order to avoid clashes with the libptp2 endianness scripts 13 | we have named libptp-endian.h and libptp-stdint.h the 14 | same way as in libptp2, though they are created by libmtp 15 | autoconfigure scripts. 16 | 17 | We will try to track libptp2 and fold changes back into 18 | libmtp. 19 | 20 | TODO: check if the following still holds! (Linus) 21 | 22 | I have changed the config script slightly for the le64atoh function 23 | in libptp-endian.h. This is required for OS X on PowerPC (not sure why). 24 | I've just cast the bytes to uint64_t to avoid shifting wrongly. 25 | 26 | -------------------------------------------------------------------------------- /src/gphoto2-sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #set -e 3 | 4 | srcdir=`dirname $0` 5 | 6 | # Get sources from gphoto2 SVN 7 | WGET=`which wget` 8 | if [ "x$WGET" != "x" ]; then 9 | wget -O tmpfile http://gphoto.svn.sourceforge.net/viewvc/*checkout*/gphoto/trunk/libgphoto2/camlibs/ptp2/ptp.c 10 | mv tmpfile ptp.c.gphoto2 11 | wget -O tmpfile http://gphoto.svn.sourceforge.net/viewvc/*checkout*/gphoto/trunk/libgphoto2/camlibs/ptp2/ptp.h 12 | mv tmpfile ptp.h.gphoto2 13 | wget -O tmpfile http://gphoto.svn.sourceforge.net/viewvc/*checkout*/gphoto/trunk/libgphoto2/camlibs/ptp2/ptp-pack.c 14 | mv tmpfile ptp-pack.c.gphoto2 15 | wget -O tmpfile http://gphoto.svn.sourceforge.net/viewvc/*checkout*/gphoto/trunk/libgphoto2/camlibs/ptp2/library.c 16 | mv tmpfile library.c.gphoto2 17 | wget -O tmpfile http://gphoto.svn.sourceforge.net/viewvc/*checkout*/gphoto/trunk/libgphoto2/camlibs/ptp2/music-players.h 18 | mv tmpfile music-players.h.gphoto2 19 | else 20 | echo "Could not sync to gphoto2. No WGET." 21 | fi 22 | 23 | echo "Finished!" 24 | 25 | -------------------------------------------------------------------------------- /examples/util.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file util.h 3 | * Header for a set of common utility functions found 4 | * in all samples. 5 | * 6 | * Copyright (C) 2008 Linus Walleij 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #ifndef LIBMTP_EXAMPLES_UTIL_H 24 | #define LIBMTP_EXAMPLES_UTIL_H 25 | void checklang(void); 26 | #endif 27 | -------------------------------------------------------------------------------- /examples/pathutils.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file pathutils.h 3 | * 4 | * Copyright (C) 2006 Chris A. Debenham 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | */ 21 | #ifndef PATHUTILS_H_INCLUSION_GUARD 22 | #define PATHUTILS_H_INCLUSION_GUARD 23 | int parse_path (char *, LIBMTP_file_t *, LIBMTP_folder_t *); 24 | LIBMTP_filetype_t find_filetype (const char *); 25 | int progress (const uint64_t, const uint64_t, void const * const); 26 | #ifndef HAVE_LIBGEN_H 27 | char *basename(char *in); 28 | #endif 29 | #endif 30 | -------------------------------------------------------------------------------- /examples/common.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file common.h 3 | * These headers are used by absolutely all sample programs. 4 | * Special quirks that apply to all samples go here. 5 | * 6 | * Copyright (C) 2005-2011 Linus Walleij 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include 24 | #ifndef _MSC_VER 25 | #include 26 | #ifdef HAVE_GETOPT_H 27 | #include 28 | #else 29 | #include 30 | #endif 31 | #else 32 | // Only if using MSVC... 33 | #include "..\windows\getopt.h" 34 | #endif 35 | -------------------------------------------------------------------------------- /libmtp.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Lifts a plugged in MTP device to user space and 3 | # optionally runs a client program. 4 | # Written by Linus Walleij 2006, based on the "usbcam" 5 | # script by Nalin Dahyabhai. 6 | DEVICEOWNER=root 7 | DEVICEPERMS=666 8 | 9 | # Special quirk for SuSE systems using "resmgr" 10 | # (see http://rechner.lst.de/~okir/resmgr/) 11 | if [ -f /sbin/resmgr ] 12 | then 13 | /sbin/resmgr "${ACTION}" "${DEVICE}" desktop usb 14 | exit 0 15 | fi 16 | 17 | # This is for most other distributions 18 | if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ] 19 | then 20 | # New code, using lock files instead of copying /dev/console permissions 21 | # This also works with non-gdm logins (e.g. on a virtual terminal) 22 | # Idea and code from Nalin Dahyabhai 23 | if [ "x$DEVICEOWNER" = "xCONSOLE" ] 24 | then 25 | if [ -f /var/run/console/console.lock ] 26 | then 27 | DEVICEOWNER=`cat /var/run/console/console.lock` 28 | elif [ -f /var/run/console.lock ] 29 | then 30 | DEVICEOWNER=`cat /var/run/console.lock` 31 | elif [ -f /var/lock/console.lock ] 32 | then 33 | DEVICEOWNER=`cat /var/lock/console.lock` 34 | else 35 | DEVICEOWNER="nobody" 36 | DEVICEPERMS="666" 37 | fi 38 | fi 39 | if [ -n "$DEVICEOWNER" ] 40 | then 41 | chmod 0000 "${DEVICE}" 42 | chown "${DEVICEOWNER}" "${DEVICE}" 43 | chmod "${DEVICEPERMS}" "${DEVICE}" 44 | fi 45 | fi 46 | -------------------------------------------------------------------------------- /src/playlist-spl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * \file playlist-spl.h 3 | * Playlist to .spl conversion functions. 4 | * 5 | * Copyright (C) 2008 Alistair Boyle 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #ifndef __MTP__PLAYLIST_SPL__H 24 | #define __MTP__PLAYLIST_SPL__H 25 | 26 | int is_spl_playlist(PTPObjectInfo *oi); 27 | 28 | void spl_to_playlist_t(LIBMTP_mtpdevice_t* device, PTPObjectInfo *oi, 29 | const uint32_t id, LIBMTP_playlist_t * const pl); 30 | int playlist_t_to_spl(LIBMTP_mtpdevice_t *device, 31 | LIBMTP_playlist_t * const metadata); 32 | int update_spl_playlist(LIBMTP_mtpdevice_t *device, 33 | LIBMTP_playlist_t * const newlist); 34 | 35 | #endif //__MTP__PLAYLIST_SPL__H 36 | -------------------------------------------------------------------------------- /src/mtpz.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mtpz.h 3 | * 4 | * Copyright (C) 2011-2012 Sajid Anwar 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the 18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 | * Boston, MA 02111-1307, USA. 20 | * 21 | */ 22 | #ifndef MTPZ_H_INCLUSION_GUARD 23 | #define MTPZ_H_INCLUSION_GUARD 24 | 25 | #include "config.h" /* USE_MTPZ or not */ 26 | #include "ptp.h" /* PTPParams */ 27 | 28 | #ifdef USE_MTPZ 29 | 30 | uint16_t ptp_mtpz_handshake (PTPParams* params); 31 | int mtpz_loaddata(void); 32 | 33 | #else 34 | 35 | /* Stubs if mtpz is unused */ 36 | static inline uint16_t ptp_mtpz_handshake (PTPParams* params) 37 | { 38 | return PTP_RC_OperationNotSupported; 39 | } 40 | 41 | static inline int mtpz_loaddata(void) 42 | { 43 | return -1; 44 | } 45 | 46 | #endif 47 | 48 | int use_mtpz; 49 | 50 | #endif /* LIBMTP_H_INCLUSION_GUARD */ 51 | 52 | -------------------------------------------------------------------------------- /examples/connect.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file connect.h 3 | * Header file for connect subfunctions 4 | * 5 | * Copyright (C) 2006 Chris A. Debenham 6 | * Copyright (C) 2008-2010 Linus Walleij 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | int delfile_function(char *); 24 | int delfile_command(int, char **); 25 | void delfile_usage(void); 26 | int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t, uint32_t, uint16_t); 27 | int sendtrack_command (int, char **); 28 | void sendtrack_usage(void); 29 | int sendfile_function(char *,char *); 30 | int sendfile_command(int, char **); 31 | void sendfile_usage(void); 32 | int getfile_function(char *,char *); 33 | int getfile_command(int, char **); 34 | void getfile_usage(void); 35 | int newfolder_function(char *); 36 | int newfolder_command(int,char **); 37 | void newfolder_usage(void); 38 | -------------------------------------------------------------------------------- /src/unicode.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file unicode.h 3 | * 4 | * This file contains general Unicode string manipulation functions. 5 | * It mainly consist of functions for converting between UCS-2 (used on 6 | * the devices) and UTF-8 (used by several applications). 7 | * 8 | * For a deeper understanding of Unicode encoding formats see the 9 | * Wikipedia entries for 10 | * UTF-16/UCS-2 11 | * and UTF-8. 12 | * 13 | * Copyright (C) 2005-2007 Linus Walleij 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the 27 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 | * Boston, MA 02111-1307, USA. 29 | * 30 | */ 31 | 32 | #ifndef __MTP__UNICODE__H 33 | #define __MTP__UNICODE__H 34 | 35 | int ucs2_strlen(uint16_t const * const); 36 | char *utf16_to_utf8(LIBMTP_mtpdevice_t*,const uint16_t*); 37 | uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t*, const char*); 38 | void strip_7bit_from_utf8(char *str); 39 | 40 | #endif /* __MTP__UNICODE__H */ 41 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | bin_PROGRAMS=mtp-connect mtp-detect mtp-tracks mtp-files \ 2 | mtp-folders mtp-trexist mtp-playlists mtp-getplaylist \ 3 | mtp-format mtp-albumart mtp-albums mtp-newplaylist mtp-emptyfolders \ 4 | mtp-thumb mtp-reset mtp-filetree 5 | 6 | mtp_connect_SOURCES=connect.c connect.h delfile.c getfile.c newfolder.c \ 7 | sendfile.c sendtr.c pathutils.c pathutils.h \ 8 | util.c util.h common.h 9 | mtp_detect_SOURCES=detect.c util.c util.h common.h 10 | mtp_tracks_SOURCES=tracks.c util.c util.h common.h 11 | mtp_files_SOURCES=files.c util.c util.h common.h 12 | mtp_folders_SOURCES=folders.c util.c util.h common.h 13 | mtp_trexist_SOURCES=trexist.c util.c util.h common.h 14 | mtp_playlists_SOURCES=playlists.c util.c util.h common.h 15 | mtp_getplaylist_SOURCES=getplaylist.c util.c util.h common.h 16 | mtp_newplaylist_SOURCES=newplaylist.c util.c util.h common.h 17 | mtp_format_SOURCES=format.c util.c util.h common.h 18 | mtp_albumart_SOURCES=albumart.c util.c util.h common.h 19 | mtp_albums_SOURCES=albums.c util.c util.h common.h 20 | mtp_emptyfolders_SOURCES=emptyfolders.c util.c util.h common.h 21 | mtp_thumb_SOURCES=thumb.c util.c util.h common.h 22 | mtp_reset_SOURCES=reset.c util.c util.h common.h 23 | mtp_filetree_SOURCES=filetree.c util.c util.h common.h 24 | 25 | AM_CPPFLAGS=-I$(top_builddir)/src 26 | LDADD=../src/libmtp.la 27 | EXTRA_DIST=evolution-sync.sh 28 | 29 | install-exec-hook: 30 | ln -f -s mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-delfile$(EXEEXT) 31 | ln -f -s mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-getfile$(EXEEXT) 32 | ln -f -s mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-newfolder$(EXEEXT) 33 | ln -f -s mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendfile$(EXEEXT) 34 | ln -f -s mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendtr$(EXEEXT) 35 | -------------------------------------------------------------------------------- /src/.mtpz-data: -------------------------------------------------------------------------------- 1 | 10001 2 | b1ce711c1e1b468784a08490d5962216 3 | cad0d4c357342dd7ad959a5029d3d316972b9b9fe234f08ba7b6bff3b522505b16f52d218c693597b2840f90807a7f77899d7454dbc2011724d45603a136682c3b4fa43a21b201ff3d8efe16cdda5ea6d225dd74c68d09b84536d3b2292beb83d1d0dbb692261eeb2ebefeb21b1836c7e19864f4198ce84fe2033fbefcd377e5 4 | 79ee227b6da9c905a92e0f9fb205cf19fdb811cf85471e765755df00bd1cec025742fee6f46b2bf50f35a5c5d1f7d33a2259aede755fa5182ce41af203b199de2ba5cf801fcb4c8863b3c40cfdb18c9985ddad8710618802fd8969127c5f0fd52931f74a11082e27890cfbd11ae21b3611e54212d9e4269801f84d4f7e4ea601 5 | 02000001350100000000b501000000010000000000000000000000000000000000125a756e6520536f6674776172652043412031000100010080336ee6aa07bfb3ffd04024cec38be6497ef60e3d7f682e0ff15e6c65ff613bde176fad7137884e80a813cf53c3101aa51b9e4f54b24fd514cdc509b6b71e1f48513df06444d9b55963e8121c4c69b67d6a1314f973c9585c29bb990ad7fd151dbbcb4f9ed7dfe292ba4ed9c6acf58e6adeef5b877a1c1545742634916946459b094b259ed85ef02b08a318e67afd68c289a8c6a61bc8023ca87fe367bdcc0856c3d15758c866e53fb52e86ec569c9c070a22174fbd7c4dcd395ec68530163451ce1f588044a06ebb95a6d4be68b089a4f25a612ffcea56c1c3f8a6880c0576f26574b64ff83d2868f0fe3696bc8425487ae062d48aadfd088a9787b806810bed000001370100000000b703000000000000000000000000000000000000000000145a756e6520536f667477617265204c6561662031000100010080e577d3fcbe3f03e24fe88c19f46498e1c736181bb2febe2eeb1e2692b6dbd0d183eb2b29b2d33645b8098dc674dd25d2a65edacd16fe8e3dff01b2213aa44f3b2c6836a10356d4241701c2db54749d89777f7a80900f84b29735698c212df5165b5022b5f3bfb6a78bf034e29f9b2b9716d3d329509a95add72d3457c3d4d0ca7eeac9776f4d73a4aafd896baa5a8685c05d5b746665218481675ed629b2553a9df03d745866c5cf240351a76c6dbbd02830e5f472e2ad24587c7cab6018fdd934c093df41cab6187e6e1ee9bb8dd599f9a210f4051fcdfd55288d9761ca22c3219e72247646ab5050b0b2c77f1dfb6f9545640361a27cafcc59f32442e21b7b 6 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | libmtp was invented by: 2 | 3 | Richard Low 4 | Linus Walleij 5 | 6 | We both came to do libmtp after working on the libnjb 7 | project, which was all about Creative Technology devices 8 | implementing the OASiS and PDE protocols. 9 | 10 | libmtp is however largely based on libptp2, which was created by 11 | Mariusz Woloszyn as part of gPhoto2 then 12 | derived into its own project. 13 | 14 | We later started to use libgphoto2 which is also based on the same 15 | code as libptp2 but with large contributions from 16 | Marcus Meissner . Marcus is also a 17 | contributor on libmtp from time to time and we're great friends. 18 | 19 | Other contributors to libmtp include: 20 | 21 | Andy Kelk 22 | Chris A. Debenham 23 | Daniel Williams 24 | Dave Kelly 25 | Matthew Wilcox 26 | Robert Reardon 27 | Orson Teodoro 28 | Ted Bullock 29 | Sean Kellogg 30 | Tero Saarni 31 | Jeff Mitchell 32 | Johannes Huber 33 | Alistair Boyle 34 | Chris Bagwell 35 | Joseph Nahmias 36 | Florent Mertens 37 | Alvin 38 | James Ravenscroft 39 | Thomas Schweitzer 40 | Nyall Dawson 41 | Nicolas VIVIEN 42 | Andrea Grillini 43 | Yavor Goulishev 44 | Jonas Salling 45 | Sajid Anwar 46 | -------------------------------------------------------------------------------- /src/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * \file util.h 3 | * Utilityfunctions. 4 | * 5 | * Copyright (C) 2005-2007 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | 23 | #ifndef __MTP__UTIL__H 24 | #define __MTP__UTIL__H 25 | 26 | void data_dump(FILE *f, void *buf, uint32_t nbytes); 27 | void data_dump_ascii (FILE *f, void *buf, uint32_t n, uint32_t dump_boundry); 28 | #ifndef HAVE_STRNDUP 29 | char *strndup (const char *s, size_t n); 30 | #endif 31 | 32 | /** 33 | * Info macro 34 | */ 35 | #define LIBMTP_INFO(format, args...) \ 36 | do { \ 37 | if (LIBMTP_debug != 0) \ 38 | fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ 39 | else \ 40 | fprintf(stdout, format, ##args); \ 41 | } while (0) 42 | 43 | /** 44 | * Error macro 45 | */ 46 | #define LIBMTP_ERROR(format, args...) \ 47 | do { \ 48 | if (LIBMTP_debug != 0) \ 49 | fprintf(stderr, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ 50 | else \ 51 | fprintf(stderr, format, ##args); \ 52 | } while (0) 53 | 54 | 55 | #endif //__MTP__UTIL__H 56 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #set -e 3 | 4 | srcdir=`dirname $0` 5 | 6 | ACLOCAL_FLAGS="-I ${srcdir}/m4 ${ACLOCAL_FLAGS}" 7 | 8 | fail() { 9 | status=$? 10 | echo "Last command failed with status $status in directory $(pwd)." 11 | echo "Aborting" 12 | exit $status 13 | } 14 | 15 | # Refresh GNU autotools toolchain: libtool 16 | echo "Removing libtool cruft" 17 | rm -f ltmain.sh config.guess config.sub 18 | echo "Running libtoolize" 19 | libtoolize --copy --force || fail 20 | 21 | # Refresh GNU autotools toolchain: aclocal autoheader 22 | echo "Removing aclocal cruft" 23 | rm -f aclocal.m4 24 | echo "Running aclocal $ACLOCAL_FLAGS" 25 | aclocal $ACLOCAL_FLAGS || fail 26 | echo "Removing autoheader cruft" 27 | rm -f config.h.in src/config.h.in 28 | echo "Running autoheader" 29 | autoheader || fail 30 | 31 | # Refresh GNU autotools toolchain: automake 32 | echo "Removing automake cruft" 33 | rm -f depcomp install-sh missing mkinstalldirs 34 | rm -f stamp-h* 35 | echo "Running automake" 36 | touch config.rpath 37 | automake --add-missing --gnu || fail 38 | 39 | # Refresh GNU autotools toolchain: autoconf 40 | echo "Removing autoconf cruft" 41 | rm -f configure 42 | rm -rf autom4te*.cache/ 43 | echo "Running autoconf" 44 | autoconf 45 | 46 | # Autoupdate config.sub and config.guess 47 | # from GNU CVS 48 | WGET=`which wget` 49 | if [ "x$WGET" != "x" ]; then 50 | echo "Autoupdate config.sub and config.guess (y/n)?" 51 | read IN 52 | if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then 53 | wget -O tmpfile http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.guess 54 | mv tmpfile config.guess 55 | wget -O tmpfile http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/config/config/config.sub 56 | mv tmpfile config.sub 57 | fi 58 | else 59 | echo "Could not autoupdate config.sub and config.guess" 60 | fi 61 | 62 | echo "Finished!" 63 | 64 | -------------------------------------------------------------------------------- /examples/trexist.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file trexist.c 3 | * Example program to check if a certain track exists on the device. 4 | * 5 | * Copyright (C) 2006 The libmtp development team. 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include 24 | #include 25 | 26 | static void usage (void) 27 | { 28 | fprintf(stderr, "trexist \n"); 29 | } 30 | 31 | int main (int argc, char **argv) 32 | { 33 | LIBMTP_mtpdevice_t *device; 34 | uint32_t id; 35 | char *endptr; 36 | 37 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 38 | 39 | // We need track ID 40 | if ( argc != 2 ) { 41 | usage(); 42 | return 1; 43 | } 44 | 45 | // Sanity check song ID 46 | id = strtoul(argv[1], &endptr, 10); 47 | if ( *endptr != 0 ) { 48 | fprintf(stderr, "illegal value %s\n", argv[1]); 49 | return 1; 50 | } else if ( ! id ) { 51 | fprintf(stderr, "bad song id %u\n", id); 52 | return 1; 53 | } 54 | 55 | LIBMTP_Init(); 56 | device = LIBMTP_Get_First_Device(); 57 | if (device == NULL) { 58 | printf("No devices. Connect/replug device and try again.\n"); 59 | exit (0); 60 | } 61 | 62 | printf("%s\n", LIBMTP_Track_Exists(device, id) ? "Yes" : "No"); 63 | 64 | LIBMTP_Release_Device(device); 65 | printf("OK.\n"); 66 | exit (0); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /examples/util.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file util.c 3 | * A set of common utility functions found 4 | * in all samples. 5 | * 6 | * Copyright (C) 2008 Linus Walleij 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "config.h" 24 | #include "util.h" 25 | #ifdef HAVE_LANGINFO_H 26 | #include 27 | #endif 28 | #ifdef HAVE_LOCALE_H 29 | #include 30 | #endif 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | void checklang(void) 37 | { 38 | const char *langsuff = NULL; 39 | const char *lang = getenv("LANG"); 40 | 41 | #ifdef HAVE_LOCALE_H 42 | // Set the locale in accordance with environment 43 | setlocale(LC_ALL, ""); 44 | #endif 45 | #ifdef HAVE_LANGINFO_H 46 | langsuff = nl_langinfo(CODESET); 47 | #else 48 | /* 49 | * Check environment variables $LANG and $LC_CTYPE 50 | * to see if we want to support UTF-8 unicode 51 | */ 52 | if (lang != NULL) { 53 | const char *sep = strrchr(lang, '.'); 54 | if (sep != NULL) { 55 | langsuff = sep + 1; 56 | } else { 57 | langsuff = lang; 58 | } 59 | } 60 | #endif 61 | if (langsuff == NULL) { 62 | printf("Could not determine language suffix for your system. Please check your setup!\n"); 63 | } else if (strcasecmp(langsuff, "UTF-8") && strcasecmp(langsuff, "UTF8")) { 64 | printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang); 65 | printf("If you want to have support for diacritics and Unicode characters,\n"); 66 | printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n"); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/newfolder.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file newfolder.c 3 | * Example program to create a folder on the device. 4 | * 5 | * Copyright (C) 2006-2009 Linus Walleij 6 | * Copyright (C) 2006 Chris A. Debenham 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include 24 | #include 25 | 26 | #include "common.h" 27 | #include "pathutils.h" 28 | #include "connect.h" 29 | 30 | extern LIBMTP_folder_t *folders; 31 | extern LIBMTP_file_t *files; 32 | extern LIBMTP_mtpdevice_t *device; 33 | 34 | int newfolder_command (int argc, char **argv) 35 | { 36 | uint32_t newid; 37 | 38 | if(argc != 4) { 39 | printf("Usage: newfolder name \n"); 40 | printf(" parent = parent folder or 0 to create the new folder in the root dir\n"); 41 | printf(" storage = storage id or 0 to create the new folder on the primary storage\n"); 42 | return 0; 43 | } 44 | 45 | newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3])); 46 | if (newid == 0) { 47 | printf("Folder creation failed.\n"); 48 | return 1; 49 | } else { 50 | printf("New folder created with ID: %d\n", newid); 51 | } 52 | return 0; 53 | } 54 | 55 | int 56 | newfolder_function(char * path) 57 | { 58 | printf("Creating new folder %s\n",path); 59 | char * parent = dirname(path); 60 | char * folder = basename(path); 61 | int id = parse_path (parent,files,folders); 62 | int newid = LIBMTP_Create_Folder(device, folder, id, 0); 63 | if (newid == 0) { 64 | printf("Folder creation failed.\n"); 65 | LIBMTP_Dump_Errorstack(device); 66 | LIBMTP_Clear_Errorstack(device); 67 | return 1; 68 | } else { 69 | printf("New folder created with ID: %d\n", newid); 70 | } 71 | return 0; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /examples/reset.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file reset.c 3 | * Example program that resets the device. 4 | * 5 | * Copyright (C) 2007 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | 24 | /** 25 | * Returns 0 if OK (yes), 1 if not OK (no) 26 | */ 27 | static int prompt() 28 | { 29 | char buff[2]; 30 | 31 | while (1) { 32 | fprintf(stdout, "> "); 33 | if ( fgets(buff, sizeof(buff), stdin) == NULL ) { 34 | if (ferror(stdin)) { 35 | fprintf(stderr, "File error on stdin\n"); 36 | } else { 37 | fprintf(stderr, "EOF on stdin\n"); 38 | } 39 | return 1; 40 | } 41 | if (buff[0] == 'y') { 42 | return 0; 43 | } else if (buff[0] == 'n') { 44 | return 1; 45 | } 46 | } 47 | } 48 | 49 | int main (int argc, char **argv) 50 | { 51 | LIBMTP_mtpdevice_t *device; 52 | int ret; 53 | 54 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 55 | 56 | LIBMTP_Init(); 57 | device = LIBMTP_Get_First_Device(); 58 | if (device == NULL) { 59 | printf("No devices.\n"); 60 | return 0; 61 | } 62 | 63 | printf("I will now reset your device. This means that\n"); 64 | printf("the device may go inactive immediately and may report errors.\n"); 65 | printf("Continue? (y/n)\n"); 66 | if (prompt() == 0) { 67 | ret = LIBMTP_Reset_Device(device); 68 | } else { 69 | printf("Aborted.\n"); 70 | ret = 0; 71 | } 72 | 73 | if ( ret != 0 ) { 74 | printf("Failed to reset device.\n"); 75 | LIBMTP_Dump_Errorstack(device); 76 | LIBMTP_Clear_Errorstack(device); 77 | LIBMTP_Release_Device(device); 78 | return 1; 79 | } 80 | 81 | // It is not possible to release the device after successful reset! 82 | // LIBMTP_Release_Device(device); 83 | printf("OK.\n"); 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /examples/format.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file format.c 3 | * Example program that formats the device storage. 4 | * 5 | * Copyright (C) 2006-2007 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | 24 | /** 25 | * Returns 0 if OK (yes), 1 if not OK (no) 26 | */ 27 | static int prompt() 28 | { 29 | char buff[2]; 30 | 31 | while (1) { 32 | fprintf(stdout, "> "); 33 | if ( fgets(buff, sizeof(buff), stdin) == NULL ) { 34 | if (ferror(stdin)) { 35 | fprintf(stderr, "File error on stdin\n"); 36 | } else { 37 | fprintf(stderr, "EOF on stdin\n"); 38 | } 39 | return 1; 40 | } 41 | if (buff[0] == 'y') { 42 | return 0; 43 | } else if (buff[0] == 'n') { 44 | return 1; 45 | } 46 | } 47 | } 48 | 49 | int main (int argc, char **argv) 50 | { 51 | LIBMTP_mtpdevice_t *device; 52 | int ret; 53 | 54 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 55 | 56 | LIBMTP_Init(); 57 | device = LIBMTP_Get_First_Device(); 58 | if (device == NULL) { 59 | printf("No devices.\n"); 60 | return 0; 61 | } 62 | 63 | printf("I will now format your device. This means that\n"); 64 | printf("all content (and licenses) will be lost forever.\n"); 65 | printf("you will not be able to undo this operation.\n"); 66 | printf("Continue? (y/n)\n"); 67 | if (prompt() == 0) { 68 | // This will just format the first storage. 69 | ret = LIBMTP_Format_Storage(device, device->storage); 70 | } else { 71 | printf("Aborted.\n"); 72 | ret = 0; 73 | } 74 | 75 | if ( ret != 0 ) { 76 | printf("Failed to format device.\n"); 77 | LIBMTP_Dump_Errorstack(device); 78 | LIBMTP_Clear_Errorstack(device); 79 | LIBMTP_Release_Device(device); 80 | return 1; 81 | } 82 | 83 | LIBMTP_Release_Device(device); 84 | printf("OK.\n"); 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /util/mtp-probe.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file mtp-probe.c 3 | * Program to probe newly connected device interfaces from 4 | * userspace to determine if they are MTP devices, used for 5 | * udev rules. 6 | * 7 | * Invoke the program from udev to check it for MTP signatures, 8 | * e.g. 9 | * ATTR{bDeviceClass}=="ff", 10 | * PROGRAM="/mtp-probe /sys$env{DEVPATH} $attr{busnum} $attr{devnum}", 11 | * RESULT=="1", ENV{ID_MTP_DEVICE}="1", ENV{ID_MEDIA_PLAYER}="1", 12 | * SYMLINK+="libmtp-%k", MODE="666" 13 | * 14 | * Is you issue this before testing your /var/log/messages 15 | * will be more verbose: 16 | * 17 | * udevadm control --log-priority=debug 18 | * 19 | * Exits with status code 1 if the device is an MTP device, 20 | * else exits with 0. 21 | * 22 | * Copyright (C) 2011-2012 Linus Walleij 23 | * 24 | * This library is free software; you can redistribute it and/or 25 | * modify it under the terms of the GNU Lesser General Public 26 | * License as published by the Free Software Foundation; either 27 | * version 2 of the License, or (at your option) any later version. 28 | * 29 | * This library is distributed in the hope that it will be useful, 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 32 | * Lesser General Public License for more details. 33 | * 34 | * You should have received a copy of the GNU Lesser General Public 35 | * License along with this library; if not, write to the 36 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 37 | * Boston, MA 02111-1307, USA. 38 | */ 39 | #ifndef __linux__ 40 | #error "This program should only be compiled for Linux!" 41 | #endif 42 | 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | int main (int argc, char **argv) 51 | { 52 | char *fname; 53 | int busno; 54 | int devno; 55 | int ret; 56 | 57 | if (argc < 4) { 58 | syslog(LOG_INFO, "need device path, busnumber, device number as argument\n"); 59 | printf("0"); 60 | exit(0); 61 | } 62 | 63 | fname = argv[1]; 64 | busno = atoi(argv[2]); 65 | devno = atoi(argv[3]); 66 | 67 | syslog(LOG_INFO, "checking bus %d, device %d: \"%s\"\n", busno, devno, fname); 68 | 69 | ret = LIBMTP_Check_Specific_Device(busno, devno); 70 | if (ret) { 71 | syslog(LOG_INFO, "bus: %d, device: %d was an MTP device\n", busno, devno); 72 | printf("1"); 73 | } else { 74 | syslog(LOG_INFO, "bus: %d, device: %d was not an MTP device\n", busno, devno); 75 | printf("0"); 76 | } 77 | 78 | exit(0); 79 | } 80 | -------------------------------------------------------------------------------- /examples/playlists.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file playlists.c 3 | * Example program to list the playlists on a device. 4 | * 5 | * Copyright (C) 2005-2007 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include 24 | 25 | static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl) 26 | { 27 | uint32_t i; 28 | 29 | printf("Playlist ID: %d\n", pl->playlist_id); 30 | if (pl->name != NULL) 31 | printf(" Name: %s\n", pl->name); 32 | printf(" Parent ID: %d\n", pl->parent_id); 33 | printf(" Tracks:\n"); 34 | 35 | for (i = 0; i < pl->no_tracks; i++) { 36 | LIBMTP_track_t *track; 37 | 38 | track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]); 39 | if (track != NULL) { 40 | printf(" %u: %s - %s\n", pl->tracks[i], track->artist, track->title); 41 | LIBMTP_destroy_track_t(track); 42 | } else { 43 | printf(" %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]); 44 | LIBMTP_Dump_Errorstack(device); 45 | LIBMTP_Clear_Errorstack(device); 46 | } 47 | } 48 | } 49 | 50 | int main (int argc, char **argv) 51 | { 52 | LIBMTP_mtpdevice_t *device; 53 | LIBMTP_playlist_t *playlists; 54 | 55 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 56 | 57 | LIBMTP_Init(); 58 | device = LIBMTP_Get_First_Device(); 59 | if (device == NULL) { 60 | printf("No devices.\n"); 61 | exit (0); 62 | } 63 | 64 | // Get playlist listing. 65 | playlists = LIBMTP_Get_Playlist_List(device); 66 | if (playlists == NULL) { 67 | printf("No playlists.\n"); 68 | } else { 69 | LIBMTP_playlist_t *pl, *tmp; 70 | pl = playlists; 71 | while (pl != NULL) { 72 | dump_plinfo(device, pl); 73 | tmp = pl; 74 | pl = pl->next; 75 | LIBMTP_destroy_playlist_t(tmp); 76 | } 77 | } 78 | 79 | LIBMTP_Release_Device(device); 80 | printf("OK.\n"); 81 | exit (0); 82 | } 83 | -------------------------------------------------------------------------------- /examples/getfile.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file getfile.c 3 | * Example program to retrieve a file off the device. 4 | * 5 | * Copyright (C) 2005-2007 Linus Walleij 6 | * Copyright (C) 2006 Chris A. Debenham 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include 24 | #include 25 | 26 | #include "common.h" 27 | #include "pathutils.h" 28 | #include "connect.h" 29 | 30 | extern LIBMTP_folder_t *folders; 31 | extern LIBMTP_file_t *files; 32 | extern LIBMTP_mtpdevice_t *device; 33 | 34 | void getfile_usage (void) 35 | { 36 | fprintf(stderr, "getfile \n"); 37 | } 38 | 39 | int 40 | getfile_function(char * from_path,char * to_path) 41 | { 42 | int id = parse_path (from_path,files,folders); 43 | if (id > 0) { 44 | printf("Getting %s to %s\n",from_path,to_path); 45 | if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) { 46 | printf("\nError getting file from MTP device.\n"); 47 | LIBMTP_Dump_Errorstack(device); 48 | LIBMTP_Clear_Errorstack(device); 49 | return 1; 50 | } 51 | } 52 | return 0; 53 | } 54 | 55 | 56 | int getfile_command(int argc, char **argv) 57 | { 58 | uint32_t id; 59 | char *endptr; 60 | char *file; 61 | int ret = 0; 62 | 63 | // We need file ID and filename 64 | if ( argc != 3 ) { 65 | getfile_usage(); 66 | return 0; 67 | } 68 | 69 | // Sanity check song ID 70 | id = strtoul(argv[1], &endptr, 10); 71 | if ( *endptr != 0 ) { 72 | fprintf(stderr, "illegal value %s\n", argv[1]); 73 | return 1; 74 | } else if ( ! id ) { 75 | fprintf(stderr, "bad file/track id %u\n", id); 76 | return 1; 77 | } 78 | 79 | // Filename, e.g. "foo.mp3" 80 | file = argv[2]; 81 | printf("Getting file/track %d to local file %s\n", id, file); 82 | 83 | // This function will also work just as well for tracks. 84 | if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) { 85 | printf("\nError getting file from MTP device.\n"); 86 | ret = 1; 87 | } 88 | // Terminate progress bar. 89 | printf("\n"); 90 | 91 | return ret; 92 | } 93 | -------------------------------------------------------------------------------- /examples/getplaylist.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file getplaylist.c 3 | * Example program that lists the abstract playlists on the device. 4 | * 5 | * Copyright (C) 2005-2007 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include 24 | #include 25 | 26 | static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl) 27 | { 28 | uint32_t i; 29 | 30 | printf("Number of items: %u\n", pl->no_tracks); 31 | if(pl->no_tracks > 0) { 32 | for(i=0;ino_tracks;i++) { 33 | LIBMTP_track_t *track; 34 | 35 | track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]); 36 | if (track != NULL) { 37 | printf(" %u: %s - %s\n", pl->tracks[i], track->artist, track->title); 38 | LIBMTP_destroy_track_t(track); 39 | } else { 40 | printf(" %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]); 41 | LIBMTP_Dump_Errorstack(device); 42 | LIBMTP_Clear_Errorstack(device); 43 | } 44 | } 45 | } 46 | return 0; 47 | } 48 | 49 | int main (int argc, char **argv) 50 | { 51 | LIBMTP_mtpdevice_t *device; 52 | LIBMTP_playlist_t *playlist; 53 | uint32_t id; 54 | char *endptr; 55 | 56 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 57 | 58 | // We need file ID 59 | if ( argc != 2 ) { 60 | fprintf(stderr, "Just a playlist ID is required\n"); 61 | return 1; 62 | } 63 | 64 | // Sanity check playlist ID 65 | id = strtoul(argv[1], &endptr, 10); 66 | if ( *endptr != 0 ) { 67 | fprintf(stderr, "illegal value %s\n", argv[1]); 68 | return 1; 69 | } else if ( ! id ) { 70 | fprintf(stderr, "bad playlist id %u\n", id); 71 | return 1; 72 | } 73 | 74 | LIBMTP_Init(); 75 | device = LIBMTP_Get_First_Device(); 76 | if (device == NULL) { 77 | printf("No devices. Connect/replug device and try again.\n"); 78 | exit (0); 79 | } 80 | 81 | playlist = LIBMTP_Get_Playlist(device,id); 82 | 83 | if (playlist != NULL) { 84 | dump_playlist(device,playlist); 85 | } 86 | 87 | LIBMTP_destroy_playlist_t(playlist); 88 | 89 | LIBMTP_Release_Device(device); 90 | printf("OK.\n"); 91 | exit (0); 92 | } 93 | 94 | -------------------------------------------------------------------------------- /README.windows.txt: -------------------------------------------------------------------------------- 1 | This file was created by James Ravenscroft as a direct revision of Farooq Zaman's work with LibMTP on Windows. 2 | 3 | CHANGELOG 4 | ---------------- 5 | 14th January 2009: Created the first revision of this file taking information from the work of Farooq Zaman. 6 | 7 | 1.0 Compilation of LibMTP on Windows 2000/XP/NT 8 | ----------------------------------------------------------- 9 | LibMTP currently compiles under Windows using MingW/MSys. The source relies upon the __WIN32__ macro which is defined by MinGW by default. 10 | 11 | Libraries: 12 | LibMTP currently depends on LibUSB and libiconv. There are currently projects that port both of these libraries to Windows. Binary files can be 13 | obtained from: 14 | 15 | LibUSB Win32 - http://libusb-win32.sourceforge.net/ 16 | 17 | LibIconv - http://gnuwin32.sourceforge.net/packages/libiconv.htm 18 | 19 | With both of these libraries extracted and placed in MinGW's search path, you can compile the library by opening the Msys prompt, navigating to 20 | the path where the extracted LibMTP source files can be found and typing: 21 | 22 | ./configure 23 | make all 24 | make install 25 | 26 | 27 | 28 | 2.0 LibUSB and Driver Issues for Windows 29 | ---------------------------------------------- 30 | 31 | Unfortunately, Windows does not have abstract USB support and depends upon specific drivers for each and every device you use. Fortunately, 32 | LibUSB-Win32 provide a solution to this problem. LibMTP takes advantage of the LibUSB-Win32 Device Driver package. 33 | 34 | 1. Download the latest device driver binary package (libusb-win32-device-bin-x.x.x.x.tar.gz) from http://sourceforge.net/project/showfiles.php?group_id=78138 35 | 2. Upon extraction, plug in your music device and run bin/inf-wizard.exe. Selecting your device and saving the inf file in the project root directory. 36 | 3. Copy the files "bin/libusb0.dll" and "libusb0.sys" or "libusb0_x64.dll" and "libusb0_x64.sys" for 32-bit or 64-bit operating systems respectively. 37 | 4. Goto Start -> Run, type "devmgmt.msc" and press "ok". 38 | 5. Select your music device from the list and click Action -> Update Driver, Choose "No, not this time" if prompted to connect to microsoft. 39 | 6. Choose "Install from a list or specific location". 40 | 7. Choose "Don't search, I will choose the driver to install 41 | 8. Click the "Have Disk..." button in the bottom right corner of the prompt 42 | 9. Browse to your .inf file and select it. Press Ok 43 | 10. The name of your music device should appear in the prompt, click it and click "Next>" (Ignore any prompts about Driver Signing, continuing 44 | installation of the selected driver). 45 | 11. Click finish to end the driver install process. 46 | 47 | To get your old driver back: 48 | 49 | 1. Goto Start -> Run, type "devmgmt.msc" and press "ok". 50 | 2. Select your music device, right click on it and click "Properties" 51 | 3. Go to the "Driver" pane and select "Roll Back Driver". 52 | 53 | 3.0 54 | ---------------------------------------------- 55 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | lib_LTLIBRARIES = libmtp.la 2 | 3 | libmtp_la_CFLAGS = @LIBUSB_CFLAGS@ 4 | libmtp_la_SOURCES = libmtp.c unicode.c unicode.h util.c util.h playlist-spl.c \ 5 | gphoto2-endian.h _stdint.h ptp.c ptp.h libusb-glue.h \ 6 | music-players.h device-flags.h playlist-spl.h mtpz.h 7 | 8 | if MTPZ_COMPILE 9 | libmtp_la_SOURCES += mtpz.c 10 | endif 11 | 12 | if LIBUSB1_COMPILE 13 | libmtp_la_SOURCES += libusb1-glue.c 14 | endif 15 | 16 | if LIBUSB0_COMPILE 17 | libmtp_la_SOURCES += libusb-glue.c 18 | endif 19 | 20 | if LIBOPENUSB_COMPILE 21 | libmtp_la_SOURCES += libopenusb1-glue.c 22 | endif 23 | 24 | include_HEADERS=libmtp.h 25 | EXTRA_DIST=libmtp.h.in libmtp.sym ptp-pack.c 26 | 27 | # --------------------------------------------------------------------------- 28 | # Advanced information about versioning: 29 | # * "Writing shared libraries" by Mike Hearn 30 | # http://plan99.net/~mike/writing-shared-libraries.html 31 | # * libtool.info chapter "Versioning" 32 | # * libtool.info chapter "Updating library version information" 33 | # --------------------------------------------------------------------------- 34 | # Versioning: 35 | # - CURRENT (Major): Increment if the interface has changes. AGE is always 36 | # *changed* at the same time. 37 | # - AGE (Micro): Increment if any interfaces have been added; set to 0 38 | # if any interfaces have been removed. Removal has 39 | # precedence over adding, so set to 0 if both happened. 40 | # It denotes upward compatibility. 41 | # - REVISION (Minor): Increment any time the source changes; set to 42 | # 0 if you incremented CURRENT. 43 | # 44 | # To summarize. Any interface *change* increment CURRENT. If that interface 45 | # change does not break upward compatibility (ie it is an addition), 46 | # increment AGE, Otherwise AGE is reset to 0. If CURRENT has changed, 47 | # REVISION is set to 0, otherwise REVISION is incremented. 48 | # --------------------------------------------------------------------------- 49 | CURRENT=9 50 | AGE=0 51 | REVISION=4 52 | SOVERSION=$(CURRENT):$(REVISION):$(AGE) 53 | LT_CURRENT_MINUS_AGE=`expr $(CURRENT) - $(AGE)` 54 | 55 | if COMPILE_MINGW32 56 | W32_LIBS=-lws2_32 57 | W32_LDFLAGS=-export-dynamic 58 | if MS_LIB_EXE 59 | noinst_DATA=libmtp.lib 60 | libmtp.def: $(srcdir)/libmtp.sym 61 | echo "LIBRARY \"@PACKAGE@\"" > libmtp.def 62 | echo "DESCRIPTION \"Media Transfer Protocol (MTP) library\"" >> libmtp.def 63 | echo "VERSION @VERSION@" >> libmtp.def 64 | echo >> libmtp.def 65 | echo "EXPORTS" >> libmtp.def 66 | cat $< >> libmtp.def 67 | libmtp.lib: libmtp.la libmtp.def 68 | lib -name:libmtp-$(LT_CURRENT_MINUS_AGE).dll -def:libmtp.def -out:$@ 69 | install-data-local: libmtp.lib libmtp.def 70 | $(INSTALL) libmtp.def $(DESTDIR)$(libdir) 71 | $(INSTALL) libmtp.lib $(DESTDIR)$(libdir) 72 | endif 73 | endif 74 | 75 | libmtp_la_LDFLAGS=@LDFLAGS@ -no-undefined -export-symbols $(srcdir)/libmtp.sym -version-info $(SOVERSION) $(W32_LDFLAGS) 76 | libmtp_la_LIBADD=$(W32_LIBS) $(LTLIBICONV) @LIBUSB_LIBS@ 77 | libmtp_la_DEPENDENCIES=$(srcdir)/libmtp.sym 78 | 79 | DISTCLEANFILES = _stdint.h gphoto2-endian.h 80 | -------------------------------------------------------------------------------- /logs/lsusb-canon-canoscan.txt: -------------------------------------------------------------------------------- 1 | Canon scanner that looks like a MTP device and disturbs MTP 2 | detection... 3 | 4 | Bus 001 Device 002: ID 04a9:220c Canon, Inc. CanoScan D1250U2 5 | Device Descriptor: 6 | bLength 18 7 | bDescriptorType 1 8 | bcdUSB 2.00 9 | bDeviceClass 255 Vendor Specific Class 10 | bDeviceSubClass 255 Vendor Specific Subclass 11 | bDeviceProtocol 255 Vendor Specific Protocol 12 | bMaxPacketSize0 64 13 | idVendor 0x04a9 Canon, Inc. 14 | idProduct 0x220c CanoScan D1250U2 15 | bcdDevice 2.00 16 | iManufacturer 3 Canon 17 | iProduct 4 CanoScan 18 | iSerial 0 19 | bNumConfigurations 1 20 | Configuration Descriptor: 21 | bLength 9 22 | bDescriptorType 2 23 | wTotalLength 39 24 | bNumInterfaces 1 25 | bConfigurationValue 1 26 | iConfiguration 0 27 | bmAttributes 0xc0 28 | Self Powered 29 | MaxPower 10mA 30 | Interface Descriptor: 31 | bLength 9 32 | bDescriptorType 4 33 | bInterfaceNumber 0 34 | bAlternateSetting 0 35 | bNumEndpoints 3 36 | bInterfaceClass 255 Vendor Specific Class 37 | bInterfaceSubClass 255 Vendor Specific Subclass 38 | bInterfaceProtocol 255 Vendor Specific Protocol 39 | iInterface 0 40 | Endpoint Descriptor: 41 | bLength 7 42 | bDescriptorType 5 43 | bEndpointAddress 0x81 EP 1 IN 44 | bmAttributes 2 45 | Transfer Type Bulk 46 | Synch Type None 47 | Usage Type Data 48 | wMaxPacketSize 0x0200 1x 512 bytes 49 | bInterval 0 50 | Endpoint Descriptor: 51 | bLength 7 52 | bDescriptorType 5 53 | bEndpointAddress 0x02 EP 2 OUT 54 | bmAttributes 2 55 | Transfer Type Bulk 56 | Synch Type None 57 | Usage Type Data 58 | wMaxPacketSize 0x0200 1x 512 bytes 59 | bInterval 0 60 | Endpoint Descriptor: 61 | bLength 7 62 | bDescriptorType 5 63 | bEndpointAddress 0x83 EP 3 IN 64 | bmAttributes 3 65 | Transfer Type Interrupt 66 | Synch Type None 67 | Usage Type Data 68 | wMaxPacketSize 0x0001 1x 1 bytes 69 | bInterval 8 70 | Device Qualifier (for other device speed): 71 | bLength 10 72 | bDescriptorType 6 73 | bcdUSB 2.00 74 | bDeviceClass 255 Vendor Specific Class 75 | bDeviceSubClass 255 Vendor Specific Subclass 76 | bDeviceProtocol 255 Vendor Specific Protocol 77 | bMaxPacketSize0 64 78 | bNumConfigurations 1 79 | Device Status: 0x0001 80 | Self Powered 81 | -------------------------------------------------------------------------------- /src/libmtp.sym: -------------------------------------------------------------------------------- 1 | LIBMTP_Set_Debug 2 | LIBMTP_Init 3 | LIBMTP_Get_Supported_Devices_List 4 | LIBMTP_Detect_Raw_Devices 5 | LIBMTP_Check_Specific_Device 6 | LIBMTP_Open_Raw_Device 7 | LIBMTP_Open_Raw_Device_Uncached 8 | LIBMTP_Get_First_Device 9 | LIBMTP_Get_Connected_Devices 10 | LIBMTP_Number_Devices_In_List 11 | LIBMTP_Release_Device_List 12 | LIBMTP_Release_Device 13 | LIBMTP_Dump_Device_Info 14 | LIBMTP_Reset_Device 15 | LIBMTP_Get_Manufacturername 16 | LIBMTP_Get_Modelname 17 | LIBMTP_Get_Serialnumber 18 | LIBMTP_Get_Deviceversion 19 | LIBMTP_Get_Friendlyname 20 | LIBMTP_Set_Friendlyname 21 | LIBMTP_Get_Syncpartner 22 | LIBMTP_Set_Syncpartner 23 | LIBMTP_Get_Batterylevel 24 | LIBMTP_Get_Secure_Time 25 | LIBMTP_Get_Device_Certificate 26 | LIBMTP_Get_Supported_Filetypes 27 | LIBMTP_Get_Errorstack 28 | LIBMTP_Clear_Errorstack 29 | LIBMTP_Dump_Errorstack 30 | LIBMTP_Get_Storage 31 | LIBMTP_Format_Storage 32 | LIBMTP_Get_String_From_Object 33 | LIBMTP_Get_u64_From_Object 34 | LIBMTP_Get_u32_From_Object 35 | LIBMTP_Get_u16_From_Object 36 | LIBMTP_Get_u8_From_Object 37 | LIBMTP_Set_Object_String 38 | LIBMTP_Set_Object_u32 39 | LIBMTP_Set_Object_u16 40 | LIBMTP_Set_Object_u8 41 | LIBMTP_Get_Property_Description 42 | LIBMTP_Is_Property_Supported 43 | LIBMTP_Get_Allowed_Property_Values 44 | LIBMTP_destroy_allowed_values_t 45 | LIBMTP_new_file_t 46 | LIBMTP_destroy_file_t 47 | LIBMTP_Get_Filetype_Description 48 | LIBMTP_Get_Filelisting 49 | LIBMTP_Get_Filelisting_With_Callback 50 | LIBMTP_Get_Files_And_Folders 51 | LIBMTP_Get_Filemetadata 52 | LIBMTP_Get_File_To_File 53 | LIBMTP_Get_File_To_File_Descriptor 54 | LIBMTP_Get_File_To_Handler 55 | LIBMTP_Send_File_From_File 56 | LIBMTP_Send_File_From_File_Descriptor 57 | LIBMTP_Send_File_From_Handler 58 | LIBMTP_new_filesampledata_t 59 | LIBMTP_destroy_filesampledata_t 60 | LIBMTP_Get_Representative_Sample_Format 61 | LIBMTP_Send_Representative_Sample 62 | LIBMTP_Get_Representative_Sample 63 | LIBMTP_new_track_t 64 | LIBMTP_destroy_track_t 65 | LIBMTP_Get_Tracklisting 66 | LIBMTP_Get_Tracklisting_With_Callback 67 | LIBMTP_Get_Tracklisting_With_Callback_For_Storage 68 | LIBMTP_Get_Trackmetadata 69 | LIBMTP_Get_Track_To_File 70 | LIBMTP_Get_Track_To_File_Descriptor 71 | LIBMTP_Get_Track_To_Handler 72 | LIBMTP_Send_Track_From_File 73 | LIBMTP_Send_Track_From_File_Descriptor 74 | LIBMTP_Send_Track_From_Handler 75 | LIBMTP_Update_Track_Metadata 76 | LIBMTP_Track_Exists 77 | LIBMTP_new_folder_t 78 | LIBMTP_destroy_folder_t 79 | LIBMTP_Get_Folder_List 80 | LIBMTP_Get_Folder_List_For_Storage 81 | LIBMTP_Find_Folder 82 | LIBMTP_Create_Folder 83 | LIBMTP_new_playlist_t 84 | LIBMTP_destroy_playlist_t 85 | LIBMTP_Get_Playlist_List 86 | LIBMTP_Get_Playlist 87 | LIBMTP_Create_New_Playlist 88 | LIBMTP_Update_Playlist 89 | LIBMTP_new_album_t 90 | LIBMTP_destroy_album_t 91 | LIBMTP_Get_Album_List 92 | LIBMTP_Get_Album_List_For_Storage 93 | LIBMTP_Get_Album 94 | LIBMTP_Create_New_Album 95 | LIBMTP_Update_Album 96 | LIBMTP_Delete_Object 97 | LIBMTP_Set_File_Name 98 | LIBMTP_Set_Folder_Name 99 | LIBMTP_Set_Track_Name 100 | LIBMTP_Set_Playlist_Name 101 | LIBMTP_Set_Album_Name 102 | LIBMTP_Set_Object_Filename 103 | LIBMTP_Get_Thumbnail 104 | LIBMTP_Read_Event 105 | -------------------------------------------------------------------------------- /examples/sendfile.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file sendfile.c 3 | * Example program to send an arbitrary file to a device. 4 | * 5 | * Copyright (C) 2005-2010 Linus Walleij 6 | * Copyright (C) 2006 Chris A. Debenham 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | 24 | #include "config.h" 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include "common.h" 33 | #include "libmtp.h" 34 | #include "pathutils.h" 35 | #include "util.h" 36 | #include "connect.h" 37 | 38 | extern LIBMTP_folder_t *folders; 39 | extern LIBMTP_file_t *files; 40 | extern LIBMTP_mtpdevice_t *device; 41 | 42 | void sendfile_usage(void) 43 | { 44 | fprintf(stderr, "usage: sendfile \n"); 45 | } 46 | 47 | int sendfile_function(char * from_path, char *to_path) 48 | { 49 | printf("Sending %s to %s\n",from_path,to_path); 50 | char *filename; 51 | uint64_t filesize; 52 | struct stat sb; 53 | LIBMTP_file_t *genfile; 54 | int ret; 55 | uint32_t parent_id = 0; 56 | 57 | if ( stat(from_path, &sb) == -1 ) { 58 | fprintf(stderr, "%s: ", from_path); 59 | perror("stat"); 60 | return 1; 61 | } 62 | 63 | filesize = sb.st_size; 64 | filename = basename(from_path); 65 | parent_id = parse_path (to_path,files,folders); 66 | if (parent_id == -1) { 67 | printf("Parent folder could not be found, skipping\n"); 68 | return 0; 69 | } 70 | 71 | genfile = LIBMTP_new_file_t(); 72 | genfile->filesize = filesize; 73 | genfile->filename = strdup(filename); 74 | genfile->filetype = find_filetype (filename); 75 | genfile->parent_id = parent_id; 76 | genfile->storage_id = 0; 77 | 78 | printf("Sending file...\n"); 79 | ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress, NULL); 80 | printf("\n"); 81 | if (ret != 0) { 82 | printf("Error sending file.\n"); 83 | LIBMTP_Dump_Errorstack(device); 84 | LIBMTP_Clear_Errorstack(device); 85 | ret = 1; 86 | } else { 87 | printf("New file ID: %d\n", genfile->item_id); 88 | } 89 | 90 | LIBMTP_destroy_file_t(genfile); 91 | 92 | return ret; 93 | } 94 | 95 | int sendfile_command (int argc, char **argv) { 96 | if (argc < 3) { 97 | sendfile_usage(); 98 | return 0; 99 | } 100 | checklang(); 101 | return sendfile_function(argv[1],argv[2]); 102 | } 103 | -------------------------------------------------------------------------------- /examples/delfile.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file delfile.c 3 | * Example program to delete a file off the device. 4 | * 5 | * Copyright (C) 2005-2008 Linus Walleij 6 | * Copyright (C) 2006 Chris A. Debenham 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include 24 | #include 25 | 26 | #include "common.h" 27 | #include "string.h" 28 | #include "pathutils.h" 29 | #include "connect.h" 30 | 31 | extern LIBMTP_mtpdevice_t *device; 32 | extern LIBMTP_folder_t *folders; 33 | extern LIBMTP_file_t *files; 34 | 35 | void delfile_usage(void) 36 | { 37 | printf("Usage: delfile [-n] | -f \n"); 38 | } 39 | 40 | int 41 | delfile_function(char * path) 42 | { 43 | uint32_t id = parse_path (path,files,folders); 44 | 45 | if (id > 0) { 46 | printf("Deleting %s which has item_id:%d\n",path,id); 47 | int ret = 1; 48 | ret = LIBMTP_Delete_Object(device, id); 49 | if (ret != 0) { 50 | LIBMTP_Dump_Errorstack(device); 51 | LIBMTP_Clear_Errorstack(device); 52 | printf("Failed to remove file\n"); 53 | return 1; 54 | } 55 | } 56 | return 0; 57 | } 58 | 59 | int delfile_command(int argc, char **argv) 60 | { 61 | int FILENAME = 1; 62 | int ITEMID = 2; 63 | int field_type = 0; 64 | int i; 65 | int ret = 0; 66 | 67 | if ( argc > 2 ) { 68 | if (strncmp(argv[1],"-f",2) == 0) { 69 | field_type = FILENAME; 70 | strcpy(argv[1],""); 71 | } else if (strncmp(argv[1],"-n",2) == 0) { 72 | field_type = ITEMID; 73 | strcpy(argv[1],"0"); 74 | } else { 75 | delfile_usage(); 76 | return 0; 77 | } 78 | } else { 79 | delfile_usage(); 80 | return 0; 81 | } 82 | 83 | for (i=1;i 0) { 96 | id = parse_path (argv[i],files,folders); 97 | } else { 98 | id = 0; 99 | } 100 | } 101 | if (id > 0 ) { 102 | printf("Deleting %s\n",argv[i]); 103 | ret = LIBMTP_Delete_Object(device, id); 104 | } 105 | if ( ret != 0 ) { 106 | printf("Failed to delete file:%s\n",argv[i]); 107 | LIBMTP_Dump_Errorstack(device); 108 | LIBMTP_Clear_Errorstack(device); 109 | ret = 1; 110 | } 111 | } 112 | return ret; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /examples/evolution-sync.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Example evolution synchronization script by Nicolas Tetreault, 4 | # modified by Linus Walleij. 5 | 6 | # Define target files 7 | SYNC_HOME=$HOME/MTP_device_sync 8 | 9 | # Define tool locations 10 | SENDFILE=`which mtp-sendfile` 11 | # SENDFILE="$HOME/comp-apps/bin/sendfile" 12 | #EADDEXP=`which evolution-addressbook-export` 13 | # This is the location in Fedora Core 5: 14 | EADDEXP="/usr/libexec/evolution/2.6/evolution-addressbook-export" 15 | 16 | # You need to change the name of the files 17 | # that contains the calendar and contacts on your device. 18 | # You can find out by starting Gnomad2, choose the data transfer 19 | # tab, sort by size (it should be small files, extension .ics and .vcf) 20 | # On my Zen Microphoto, the calendar and contacts files are called 21 | # 6651416 with the ics and vcf extensions, respectively. 22 | CALENDAR_FILE="6651416.ics" 23 | CONTACTS_FILE="6651416.vcf" 24 | 25 | # The evolution address book. To list your addressbooks, type: 26 | # evolution-addressbook-export -l 27 | # the output for me: 28 | # "file:///home/nt271/.evolution/addressbook/local/system 29 | # ","Personal",26 30 | # "file:///home/nt271/.evolution/addressbook/local/1158600180.5386.0@sierra" 31 | # ,"MicroPhoto",24 32 | # I only want the Microphoto addressbook and the output will be 33 | # $SYNC_HOME/contacts/Evolution_contacts.vcf 34 | EVOLUTION_CONTACTS="file:///home/linus/.evolution/addressbook/local/system" 35 | 36 | # Check for sync dir, create it if needed 37 | 38 | if test -d $SYNC_HOME ; then 39 | echo "$SYNC_HOME exists, OK." 40 | else 41 | echo "$SYNC_HOME must first be created..." 42 | mkdir $SYNC_HOME 43 | # This is a working dir for contact merging, you can put 44 | # in some extra .vcf files here as well if you like. 45 | mkdir $SYNC_HOME/contacts 46 | # Here you can place some extra calendars to be sync:ed, you 47 | # can put in some extra .ics files of any kind here. 48 | mkdir $SYNC_HOME/calendars 49 | fi 50 | 51 | # Check for prerequisites 52 | 53 | if test -f $EADDEXP ; then 54 | echo "evolution-addressbook-export present in $EADDEXP, OK." 55 | else 56 | echo "Cannot locate evolution-addressbook-export!!" 57 | exit 0 58 | fi 59 | 60 | 61 | # Next line merges all of your tasklist, your personal calendar, 62 | # and then any saved to disk calendar you have placed in 63 | # $SYNC_HOME/calendars 64 | 65 | cat $HOME/.evolution/tasks/local/system/tasks.ics \ 66 | $HOME/.evolution/calendar/local/system/calendar.ics \ 67 | $SYNC_HOME/calendars/*.ics > $SYNC_HOME/$CALENDAR_FILE 68 | 69 | # Use evolution-addressbook-export (installed with Evolution) to 70 | # export your contacts to vcard. 71 | 72 | $EADDEXP --format=vcard \ 73 | --output=$SYNC_HOME/contacts/Evolution_contacts.vcf \ 74 | $EVOLUTION_CONTACTS 75 | 76 | # Repeat for each addressbook you want to upload. 77 | 78 | # The next command will then merge all the contact lists 79 | 80 | cat $SYNC_HOME/contacts/*.vcf > $SYNC_HOME/$CONTACTS_FILE 81 | 82 | # The calendar and contacts files now need to be converted from unix 83 | # to DOS linefeeds (CR+LF instead of just LF) 84 | 85 | unix2dos $SYNC_HOME/$CALENDAR_FILE $SYNC_HOME/$CONTACTS_FILE 86 | 87 | # You can now upload the ics and vcf files to you My Organizer folder 88 | # on your device. Change the path to your sendfile command. 89 | # Sending the vcf file is only supported in CVS version at this time 90 | 91 | $SENDFILE -f "My Organizer" -t ics $SYNC_HOME/$CALENDAR_FILE 92 | $SENDFILE -f "My Organizer" -t vcf $SYNC_HOME/$CONTACTS_FILE 93 | 94 | -------------------------------------------------------------------------------- /examples/emptyfolders.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file emptyfolders.c 3 | * Example program that prunes empty folders. 4 | * 5 | * Copyright (C) 2006 Andy Kelk 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include 24 | 25 | static void prune_empty_folders(LIBMTP_mtpdevice_t *device, LIBMTP_file_t *files, LIBMTP_folder_t *folderlist, int do_delete) 26 | { 27 | if(folderlist==NULL) 28 | return; 29 | 30 | if(folderlist->child == NULL) { // this *might* be empty 31 | // therefore, check every file for this parent_id 32 | int found = 0; 33 | LIBMTP_file_t *file; 34 | file = files; 35 | while (file != NULL) { 36 | if(file->parent_id == folderlist->folder_id) { // folder has a child 37 | found = 1; 38 | break; 39 | } 40 | file = file->next; 41 | } 42 | 43 | if(found == 0) { // no files claim this as a parent 44 | printf("empty folder %u (%s)\n",folderlist->folder_id,folderlist->name); 45 | if(do_delete) { 46 | if (LIBMTP_Delete_Object(device,folderlist->folder_id) != 0) { 47 | printf("Couldn't delete folder %u\n",folderlist->folder_id); 48 | LIBMTP_Dump_Errorstack(device); 49 | LIBMTP_Clear_Errorstack(device); 50 | } 51 | } 52 | } 53 | } 54 | 55 | prune_empty_folders(device,files,folderlist->child,do_delete); // recurse down 56 | prune_empty_folders(device,files,folderlist->sibling,do_delete); // recurse along 57 | } 58 | 59 | int main (int argc, char **argv) 60 | { 61 | // check if we're doing a dummy run 62 | int do_delete = 0; 63 | int opt; 64 | 65 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 66 | 67 | while ( (opt = getopt(argc, argv, "d")) != -1 ) { 68 | switch (opt) { 69 | case 'd': 70 | do_delete = 1; 71 | break; 72 | default: 73 | break; 74 | } 75 | } 76 | 77 | if(do_delete == 0) { 78 | printf("This is a dummy run. No folders will be deleted.\n"); 79 | printf("To delete folders, use the '-d' option.\n"); 80 | } 81 | 82 | LIBMTP_mtpdevice_t *device; 83 | LIBMTP_folder_t *folders; 84 | LIBMTP_file_t *files; 85 | 86 | LIBMTP_Init(); 87 | device = LIBMTP_Get_First_Device(); 88 | if (device == NULL) { 89 | printf("No devices.\n"); 90 | exit (0); 91 | } 92 | 93 | // Get file listing. 94 | files = LIBMTP_Get_Filelisting_With_Callback(device,NULL,NULL); 95 | 96 | // Get folder listing. 97 | folders = LIBMTP_Get_Folder_List(device); 98 | 99 | if(folders == NULL) { 100 | printf("No folders found\n"); 101 | } else { 102 | prune_empty_folders(device,files,folders,do_delete); 103 | } 104 | 105 | LIBMTP_destroy_folder_t(folders); 106 | LIBMTP_destroy_file_t(files); 107 | 108 | LIBMTP_Release_Device(device); 109 | printf("OK.\n"); 110 | exit (0); 111 | } 112 | 113 | -------------------------------------------------------------------------------- /examples/newplaylist.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file newplaylist.c 3 | * Example program to create a playlist on a device. 4 | * 5 | * Copyright (C) 2006 Robert Reardon 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include "string.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | static void usage(void) { 31 | printf("Usage: newplaylist -i -n -s -p \n"); 32 | exit(0); 33 | } 34 | 35 | int main (int argc, char **argv) { 36 | int opt; 37 | extern int optind; 38 | extern char *optarg; 39 | LIBMTP_mtpdevice_t *device = NULL; 40 | int idcount = 0; 41 | uint32_t *ids = NULL; 42 | uint32_t *tmp = NULL; 43 | char *playlistname = NULL; 44 | char *rest; 45 | uint32_t storageid = 0; 46 | uint32_t parentid = 0; 47 | 48 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 49 | 50 | while ( (opt = getopt(argc, argv, "hn:i:s:p:")) != -1 ) { 51 | switch (opt) { 52 | case 'h': 53 | usage(); 54 | case 'i': 55 | idcount++; 56 | if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) { 57 | printf("realloc failed\n"); 58 | return 1; 59 | } 60 | ids = tmp; 61 | ids[(idcount-1)] = strtoul(optarg, &rest, 0); 62 | break; 63 | case 'n': 64 | playlistname = strdup(optarg); 65 | break; 66 | case 's': 67 | storageid = (uint32_t) strtoul(optarg, NULL, 0); 68 | break; 69 | case 'p': 70 | parentid = (uint32_t) strtoul(optarg, NULL, 0); 71 | break; 72 | default: 73 | usage(); 74 | } 75 | } 76 | argc -= optind; 77 | argv += optind; 78 | 79 | if ( playlistname == NULL) { 80 | printf("You need to supply a playlist name.\n"); 81 | usage(); 82 | } 83 | 84 | if (idcount == 0) { 85 | printf("You need to supply one or more track IDs\n"); 86 | usage(); 87 | } 88 | 89 | 90 | LIBMTP_Init(); 91 | device = LIBMTP_Get_First_Device(); 92 | if (device == NULL) { 93 | printf("No devices.\n"); 94 | return 0; 95 | } 96 | 97 | LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t(); 98 | playlist->name = playlistname; 99 | playlist->no_tracks = idcount; 100 | playlist->tracks = ids; 101 | playlist->parent_id = parentid; 102 | playlist->storage_id = storageid; 103 | int ret = LIBMTP_Create_New_Playlist(device,playlist); 104 | if (ret != 0) { 105 | printf("Couldn't create playlist object\n"); 106 | LIBMTP_Dump_Errorstack(device); 107 | LIBMTP_Clear_Errorstack(device); 108 | } 109 | else { 110 | printf("Created new playlist: %u\n", playlist->playlist_id); 111 | } 112 | 113 | LIBMTP_Release_Device(device); 114 | printf("OK.\n"); 115 | return 0; 116 | } 117 | 118 | -------------------------------------------------------------------------------- /examples/thumb.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file thumb.c 3 | * Example program to send and associate album art to an entity 4 | * on a device. 5 | * 6 | * Copyright (C) 2006 Robert Reardon 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "config.h" 24 | #include "common.h" 25 | #include "string.h" 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #ifdef HAVE_SYS_UIO_H 33 | #include 34 | #endif 35 | #include 36 | 37 | static void usage(void) { 38 | printf("Usage: thumb -i \n"); 39 | exit(0); 40 | } 41 | 42 | int main (int argc, char **argv) { 43 | int opt; 44 | extern int optind; 45 | extern char *optarg; 46 | LIBMTP_mtpdevice_t *device = NULL; 47 | int fd; 48 | uint32_t id = 0; 49 | uint64_t filesize; 50 | uint8_t *imagedata = NULL; 51 | char *path = NULL; 52 | char *rest; 53 | struct stat statbuff; 54 | int ret; 55 | 56 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 57 | 58 | while ( (opt = getopt(argc, argv, "hi:")) != -1 ) { 59 | switch (opt) { 60 | case 'h': 61 | usage(); 62 | case 'i': 63 | id = strtoul(optarg, &rest, 0); 64 | break; 65 | default: 66 | usage(); 67 | } 68 | } 69 | argc -= optind; 70 | argv += optind; 71 | 72 | if ( argc != 1 ) { 73 | printf("You need to pass a filename.\n"); 74 | usage(); 75 | } 76 | 77 | path = argv[0]; 78 | 79 | if ( stat(path, &statbuff) == -1 ) { 80 | fprintf(stderr, "%s: ", path); 81 | perror("stat"); 82 | exit(1); 83 | } 84 | filesize = (uint64_t) statbuff.st_size; 85 | imagedata = malloc(filesize * sizeof(uint16_t)); 86 | 87 | #ifdef __WIN32__ 88 | if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { 89 | #else 90 | if ( (fd = open(path, O_RDONLY)) == -1) { 91 | #endif 92 | printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); 93 | return 1; 94 | } 95 | else { 96 | read(fd, imagedata, filesize); 97 | close(fd); 98 | } 99 | 100 | LIBMTP_Init(); 101 | device = LIBMTP_Get_First_Device(); 102 | if (device == NULL) { 103 | printf("No devices.\n"); 104 | return 0; 105 | } 106 | 107 | LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t(); 108 | 109 | int i; 110 | thumb->data = malloc(sizeof(uint16_t) * filesize); 111 | for (i = 0; i < filesize; i++) { 112 | thumb->data[i] = imagedata[i]; 113 | } 114 | 115 | thumb->size = filesize; 116 | thumb->filetype = LIBMTP_FILETYPE_JPEG; 117 | 118 | ret = LIBMTP_Send_Representative_Sample(device,id,thumb); 119 | if (ret != 0) { 120 | printf("Couldn't send thumbnail\n"); 121 | LIBMTP_Dump_Errorstack(device); 122 | LIBMTP_Clear_Errorstack(device); 123 | } 124 | 125 | free(imagedata); 126 | LIBMTP_destroy_filesampledata_t(thumb); 127 | 128 | LIBMTP_Release_Device(device); 129 | printf("OK.\n"); 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /src/util.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file util.c 3 | * 4 | * This file contains generic utility functions such as can be 5 | * used for debugging for example. 6 | * 7 | * Copyright (C) 2005-2007 Linus Walleij 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the 21 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 22 | * Boston, MA 02111-1307, USA. 23 | */ 24 | 25 | /* MSVC does not have these */ 26 | #ifndef _MSC_VER 27 | #include 28 | #include 29 | #endif 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include "libmtp.h" 38 | #include "util.h" 39 | 40 | /** 41 | * This dumps out a number of bytes to a textual, hexadecimal 42 | * dump. 43 | * 44 | * @param f the file to dump to (e.g. stdout or stderr) 45 | * @param buf a pointer to the buffer containing the bytes to 46 | * be dumped out in hex 47 | * @param n the number of bytes to dump from this buffer 48 | */ 49 | void data_dump (FILE *f, void *buf, uint32_t n) 50 | { 51 | unsigned char *bp = (unsigned char *) buf; 52 | uint32_t i; 53 | 54 | for (i = 0; i < n; i++) { 55 | fprintf(f, "%02x ", *bp); 56 | bp++; 57 | } 58 | fprintf(f, "\n"); 59 | } 60 | 61 | /** 62 | * This dumps out a number of bytes to a textual, hexadecimal 63 | * dump, and also prints out the string ASCII representation 64 | * for each line of bytes. It will also print the memory address 65 | * offset from a certain boundry. 66 | * 67 | * @param f the file to dump to (e.g. stdout or stderr) 68 | * @param buf a pointer to the buffer containing the bytes to 69 | * be dumped out in hex 70 | * @param n the number of bytes to dump from this buffer 71 | * @param dump_boundry the address offset to start at (usually 0) 72 | */ 73 | void data_dump_ascii (FILE *f, void *buf, uint32_t n, uint32_t dump_boundry) 74 | { 75 | uint32_t remain = n; 76 | uint32_t ln, lc; 77 | int i; 78 | unsigned char *bp = (unsigned char *) buf; 79 | 80 | lc = 0; 81 | while (remain) { 82 | fprintf(f, "\t%04x:", dump_boundry-0x10); 83 | 84 | ln = ( remain > 16 ) ? 16 : remain; 85 | 86 | for (i = 0; i < ln; i++) { 87 | if ( ! (i%2) ) fprintf(f, " "); 88 | fprintf(f, "%02x", bp[16*lc+i]); 89 | } 90 | 91 | if ( ln < 16 ) { 92 | int width = ((16-ln)/2)*5 + (2*(ln%2)); 93 | fprintf(f, "%*.*s", width, width, ""); 94 | } 95 | 96 | fprintf(f, "\t"); 97 | for (i = 0; i < ln; i++) { 98 | unsigned char ch= bp[16*lc+i]; 99 | fprintf(f, "%c", ( ch >= 0x20 && ch <= 0x7e ) ? 100 | ch : '.'); 101 | } 102 | fprintf(f, "\n"); 103 | 104 | lc++; 105 | remain -= ln; 106 | dump_boundry += ln; 107 | } 108 | } 109 | 110 | #ifndef HAVE_STRNDUP 111 | char *strndup (const char *s, size_t n) 112 | { 113 | size_t len = strlen (s); 114 | char *ret; 115 | 116 | if (len <= n) 117 | return strdup (s); 118 | 119 | ret = malloc(n + 1); 120 | strncpy(ret, s, n); 121 | ret[n] = '\0'; 122 | return ret; 123 | } 124 | #endif 125 | 126 | -------------------------------------------------------------------------------- /examples/albums.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file albums.c 3 | * Example program that lists the albums on the device. 4 | * 5 | * Copyright (C) 2006 Chris A. Debenham 6 | * Copyright (C) 2007 Ted Bullock 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "common.h" 24 | #include 25 | 26 | static void dump_albuminfo(LIBMTP_album_t *album) 27 | { 28 | printf("Album ID: %d\n",album->album_id); 29 | printf(" Parent ID: %d\n",album->parent_id); 30 | printf(" Name: %s\n",album->name); 31 | printf(" Artist: %s\n", album->artist); 32 | printf(" Composer: %s\n", album->composer); 33 | printf(" Genre: %s\n", album->genre); 34 | printf(" Tracks: %d\n\n",album->no_tracks); 35 | } 36 | 37 | int main (int argc, char *argv[]) { 38 | LIBMTP_mtpdevice_t *device_list, *device; 39 | 40 | int opt; 41 | extern int optind; 42 | extern char *optarg; 43 | 44 | while ((opt = getopt(argc, argv, "d")) != -1 ) { 45 | switch (opt) { 46 | case 'd': 47 | LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); 48 | break; 49 | } 50 | } 51 | 52 | argc -= optind; 53 | argv += optind; 54 | 55 | LIBMTP_Init(); 56 | 57 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 58 | 59 | switch(LIBMTP_Get_Connected_Devices(&device_list)) 60 | { 61 | case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 62 | fprintf(stdout, "mtp-albums: No Devices have been found\n"); 63 | return 0; 64 | case LIBMTP_ERROR_CONNECTING: 65 | fprintf(stderr, "mtp-albums: There has been an error connecting. Exit\n"); 66 | return 1; 67 | case LIBMTP_ERROR_MEMORY_ALLOCATION: 68 | fprintf(stderr, "mtp-albums: Memory Allocation Error. Exit\n"); 69 | return 1; 70 | 71 | /* Unknown general errors - This should never execute */ 72 | case LIBMTP_ERROR_GENERAL: 73 | default: 74 | fprintf(stderr, "mtp-albums: Unknown error, please report " 75 | "this to the libmtp developers\n"); 76 | return 1; 77 | 78 | /* Successfully connected at least one device, so continue */ 79 | case LIBMTP_ERROR_NONE: 80 | fprintf(stdout, "mtp-albums: Successfully connected\n"); 81 | fflush(stdout); 82 | } 83 | 84 | /* iterate through connected MTP devices */ 85 | for(device = device_list; device != NULL; device = device->next) 86 | { 87 | char *friendlyname; 88 | LIBMTP_album_t *album_list, *album, *tmp; 89 | 90 | /* Echo the friendly name so we know which device we are working with */ 91 | friendlyname = LIBMTP_Get_Friendlyname(device); 92 | if (friendlyname == NULL) { 93 | printf("Retrieving Albums on Device with name: (NULL)\n"); 94 | } else { 95 | printf("Retrieving Albums on Device with name: %s\n", friendlyname); 96 | free(friendlyname); 97 | } 98 | 99 | album_list = LIBMTP_Get_Album_List(device); 100 | album = album_list; 101 | while(album != NULL) 102 | { 103 | dump_albuminfo(album); 104 | tmp = album; 105 | album = album->next; 106 | LIBMTP_destroy_album_t(tmp); 107 | } 108 | } 109 | 110 | LIBMTP_Release_Device_List(device_list); 111 | printf("OK.\n"); 112 | return 0; 113 | } 114 | 115 | -------------------------------------------------------------------------------- /examples/folders.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file folders.c 3 | * Example program that lists all folders on a device. 4 | * 5 | * Copyright (C) 2005-2011 Linus Walleij 6 | * Copyright (C) 2007 Ted Bullock 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "common.h" 24 | #include 25 | 26 | static void dump_folder_list(LIBMTP_folder_t *folderlist, int level) 27 | { 28 | int i; 29 | if(folderlist==NULL) { 30 | return; 31 | } 32 | 33 | printf("%u\t", folderlist->folder_id); 34 | for(i=0;iname); 37 | 38 | dump_folder_list(folderlist->child, level+1); 39 | dump_folder_list(folderlist->sibling, level); 40 | } 41 | 42 | int main (int argc, char **argv) 43 | { 44 | LIBMTP_mtpdevice_t *device_list, *device; 45 | 46 | LIBMTP_Init(); 47 | printf("Attempting to connect device(s)\n"); 48 | 49 | switch(LIBMTP_Get_Connected_Devices(&device_list)) 50 | { 51 | case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 52 | printf("mtp-folders: no devices found\n"); 53 | return 0; 54 | case LIBMTP_ERROR_CONNECTING: 55 | fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n"); 56 | return 1; 57 | case LIBMTP_ERROR_MEMORY_ALLOCATION: 58 | fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n"); 59 | return 1; 60 | 61 | /* Unknown general errors - This should never execute */ 62 | case LIBMTP_ERROR_GENERAL: 63 | default: 64 | fprintf(stderr, "mtp-folders: Unknown error, please report " 65 | "this to the libmtp developers\n"); 66 | return 1; 67 | 68 | /* Successfully connected at least one device, so continue */ 69 | case LIBMTP_ERROR_NONE: 70 | printf("mtp-folders: Successfully connected\n"); 71 | } 72 | 73 | /* iterate through connected MTP devices */ 74 | for(device = device_list; device != NULL; device = device->next) 75 | { 76 | LIBMTP_devicestorage_t *storage; 77 | char *friendlyname; 78 | int ret; 79 | 80 | /* Echo the friendly name so we know which device we are working with */ 81 | friendlyname = LIBMTP_Get_Friendlyname(device); 82 | if (friendlyname == NULL) { 83 | printf("Friendly name: (NULL)\n"); 84 | } else { 85 | printf("Friendly name: %s\n", friendlyname); 86 | free(friendlyname); 87 | } 88 | 89 | LIBMTP_Dump_Errorstack(device); 90 | LIBMTP_Clear_Errorstack(device); 91 | 92 | /* Get all storages for this device */ 93 | ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED); 94 | if (ret != 0) { 95 | perror("LIBMTP_Get_Storage()\n"); 96 | LIBMTP_Dump_Errorstack(device); 97 | LIBMTP_Clear_Errorstack(device); 98 | continue; 99 | } 100 | 101 | /* Loop over storages, dump folder for each one */ 102 | for (storage = device->storage; storage != 0; storage = storage->next) { 103 | LIBMTP_folder_t *folders; 104 | 105 | printf("Storage: %s\n", storage->StorageDescription); 106 | folders = LIBMTP_Get_Folder_List_For_Storage(device, storage->id); 107 | 108 | if (folders == NULL) { 109 | fprintf(stdout, "No folders found\n"); 110 | LIBMTP_Dump_Errorstack(device); 111 | LIBMTP_Clear_Errorstack(device); 112 | } else { 113 | dump_folder_list(folders,0); 114 | } 115 | LIBMTP_destroy_folder_t(folders); 116 | } 117 | } 118 | 119 | LIBMTP_Release_Device_List(device_list); 120 | printf("OK.\n"); 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /examples/files.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file files.c 3 | * Example program that lists all files on a device. 4 | * 5 | * Copyright (C) 2005-2012 Linus Walleij 6 | * Copyright (C) 2007 Ted Bullock 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "common.h" 24 | #include 25 | 26 | static void dump_fileinfo(LIBMTP_file_t *file) 27 | { 28 | printf("File ID: %u\n", file->item_id); 29 | if (file->filename != NULL) 30 | printf(" Filename: %s\n", file->filename); 31 | 32 | // This is sort of special... 33 | if (file->filesize == (uint32_t) -1) { 34 | printf(" None. (abstract file, size = -1)\n"); 35 | } else { 36 | #ifdef __WIN32__ 37 | printf(" File size %llu (0x%016I64X) bytes\n", file->filesize, file->filesize); 38 | #else 39 | printf(" File size %llu (0x%016llX) bytes\n", 40 | (long long unsigned int) file->filesize, 41 | (long long unsigned int) file->filesize); 42 | #endif 43 | } 44 | printf(" Parent ID: %u\n", file->parent_id); 45 | printf(" Storage ID: 0x%08X\n", file->storage_id); 46 | printf(" Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype)); 47 | } 48 | 49 | int main (int argc, char **argv) 50 | { 51 | LIBMTP_mtpdevice_t *device_list, *device; 52 | LIBMTP_file_t *files; 53 | 54 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 55 | 56 | LIBMTP_Init(); 57 | 58 | switch(LIBMTP_Get_Connected_Devices(&device_list)) 59 | { 60 | case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 61 | fprintf(stdout, "mtp-files: No Devices have been found\n"); 62 | return 0; 63 | case LIBMTP_ERROR_CONNECTING: 64 | fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n"); 65 | return 1; 66 | case LIBMTP_ERROR_MEMORY_ALLOCATION: 67 | fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n"); 68 | return 1; 69 | 70 | /* Unknown general errors - This should never execute */ 71 | case LIBMTP_ERROR_GENERAL: 72 | default: 73 | fprintf(stderr, "mtp-files: Unknown error, please report " 74 | "this to the libmtp developers\n"); 75 | return 1; 76 | 77 | /* Successfully connected at least one device, so continue */ 78 | case LIBMTP_ERROR_NONE: 79 | fprintf(stdout, "mtp-files: Successfully connected\n"); 80 | fflush(stdout); 81 | } 82 | 83 | /* iterate through connected MTP devices */ 84 | for(device = device_list; device != NULL; device = device->next) 85 | { 86 | char *friendlyname; 87 | 88 | /* Echo the friendly name so we know which device we are working with */ 89 | friendlyname = LIBMTP_Get_Friendlyname(device); 90 | if (friendlyname == NULL) { 91 | printf("Listing File Information on Device with name: (NULL)\n"); 92 | } else { 93 | printf("Listing File Information on Device with name: %s\n", friendlyname); 94 | free(friendlyname); 95 | } 96 | 97 | /* Get track listing. */ 98 | files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL); 99 | if (files == NULL) { 100 | printf("No files.\n"); 101 | LIBMTP_Dump_Errorstack(device); 102 | LIBMTP_Clear_Errorstack(device); 103 | } else { 104 | LIBMTP_file_t *file, *tmp; 105 | file = files; 106 | while (file != NULL) { 107 | dump_fileinfo(file); 108 | tmp = file; 109 | file = file->next; 110 | LIBMTP_destroy_file_t(tmp); 111 | } 112 | } 113 | } 114 | 115 | LIBMTP_Release_Device_List(device_list); 116 | printf("OK.\n"); 117 | exit (0); 118 | } 119 | -------------------------------------------------------------------------------- /logs/mtp-detect-toshiba-gigabeat-p10.txt: -------------------------------------------------------------------------------- 1 | USB low-level info: 2 | Using kernel interface "usbfs" 3 | bcdUSB: 512 4 | bDeviceClass: 0 5 | bDeviceSubClass: 0 6 | bDeviceProtocol: 0 7 | idVendor: 0930 8 | idProduct: 0011 9 | IN endpoint maxpacket: 512 bytes 10 | OUT endpoint maxpacket: 512 bytes 11 | Device flags: 0x00000000 12 | Device info: 13 | Manufacturer: TOSHIBA 14 | Model: gigabeat 15 | Device version: %OUT_PAD:128% 16 | Serial number: 4002F9D1641284A0 17 | Vendor extension ID: 0x00000006 18 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1 19 | Supported operations: 20 | 0x1001 21 | 0x1002 22 | 0x1003 23 | 0x1004 24 | 0x1005 25 | 0x1006 26 | 0x1007 27 | 0x1008 28 | 0x1009 29 | 0x100b 30 | 0x100c 31 | 0x100d 32 | 0x1014 33 | 0x1015 34 | 0x1016 35 | 0x9802 36 | 0x9801 37 | 0x9803 38 | 0x9804 39 | 0x9805 40 | 0x9806 41 | 0x9808 42 | 0x9101 43 | 0x9102 44 | 0x9103 45 | 0x9104 46 | 0x9105 47 | 0x9106 48 | 0x9107 49 | 0x9108 50 | 0x9109 51 | 0x910a 52 | 0x910b 53 | 0x100f 54 | 0x97f1 55 | 0x97f2 56 | Events supported: 57 | 0x4002 58 | 0x4003 59 | Device Properties Supported: 60 | 0xd101: Secure Time 61 | 0xd102: Device Certificate 62 | Playable File (Object) Types and Object Properties Supported: 63 | 3009: MP3 64 | dc01: StorageID 65 | dc02: ObjectFormat 66 | dc03: ProtectionStatus 67 | dc04: ObjectSize 68 | dc07: ObjectFileName 69 | dc08: DateCreated 70 | dc0b: ParentObject 71 | dc41: PersistantUniqueObjectIdentifier 72 | dc4f: NonConsumable 73 | dc9a: AlbumName 74 | dc46: Artist 75 | de93: SampleRate 76 | de94: NumberOfChannels 77 | de9a: AudioBitRate 78 | dc44: Name 79 | dc89: Duration 80 | 3008: MS Wave 81 | dc01: StorageID 82 | dc02: ObjectFormat 83 | dc03: ProtectionStatus 84 | dc04: ObjectSize 85 | dc07: ObjectFileName 86 | dc08: DateCreated 87 | dc0b: ParentObject 88 | dc41: PersistantUniqueObjectIdentifier 89 | dc4f: NonConsumable 90 | dc9a: AlbumName 91 | dc46: Artist 92 | de93: SampleRate 93 | de94: NumberOfChannels 94 | de9a: AudioBitRate 95 | dc44: Name 96 | dc89: Duration 97 | b901: WMA 98 | dc01: StorageID 99 | dc02: ObjectFormat 100 | dc03: ProtectionStatus 101 | dc04: ObjectSize 102 | dc07: ObjectFileName 103 | dc08: DateCreated 104 | dc0b: ParentObject 105 | dc41: PersistantUniqueObjectIdentifier 106 | dc4f: NonConsumable 107 | dc9a: AlbumName 108 | dc46: Artist 109 | de93: SampleRate 110 | de94: NumberOfChannels 111 | de9a: AudioBitRate 112 | dc44: Name 113 | dc89: Duration 114 | de99: AudioWAVECodec 115 | 3001: Association/Directory 116 | dc01: StorageID 117 | dc02: ObjectFormat 118 | dc03: ProtectionStatus 119 | dc04: ObjectSize 120 | dc05: AssociationType 121 | dc07: ObjectFileName 122 | dc08: DateCreated 123 | dc0b: ParentObject 124 | dc41: PersistantUniqueObjectIdentifier 125 | dc4f: NonConsumable 126 | dc44: Name 127 | 3000: Undefined Type 128 | dc01: StorageID 129 | dc02: ObjectFormat 130 | dc03: ProtectionStatus 131 | dc04: ObjectSize 132 | dc07: ObjectFileName 133 | dc08: DateCreated 134 | dc0b: ParentObject 135 | dc41: PersistantUniqueObjectIdentifier 136 | dc4f: NonConsumable 137 | Special directories: 138 | Default music folder: 0x00000000 139 | Default playlist folder: 0x00000000 140 | Default picture folder: 0x00000000 141 | Default video folder: 0x00000000 142 | Default organizer folder: 0x00000000 143 | Default zencast folder: 0x00000000 144 | MTP-specific device properties: 145 | Friendly name: (NULL) 146 | Synchronization partner: (NULL) 147 | Total bytes on device: 1022623744 (975 MB) 148 | Free bytes on device: 1007583232 (960 MB) 149 | Storage description: "Internal Storage" 150 | Error getting battery info... 151 | libmtp supported (playable) filetypes: 152 | ISO MPEG Audio Layer 3 153 | RIFF WAVE file 154 | Microsoft Windows Media Audio 155 | 156 | Secure Time: 157 | #19700101 158 | 05:23:25Z#DRM_CLK_NOT_SET 159 | 160 | -------------------------------------------------------------------------------- /logs/mtp-detect-mymusix-pd6070.txt: -------------------------------------------------------------------------------- 1 | Listing raw device(s) 2 | Found 1 device(s): 3 | MyMusix: PD-6070 (0aa6:9601) @ bus 0, dev 16 4 | Attempting to connect device(s) 5 | PTP_ERROR_IO: Trying again after re-initializing USB interface 6 | USB low-level info: 7 | Using kernel interface "usbfs" 8 | bcdUSB: 512 9 | bDeviceClass: 0 10 | bDeviceSubClass: 0 11 | bDeviceProtocol: 0 12 | idVendor: 0aa6 13 | idProduct: 9601 14 | IN endpoint maxpacket: 64 bytes 15 | OUT endpoint maxpacket: 64 bytes 16 | Raw device info: 17 | Bus location: 0 18 | Device number: 16 19 | Device entry info: 20 | Vendor: MyMusix 21 | Vendor id: 0x0aa6 22 | Product: PD-6070 23 | Vendor id: 0x9601 24 | Device flags: 0x00000002 25 | Microsoft device descriptor 0xee: 26 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 27 | 0010: 0100 .. 28 | Device info: 29 | Manufacturer: Generic 30 | Model: Audio Player 31 | Device version: RAD2010005%OUT_PAD:128% 32 | Serial number: F03A085089ECCB0C 33 | Vendor extension ID: 0x00000006 34 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1 35 | Detected object size: 64 bits 36 | Supported operations: 37 | 1001: get device info 38 | 1002: Open session 39 | 1003: Close session 40 | 1004: Get storage IDs 41 | 1005: Get storage info 42 | 1006: Get number of objects 43 | 1007: Get object handles 44 | 1008: Get object info 45 | 1009: Get object 46 | 100b: Delete object 47 | 100c: Send object info 48 | 100d: Send object 49 | 1014: Get device property description 50 | 1015: Get device property value 51 | 1016: Set device property value 52 | 9802: Get object property description 53 | 9801: Get object properties supported 54 | 9803: Get object property value 55 | 9804: Set object property value 56 | 9805: Get object property list 57 | 9806: Set object property list 58 | 9808: Send object property list 59 | 9101: Get secure time challenge 60 | 9102: Get secure time response 61 | 9103: Set license response 62 | 9104: Get sync list 63 | 9105: Send meter challenge query 64 | 9106: Get meter challenge 65 | 9107: Get meter response 66 | 9108: Clean data store 67 | 9109: Get license state 68 | 910a: Send WMDRM-PD Command 69 | 910b: Send WMDRM-PD Request 70 | 100f: Format storage 71 | 97f1: Unknown (97f1) 72 | 97f2: Unknown (97f2) 73 | Events supported: 74 | 0x4002 75 | 0x4003 76 | Device Properties Supported: 77 | 0xd101: Secure Time 78 | 0xd102: Device Certificate 79 | Playable File (Object) Types and Object Properties Supported: 80 | 3009: MP3 81 | 3008: MS Wave 82 | b901: WMA 83 | 3001: Association/Directory 84 | 3000: Undefined Type 85 | Storage Devices: 86 | StorageID: 0x00010001 87 | StorageType: 0x0003 fixed RAM storage 88 | FilesystemType: 0x0002 generic hierarchical 89 | AccessCapability: 0x0000 read/write 90 | MaxCapacity: 1010696192 91 | FreeSpaceInBytes: 896000000 92 | FreeSpaceInObjects: 4294967295 93 | StorageDescription: Internal Storage 94 | VolumeIdentifier: (null) 95 | Special directories: 96 | Default music folder: 0x00000002 97 | Default playlist folder: 0x00000000 98 | Default picture folder: 0x00000000 99 | Default video folder: 0x00000000 100 | Default organizer folder: 0x00000000 101 | Default zencast folder: 0x00000000 102 | Default album folder: 0x00000000 103 | Default text folder: 0x00000000 104 | MTP-specific device properties: 105 | Friendly name: (NULL) 106 | Synchronization partner: (NULL) 107 | libmtp supported (playable) filetypes: 108 | ISO MPEG-1 Audio Layer 3 109 | RIFF WAVE file 110 | Microsoft Windows Media Audio 111 | Unable to acquire device certificate, perhaps this device does not support this 112 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get 113 | unicode property. 114 | Error 2: (Look this up in ptp.h for an explanation.) 115 | Error 2: PTP Layer error 02ff: LIBMTP_Get_File_To_File_Descriptor(): Could not 116 | get file from device. 117 | Error 2: (Look this up in ptp.h for an explanation.) 118 | ERROR: Could not close session! 119 | inep: usb_get_endpoint_status(): No such device 120 | outep: usb_get_endpoint_status(): No such device 121 | usb_clear_halt() on IN endpoint: No such device 122 | usb_clear_halt() on OUT endpoint: No such device 123 | usb_clear_halt() on INTERRUPT endpoint: No such device 124 | OK. 125 | -------------------------------------------------------------------------------- /examples/filetree.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file filetree.c 3 | * List all files and folders of all storages recursively 4 | * 5 | * Copyright (C) 2011 Linus Walleij 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "common.h" 23 | #include "util.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | /* Clever prototype to be able to recurse */ 31 | void recursive_file_tree(LIBMTP_mtpdevice_t *, 32 | LIBMTP_devicestorage_t *, 33 | uint32_t, 34 | int); 35 | 36 | void recursive_file_tree(LIBMTP_mtpdevice_t *device, 37 | LIBMTP_devicestorage_t *storage, 38 | uint32_t leaf, 39 | int depth) 40 | { 41 | LIBMTP_file_t *files; 42 | LIBMTP_file_t *file; 43 | 44 | files = LIBMTP_Get_Files_And_Folders(device, 45 | storage->id, 46 | leaf); 47 | if (files == NULL) { 48 | return; 49 | } 50 | 51 | /* Iterate over the filelisting */ 52 | for (file = files; file != NULL; file = file->next) { 53 | int i; 54 | 55 | /* Indent */ 56 | for (i = 0; i < depth; i++) { 57 | printf(" "); 58 | } 59 | printf("%u %s\n", file->item_id, file->filename); 60 | if (file->filetype == LIBMTP_FILETYPE_FOLDER) { 61 | recursive_file_tree(device, storage, file->item_id, depth+2); 62 | } 63 | } 64 | } 65 | 66 | int main (int argc, char **argv) 67 | { 68 | LIBMTP_raw_device_t * rawdevices; 69 | int numrawdevices; 70 | LIBMTP_error_number_t err; 71 | int i; 72 | 73 | int opt; 74 | extern int optind; 75 | extern char *optarg; 76 | 77 | while ((opt = getopt(argc, argv, "d")) != -1 ) { 78 | switch (opt) { 79 | case 'd': 80 | LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); 81 | break; 82 | } 83 | } 84 | 85 | argc -= optind; 86 | argv += optind; 87 | 88 | LIBMTP_Init(); 89 | 90 | err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices); 91 | switch(err) { 92 | case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 93 | fprintf(stdout, " No raw devices found.\n"); 94 | return 0; 95 | case LIBMTP_ERROR_CONNECTING: 96 | fprintf(stderr, "Detect: There has been an error connecting. Exiting\n"); 97 | return 1; 98 | case LIBMTP_ERROR_MEMORY_ALLOCATION: 99 | fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n"); 100 | return 1; 101 | case LIBMTP_ERROR_NONE: 102 | break; 103 | case LIBMTP_ERROR_GENERAL: 104 | default: 105 | fprintf(stderr, "Unknown connection error.\n"); 106 | return 1; 107 | } 108 | 109 | /* Iterate over connected MTP devices */ 110 | fprintf(stdout, "Attempting to connect device(s)\n"); 111 | for (i = 0; i < numrawdevices; i++) { 112 | LIBMTP_mtpdevice_t *device; 113 | LIBMTP_devicestorage_t *storage; 114 | char *friendlyname; 115 | int ret; 116 | 117 | device = LIBMTP_Open_Raw_Device_Uncached(&rawdevices[i]); 118 | if (device == NULL) { 119 | fprintf(stderr, "Unable to open raw device %d\n", i); 120 | continue; 121 | } 122 | 123 | LIBMTP_Dump_Errorstack(device); 124 | LIBMTP_Clear_Errorstack(device); 125 | 126 | friendlyname = LIBMTP_Get_Friendlyname(device); 127 | if (friendlyname == NULL) { 128 | printf("Device: (NULL)\n"); 129 | } else { 130 | printf("Device: %s\n", friendlyname); 131 | free(friendlyname); 132 | } 133 | 134 | /* Get all storages for this device */ 135 | ret = LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED); 136 | if (ret != 0) { 137 | perror("LIBMTP_Get_Storage()"); 138 | goto bailout; 139 | } 140 | 141 | /* Loop over storages */ 142 | for (storage = device->storage; storage != 0; storage = storage->next) { 143 | fprintf(stdout, "Storage: %s\n", storage->StorageDescription); 144 | recursive_file_tree(device, storage, 0, 0); 145 | } 146 | 147 | bailout: 148 | LIBMTP_Release_Device(device); 149 | } /* End For Loop */ 150 | 151 | free(rawdevices); 152 | 153 | printf("OK.\n"); 154 | 155 | return 0; 156 | } 157 | -------------------------------------------------------------------------------- /logs/mtp-detect-thomson-m51.txt: -------------------------------------------------------------------------------- 1 | mtp-detect 2 | libmtp version: 0.3.6 3 | 4 | Listing raw device(s) 5 | Found 1 device(s): 6 | Thomson: Lyra MC5104B (M51 Series) (069b:077c) @ bus 0, dev 6 7 | Attempting to connect device(s) 8 | USB low-level info: 9 | Using kernel interface "usbfs" 10 | bcdUSB: 512 11 | bDeviceClass: 0 12 | bDeviceSubClass: 0 13 | bDeviceProtocol: 0 14 | idVendor: 069b 15 | idProduct: 077c 16 | IN endpoint maxpacket: 512 bytes 17 | OUT endpoint maxpacket: 512 bytes 18 | Raw device info: 19 | Bus location: 0 20 | Device number: 6 21 | Device entry info: 22 | Vendor: Thomson 23 | Vendor id: 0x069b 24 | Product: Lyra MC5104B (M51 Series) 25 | Vendor id: 0x077c 26 | Device flags: 0x00000000 27 | Microsoft device descriptor 0xee: 28 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 29 | 0010: 0100 .. 30 | Device info: 31 | Manufacturer: Thomson 32 | Model: M51 Series 33 | Device version: SDK4.210 34 | Serial number: 0002FA937F63C19B0002FA937F610D8C 35 | Vendor extension ID: 0x00000006 36 | Vendor extension description: microsoft.com: 1.0; 37 | microsoft.com/WMDRMPD: 10.1; microsoft.com/WMPPD: 10.0; audible.com: 1.0 38 | Detected object size: 64 bits 39 | Supported operations: 40 | 1001: get device info 41 | 1002: Open session 42 | 1003: Close session 43 | 1004: Get storage IDs 44 | 1005: Get storage info 45 | 1006: Get number of objects 46 | 1007: Get object handles 47 | 1008: Get object info 48 | 1009: Get object 49 | 101b: Get partial object 50 | 100b: Delete object 51 | 100c: Send object info 52 | 100d: Send object 53 | 1014: Get device property description 54 | 1015: Get device property value 55 | 1016: Set device property value 56 | 9802: Get object property description 57 | 9801: Get object properties supported 58 | 9803: Get object property value 59 | 9804: Set object property value 60 | 9805: Get object property list 61 | 9806: Set object property list 62 | 9808: Send object property list 63 | 9101: Get secure time challenge 64 | 9102: Get secure time response 65 | 9103: Set license response 66 | 9104: Get sync list 67 | 9105: Send meter challenge query 68 | 9106: Get meter challenge 69 | 9107: Get meter response 70 | 9108: Clean data store 71 | 9109: Get license state 72 | 910a: Send WMDRM-PD Command 73 | 910b: Send WMDRM-PD Request 74 | 100f: Format storage 75 | 9810: Get object references 76 | 9811: Set object references 77 | 9201: Report Added/Deleted Items 78 | 97f1: Unknown (97f1) 79 | 97f2: Unknown (97f2) 80 | 97f3: Unknown (97f3) 81 | 1010: Reset device 82 | Events supported: 83 | 0x4004 84 | 0x4005 85 | Device Properties Supported: 86 | 0xd101: Secure Time 87 | 0xd102: Device Certificate 88 | 0xd402: Friendly Device Name 89 | 0xd401: Synchronization Partner 90 | 0x5001: Battery Level 91 | 0xd100: Unknown property 92 | Playable File (Object) Types and Object Properties Supported: 93 | 3009: MP3 94 | 3008: MS Wave 95 | b901: WMA 96 | b902: OGG 97 | 3007: AIFF 98 | b903: AAC 99 | 300c: ASF 100 | 3001: Association/Directory 101 | ba05: Abstract Audio Video Playlist 102 | 3801: JPEG 103 | ba11: M3U Playlist 104 | ba03: Abstract Audio Album 105 | 3000: Undefined Type 106 | b904: Audible.com Codec 107 | Storage Devices: 108 | StorageID: 0x00010001 109 | StorageType: 0x0003 fixed RAM storage 110 | FilesystemType: 0x0002 generic hierarchical 111 | AccessCapability: 0x0000 read/write 112 | MaxCapacity: 4073979904 113 | FreeSpaceInBytes: 2900426752 114 | FreeSpaceInObjects: 4294967295 115 | StorageDescription: Internal Storage 116 | VolumeIdentifier: 0002FA937F63C19B0002FA937F610D8C 117 | Special directories: 118 | Default music folder: 0x00000000 119 | Default playlist folder: 0x00000000 120 | Default picture folder: 0x00000000 121 | Default video folder: 0x00000000 122 | Default organizer folder: 0x00000000 123 | Default zencast folder: 0x00000000 124 | Default album folder: 0x00000000 125 | Default text folder: 0x00000000 126 | MTP-specific device properties: 127 | Friendly name: (NULL) 128 | Synchronization partner: (NULL) 129 | libmtp supported (playable) filetypes: 130 | ISO MPEG-1 Audio Layer 3 131 | RIFF WAVE file 132 | Microsoft Windows Media Audio 133 | Ogg container format 134 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 135 | Microsoft Advanced Systems Format 136 | JPEG file 137 | Audible.com Audio Codec 138 | Unable to acquire device certificate, perhaps this device does not support 139 | this 140 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to 141 | get unicode property. 142 | Error 2: (Look this up in ptp.h for an explanation.) 143 | ERROR: Could not close session! 144 | inep: usb_get_endpoint_status(): No such device 145 | outep: usb_get_endpoint_status(): No such device 146 | usb_clear_halt() on IN endpoint: No such device 147 | usb_clear_halt() on OUT endpoint: No such device 148 | usb_clear_halt() on INTERRUPT endpoint: No such device 149 | OK. 150 | ************************ 151 | -------------------------------------------------------------------------------- /logs/mtp-detect-hp-touchpad.txt: -------------------------------------------------------------------------------- 1 | $ mtp-detect 2 | libmtp version: 1.0.2 3 | 4 | Listing raw device(s) 5 | Device 0 (VID=0bb4 and PID=685c) is UNKNOWN. 6 | Please report this VID/PID and the device model to the libmtp development team 7 | Found 1 device(s): 8 | 0bb4:685c @ bus 1, dev 43 9 | Attempting to connect device(s) 10 | PTP_ERROR_IO: Trying again after re-initializing USB interface 11 | Error 2: PTP Layer error 02ff: get_all_metadata_fast(): could not get proplist of all objects. 12 | Error 2: (Look this up in ptp.h for an explanation.) 13 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get object handles. 14 | Error 2: (Look this up in ptp.h for an explanation.) 15 | USB low-level info: 16 | Using kernel interface "usbfs" 17 | bcdUSB: 512 18 | bDeviceClass: 0 19 | bDeviceSubClass: 0 20 | bDeviceProtocol: 0 21 | idVendor: 0bb4 22 | idProduct: 685c 23 | IN endpoint maxpacket: 512 bytes 24 | OUT endpoint maxpacket: 512 bytes 25 | Raw device info: 26 | Bus location: 1 27 | Device number: 43 28 | Device entry info: 29 | Vendor: (null) 30 | Vendor id: 0x0bb4 31 | Product: (null) 32 | Vendor id: 0x685c 33 | Device flags: 0x00000000 34 | Configuration 0, interface 0, altsetting 0: 35 | Interface description contains the string "MTP" 36 | Device recognized as MTP, no further probing. 37 | Device info: 38 | Manufacturer: unknown 39 | Model: cm_tenderloin 40 | Device version: 1.0 41 | Serial number: 04bb35a30455e13214a1fb449cd225a7b6fbcc0c 42 | Vendor extension ID: 0x00000006 43 | Vendor extension description: microsoft.com: 1.0; android.com: 1.0; 44 | Detected object size: 64 bits 45 | Supported operations: 46 | 1001: get device info 47 | 1002: Open session 48 | 1003: Close session 49 | 1004: Get storage IDs 50 | 1005: Get storage info 51 | 1006: Get number of objects 52 | 1007: Get object handles 53 | 1008: Get object info 54 | 1009: Get object 55 | 100a: Get thumbnail 56 | 100b: Delete object 57 | 100c: Send object info 58 | 100d: Send object 59 | 1014: Get device property description 60 | 1015: Get device property value 61 | 1016: Set device property value 62 | 1017: Reset device property value 63 | 101b: Get partial object 64 | 9801: Get object properties supported 65 | 9802: Get object property description 66 | 9803: Get object property value 67 | 9804: Set object property value 68 | 9805: Get object property list 69 | 9810: Get object references 70 | 9811: Set object references 71 | 95c1: Unknown (95c1) 72 | 95c2: Unknown (95c2) 73 | 95c3: Unknown (95c3) 74 | 95c4: Unknown (95c4) 75 | 95c5: Unknown (95c5) 76 | Events supported: 77 | 0x4002 78 | 0x4003 79 | 0x4004 80 | 0x4005 81 | Device Properties Supported: 82 | 0xd401: Synchronization Partner 83 | 0xd402: Friendly Device Name 84 | 0x5003: Image Size 85 | Playable File (Object) Types and Object Properties Supported: 86 | 3000: Undefined Type 87 | 3001: Association/Directory 88 | 3004: Text 89 | 3005: HTML 90 | 3008: MS Wave 91 | 3009: MP3 92 | 300b: MPEG 93 | 3801: JPEG 94 | 3802: TIFF EP 95 | 3807: GIF 96 | 3808: JFIF 97 | 380b: PNG 98 | 380d: TIFF 99 | b901: WMA 100 | b902: OGG 101 | b903: AAC 102 | b982: MP4 103 | b983: MP2 104 | b984: 3GP 105 | ba05: Abstract Audio Video Playlist 106 | ba10: WPL Playlist 107 | ba11: M3U Playlist 108 | ba14: PLS Playlist 109 | ba82: XMLDocument 110 | b906: FLAC 111 | Storage Devices: 112 | StorageID: 0x00010001 113 | StorageType: 0x0003 fixed RAM storage 114 | FilesystemType: 0x0002 generic hierarchical 115 | AccessCapability: 0x0000 read/write 116 | MaxCapacity: 27392163840 117 | FreeSpaceInBytes: 16716693504 118 | FreeSpaceInObjects: 1073741824 119 | StorageDescription: SD Card 120 | VolumeIdentifier: (null) 121 | Special directories: 122 | Default music folder: 0xffffffff 123 | Default playlist folder: 0xffffffff 124 | Default picture folder: 0xffffffff 125 | Default video folder: 0xffffffff 126 | Default organizer folder: 0xffffffff 127 | Default zencast folder: 0xffffffff 128 | Default album folder: 0xffffffff 129 | Default text folder: 0xffffffff 130 | MTP-specific device properties: 131 | Friendly name: (NULL) 132 | Synchronization partner: (NULL) 133 | libmtp supported (playable) filetypes: 134 | Text file 135 | HTML file 136 | RIFF WAVE file 137 | ISO MPEG-1 Audio Layer 3 138 | MPEG video stream 139 | JPEG file 140 | GIF bitmap file 141 | JFIF file 142 | Portable Network Graphics 143 | TIFF bitmap file 144 | Microsoft Windows Media Audio 145 | Ogg container format 146 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 147 | MPEG-4 Part 14 Container Format (Audio+Video Emphasis) 148 | ISO MPEG-1 Audio Layer 2 149 | Abstract Playlist file 150 | XML file 151 | Free Lossless Audio Codec (FLAC) 152 | ERROR: Could not close session! 153 | OK. 154 | -------------------------------------------------------------------------------- /examples/connect.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file connect.c 3 | * Main programs implementing several utilities in one. 4 | * 5 | * Copyright (C) 2006 Chris A. Debenham 6 | * Copyright (C) 2008-2010 Linus Walleij 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include "common.h" 29 | #include "util.h" 30 | #include "pathutils.h" 31 | #include "connect.h" 32 | 33 | LIBMTP_folder_t *folders; 34 | LIBMTP_file_t *files; 35 | LIBMTP_mtpdevice_t *device; 36 | 37 | static void 38 | split_arg(char * argument, char ** part1, char ** part2) 39 | { 40 | char *sepp; 41 | *part1 = NULL; 42 | *part2 = NULL; 43 | 44 | sepp = argument + strcspn(argument, ","); 45 | sepp[0] = '\0'; 46 | *part1 = argument; 47 | *part2 = sepp+1; 48 | } 49 | 50 | static void 51 | usage(void) 52 | { 53 | printf("Usage: connect \n"); 54 | printf("Commands: --delete [filename]\n"); 55 | printf(" --sendfile [source] [destination]\n"); 56 | printf(" --sendtrack [source] [destination]\n"); 57 | printf(" --getfile [source] [destination]\n"); 58 | printf(" --newfolder [foldername]\n"); 59 | } 60 | 61 | 62 | int main (int argc, char **argv) 63 | { 64 | int ret = 0; 65 | 66 | checklang(); 67 | 68 | LIBMTP_Init(); 69 | 70 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 71 | 72 | device = LIBMTP_Get_First_Device(); 73 | if (device == NULL) { 74 | printf("No devices.\n"); 75 | return 0; 76 | } 77 | files = LIBMTP_Get_Filelisting_With_Callback (device, NULL, NULL); 78 | folders = LIBMTP_Get_Folder_List (device); 79 | 80 | if ((strncmp(basename(argv[0]),"mtp-delfile",11) == 0) || (strncmp(basename(argv[0]),"delfile",7) == 0)) { 81 | ret = delfile_command(argc,argv); 82 | } else if ((strncmp(basename(argv[0]),"mtp-getfile",13) == 0) || (strncmp(basename(argv[0]),"getfile",9) == 0)) { 83 | ret = getfile_command(argc,argv); 84 | } else if ((strncmp(basename(argv[0]),"mtp-newfolder",13) == 0) || (strncmp(basename(argv[0]),"newfolder",9) == 0)) { 85 | ret = newfolder_command(argc,argv); 86 | } else if ((strncmp(basename(argv[0]),"mtp-sendfile",11) == 0) || (strncmp(basename(argv[0]),"sendfile",7) == 0)) { 87 | ret = sendfile_command(argc, argv); 88 | } else if ((strncmp(basename(argv[0]),"mtp-sendtr",10) == 0) || (strncmp(basename(argv[0]),"sendtr",6) == 0)) { 89 | ret = sendtrack_command(argc, argv); 90 | } else { 91 | if ( argc < 2 ) { 92 | usage (); 93 | return 1; 94 | } 95 | 96 | while (1) { 97 | int option_index = 0; 98 | static struct option long_options[] = { 99 | {"delete", 1, 0, 'd'}, 100 | {"sendfile", 1, 0, 'f'}, 101 | {"getfile", 1, 0, 'g'}, 102 | {"newfolder", 1, 0, 'n'}, 103 | {"sendtrack", 1, 0, 't'}, 104 | {0, 0, 0, 0} 105 | }; 106 | 107 | int c = getopt_long (argc, argv, "d:f:g:n:t:", long_options, &option_index); 108 | if (c == -1) 109 | break; 110 | 111 | char *arg1, *arg2; 112 | switch (c) { 113 | case 'd': 114 | printf("Delete %s\n",optarg); 115 | ret = delfile_function(optarg); 116 | break; 117 | 118 | case 'f': 119 | printf("Send file %s\n",optarg); 120 | split_arg(optarg,&arg1,&arg2); 121 | ret = sendfile_function(arg1,arg2); 122 | break; 123 | 124 | case 'g': 125 | printf("Get file %s\n",optarg); 126 | split_arg(optarg,&arg1,&arg2); 127 | ret = getfile_function(arg1,arg2); 128 | break; 129 | 130 | case 'n': 131 | printf("New folder %s\n",optarg); 132 | ret = newfolder_function(optarg); 133 | break; 134 | 135 | case 't': 136 | printf("Send track %s\n",optarg); 137 | split_arg(optarg,&arg1,&arg2); 138 | ret = sendtrack_function(arg1,arg2,NULL,NULL,NULL,NULL,NULL,NULL,0,0,0,0,0); 139 | break; 140 | } 141 | } 142 | 143 | if (optind < argc) { 144 | printf("Unknown options: "); 145 | while (optind < argc) 146 | printf("%s ", argv[optind++]); 147 | printf("\n"); 148 | } 149 | } 150 | 151 | LIBMTP_Release_Device(device); 152 | 153 | return ret; 154 | } 155 | -------------------------------------------------------------------------------- /examples/albumart.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file albumart.c 3 | * Example program to send album art. 4 | * 5 | * Copyright (C) 2006 Andy Kelk 6 | * 7 | * This library is free software; you can redistribute it and/or 8 | * modify it under the terms of the GNU Lesser General Public 9 | * License as published by the Free Software Foundation; either 10 | * version 2 of the License, or (at your option) any later version. 11 | * 12 | * This library is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this library; if not, write to the 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 | * Boston, MA 02111-1307, USA. 21 | */ 22 | #include "config.h" 23 | #include "common.h" 24 | #include "string.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #ifdef HAVE_SYS_UIO_H 33 | #include 34 | #endif 35 | 36 | static void usage(void) { 37 | printf("Usage: albumart -d -i -n -s -p \n"); 38 | exit(0); 39 | } 40 | 41 | int main (int argc, char **argv) { 42 | int opt; 43 | extern int optind; 44 | extern char *optarg; 45 | LIBMTP_mtpdevice_t *device = NULL; 46 | int idcount = 0; 47 | int fd; 48 | uint32_t *ids = NULL; 49 | uint32_t *tmp = NULL; 50 | uint64_t filesize; 51 | char *imagedata = NULL; 52 | char *albumname = NULL; 53 | char *path = NULL; 54 | char *rest; 55 | struct stat statbuff; 56 | uint32_t storageid = 0; 57 | uint32_t parentid = 0; 58 | 59 | fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n"); 60 | 61 | while ( (opt = getopt(argc, argv, "dhn:i:s:p:")) != -1 ) { 62 | switch (opt) { 63 | case 'h': 64 | usage(); 65 | case 'd': 66 | LIBMTP_Set_Debug(LIBMTP_DEBUG_PTP | LIBMTP_DEBUG_DATA); 67 | break; 68 | case 'i': 69 | idcount++; 70 | if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) { 71 | printf("realloc failed\n"); 72 | return 1; 73 | } 74 | ids = tmp; 75 | ids[(idcount-1)] = strtoul(optarg, &rest, 0); 76 | break; 77 | case 'n': 78 | albumname = strdup(optarg); 79 | break; 80 | case 's': 81 | storageid = (uint32_t) strtoul(optarg, NULL, 0); 82 | break; 83 | case 'p': 84 | parentid = (uint32_t) strtoul(optarg, NULL, 0); 85 | break; 86 | default: 87 | usage(); 88 | } 89 | } 90 | argc -= optind; 91 | argv += optind; 92 | 93 | if ( argc != 1 ) { 94 | printf("You need to pass a filename.\n"); 95 | usage(); 96 | } 97 | 98 | if ( albumname == NULL) { 99 | printf("You need to supply an album name.\n"); 100 | usage(); 101 | } 102 | 103 | if (idcount == 0) { 104 | printf("You need to supply one or more track IDs\n"); 105 | usage(); 106 | } 107 | 108 | path = argv[0]; 109 | 110 | if ( stat(path, &statbuff) == -1 ) { 111 | fprintf(stderr, "%s: ", path); 112 | perror("stat"); 113 | exit(1); 114 | } 115 | filesize = (uint64_t) statbuff.st_size; 116 | imagedata = malloc(filesize * sizeof(uint8_t)); 117 | 118 | #ifdef __WIN32__ 119 | if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) { 120 | #else 121 | if ( (fd = open(path, O_RDONLY)) == -1) { 122 | #endif 123 | printf("Couldn't open image file %s (%s)\n",path,strerror(errno)); 124 | return 1; 125 | } 126 | else { 127 | read(fd, imagedata, filesize); 128 | close(fd); 129 | } 130 | 131 | LIBMTP_Init(); 132 | device = LIBMTP_Get_First_Device(); 133 | if (device == NULL) { 134 | printf("No devices.\n"); 135 | return 0; 136 | } 137 | 138 | LIBMTP_filesampledata_t *albumart = LIBMTP_new_filesampledata_t(); 139 | albumart->data = imagedata; 140 | albumart->size = filesize; 141 | albumart->filetype = LIBMTP_FILETYPE_JPEG; 142 | 143 | LIBMTP_album_t *album = LIBMTP_new_album_t(); 144 | album->name = albumname; 145 | album->no_tracks = idcount; 146 | album->tracks = ids; 147 | album->parent_id = parentid; 148 | album->storage_id = storageid; 149 | int ret = LIBMTP_Create_New_Album(device,album); 150 | if (ret == 0) { 151 | ret = LIBMTP_Send_Representative_Sample(device,album->album_id, albumart); 152 | if (ret != 0) { 153 | printf("Couldn't send album art\n"); 154 | LIBMTP_Dump_Errorstack(device); 155 | LIBMTP_Clear_Errorstack(device); 156 | } 157 | } 158 | else { 159 | printf("Couldn't create album object\n"); 160 | LIBMTP_Dump_Errorstack(device); 161 | LIBMTP_Clear_Errorstack(device); 162 | } 163 | 164 | LIBMTP_destroy_filesampledata_t(albumart); 165 | LIBMTP_destroy_album_t(album); 166 | 167 | LIBMTP_Release_Device(device); 168 | printf("OK.\n"); 169 | return 0; 170 | } 171 | 172 | -------------------------------------------------------------------------------- /logs/mtp-detect-medion-lifetab-p9514.txt: -------------------------------------------------------------------------------- 1 | libmtp version: 1.1.3 2 | 3 | Listing raw device(s) 4 | Device 0 (VID=0408 and PID=b00a) is UNKNOWN. 5 | Please report this VID/PID and the device model to the libmtp development team 6 | Found 1 device(s): 7 | 0408:b00a @ bus 2, dev 27 8 | Attempting to connect device(s) 9 | Android device detected, assigning default bug flags 10 | Error 7: Found a bad handle, trying to ignore it. 11 | Error 7: Found a bad handle, trying to ignore it. 12 | Error 7: Found a bad handle, trying to ignore it. 13 | Error 7: Found a bad handle, trying to ignore it. 14 | USB low-level info: 15 | Interface has a kernel driver attached. 16 | bcdUSB: 20475 17 | bDeviceClass: 63 18 | bDeviceSubClass: 127 19 | bDeviceProtocol: 0 20 | idVendor: 9f27 21 | idProduct: 4fc9 22 | IN endpoint maxpacket: 512 bytes 23 | OUT endpoint maxpacket: 512 bytes 24 | Raw device info: 25 | Bus location: 2 26 | Device number: 27 27 | Device entry info: 28 | Vendor: (null) 29 | Vendor id: 0x0408 30 | Product: (null) 31 | Vendor id: 0xb00a 32 | Device flags: 0x08008106 33 | Device info: 34 | Manufacturer: MEDION 35 | Model: LIFETAB_P9514 36 | Device version: 1.0 37 | Serial number: 037c61c24140d657 38 | Vendor extension ID: 0x00000006 39 | Vendor extension description: microsoft.com: 1.0; android.com: 1.0; 40 | Detected object size: 64 bits 41 | Extensions: 42 | microsoft.com: 1.0 43 | android.com: 1.0 44 | Supported operations: 45 | 1001: get device info 46 | 1002: Open session 47 | 1003: Close session 48 | 1004: Get storage IDs 49 | 1005: Get storage info 50 | 1006: Get number of objects 51 | 1007: Get object handles 52 | 1008: Get object info 53 | 1009: Get object 54 | 100a: Get thumbnail 55 | 100b: Delete object 56 | 100c: Send object info 57 | 100d: Send object 58 | 1014: Get device property description 59 | 1015: Get device property value 60 | 1016: Set device property value 61 | 1017: Reset device property value 62 | 101b: Get partial object 63 | 9801: Get object properties supported 64 | 9802: Get object property description 65 | 9803: Get object property value 66 | 9804: Set object property value 67 | 9805: Get object property list 68 | 9810: Get object references 69 | 9811: Set object references 70 | 95c1: Unknown (95c1) 71 | 95c2: Unknown (95c2) 72 | 95c3: Unknown (95c3) 73 | 95c4: Unknown (95c4) 74 | 95c5: Unknown (95c5) 75 | Events supported: 76 | 0x4002 77 | 0x4003 78 | 0x4004 79 | 0x4005 80 | Device Properties Supported: 81 | 0xd401: Synchronization Partner 82 | 0xd402: Friendly Device Name 83 | 0x5003: Image Size 84 | Playable File (Object) Types and Object Properties Supported: 85 | 3000: Undefined Type 86 | 3001: Association/Directory 87 | 3004: Text 88 | 3005: HTML 89 | 3008: MS Wave 90 | 3009: MP3 91 | 300b: MPEG 92 | 3801: JPEG 93 | 3802: TIFF EP 94 | 3807: GIF 95 | 3808: JFIF 96 | 380b: PNG 97 | 380d: TIFF 98 | b901: WMA 99 | b902: OGG 100 | b903: AAC 101 | b982: MP4 102 | b983: MP2 103 | b984: 3GP 104 | ba05: Abstract Audio Video Playlist 105 | ba10: WPL Playlist 106 | ba11: M3U Playlist 107 | ba14: PLS Playlist 108 | ba82: XMLDocument 109 | b906: FLAC 110 | Storage Devices: 111 | StorageID: 0x00010001 112 | StorageType: 0x0003 fixed RAM storage 113 | FilesystemType: 0x0002 generic hierarchical 114 | AccessCapability: 0x0000 read/write 115 | MaxCapacity: 30042714112 116 | FreeSpaceInBytes: 552730524 117 | FreeSpaceInObjects: 1073741824 118 | StorageDescription: Internal Storage 119 | VolumeIdentifier: (null) 120 | Special directories: 121 | Default music folder: 0x00000002 122 | Default playlist folder: 0xffffffff 123 | Default picture folder: 0xffffffff 124 | Default video folder: 0xffffffff 125 | Default organizer folder: 0xffffffff 126 | Default zencast folder: 0xffffffff 127 | Default album folder: 0xffffffff 128 | Default text folder: 0xffffffff 129 | MTP-specific device properties: 130 | Friendly name: (NULL) 131 | Synchronization partner: (NULL) 132 | libmtp supported (playable) filetypes: 133 | Folder 134 | Text file 135 | HTML file 136 | RIFF WAVE file 137 | ISO MPEG-1 Audio Layer 3 138 | MPEG video stream 139 | JPEG file 140 | GIF bitmap file 141 | JFIF file 142 | Portable Network Graphics 143 | TIFF bitmap file 144 | Microsoft Windows Media Audio 145 | Ogg container format 146 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 147 | MPEG-4 Part 14 Container Format (Audio+Video Emphasis) 148 | ISO MPEG-1 Audio Layer 2 149 | Abstract Playlist file 150 | XML file 151 | Free Lossless Audio Codec (FLAC) 152 | ERROR: Could not close session! 153 | inep: usb_get_endpoint_status(): No such device 154 | outep: usb_get_endpoint_status(): No such device 155 | usb_clear_halt() on IN endpoint: No such device 156 | usb_clear_halt() on OUT endpoint: No such device 157 | usb_clear_halt() on INTERRUPT endpoint: No such device 158 | OK. 159 | -------------------------------------------------------------------------------- /logs/mtp-detect-maxfield-g-flash-ng-1GB.txt: -------------------------------------------------------------------------------- 1 | Device 0 (VID=066f and PID=846c) is a Maxfield G-Flash NG 1GB. 2 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get unicode property. 3 | Error 2: (Look this up in ptp.h for an explanation.) 4 | ERROR: Could not close session! 5 | inep: usb_get_endpoint_status(): No such device 6 | outep: usb_get_endpoint_status(): No such device 7 | usb_clear_halt() on IN endpoint: No such device 8 | usb_clear_halt() on OUT endpoint: No such device 9 | usb_clear_halt() on INTERRUPT endpoint: No such device 10 | libmtp version: 0.3.7 11 | 12 | Listing raw device(s) 13 | Found 1 device(s): 14 | Maxfield: G-Flash NG 1GB (066f:846c) @ bus 0, dev 30 15 | Attempting to connect device(s) 16 | USB low-level info: 17 | Using kernel interface "usbfs" 18 | bcdUSB: 512 19 | bDeviceClass: 0 20 | bDeviceSubClass: 0 21 | bDeviceProtocol: 0 22 | idVendor: 066f 23 | idProduct: 846c 24 | IN endpoint maxpacket: 512 bytes 25 | OUT endpoint maxpacket: 512 bytes 26 | Raw device info: 27 | Bus location: 0 28 | Device number: 30 29 | Device entry info: 30 | Vendor: Maxfield 31 | Vendor id: 0x066f 32 | Product: G-Flash NG 1GB 33 | Vendor id: 0x846c 34 | Device flags: 0x00000006 35 | Microsoft device descriptor 0xee: 36 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 37 | 0010: 0100 .. 38 | Device info: 39 | Manufacturer: SigmaTel 40 | Model: MTP Player 41 | Device version: SDK4.210 42 | Serial number: 0002FA82174ED9C80002FA82174ACA0C 43 | Vendor extension ID: 0x00000006 44 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1; microsoft.com/WMPPD: 10.0 45 | Detected object size: 64 bits 46 | Supported operations: 47 | 1001: get device info 48 | 1002: Open session 49 | 1003: Close session 50 | 1004: Get storage IDs 51 | 1005: Get storage info 52 | 1006: Get number of objects 53 | 1007: Get object handles 54 | 1008: Get object info 55 | 1009: Get object 56 | 101b: Get partial object 57 | 100b: Delete object 58 | 100c: Send object info 59 | 100d: Send object 60 | 1014: Get device property description 61 | 1015: Get device property value 62 | 1016: Set device property value 63 | 9802: Get object property description 64 | 9801: Get object properties supported 65 | 9803: Get object property value 66 | 9804: Set object property value 67 | 9805: Get object property list 68 | 9806: Set object property list 69 | 9808: Send object property list 70 | 9101: Get secure time challenge 71 | 9102: Get secure time response 72 | 9103: Set license response 73 | 9104: Get sync list 74 | 9105: Send meter challenge query 75 | 9106: Get meter challenge 76 | 9107: Get meter response 77 | 9108: Clean data store 78 | 9109: Get license state 79 | 910a: Send WMDRM-PD Command 80 | 910b: Send WMDRM-PD Request 81 | 100f: Format storage 82 | 9810: Get object references 83 | 9811: Set object references 84 | 9201: Report Added/Deleted Items 85 | 97f1: Unknown (97f1) 86 | 97f2: Unknown (97f2) 87 | 97f3: Unknown (97f3) 88 | 1010: Reset device 89 | Events supported: 90 | 0x4004 91 | 0x4005 92 | Device Properties Supported: 93 | 0xd101: Secure Time 94 | 0xd102: Device Certificate 95 | 0xd402: Friendly Device Name 96 | 0xd401: Synchronization Partner 97 | 0x5001: Battery Level 98 | Playable File (Object) Types and Object Properties Supported: 99 | 3009: MP3 100 | 3008: MS Wave 101 | b901: WMA 102 | b902: OGG 103 | 3007: AIFF 104 | b903: AAC 105 | 300c: ASF 106 | 3001: Association/Directory 107 | ba05: Abstract Audio Video Playlist 108 | 3801: JPEG 109 | ba11: M3U Playlist 110 | ba03: Abstract Audio Album 111 | 3000: Undefined Type 112 | Storage Devices: 113 | StorageID: 0x00010001 114 | StorageType: 0x0003 fixed RAM storage 115 | FilesystemType: 0x0002 generic hierarchical 116 | AccessCapability: 0x0000 read/write 117 | MaxCapacity: 990117888 118 | FreeSpaceInBytes: 478984104 119 | FreeSpaceInObjects: 4294967295 120 | StorageDescription: Internal Storage 121 | VolumeIdentifier: 0002FA82174ED9C80002FA82174ACA0C 122 | Special directories: 123 | Default music folder: 0x00000000 124 | Default playlist folder: 0x00000000 125 | Default picture folder: 0x00000000 126 | Default video folder: 0x00000000 127 | Default organizer folder: 0x00000000 128 | Default zencast folder: 0x00000000 129 | Default album folder: 0x00000000 130 | Default text folder: 0x00000000 131 | MTP-specific device properties: 132 | Friendly name: (NULL) 133 | Synchronization partner: (NULL) 134 | libmtp supported (playable) filetypes: 135 | ISO MPEG-1 Audio Layer 3 136 | RIFF WAVE file 137 | Microsoft Windows Media Audio 138 | Ogg container format 139 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 140 | Microsoft Advanced Systems Format 141 | JPEG file 142 | Unable to acquire device certificate, perhaps this device does not support this 143 | OK. 144 | 145 | 146 | -------------------------------------------------------------------------------- /logs/mtp-detect-samsung-sgh-u900.txt: -------------------------------------------------------------------------------- 1 | PTP: Opening session 2 | Error 1: Get Storage information failed. 3 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get object handles. 4 | Error 2: (Look this up in ptp.h for an explanation.) 5 | libmtp version: 0.3.3 6 | 7 | Listing raw device(s) 8 | Found 1 device(s): 9 | Samsung: YH-999 Portable Media Center/SGH-A707/SGH-L760V (04e8:5a0f) @ bus 0, dev 7 10 | Attempting to connect device(s) 11 | USB low-level info: 12 | Using kernel interface "usbfs" 13 | bcdUSB: 272 14 | bDeviceClass: 0 15 | bDeviceSubClass: 0 16 | bDeviceProtocol: 0 17 | idVendor: 04e8 18 | idProduct: 5a0f 19 | IN endpoint maxpacket: 64 bytes 20 | OUT endpoint maxpacket: 64 bytes 21 | Raw device info: 22 | Bus location: 0 23 | Device number: 7 24 | Device entry info: 25 | Vendor: Samsung 26 | Vendor id: 0x04e8 27 | Product: YH-999 Portable Media Center/SGH-A707/SGH-L760V 28 | Vendor id: 0x5a0f 29 | Device flags: 0x00000001 30 | Microsoft device descriptor 0xee: 31 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 32 | 0010: 0900 .. 33 | Microsoft device response to control message 1, CMD 0x09: 34 | 0000: 6a00 0000 0001 0400 0100 0000 0000 0000 j............... 35 | 0010: 0001 4d00 0000 5400 0000 5000 0000 0000 ..M...T...P..... 36 | 0020: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 37 | 0030: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 38 | 0040: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 39 | 0050: 0000 0000 0000 0000 0000 0000 0000 0000 ................ 40 | 0060: 0000 0000 0000 0000 0000 .......... 41 | Device info: 42 | Manufacturer: Samsung Electronics Co., Ltd. 43 | Model: SGH-U900 44 | Device version: U90U+XX+H 45 | Serial number: 355243021321028 46 | Vendor extension ID: 0x00000006 47 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMPPD: 11.0; microsoft.com/WMPPD: 10.0; microsoft.com/WMDRMPD: 10.1; 48 | Detected object size: 64 bits 49 | Supported operations: 50 | 1001: get device info 51 | 1002: Open session 52 | 1003: Close session 53 | 1004: Get storage IDs 54 | 1005: Get storage info 55 | 1006: Get number of objects 56 | 1007: Get object handles 57 | 1008: Get object info 58 | 1009: Get object 59 | 100b: Delete object 60 | 100c: Send object info 61 | 100d: Send object 62 | 100f: Format storage 63 | 1014: Get device property description 64 | 1015: Get device property value 65 | 1016: Set device property value 66 | 101b: Get partial object 67 | 9810: Get object references 68 | 9811: Set object references 69 | 9802: Get object property description 70 | 9801: Get object properties supported 71 | 9803: Get object property value 72 | 9804: Set object property value 73 | 9805: Get object property list 74 | 9806: Set object property list 75 | 9201: Report Added/Deleted Items 76 | 1011: Self test device 77 | 1012: Set object protection 78 | 1017: Reset device property value 79 | 1019: Move object 80 | 101a: Copy object 81 | 9808: Send object property list 82 | 9001: Unknown (9001) 83 | 9100: Unknown (9100) 84 | 9101: Get secure time challenge 85 | 9102: Get secure time response 86 | 9103: Set license response 87 | 9104: Get sync list 88 | 9105: Send meter challenge query 89 | 9106: Get meter challenge 90 | 9107: Get meter response 91 | 9108: Clean data store 92 | 9109: Get license state 93 | 910a: Send WMDRM-PD Command 94 | 910b: Send WMDRM-PD Request 95 | 9202: Report Acquired Items 96 | Events supported: 97 | 0x4001 98 | 0x4004 99 | 0x4005 100 | 0x4006 101 | Device Properties Supported: 102 | 0x5001: Battery Level 103 | 0xd401: Synchronization Partner 104 | 0xd402: Friendly Device Name 105 | 0xd404: Unknown property 106 | 0xd407: Unknown property 107 | 0xd101: Secure Time 108 | 0xd102: Device Certificate 109 | Playable File (Object) Types and Object Properties Supported: 110 | b984: 3GP 111 | 3009: MP3 112 | b901: WMA 113 | b981: WMV 114 | 3801: JPEG 115 | 3001: Association/Directory 116 | ba05: Abstract Audio Video Playlist 117 | 3000: Undefined Type 118 | 3807: GIF 119 | 300c: ASF 120 | ba03: Abstract Audio Album 121 | Special directories: 122 | Default music folder: 0x00000000 123 | Default playlist folder: 0x00000000 124 | Default picture folder: 0x00000000 125 | Default video folder: 0x00000000 126 | Default organizer folder: 0x00000000 127 | Default zencast folder: 0x00000000 128 | Default album folder: 0x00000000 129 | Default text folder: 0x00000000 130 | MTP-specific device properties: 131 | Friendly name: (NULL) 132 | Synchronization partner: (NULL) 133 | libmtp supported (playable) filetypes: 134 | ISO MPEGError 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get unicode property. 135 | Error 2: (Look this up in ptp.h for an explanation.) 136 | PTP: Closing session 137 | ERROR: Could not close session! 138 | -1 Audio Layer 3 139 | Microsoft Windows Media Audio 140 | Microsoft Windows Media Video 141 | JPEG file 142 | GIF bitmap file 143 | Microsoft Advanced Systems Format 144 | Unable to acquire device certificate, perhaps this device does not support this 145 | WMPInfo.xml Does not exist on this device 146 | OK. 147 | -------------------------------------------------------------------------------- /examples/tracks.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file tracks.c 3 | * Example program to list the tracks on a device. 4 | * 5 | * Copyright (C) 2005-2012 Linus Walleij 6 | * Copyright (C) 2007 Ted Bullock 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the 20 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21 | * Boston, MA 02111-1307, USA. 22 | */ 23 | #include "common.h" 24 | #include 25 | 26 | static void dump_trackinfo(LIBMTP_track_t *track) 27 | { 28 | printf("Track ID: %u\n", track->item_id); 29 | if (track->title != NULL) 30 | printf(" Title: %s\n", track->title); 31 | if (track->artist != NULL) 32 | printf(" Artist: %s\n", track->artist); 33 | if (track->genre != NULL) 34 | printf(" Genre: %s\n", track->genre); 35 | if (track->composer != NULL) 36 | printf(" Composer: %s\n", track->composer); 37 | if (track->album != NULL) 38 | printf(" Album: %s\n", track->album); 39 | if (track->date != NULL) 40 | printf(" Date: %s\n", track->date); 41 | if (track->filename != NULL) 42 | printf(" Origfilename: %s\n", track->filename); 43 | printf(" Track number: %d\n", track->tracknumber); 44 | printf(" Duration: %d milliseconds\n", track->duration); 45 | #ifdef __WIN32__ 46 | printf(" File size %I64u bytes\n", track->filesize); 47 | #else 48 | printf(" File size %llu bytes\n", (long long unsigned int) track->filesize); 49 | #endif 50 | printf(" Filetype: %s\n", LIBMTP_Get_Filetype_Description(track->filetype)); 51 | if (track->samplerate != 0) { 52 | printf(" Sample rate: %u Hz\n", track->samplerate); 53 | } 54 | if (track->nochannels != 0) { 55 | printf(" Number of channels: %u\n", track->nochannels); 56 | } 57 | if (track->wavecodec != 0) { 58 | printf(" WAVE fourCC code: 0x%08X\n", track->wavecodec); 59 | } 60 | if (track->bitrate != 0) { 61 | printf(" Bitrate: %u bits/s\n", track->bitrate); 62 | } 63 | if (track->bitratetype != 0) { 64 | if (track->bitratetype == 1) { 65 | printf(" Bitrate type: Constant\n"); 66 | } else if (track->bitratetype == 2) { 67 | printf(" Bitrate type: Variable (VBR)\n"); 68 | } else if (track->bitratetype == 3) { 69 | printf(" Bitrate type: Free\n"); 70 | } else { 71 | printf(" Bitrate type: Unknown/Erroneous value\n"); 72 | } 73 | } 74 | if (track->rating != 0) { 75 | printf(" User rating: %u (out of 100)\n", track->rating); 76 | } 77 | if (track->usecount != 0) { 78 | printf(" Use count: %u times\n", track->usecount); 79 | } 80 | } 81 | 82 | int main (int argc, char **argv) 83 | { 84 | LIBMTP_mtpdevice_t *device_list, *device; 85 | LIBMTP_track_t *tracks; 86 | 87 | LIBMTP_Init(); 88 | fprintf(stdout, "Attempting to connect device(s)\n"); 89 | 90 | switch(LIBMTP_Get_Connected_Devices(&device_list)) 91 | { 92 | case LIBMTP_ERROR_NO_DEVICE_ATTACHED: 93 | fprintf(stdout, "mtp-tracks: No Devices have been found\n"); 94 | return 0; 95 | case LIBMTP_ERROR_CONNECTING: 96 | fprintf(stderr, "mtp-tracks: There has been an error connecting. Exit\n"); 97 | return 1; 98 | case LIBMTP_ERROR_MEMORY_ALLOCATION: 99 | fprintf(stderr, "mtp-tracks: Memory Allocation Error. Exit\n"); 100 | return 1; 101 | 102 | /* Unknown general errors - This should never execute */ 103 | case LIBMTP_ERROR_GENERAL: 104 | default: 105 | fprintf(stderr, "mtp-tracks: Unknown error, please report " 106 | "this to the libmtp developers\n"); 107 | return 1; 108 | 109 | /* Successfully connected at least one device, so continue */ 110 | case LIBMTP_ERROR_NONE: 111 | fprintf(stdout, "mtp-tracks: Successfully connected\n"); 112 | fflush(stdout); 113 | } 114 | 115 | /* iterate through connected MTP devices */ 116 | for(device = device_list; device != NULL; device = device->next) { 117 | char *friendlyname; 118 | 119 | /* Echo the friendly name so we know which device we are working with */ 120 | friendlyname = LIBMTP_Get_Friendlyname(device); 121 | if (friendlyname == NULL) { 122 | printf("Friendly name: (NULL)\n"); 123 | } else { 124 | printf("Friendly name: %s\n", friendlyname); 125 | free(friendlyname); 126 | } 127 | // Get track listing. 128 | tracks = LIBMTP_Get_Tracklisting_With_Callback(device, NULL, NULL); 129 | if (tracks == NULL) { 130 | printf("No tracks.\n"); 131 | } else { 132 | LIBMTP_track_t *track, *tmp; 133 | track = tracks; 134 | while (track != NULL) { 135 | dump_trackinfo(track); 136 | tmp = track; 137 | track = track->next; 138 | LIBMTP_destroy_track_t(tmp); 139 | } 140 | } 141 | } 142 | 143 | LIBMTP_Release_Device_List(device_list); 144 | printf("OK.\n"); 145 | exit (0); 146 | } 147 | 148 | -------------------------------------------------------------------------------- /logs/mtp-detect-toshiba-gigabeat-v30.txt: -------------------------------------------------------------------------------- 1 | libmtp version: 0.2.2 2 | 3 | Attempting to connect device(s) 4 | PTP: Opening session 5 | Detect: Successfully connected 1 devices 6 | Error 2: PTP Layer error 02ff: get_all_metadata_fast(): could not get proplist of all objects. 7 | Error 2: (Look this up in ptp.h for an explanation.) 8 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get object handles. 9 | Error 2: (Look this up in ptp.h for an explanation.) 10 | USB low-level info: 11 | Using kernel interface "usbfs" 12 | bcdUSB: 512 13 | bDeviceClass: 255 14 | bDeviceSubClass: 0 15 | bDeviceProtocol: 0 16 | idVendor: 0930 17 | idProduct: 0014 18 | IN endpoint maxpacket: 512 bytes 19 | OUT endpoint maxpacket: 512 bytes 20 | Device flags: 0x00000000 21 | Microsoft device descriptor 0xee: 22 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 23 | 0010: fe00 .. 24 | Microsoft device response to control message 1, CMD 0xfe: 25 | 0000: 2800 0000 0001 0400 0100 0000 0000 0000 (............... 26 | 0010: 0001 4d54 5000 0000 0000 0000 0000 0000 ..MTP........... 27 | 0020: 0000 0000 0000 0000 ........ 28 | Potential MTP Device with VendorID:0930 and ProductID:0014 responded to control message 2 with a response that was too short. Problems may arrise but continuing 29 | Device info: 30 | Manufacturer: TOSHIBA 31 | Model: gigabeat V 32 | Device version: PMC: 2.11 (632:1400); Platform: 1.0 (632.4) 33 | Serial number: 019fdbe0 - acee5a4e - 80bd1ff8 - 8ee00652 34 | Vendor extension ID: 0x00000006 35 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1; microsoft.com/WMPPD: 11.1; microsoft.com/WMPMCPREMCONT: 1.0 36 | Detected object size: 64 bits 37 | Supported operations: 38 | 1001: get device info 39 | 1002: Open session 40 | 1003: Close session 41 | 1004: Get storage IDs 42 | 1005: Get storage info 43 | 1006: Get number of objects 44 | 1007: Get object handles 45 | 1008: Get object info 46 | 1009: Get object 47 | 100b: Delete object 48 | 100c: Send object info 49 | 100d: Send object 50 | 100f: Format storage 51 | 1010: Reset device 52 | 1014: Get device property description 53 | 1015: Get device property value 54 | 1016: Set device property value 55 | 1019: Move object 56 | 101b: Get partial object 57 | 9810: Get object references 58 | 9811: Set object references 59 | 9802: Get object property description 60 | 9807: Get interdependent property description 61 | 9801: Get object properties supported 62 | 9803: Get object property value 63 | 9804: Set object property value 64 | 9805: Get object property list 65 | 9806: Set object property list 66 | 9808: Send object property list 67 | 9101: Get secure time challenge 68 | 9102: Get secure time response 69 | 9103: Set license response 70 | 9104: Get sync list 71 | 9105: Send meter challenge query 72 | 9106: Get meter challenge 73 | 9107: Get meter response 74 | 9108: Clean data store 75 | 9109: Get license state 76 | 910a: Send WMDRM-PD Command 77 | 910b: Send WMDRM-PD Request 78 | 9201: Report Added/Deleted Items 79 | 9202: Report Acquired Items 80 | 9204: Unknown (9204) 81 | Events supported: 82 | None. 83 | Device Properties Supported: 84 | 0xd181: Unknown property 85 | 0xd101: Secure Time 86 | 0xd401: Synchronization Partner 87 | 0x5001: Battery Level 88 | 0xd102: Device Certificate 89 | 0xd402: Friendly Device Name 90 | 0xd131: PlaysForSure ID 91 | Playable File (Object) Types and Object Properties Supported: 92 | 3009: MP3 93 | b901: WMA 94 | 3008: MS Wave 95 | 300c: ASF 96 | b981: WMV 97 | 3801: JPEG 98 | 3804: BMP 99 | 3001: Association/Directory 100 | ba03: Abstract Audio Album 101 | ba05: Abstract Audio Video Playlist 102 | 3000: Undefined Type 103 | b802: Firmware 104 | Storage Devices: 105 | StorageID: 0x00010001 106 | StorageType: 0x0003 107 | FilesystemType: 0x0002 108 | AccessCapability: 0x0000 109 | MaxCapacity: 29804494848 110 | FreeSpaceInBytes: 19031097344 111 | FreeSpaceInObjects: 4294967295 112 | StorageDescription: Storage 113 | VolumeIdentifier: 019fdbe0 - acee5a4e - 80bd1ff8 - 8ee00652 114 | Special directories: 115 | Default music folder: 0x00000000 116 | Default playlist folder: 0x00000000 117 | Default picture folder: 0x00000000 118 | Default video folder: 0x00000000 119 | Default organizer folder: 0x00000000 120 | Default zencast folder: 0x00000000 121 | Default album folder: 0x00000000 122 | Default text folder: 0x00000000 123 | MTP-specific device properties: 124 | Friendly name: (NULL) 125 | Synchronization partner: (NULL) 126 | libmtp supported (playable) filetypes: 127 | ISO MPEG-1 Audio Layer 3 128 | Microsoft Windows Media Audio 129 | RIFF WAVE file 130 | Microsoft Advanced Systems Format 131 | Microsoft Windows Media Video 132 | JPEG file 133 | BMP bitmap file 134 | Firmware file 135 | Unable to acquire device certificate, perhaps this device does not support this 136 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get unicode property. 137 | Error 2: (Look this up in ptp.h for an explanation.) 138 | WMPInfo.xml Does not exist on this device 139 | PTP: Closing session 140 | ERROR: Could not close session! 141 | OK. 142 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO file: 2 | ---------- 3 | 4 | COMPATIBILITY fixes: 5 | 6 | 1. COMPATIBILITY: dual-mode devices, i.e. devices exposing both an MTP 7 | and a USB Mass Storage Device Class (flashdrive) interface are and 8 | have always been problematic. We must find a way to get this to work, 9 | eventually. The problem is that the in-kernel mass storage driver hogs 10 | the device before the MTP mode gets a chance of being used, whereas 11 | the Windows kernel driver apparently does it the other way around, 12 | trying the MTP mode first and then not fall back on mass storage if 13 | MTP is available. (For some more explanations se src/libusb-glue.h.) 14 | This may involve kernel modifications. Perhaps it is only necessary 15 | to tweak the udev config not to load USB mass storage support for 16 | these devices. Dunno. 17 | 18 | 2. COMPATIBILITY: several devices tend to "hang" after disconnect, 19 | needing to be unplugged and replugged before they can be used again. 20 | We don't know why, it may be related to low-level USB behaviour that 21 | is not exposed in the logs we read. On some devices it appear that 22 | avoiding to release the USB interface after closing the PTP/MTP 23 | session solves this, and might be a hint at how the Windows MTP stack 24 | works: perhaps the Windows MTP daemon grabs the interface once the 25 | device is plugged in, created a session and NEVER release it. 26 | Thus only unplug or shutdown ends the session. This behaviour can be 27 | emulated (sort of) by DEVICE_FLAG_NO_RELEASE_INTERFACE which will 28 | make the device not release the USB low-level interface, though it'll 29 | still close the session. But is it really desireable to have 30 | as default? Not unless we run an MTP daemon as well, probably, and 31 | the behaviour is questionable from an USB interoperability point 32 | of view. 33 | 34 | 35 | SPEEDUP fixes: 36 | 37 | None known. libmtp is fast :-) 38 | 39 | 40 | FEATURE fixes: 41 | 42 | 1. FEATURE: Support playback and volume setting on devices that have it. 43 | (I don't have one that does - Linus.) 44 | 45 | 2. FEATURE: Support relevant events. MTP devices seen in existance provide 46 | events for "object added" and "object deleted". These should result in 47 | atleast a call to the cache update function. 48 | 49 | 3. FEATURE: Mechanism to retrieve the device icon device property, else if not 50 | present, look for DevIcon.fil (Windows ICO format) and 51 | DevLogo.fil (PNG Format) images from the device (if available). 52 | 53 | 4. FEATURE: Shared device access so that multiple client applications can have 54 | an open connection to the device at the same time via a handle. For example, 55 | it should be somehow possible to run mtp-detect at the same time as amarok or 56 | mtpfs is connected to a device. This would require some form of resource 57 | sharing. 58 | 59 | 5. FEATURE: Implement an OpenSync backend for devices which have 60 | calendaring, contact etc support. http://opensync.org/ 61 | 62 | 63 | THOSE ARE ALREADY DONE: 64 | 65 | 1. FEATURE: Make an API that can return several devices and let the user 66 | choose which one to operate, not just connect to the first one... 67 | 68 | 2. SPEED: Cache the object info for all items on the device. 69 | Right now, ptp_getobjectinfo() is called repeatedly on the same 70 | objects during startup, track listing, file listing, playlist listing, 71 | album listing and whatever we implement tomorrow. A lot of useless 72 | communication can be saved by cacheing this info. Notice that this 73 | needs to be updated whenever flush_handles() is called too. 74 | (This came from libgphoto2 implementing it!) 75 | 76 | 3. SPEED: Cache track metadata, file metadata etc in params->proplist. 77 | 78 | 4. SPEED: Whenever we add an object (file, track, playlist...) we 79 | should only need to update the cache with relevant data. Atleast for 80 | speedup caches. 81 | 82 | 5. COMPATIBILITY: account for different step sizes and intervals on some 83 | numeric properties we set, make the functions round off when possible. 84 | 85 | 6. SPEED: Cache the supported object properties at first read/startup. 86 | then use the cache to check for supported props instead of calling 87 | out to PTP with ptp_mtp_getobjectpropssupported() every time. 88 | The cache would be an array of size params->deviceinfo.ImageFormats_len 89 | with a list for each format of the properties it will support. Notice 90 | that this needs to be updated whenever flush_handles() is called too. 91 | THIS HAS BEEN DISCARDED, TERO IMPLEMENTED IT BUT IT DOESN'T SEEM TO 92 | YIELD MUCH. 93 | 94 | 7. FEATURE: Make abstract playlists really become size -1 when created as 95 | the ones created on the device instead of the current 1 byte size. 96 | (Is this possible using enhanced commands? See TODO remarks in 97 | the create_abstract_entity() function) 98 | 99 | 8. FEATURE: Integrate libmtp with HAL / D-Bus so applications can dynamically 100 | know when a device has been plugged in or removed. Need a mechanism to 101 | connect a specific hal UDI. 102 | 103 | 9. SPEEDUP: The recursive function that builds the folder tree is 104 | O(n^2)! Atleast remove all non-folders (PTP associations) from the 105 | list before we start sorting and building that tree. We walk the 106 | entire list for each group of siblings right now! 107 | 108 | 10. FEATURE: program to autoprobe device interfaces on connection. 109 | 110 | 11. FEATURE: accomodate Googles uncached device needs. 111 | 112 | 12. FEATURE: rudimentary event interface. 113 | -------------------------------------------------------------------------------- /logs/mtp-detect-lg-gr500.txt: -------------------------------------------------------------------------------- 1 | libmtp version: 1.0.1 2 | 3 | Listing raw device(s) 4 | Device 0 (VID=1004 and PID=611b) is a LG Electronics Inc. GR-500 Music Sync Player. 5 | Found 1 device(s): 6 | LG Electronics Inc.: GR-500 Music Sync Player (1004:611b) @ bus 2, dev 7 7 | Attempting to connect device(s) 8 | LIBMTP PANIC: could not inspect object property descriptions! 9 | LIBMTP PANIC: could not inspect object property descriptions! 10 | LIBMTP PANIC: could not inspect object property descriptions! 11 | LIBMTP PANIC: could not inspect object property descriptions! 12 | LIBMTP PANIC: could not inspect object property descriptions! 13 | LIBMTP PANIC: could not inspect object property descriptions! 14 | LIBMTP PANIC: could not inspect object property descriptions! 15 | LIBMTP PANIC: could not inspect object property descriptions! 16 | LIBMTP PANIC: could not inspect object property descriptions! 17 | LIBMTP PANIC: could not inspect object property descriptions! 18 | LIBMTP PANIC: could not inspect object property descriptions! 19 | LIBMTP PANIC: could not inspect object property descriptions! 20 | LIBMTP PANIC: could not inspect object property descriptions! 21 | Error 7: Unable to read Maximum Battery Level for this device even though the device supposedly supports this functionality 22 | Error 1: Get Storage information failed. 23 | Error 2: PTP Layer error 02fe: get_handles_recursively(): could not get object handles. 24 | Error 2: (Look this up in ptp.h for an explanation.) 25 | USB low-level info: 26 | Using kernel interface "usbfs" 27 | bcdUSB: 512 28 | bDeviceClass: 0 29 | bDeviceSubClass: 0 30 | bDeviceProtocol: 0 31 | idVendor: 1004 32 | idProduct: 611b 33 | IN endpoint maxpacket: 512 bytes 34 | OUT endpoint maxpacket: 512 bytes 35 | Raw device info: 36 | Bus location: 2 37 | Device number: 7 38 | Device entry info: 39 | Vendor: LG Electronics Inc. 40 | Vendor id: 0x1004 41 | Product: GR-500 Music Sync Player 42 | Vendor id: 0x611b 43 | Device flags: 0x00000804 44 | Configuration 0, interface 0, altsetting 0: 45 | Interface implements PTP class, no further probing. 46 | Device info: 47 | Manufacturer: LGE 48 | Model: GR500 Music Sync Player 49 | Device version: 1.00 50 | Serial number: 00000000000000000011793007979534 51 | Vendor extension ID: 0x00000006 52 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1; microsoft.com/WMPPD: 11.0; microsoft.com/WMPPD: 10.0; vodafone.com/omadrmv2: 1.0; 53 | Detected object size: 32 bits 54 | Supported operations: 55 | 1001: get device info 56 | 1002: Open session 57 | 1003: Close session 58 | 1004: Get storage IDs 59 | 1005: Get storage info 60 | 1006: Get number of objects 61 | 1007: Get object handles 62 | 1008: Get object info 63 | 1009: Get object 64 | 100a: Get thumbnail 65 | 100b: Delete object 66 | 100c: Send object info 67 | 100d: Send object 68 | 100f: Format storage 69 | 1010: Reset device 70 | 1014: Get device property description 71 | 1015: Get device property value 72 | 1016: Set device property value 73 | 1017: Reset device property value 74 | 101b: Get partial object 75 | 9801: Get object properties supported 76 | 9802: Get object property description 77 | 9803: Get object property value 78 | 9804: Set object property value 79 | 9810: Get object references 80 | 9811: Set object references 81 | 9805: Get object property list 82 | 9806: Set object property list 83 | 9808: Send object property list 84 | 9103: Set license response 85 | 9104: Get sync list 86 | 9105: Send meter challenge query 87 | 9106: Get meter challenge 88 | 9107: Get meter response 89 | 9108: Clean data store 90 | 9109: Get license state 91 | 910a: Send WMDRM-PD Command 92 | 910b: Send WMDRM-PD Request 93 | 9201: Report Added/Deleted Items 94 | 9202: Report Acquired Items 95 | Events supported: 96 | 0x4004 97 | 0x4005 98 | 0x400a 99 | Device Properties Supported: 100 | 0x5001: Battery Level 101 | 0xd401: Synchronization Partner 102 | 0xd402: Friendly Device Name 103 | 0xd404: Unknown property 104 | 0xd102: Device Certificate 105 | Playable File (Object) Types and Object Properties Supported: 106 | b984: 3GP 107 | 3000: Undefined Type 108 | 3001: Association/Directory 109 | 3008: MS Wave 110 | 3009: MP3 111 | 300c: ASF 112 | 3801: JPEG 113 | b901: WMA 114 | b902: OGG 115 | b903: AAC 116 | ba03: Abstract Audio Album 117 | ba05: Abstract Audio Video Playlist 118 | ba10: WPL Playlist 119 | Special directories: 120 | Default music folder: 0x00000000 121 | Default playlist folder: 0x00000000 122 | Default picture folder: 0x00000000 123 | Default video folder: 0x00000000 124 | Default organizer folder: 0x00000000 125 | Default zencast folder: 0x00000000 126 | Default album folder: 0x00000000 127 | Default text folder: 0x00000000 128 | MTP-specific device properties: 129 | Friendly name: (NULL) 130 | Synchronization partner: (NULL) 131 | libmtp supported (playable) filetypes: 132 | RIFF WAVE file 133 | ISO MPEG-1 Audio Layer 3 134 | Microsoft Advanced Systems Format 135 | JPEG file 136 | Microsoft Windows Media Audio 137 | Ogg container format 138 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 139 | Abstract Album file 140 | Abstract Playlist file 141 | Unable to acquire device certificate, perhaps this device does not support this 142 | Error 2: PTP Layer error 02fe: get_device_unicode_property(): failed to get unicode property. 143 | Error 2: (Look this up in ptp.h for an explanation.) 144 | OK. 145 | -------------------------------------------------------------------------------- /logs/mtp-detect-nokia-5800.txt: -------------------------------------------------------------------------------- 1 | Device 0 (VID=0421 and PID=0155) is UNKNOWN. 2 | Please report this VID/PID and the device model to the libmtp development team 3 | Error 2: PTP Layer error 02ff: get_all_metadata_fast(): could not get proplist of all objects. 4 | Error 2: (Look this up in ptp.h for an explanation.) 5 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get object handles. 6 | Error 2: (Look this up in ptp.h for an explanation.) 7 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get object handles. 8 | Error 2: (Look this up in ptp.h for an explanation.) 9 | libmtp version: 0.3.6 10 | 11 | Listing raw device(s) 12 | Found 1 device(s): 13 | 0421:0155 @ bus 0, dev 14 14 | Attempting to connect device(s) 15 | USB low-level info: 16 | Using kernel interface "usbfs" 17 | bcdUSB: 512 18 | bDeviceClass: 255 19 | bDeviceSubClass: 0 20 | bDeviceProtocol: 0 21 | idVendor: 0421 22 | idProduct: 0155 23 | IN endpoint maxpacket: 512 bytes 24 | OUT endpoint maxpacket: 512 bytes 25 | Raw device info: 26 | Bus location: 0 27 | Device number: 14 28 | Device entry info: 29 | Vendor: (null) 30 | Vendor id: 0x0421 31 | Product: (null) 32 | Vendor id: 0x0155 33 | Device flags: 0x00000000 34 | Configuration 0, interface 0, altsetting 0: 35 | Interface description contains the string "MTP" 36 | Device recognized as MTP, no further probing. 37 | Device info: 38 | Manufacturer: Nokia 39 | Model: 5800 XpressMusic 40 | Device version: 01 41 | Serial number: 354183023422153 42 | Vendor extension ID: 0x00000006 43 | Vendor extension description: microsoft.com:1.0;microsoft.com/WMPPD: 11.0;microsoft.com/WMDRMPD: 10.1;vodafone.com/omadrmv2: 1.0 44 | Detected object size: 64 bits 45 | Supported operations: 46 | 1001: get device info 47 | 1002: Open session 48 | 1003: Close session 49 | 1004: Get storage IDs 50 | 1005: Get storage info 51 | 1006: Get number of objects 52 | 1007: Get object handles 53 | 1008: Get object info 54 | 1009: Get object 55 | 100b: Delete object 56 | 100c: Send object info 57 | 100d: Send object 58 | 1010: Reset device 59 | 1014: Get device property description 60 | 1015: Get device property value 61 | 1016: Set device property value 62 | 9801: Get object properties supported 63 | 9802: Get object property description 64 | 9803: Get object property value 65 | 9804: Set object property value 66 | 9810: Get object references 67 | 9811: Set object references 68 | 9805: Get object property list 69 | 9806: Set object property list 70 | 9807: Get interdependent property description 71 | 9201: Report Added/Deleted Items 72 | 9202: Report Acquired Items 73 | 9203: Get transferable playlist types 74 | 9103: Set license response 75 | 9104: Get sync list 76 | 9105: Send meter challenge query 77 | 9106: Get meter challenge 78 | 9107: Get meter response 79 | 9108: Clean data store 80 | 9109: Get license state 81 | 910a: Send WMDRM-PD Command 82 | 910b: Send WMDRM-PD Request 83 | Events supported: 84 | 0x400a 85 | 0x4004 86 | 0x4005 87 | 0x4003 88 | Device Properties Supported: 89 | 0xd401: Synchronization Partner 90 | 0xd402: Friendly Device Name 91 | 0xd404: Unknown property 92 | 0xd102: Device Certificate 93 | 0xd406: Unknown property 94 | Playable File (Object) Types and Object Properties Supported: 95 | 3000: Undefined Type 96 | 3001: Association/Directory 97 | b903: AAC 98 | b982: MP4 99 | 3009: MP3 100 | b984: 3GP 101 | b004: Unknown(b004) 102 | b982: MP4 103 | b901: WMA 104 | 300c: ASF 105 | b981: WMV 106 | ba11: M3U Playlist 107 | ba05: Abstract Audio Video Playlist 108 | 3008: MS Wave 109 | Storage Devices: 110 | StorageID: 0x00040001 111 | StorageType: 0x0004 removable RAM storage 112 | FilesystemType: 0x0002 generic hierarchical 113 | AccessCapability: 0x0000 read/write 114 | MaxCapacity: 7964983296 115 | FreeSpaceInBytes: 1893857280 116 | FreeSpaceInObjects: 908 117 | StorageDescription: Memory card 118 | VolumeIdentifier: 3455216610 119 | StorageID: 0x00020001 120 | StorageType: 0x0003 fixed RAM storage 121 | FilesystemType: 0x0002 generic hierarchical 122 | AccessCapability: 0x0000 read/write 123 | MaxCapacity: 90251264 124 | FreeSpaceInBytes: 73989120 125 | FreeSpaceInObjects: 35 126 | StorageDescription: Phone memory (NOKIA) 127 | VolumeIdentifier: 1196836185 128 | Special directories: 129 | Default music folder: 0x00000000 130 | Default playlist folder: 0x00000000 131 | Default picture folder: 0x00000000 132 | Default video folder: 0x00000000 133 | Default organizer folder: 0x00000000 134 | Default zencast folder: 0x00000000 135 | Default album folder: 0x00000000 136 | Default text folder: 0x00000000 137 | MTP-specific device properties: 138 | Friendly name: (NULL) 139 | Synchronization partner: (NULL) 140 | libmtp supported (playable) filetypes: 141 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 142 | MPEG-4 Part 14 Container Format (Audio+Video Empahsis) 143 | ISO MPEG-1 Audio Layer 3 144 | MPEG-4 Part 14 Container Format (Audio+VError 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get unicode property. 145 | Error 2: (Look this up in ptp.h for an explanation.) 146 | ERROR: Could not close session! 147 | ideo Empahsis) 148 | Microsoft Windows Media Audio 149 | Microsoft Advanced Systems Format 150 | Microsoft Windows Media Video 151 | RIFF WAVE file 152 | Unable to acquire device certificate, perhaps this device does not support this 153 | OK. 154 | 155 | 156 | -------------------------------------------------------------------------------- /hotplug.sh.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | INSTALL="@INSTALL@" 4 | HOTPLUGPATH=/etc/hotplug 5 | SCRIPTNAME=libmtp.sh 6 | USERMAP=libmtp.usermap 7 | UDEVPATH=/etc/udev/rules.d 8 | UDEVRULES=libmtp.rules 9 | HALBASEPATH=/usr/share/hal/fdi/information 10 | HALPATH=/usr/share/hal/fdi/information/20thirdparty 11 | HALRULES=libmtp.fdi 12 | 13 | # See if the parameter script ($2), device ($3) and productid ($4) 14 | # are already defined in the usermap ($1) 15 | function inmap { 16 | while read LINE; do 17 | if [ "x${LINE}" != "x" ]; then 18 | firstword=`echo ${LINE} | awk '{ print $1 }'` 19 | if [ ${firstword} != "#" ]; then 20 | # This is a device line entry 21 | script=${firstword} 22 | manid=`echo ${LINE} | awk '{ print $3 }'` 23 | productid=`echo ${LINE} | awk '{ print $4 }'` 24 | # Skip blank products... 25 | if [ "x${script}" = "x$2" ]; then 26 | if [ "x${manid}" = "x$3" ]; then 27 | if [ "x${productid}" = "x$4" ]; then 28 | echo "yes" 29 | return 0 30 | fi 31 | fi 32 | fi 33 | fi 34 | fi 35 | done < $1 36 | echo "no" 37 | return 0 38 | } 39 | 40 | # Scan the usermap $2 for all devices in $1 to see if they are already 41 | # there, else patch the usermap. 42 | function patchusermap { 43 | # Nullify comment 44 | comment="" 45 | while read LINE; do 46 | if [ "x$LINE" != "x" ]; then 47 | firstword=`echo ${LINE} | awk '{ print $1 }'` 48 | if [ ${firstword} = "#" ]; then 49 | # This is a comment line, save it. 50 | comment=${LINE} 51 | else 52 | # This is a device line entry 53 | script=${firstword} 54 | manid=`echo ${LINE} | awk '{ print $3 }'` 55 | productid=`echo ${LINE} | awk '{ print $4 }'` 56 | # Skip blank products... 57 | if [ "x${manid}" != "x" ]; then 58 | # See if this product is already in the usermap 59 | echo "Checking for product ${productid} in $2..." 60 | if [ `inmap $2 ${script} ${manid} ${productid}` = "no" ]; then 61 | echo "Not present, adding to hotplug map." 62 | echo ${comment} >> $2 63 | echo ${LINE} >> $2 64 | comment="" 65 | else 66 | echo "Already installed." 67 | fi 68 | fi 69 | fi 70 | fi 71 | done < $1 72 | } 73 | 74 | # Check for udev first 75 | if test -d ${UDEVPATH} ; then 76 | echo "You seem to have udev on your system. Installing udev rules..." 77 | ${INSTALL} ${UDEVRULES} ${UDEVPATH} 78 | echo "You may need additional setup to get correct permissions on your device." 79 | echo "See the INSTALL file for information." 80 | echo "Do you also want to install HAL support or the old hotplug support (y/n)?" 81 | read IN 82 | if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then 83 | echo "Continuing..." 84 | else 85 | exit 0 86 | fi 87 | fi 88 | 89 | # Check for HAL next 90 | if test -d ${HALBASEPATH} ; then 91 | echo "You seem to have HAL on your system. Installing HAL rules..." 92 | mkdir -p ${HALPATH} 93 | ${INSTALL} ${HALRULES} ${HALPATH} 94 | echo "Do you also want to install the old hotplug support (y/n)?" 95 | read IN 96 | if [ "$IN" = "y" ] || [ "$IN" = "Y" ]; then 97 | echo "Continuing..." 98 | else 99 | exit 0 100 | fi 101 | fi 102 | 103 | 104 | # Check prerequisites 105 | COMMAND=`which grep 2> /dev/null` 106 | if [ "x${COMMAND}" = "x" ]; 107 | then 108 | echo "Missing grep program. Fatal error." 109 | exit 1 110 | fi 111 | COMMAND=`which awk 2> /dev/null` 112 | if [ "x${COMMAND}" = "x" ]; 113 | then 114 | echo "Missing awk program. Fatal error." 115 | exit 1 116 | fi 117 | if [ "x${USER}" != "xroot" ]; 118 | then 119 | echo "WARNING: this program should be run as root!" 120 | fi 121 | 122 | 123 | # This script locates the hotplug distribution on a certain host 124 | # and sets up userland hotplugging scripts according to rules. 125 | # The in-parameters are the hotplug directory and the name of a 126 | # file of hotplug device entries and a script to be executed for 127 | # these deviced. 128 | 129 | if test -d ${HOTPLUGPATH} 130 | then 131 | echo "Hotplug in ${HOTPLUGPATH}" 132 | else 133 | echo "Hotplug missing on this system. Cannot install." 134 | exit 1 135 | fi 136 | 137 | if test -d ${HOTPLUGPATH}/usb 138 | then 139 | echo "Has usb subdirectory." 140 | else 141 | mkdir ${HOTPLUGPATH}/usb 142 | fi 143 | 144 | echo "Installing script." 145 | ${INSTALL} libmtp.sh ${HOTPLUGPATH}/usb 146 | echo "Installing usermap." 147 | ${INSTALL} -m 644 ${USERMAP} ${HOTPLUGPATH}/usb 148 | # If we find a usb.usermap file, and we see that this distribution 149 | # of hotplug does not support private usermaps, then we need to 150 | # patch the usb.usermap file. 151 | # 152 | # Create a merged file, diff the files to each other, and if there 153 | # were mismatches, then patch the installed file. 154 | echo "Checking hotplugging CVS version..." 155 | echo "/etc/hotplug/usb/*.usermap support was added in august 2002" 156 | EDITMAP="yes" 157 | CVSTAG=`grep '\$Id:' /etc/hotplug/usb.agent` 158 | if [ "x${CVSTAG}" != "x" ]; then 159 | DATE=`echo ${CVSTAG} | awk '{ print $5 }'` 160 | echo "Hotplug version seems to be from ${DATE}" 161 | YEAR=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $1; }'` 162 | MONTH=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $2; }'` 163 | DAY=`echo ${DATE} | awk 'BEGIN { FS="/"} {print $3; }'` 164 | if [ "${YEAR}" -gt "2002" ]; then 165 | EDITMAP="no" 166 | else 167 | if [ "${YEAR}" -eq "2002" ]; then 168 | if [ "${MONTH}" -ge "08" ]; then 169 | EDITMAP="no" 170 | fi 171 | fi 172 | fi 173 | fi 174 | if [ "x${EDITMAP}" == "xyes" ]; then 175 | echo "We need to edit the ${HOTPLUGPATH}/usb.usermap if it exists..." 176 | if test -f ${HOTPLUGPATH}/usb.usermap 177 | then 178 | echo "We have a usb.usermap..." 179 | patchusermap ${USERMAP} /etc/hotplug/usb.usermap 180 | fi 181 | fi 182 | 183 | echo "Hotplugging successfully installed." 184 | 185 | exit 0 186 | 187 | -------------------------------------------------------------------------------- /logs/mtp-detect-slacker-pmp.txt: -------------------------------------------------------------------------------- 1 | libmtp version: 0.3.6 2 | 3 | Listing raw device(s) 4 | Device 0 (VID=1bdc and PID=fabf) is UNKNOWN. 5 | Please report this VID/PID and the device model to the libmtp development 6 | team 7 | Found 1 device(s): 8 | 1bdc:fabf @ bus 0, dev 14 9 | Attempting to connect device(s) 10 | Error 7: Unable to read Maximum Battery Level for this device even though 11 | the device supposedly supports this functionality 12 | Error 1: Get Storage information failed. 13 | Error 2: PTP Layer error 02fe: get_all_metadata_fast(): could not get 14 | proplist of all objects. 15 | Error 2: (Look this up in ptp.h for an explanation.) 16 | Error 2: PTP Layer error 02ff: get_handles_recursively(): could not get 17 | object handles. 18 | Error 2: (Look this up in ptp.h for an explanation.) 19 | USB low-level info: 20 | Using kernel interface "usbfs" 21 | bcdUSB: 512 22 | bDeviceClass: 0 23 | bDeviceSubClass: 0 24 | bDeviceProtocol: 0 25 | idVendor: 1bdc 26 | idProduct: fabf 27 | IN endpoint maxpacket: 512 bytes 28 | OUT endpoint maxpacket: 512 bytes 29 | Raw device info: 30 | Bus location: 0 31 | Device number: 14 32 | Device entry info: 33 | Vendor: (null) 34 | Vendor id: 0x1bdc 35 | Product: (null) 36 | Vendor id: 0xfabf 37 | Device flags: 0x00000000 38 | Microsoft device descriptor 0xee: 39 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 40 | 0010: 0d00 .. 41 | Microsoft device response to control message 1, CMD 0x0d: 42 | 0000: 2800 0000 0001 0400 0100 0000 0000 0000 (............... 43 | 0010: 0001 4d54 5000 0000 0000 0000 0000 0000 ..MTP........... 44 | 0020: 0000 0000 0000 0000 ........ 45 | Microsoft device response to control message 2, CMD 0x0d: 46 | 0000: 2800 0000 0001 0400 0100 0000 0000 0000 (............... 47 | 0010: 0001 4d54 5000 0000 0000 0000 0000 0000 ..MTP........... 48 | 0020: 0000 0000 0000 0000 ........ 49 | Device info: 50 | Manufacturer: Slacker Inc. 51 | Model: Slacker Portable Media Player 52 | Device version: V1.0 53 | Serial number: 00000000000000000601f00e2067d2d6 54 | Vendor extension ID: 0x00000006 55 | Vendor extension description: microsoft.com/WMDRMPD: 10.1; 56 | microsoft.com/WMPPD: 10.0; microsoft.com/WMPPD: 11.0; slacker.com/PRD: 57 | 1.0; 58 | Detected object size: 64 bits 59 | Supported operations: 60 | 1001: get device info 61 | 1002: Open session 62 | 1003: Close session 63 | 1004: Get storage IDs 64 | 1005: Get storage info 65 | 1006: Get number of objects 66 | 1007: Get object handles 67 | 1008: Get object info 68 | 1009: Get object 69 | 100c: Send object info 70 | 100d: Send object 71 | 1012: Set object protection 72 | 9803: Get object property value 73 | 9804: Set object property value 74 | 9805: Get object property list 75 | 9808: Send object property list 76 | 100b: Delete object 77 | 100f: Format storage 78 | 1014: Get device property description 79 | 1015: Get device property value 80 | 1016: Set device property value 81 | 101b: Get partial object 82 | 9802: Get object property description 83 | 9810: Get object references 84 | 9811: Set object references 85 | 9801: Get object properties supported 86 | 9101: Get secure time challenge 87 | 9102: Get secure time response 88 | 9103: Set license response 89 | 9104: Get sync list 90 | 9105: Send meter challenge query 91 | 9106: Get meter challenge 92 | 9107: Get meter response 93 | 9108: Clean data store 94 | 9109: Get license state 95 | 910a: Send WMDRM-PD Command 96 | 910b: Send WMDRM-PD Request 97 | 9201: Report Added/Deleted Items 98 | 9202: Report Acquired Items 99 | 9701: Unknown (9701) 100 | Events supported: 101 | None. 102 | Device Properties Supported: 103 | 0x5001: Battery Level 104 | 0xd401: Synchronization Partner 105 | 0xd402: Friendly Device Name 106 | 0xd101: Secure Time 107 | 0xd102: Device Certificate 108 | 0xd103: Revocation Info 109 | Playable File (Object) Types and Object Properties Supported: 110 | 3000: Undefined Type 111 | 3001: Association/Directory 112 | 3004: Text 113 | 3008: MS Wave 114 | 3009: MP3 115 | 300a: MS AVI 116 | 300c: ASF 117 | 3801: JPEG 118 | 3804: BMP 119 | 3808: JFIF 120 | b901: WMA 121 | b802: Firmware 122 | b903: AAC 123 | b981: WMV 124 | b982: MP4 125 | b983: MP2 126 | 300b: MPEG 127 | ba03: Abstract Audio Album 128 | ba05: Abstract Audio Video Playlist 129 | Special directories: 130 | Default music folder: 0x00000000 131 | Default playlist folder: 0x00000000 132 | Default picture folder: 0x00000000 133 | Default video folder: 0x00000000 134 | Default organizer folder: 0x00000000 135 | Default zencast folder: 0x00000000 136 | Default album folder: 0x00000000 137 | Default text folder: 0x00000000 138 | MTP-specific device properties: 139 | Friendly name: (NULL) 140 | Synchronization partner: (NULL) 141 | libmtp supported (playable) filetypes: 142 | Text file 143 | RIFF WAVE file 144 | ISO MPEG-1 Audio Layer 3 145 | Audio Video Interleave 146 | Microsoft Advanced Systems Format 147 | JPEG file 148 | BMP bitmap file 149 | JFIF file 150 | Microsoft Windows Media Audio 151 | Firmware file 152 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 153 | Microsoft Windows Media Video 154 | MPEG-4 Part 14 Container Format (Audio+Video Empahsis) 155 | ISO MPEG-1 Audio Layer 2 156 | MPEG video stream 157 | Unable to acquire device certificate, perhaps this device does not support 158 | this 159 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to 160 | get unicode property. 161 | Error 2: (Look this up in ptp.h for an explanation.) 162 | ERROR: Could not close session! 163 | OK. 164 | -------------------------------------------------------------------------------- /logs/mtp-detect-iriver-h10-20GB.txt: -------------------------------------------------------------------------------- 1 | USB low-level info: 2 | Using kernel interface "usbfs" 3 | bcdUSB: 512 4 | bDeviceClass: 0 5 | bDeviceSubClass: 0 6 | bDeviceProtocol: 0 7 | idVendor: 4102 8 | idProduct: 2101 9 | IN endpoint maxpacket: 512 bytes 10 | OUT endpoint maxpacket: 512 bytes 11 | Device flags: 0x00000000 12 | Device info: 13 | Manufacturer: iriver 14 | Model: iriver Device 15 | Device version: PP5020AF-01.02-FRE-MT-DT, (Build 129) 16 | Serial number: 3fff0040-0010c837-00000000-0000003f-36310000 17 | Vendor extension ID: 0x00000006 18 | Vendor extension description: microsoft.com/WMDRMPD: 10.1 19 | Supported operations: 20 | 1014: Get device property description 21 | 1015: Get device property value 22 | 1001: Get device info 23 | 1002: Open session 24 | 1003: Close session 25 | 1004: Get storage IDs 26 | 1005: Get storage info 27 | 1007: Get object handles 28 | 1008: Get object info 29 | 1009: Get object 30 | 101b: Get partial object 31 | 100c: Send object info 32 | 100d: Send object 33 | 100b: Delete object 34 | 1012: Set object protection 35 | 1016: Set device property value 36 | 9801: Get object properties supported 37 | 9802: Get object property description 38 | 9803: Get object property value 39 | 9805: Get object property list 40 | 9806: Set object property list 41 | 9810: Get object references 42 | 9811: Set object references 43 | 9101: Get secure time challenge 44 | 9102: Get secure time response 45 | 9103: Set license response 46 | 9104: Get sync list 47 | 9105: Send meter challenge query 48 | 9106: Get meter challenge 49 | 9107: Set meter response 50 | 9108: Clean data store 51 | 9109: Get license state 52 | Events supported: 53 | None. 54 | Device Properties Supported: 55 | 0x5001: Battery Level 56 | 0xd101: Secure Time 57 | 0xd102: Device Certificate 58 | 0xd402: Device Friendly Name 59 | Playable File (Object) Types and Object Properties Supported: 60 | 3001: Association/Directory 61 | 3009: MP3 62 | 3008: MS Wave 63 | 3801: JPEG 64 | ba05: Abstract Audio Video Playlist 65 | b901: WMA 66 | dc01: StorageID 67 | dc0b: ParentObject 68 | dc07: ObjectFileName 69 | dc04: ObjectSize 70 | dc02: ObjectFormat 71 | dc41: PersistantUniqueObjectIdentifier 72 | dc4f: NonConsumable 73 | dc03: ProtectionStatus 74 | dc09: DateModified 75 | dc8b: Track 76 | dc99: OriginalReleaseDate 77 | dc44: Name 78 | dc46: Artist 79 | dc8c: Genre 80 | dc9a: AlbumName 81 | dc89: Duration 82 | de9a: AudioBitRate 83 | de93: SampleRate 84 | de94: NumberOfChannels 85 | de99: AudioWAVECodec 86 | dc8a: Rating 87 | Special directories: 88 | Default music folder: 0x00000000 89 | Default playlist folder: 0x00000000 90 | Default picture folder: 0x00000000 91 | Default video folder: 0x00000000 92 | Default organizer folder: 0x00000000 93 | Default zencast folder: 0x00000000 94 | MTP-specific device properties: 95 | Friendly name: iriver H10 20GC 96 | Synchronization partner: (NULL) 97 | Total bytes on device: 19994066944 (19067 MB) 98 | Free bytes on device: 1643121664 (1567 MB) 99 | Storage description: "iriver HDD" 100 | Volume label: "H10_20GB" 101 | Battery level 176 of 100 (176%) 102 | libmtp supported (playable) filetypes: 103 | ISO MPEG Audio Layer 3 104 | RIFF WAVE file 105 | JPEG file 106 | Microsoft Windows Media Audio 107 | 108 | Secure Time: 109 | #20061030 110 | 20:30:04Z#DRM_CLK_NEEDS_REFRESH 111 | 112 | Device Certificate: 113 | QAD/PzfIEAAAAAAAPwAAAAAAMTY=FQBk2GzllIEzGlDOml7u6bqep4er94r3KKYJuEKcsn1ODyL2z8D3Ew== 116 | KrDm/ouWvbmZJxFfUwGxeoUglus=S3Z 117 | Iz9wduynaJZaZvQgs/NqGGxJL1mGTieY2A1rYkn0+fUMUc6Djcw==261d87MS77pUbix3Cnfuq5eNH94=2.4.101.59FQBk2GzllIEz 120 | GlDOml7u6bqep4er94r3KKYJuEKcsn1ODyL2z8D3EwIEZTsZnkCC5cxjRgmjXeaAMuNdn2RsNykcD+hj 121 | KESFyhpVZDJoyWVin7RDiRiver H10 SeriesiRiveriRiverReignComH10200010102http://go.microsoft 127 | .com/fwlink/?LinkId=25817!CNhvvz1WaNV1AFUmetxkvm9iD4UrE9cnGUi!qcqdxMiXmD1*ikYGA==111 130 | 112102405120anriOiRlE5HtYKyjesddaEu 133 | A7Hha3F3gn0l1J3T6lzRRwX9TKrGmWA==iZeXW 134 | IVwHQsIfNuYamP+4+/emoVa+qDvr6rtxKFvY3tw9YxKtRveSA==2000159uTJijzQAocsraT8vDT4rY4klgmorx3ejgic57TT4scC 137 | JSpSnj5YkaA==GspA/RcLJHtiUqdOwiGn0DfGo 138 | wAyKCKxBSNdFD20ArIxGnT+SqwQeg==1a1t3hxrg!qbOgkt 140 | nbYaEEi4teCse!gz6RvTPuC!zizKJl 141 | pU7xoduSw==SGUL1ilPv1AhZ4LcGX0d2Da4QD 142 | XtUmpZCbsbD4NRLzgHHU6zEKzdYA== -------------------------------------------------------------------------------- /logs/mtp-detect-sonyericsson-w890i.txt: -------------------------------------------------------------------------------- 1 | # mtp-detect 2 | libmtp version: 0.2.6.1 3 | 4 | Attempting to connect device(s) 5 | Potential MTP Device with VendorID:0fce and ProductID:00b3 responded to control message 2 with a response that was too short. Problems may arrise but continuing 6 | Device 1 (VID=0fce and PID=00b3) is UNKNOWN. 7 | Please report this VID/PID and the device model to the libmtp development team 8 | PTP: Opening session 9 | Detect: Successfully connected 1 devices 10 | Error 7: Found a bad handle, trying to ignore it. 11 | Error 7: Found a bad handle, trying to ignore it. 12 | Error 7: Found a bad handle, trying to ignore it. 13 | Error 7: Found a bad handle, trying to ignore it. 14 | Error 7: Found a bad handle, trying to ignore it. 15 | Error 7: Found a bad handle, trying to ignore it. 16 | Error 7: Found a bad handle, trying to ignore it. 17 | Error 7: Found a bad handle, trying to ignore it. 18 | Error 7: Found a bad handle, trying to ignore it. 19 | USB low-level info: 20 | Using kernel interface "usbfs" 21 | bcdUSB: 512 22 | bDeviceClass: 0 23 | bDeviceSubClass: 0 24 | bDeviceProtocol: 0 25 | idVendor: 0fce 26 | idProduct: 00b3 27 | IN endpoint maxpacket: 512 bytes 28 | OUT endpoint maxpacket: 512 bytes 29 | Device flags: 0x00000000 30 | Microsoft device descriptor 0xee: 31 | 0000: 1203 4d00 5300 4600 5400 3100 3000 3000 ..M.S.F.T.1.0.0. 32 | 0010: 0800 .. 33 | Microsoft device response to control message 1, CMD 0x08: 34 | 0000: 2800 0000 0001 0400 0100 0000 0000 0000 (............... 35 | 0010: 0001 4d54 5000 0000 0000 0000 0000 0000 ..MTP........... 36 | 0020: 0000 0000 0000 0000 ........ 37 | Potential MTP Device with VendorID:0fce and ProductID:00b3 responded to control message 2 with a response that was too short. Problems may arrise but continuing 38 | Device info: 39 | Manufacturer: Sony Ericsson 40 | Model: W890i 41 | Device version: 1.20 42 | Serial number: 00000000000000000352382025808094 43 | Vendor extension ID: 0x00000006 44 | Vendor extension description: microsoft.com: 1.0; microsoft.com/WMDRMPD: 10.1; microsoft.com/WMPPD: 11.0; microsoft.com/WMPPD: 10.0; vodafone.com/omadrmv2: 1.0; 45 | Detected object size: 64 bits 46 | Supported operations: 47 | 1001: get device info 48 | 1002: Open session 49 | 1003: Close session 50 | 1004: Get storage IDs 51 | 1005: Get storage info 52 | 1006: Get number of objects 53 | 1007: Get object handles 54 | 1008: Get object info 55 | 1009: Get object 56 | 100b: Delete object 57 | 100c: Send object info 58 | 100d: Send object 59 | 1014: Get device property description 60 | 1015: Get device property value 61 | 1016: Set device property value 62 | 9801: Get object properties supported 63 | 9802: Get object property description 64 | 9803: Get object property value 65 | 9804: Set object property value 66 | 9810: Get object references 67 | 9811: Set object references 68 | 9808: Send object property list 69 | 9103: Set license response 70 | 9104: Get sync list 71 | 9105: Send meter challenge query 72 | 9106: Get meter challenge 73 | 9107: Get meter response 74 | 9108: Clean data store 75 | 9109: Get license state 76 | 910a: Send WMDRM-PD Command 77 | 910b: Send WMDRM-PD Request 78 | 9202: Report Acquired Items 79 | Events supported: 80 | 0x4004 81 | 0x4005 82 | 0x400a 83 | Device Properties Supported: 84 | 0x5002: Functional Mode 85 | 0xd401: Synchronization Partner 86 | 0xd402: Friendly Device Name 87 | 0xd404: Unknown property 88 | 0xd405: Device Icon 89 | 0xd102: Device Certificate 90 | Playable File (Object) Types and Object Properties Supported: 91 | b984: 3GP 92 | 3000: Undefined Type 93 | 3001: Association/Directory 94 | 3004: Text 95 | 3005: HTML 96 | 3008: MS Wave 97 | 3009: MP3 98 | 300c: ASF 99 | 3801: JPEG 100 | 3804: BMP 101 | 3807: GIF 102 | 380b: PNG 103 | b901: WMA 104 | b903: AAC 105 | b981: WMV 106 | b982: MP4 107 | ba05: Abstract Audio Video Playlist 108 | ba11: M3U Playlist 109 | Storage Devices: 110 | StorageID: 0x00010001 111 | StorageType: 0x0003 112 | FilesystemType: 0x0002 113 | AccessCapability: 0x0000 114 | MaxCapacity: 25137152 115 | FreeSpaceInBytes: 19210240 116 | FreeSpaceInObjects: 0 117 | StorageDescription: Phone Memory 118 | VolumeIdentifier: 119 | StorageID: 0x00020001 120 | StorageType: 0x0004 121 | FilesystemType: 0x0002 122 | AccessCapability: 0x0000 123 | MaxCapacity: 2045247488 124 | FreeSpaceInBytes: 1928822784 125 | FreeSpaceInObjects: 0 126 | StorageDescription: Memory Stick (TM) 127 | VolumeIdentifier: 128 | Special directories: 129 | Default music folder: 0x00000006 130 | Default playlist folder: 0x00000000 131 | Default picture folder: 0x00000000 132 | Default video folder: 0x0000004e 133 | Default organizer folder: 0x00000000 134 | Default zencast folder: 0x00000000 135 | Default album folder: 0x00000000 136 | Default text folder: 0x00000000 137 | MTP-specific device properties: 138 | Friendly name: (NULL) 139 | Synchronization partner: (NULL) 140 | libmtp supported (playable) filetypes: 141 | Text file 142 | HTML file 143 | RIFF WAVE file 144 | ISO MPEG-1 Audio Layer 3 145 | Microsoft Advanced Systems Format 146 | JPEG file 147 | BMP bitmap file 148 | GIF bitmap file 149 | Portable Network Graphics 150 | Microsoft Windows Media Audio 151 | Advanced Audio Coding (AAC)/MPEG-2 Part 7/MPEG-4 Part 3 152 | Microsoft Windows Media Video 153 | MPEG-4 Part 14 Container Format (Audio+Video Empahsis) 154 | Unable to acquire device certificate, perhaps this device does not support this 155 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed to get unicode property. 156 | Error 2: (Look this up in ptp.h for an explanation.) 157 | WMPInfo.xml Does not exist on this device 158 | PTP: Closing session 159 | ERROR: Could not close session! 160 | OK. 161 | -------------------------------------------------------------------------------- /src/unicode.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file unicode.c 3 | * 4 | * This file contains general Unicode string manipulation functions. 5 | * It mainly consist of functions for converting between UCS-2 (used on 6 | * the devices) and UTF-8 (used by several applications). 7 | * 8 | * For a deeper understanding of Unicode encoding formats see the 9 | * Wikipedia entries for 10 | * UTF-16/UCS-2 11 | * and UTF-8. 12 | * 13 | * Copyright (C) 2005-2009 Linus Walleij 14 | * 15 | * This library is free software; you can redistribute it and/or 16 | * modify it under the terms of the GNU Lesser General Public 17 | * License as published by the Free Software Foundation; either 18 | * version 2 of the License, or (at your option) any later version. 19 | * 20 | * This library is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 23 | * Lesser General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU Lesser General Public 26 | * License along with this library; if not, write to the 27 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 28 | * Boston, MA 02111-1307, USA. 29 | * 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #ifdef HAVE_ICONV 36 | #include "iconv.h" 37 | #else 38 | #error "libmtp unicode.c needs fixing to work without iconv()!" 39 | #endif 40 | #include "libmtp.h" 41 | #include "unicode.h" 42 | #include "util.h" 43 | #include "ptp.h" 44 | 45 | /** 46 | * The size of the buffer (in characters) used for creating string copies. 47 | */ 48 | #define STRING_BUFFER_LENGTH 1024 49 | 50 | /** 51 | * Gets the length (in characters, not bytes) of a unicode 52 | * UCS-2 string, eg a string which physically is 0x00 0x41 0x00 0x00 53 | * will return a value of 1. 54 | * 55 | * @param unicstr a UCS-2 Unicode string 56 | * @return the length of the string, in number of characters. If you 57 | * want to know the length in bytes, multiply this by two and 58 | * add two (for zero terminator). 59 | */ 60 | int ucs2_strlen(uint16_t const * const unicstr) 61 | { 62 | int length; 63 | 64 | /* Unicode strings are terminated with 2 * 0x00 */ 65 | for(length = 0; unicstr[length] != 0x0000U; length ++); 66 | return length; 67 | } 68 | 69 | /** 70 | * Converts a big-endian UTF-16 2-byte string 71 | * to a UTF-8 string. Actually just a UCS-2 internal conversion 72 | * routine that strips off the BOM if there is one. 73 | * 74 | * @param device a pointer to the current device. 75 | * @param unicstr the UTF-16 unicode string to convert 76 | * @return a UTF-8 string. 77 | */ 78 | char *utf16_to_utf8(LIBMTP_mtpdevice_t *device, const uint16_t *unicstr) 79 | { 80 | PTPParams *params = (PTPParams *) device->params; 81 | char *stringp = (char *) unicstr; 82 | char loclstr[STRING_BUFFER_LENGTH*3+1]; // UTF-8 encoding is max 3 bytes per UCS2 char. 83 | char *locp = loclstr; 84 | size_t nconv; 85 | size_t convlen = (ucs2_strlen(unicstr)+1) * sizeof(uint16_t); // UCS-2 is 16 bit wide, include terminator 86 | size_t convmax = STRING_BUFFER_LENGTH*3; 87 | 88 | loclstr[0]='\0'; 89 | /* Do the conversion. */ 90 | nconv = iconv(params->cd_ucs2_to_locale, &stringp, &convlen, &locp, &convmax); 91 | if (nconv == (size_t) -1) { 92 | // Return partial string anyway. 93 | *locp = '\0'; 94 | } 95 | loclstr[STRING_BUFFER_LENGTH*3] = '\0'; 96 | // Strip off any BOM, it's totally useless... 97 | if ((uint8_t) loclstr[0] == 0xEFU && (uint8_t) loclstr[1] == 0xBBU && (uint8_t) loclstr[2] == 0xBFU) { 98 | return strdup(loclstr+3); 99 | } 100 | return strdup(loclstr); 101 | } 102 | 103 | /** 104 | * Converts a UTF-8 string to a big-endian UTF-16 2-byte string 105 | * Actually just a UCS-2 internal conversion. 106 | * 107 | * @param device a pointer to the current device. 108 | * @param localstr the UTF-8 unicode string to convert 109 | * @return a UTF-16 string. 110 | */ 111 | uint16_t *utf8_to_utf16(LIBMTP_mtpdevice_t *device, const char *localstr) 112 | { 113 | PTPParams *params = (PTPParams *) device->params; 114 | char *stringp = (char *) localstr; // cast away "const" 115 | char unicstr[(STRING_BUFFER_LENGTH+1)*2]; // UCS2 encoding is 2 bytes per UTF-8 char. 116 | char *unip = unicstr; 117 | size_t nconv = 0; 118 | size_t convlen = strlen(localstr)+1; // utf8 bytes, include terminator 119 | size_t convmax = STRING_BUFFER_LENGTH*2; 120 | 121 | unicstr[0]='\0'; 122 | unicstr[1]='\0'; 123 | 124 | /* Do the conversion. */ 125 | nconv = iconv(params->cd_locale_to_ucs2, &stringp, &convlen, &unip, &convmax); 126 | 127 | if (nconv == (size_t) -1) { 128 | // Return partial string anyway. 129 | unip[0] = '\0'; 130 | unip[1] = '\0'; 131 | } 132 | // make sure the string is null terminated 133 | unicstr[STRING_BUFFER_LENGTH*2] = '\0'; 134 | unicstr[STRING_BUFFER_LENGTH*2+1] = '\0'; 135 | 136 | // allocate the string to be returned 137 | // Note: can't use strdup since every other byte is a null byte 138 | int ret_len = ucs2_strlen((uint16_t*)unicstr)*sizeof(uint16_t)+2; 139 | uint16_t* ret = malloc(ret_len); 140 | memcpy(ret,unicstr,(size_t)ret_len); 141 | return ret; 142 | } 143 | 144 | /** 145 | * This helper function simply removes any consecutive chars 146 | * > 0x7F and replace then with an underscore. In UTF-8 147 | * consequtive chars > 0x7F represent one single character so 148 | * it has to be done like this (and it's elegant). It will only 149 | * shrink the string in size so no copying is needed. 150 | */ 151 | void strip_7bit_from_utf8(char *str) 152 | { 153 | int i,j,k; 154 | i = 0; 155 | j = 0; 156 | k = strlen(str); 157 | while (i < k) { 158 | if ((uint8_t) str[i] > 0x7FU) { 159 | str[j] = '_'; 160 | i++; 161 | // Skip over any consequtive > 0x7F chars. 162 | while((uint8_t) str[i] > 0x7FU) { 163 | i++; 164 | } 165 | } else { 166 | str[j] = str[i]; 167 | i++; 168 | } 169 | j++; 170 | } 171 | // Terminate stripped string... 172 | str[j] = '\0'; 173 | } 174 | -------------------------------------------------------------------------------- /logs/mtp-detect-iriver-t60.txt: -------------------------------------------------------------------------------- 1 | mtp-detect log: 2 | Autodetected device with VID=4102 and PID=1134 is UNKNOWN. 3 | Please report this VID/PID and the device model name etc to the 4 | libmtp development team! 5 | PTP: Opening session 6 | Connected to MTP device. 7 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 8 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 9 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 10 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 11 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 12 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 13 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 14 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 15 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 16 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 17 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 18 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 19 | USB low-level info: 20 | Using kernel interface "usbfs" 21 | bcdUSB: 512 22 | bDeviceClass: 0 23 | bDeviceSubClass: 0 24 | bDeviceProtocol: 0 25 | idVendor: 4102 26 | idProduct: 1134 27 | IN endpoint maxpacket: 512 bytes 28 | OUT endpoint maxpacket: 512 bytes 29 | Device flags: 0x00000000 30 | Device info: 31 | Manufacturer: iriver 32 | Model: iriver MP3 T60 33 | Device version: MTP-1.03-N-ENG 34 | Serial number: 1557c6f40000003a3230303630313031 35 | Vendor extension ID: 0x00000006 36 | Vendor extension description: microsoft.com/WMDRMPD: 10.1; audible.com: 37 | 1.0 38 | Supported operations: 39 | 1001: get device info 40 | 1002: Open session 41 | 1003: Close session 42 | 1004: Get storage IDs 43 | 1005: Get storage info 44 | 1006: Get number of objects 45 | 1007: Get object handles 46 | 1008: Get object info 47 | 1009: Get object 48 | 100b: Delete object 49 | 100c: Send object info 50 | 100d: Send object 51 | 100f: Format storage 52 | 1014: Get device property description 53 | 1015: Get device property value 54 | 1016: Set device property value 55 | 9801: Get object properties supported 56 | 9802: Get object property description 57 | 9803: Get object property value 58 | 9804: Set object property value 59 | 9805: Get object property list 60 | 9810: Get object references 61 | 9811: Set object references 62 | 9101: Get secure time challenge 63 | 9102: Get secure time response 64 | 9103: Set license response 65 | 9104: Get sync list 66 | 9105: Send meter challenge query 67 | 9106: Get meter challenge 68 | 9107: Get meter response 69 | 9108: Clean data store 70 | 9109: Get license state 71 | 910a: Send WMDRM-PD Command 72 | 910b: Send WMDRM-PD Request 73 | Events supported: 74 | None. 75 | Device Properties Supported: 76 | 0x5001: Battery Level 77 | 0xd401: Synchronization Partner 78 | 0xd402: Device Friendly Name 79 | 0xd101: Secure Time 80 | 0xd102: Device Certificate 81 | 0xd100: Unknown property 82 | Playable File (Object) Types and Object Properties Supported: 83 | 3000: Undefined Type 84 | dc01: StorageID 85 | dc02: ObjectFormat 86 | dc04: ObjectSize 87 | dc07: ObjectFileName 88 | dc0b: ParentObject 89 | dc41: PersistantUniqueObjectIdentifier 90 | dc44: Name 91 | dc4f: NonConsumable 92 | 3001: Association/Directory 93 | dc01: StorageID 94 | dc02: ObjectFormat 95 | dc04: ObjectSize 96 | dc07: ObjectFileName 97 | dc0b: ParentObject 98 | dc41: PersistantUniqueObjectIdentifier 99 | dc44: Name 100 | dc4f: NonConsumable 101 | 3009: MP3 102 | dc01: StorageID 103 | dc02: ObjectFormat 104 | dc04: ObjectSize 105 | dc07: ObjectFileName 106 | dc0b: ParentObject 107 | dc41: PersistantUniqueObjectIdentifier 108 | dc44: Name 109 | dc4f: NonConsumable 110 | dc46: Artist 111 | dc95: MetaGenre 112 | de93: SampleRate 113 | de94: NumberOfChannels 114 | de99: AudioWAVECodec 115 | de9a: AudioBitRate 116 | b901: WMA 117 | dc01: StorageID 118 | dc02: ObjectFormat 119 | dc04: ObjectSize 120 | dc07: ObjectFileName 121 | dc0b: ParentObject 122 | dc41: PersistantUniqueObjectIdentifier 123 | dc44: Name 124 | dc4f: NonConsumable 125 | dc46: Artist 126 | dc95: MetaGenre 127 | de93: SampleRate 128 | de94: NumberOfChannels 129 | de99: AudioWAVECodec 130 | de9a: AudioBitRate 131 | b902: OGG 132 | dc01: StorageID 133 | dc02: ObjectFormat 134 | dc04: ObjectSize 135 | dc07: ObjectFileName 136 | dc0b: ParentObject 137 | dc41: PersistantUniqueObjectIdentifier 138 | dc44: Name 139 | dc4f: NonConsumable 140 | b904: Audible.com Codec 141 | dc01: StorageID 142 | dc02: ObjectFormat 143 | dc04: ObjectSize 144 | dc07: ObjectFileName 145 | dc0b: ParentObject 146 | dc41: PersistantUniqueObjectIdentifier 147 | dc44: Name 148 | dc4f: NonConsumable 149 | da00: unknown(da00) 150 | da01: unknown(da01) 151 | da02: unknown(da02) 152 | da03: unknown(da03) 153 | da04: unknown(da04) 154 | dc89: Duration 155 | ba05: Abstract Audio Video Playlist 156 | dc01: StorageID 157 | dc02: ObjectFormat 158 | dc04: ObjectSize 159 | dc07: ObjectFileName 160 | dc0b: ParentObject 161 | dc41: PersistantUniqueObjectIdentifier 162 | dc44: Name 163 | dc4f: NonConsumable 164 | Storage Devices: 165 | StorageID: 0x00010001 166 | StorageType: 0x0003 167 | FilesystemType: 0x0002 168 | AccessCapability: 0x0000 169 | MaxCapacity: 2009825280 170 | FreeSpaceInBytes: 209584128 171 | FreeSpaceInObjects: 4294967295 172 | StorageDescription: iriver MP3 T60 files 173 | VolumeIdentifier: fbhfgmepaaaaaakdcdadadgdadbdadbd 174 | Special directories: 175 | Default music folder: 0x00010000 176 | Default playlist folder: 0x00040000 177 | Default picture folder: 0x00000000 178 | Default video folder: 0x00000000 179 | Default organizer folder: 0x00000000 180 | Default zencast folder: 0x00000000 181 | Default album folder: 0x00000000 182 | Default text folder: 0x00000000 183 | MTP-specific device properties: 184 | Friendly name: iriver MP3 T60 185 | Synchronization partner: WMP 10; Napster; 186 | Battery level 3 of 4 (75%) 187 | libmtp supported (playable) filetypes: 188 | ISO MPEG-1 Audio Layer 3 189 | Microsoft Windows Media Audio 190 | Ogg container format 191 | Audible.com Audio Codec 192 | 193 | Secure Time: 194 | #20070731 195 | 19:24:07Z#DRM_CLK_SET 196 | LIBMTP panic: Found a bad handle, trying to ignore it. 197 | LIBMTP panic: Found a bad handle, trying to ignore it. 198 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 199 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 200 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 201 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 202 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 203 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 204 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 205 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 206 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 207 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 208 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 209 | ptp2/ptp_usb_getdata: read 1 bytes too much, expect problems! 210 | PTP: Closing session 211 | OK. 212 | -------------------------------------------------------------------------------- /src/libusb-glue.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \file libusb-glue.h 3 | * Low-level USB interface glue towards libusb. 4 | * 5 | * Copyright (C) 2005-2007 Richard A. Low 6 | * Copyright (C) 2005-2012 Linus Walleij 7 | * Copyright (C) 2006-2011 Marcus Meissner 8 | * Copyright (C) 2007 Ted Bullock 9 | * Copyright (C) 2008 Chris Bagwell 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 28 | * 29 | */ 30 | #ifndef LIBUSB_GLUE_H 31 | #define LIBUSB_GLUE_H 32 | 33 | #include "ptp.h" 34 | #ifdef HAVE_LIBUSB1 35 | #include 36 | #endif 37 | #ifdef HAVE_LIBUSB0 38 | #include 39 | #endif 40 | #ifdef HAVE_LIBOPENUSB 41 | #include 42 | #endif 43 | #include "libmtp.h" 44 | #include "device-flags.h" 45 | 46 | /* Make functions available for C++ */ 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif /* __cplusplus */ 50 | 51 | /** 52 | * Debug macro 53 | */ 54 | #define LIBMTP_USB_DEBUG(format, args...) \ 55 | do { \ 56 | if ((LIBMTP_debug & LIBMTP_DEBUG_USB) != 0) \ 57 | fprintf(stdout, "LIBMTP %s[%d]: " format, __FUNCTION__, __LINE__, ##args); \ 58 | } while (0) 59 | 60 | #define LIBMTP_USB_DATA(buffer, length, base) \ 61 | do { \ 62 | if ((LIBMTP_debug & LIBMTP_DEBUG_DATA) != 0) \ 63 | data_dump_ascii (stdout, buffer, length, base); \ 64 | } while (0) 65 | 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 71 | #define USB_BULK_READ usb_bulk_read 72 | #define USB_BULK_WRITE usb_bulk_write 73 | #endif 74 | #ifdef HAVE_LIBOPENUSB 75 | #define USB_BULK_READ openusb_bulk_xfer 76 | #define USB_BULK_WRITE openusb_bulk_xfer 77 | #endif 78 | 79 | /** 80 | * Internal USB struct. 81 | */ 82 | typedef struct _PTP_USB PTP_USB; 83 | struct _PTP_USB { 84 | PTPParams *params; 85 | #ifdef HAVE_LIBUSB1 86 | libusb_device_handle* handle; 87 | #endif 88 | #ifdef HAVE_LIBUSB0 89 | usb_dev_handle* handle; 90 | #endif 91 | #ifdef HAVE_LIBOPENUSB 92 | openusb_dev_handle_t* handle; 93 | #endif 94 | uint8_t config; 95 | uint8_t interface; 96 | uint8_t altsetting; 97 | int inep; 98 | int inep_maxpacket; 99 | int outep; 100 | int outep_maxpacket; 101 | int intep; 102 | /** File transfer callbacks and counters */ 103 | int callback_active; 104 | int timeout; 105 | uint16_t bcdusb; 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; 112 | }; 113 | 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, 118 | PTPParams *params, 119 | void **usbinfo); 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); 123 | 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) 173 | 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 178 | 179 | #ifdef __cplusplus 180 | } 181 | #endif /* __cplusplus */ 182 | 183 | #endif // LIBUSB-GLUE_H 184 | --------------------------------------------------------------------------------