blob: e39b7fa5bb231297016ceb1373a13e921d24b11f [file] [log] [blame]
Linus Walleij0dd71e92006-05-04 18:47:07 +00001Building and Installing
2-----------------------
Linus Walleij6fd2f082006-03-28 07:19:22 +00003
Linus Walleij0dd71e92006-05-04 18:47:07 +00004See the "INSTALL" file.
5
6
7Heritage
8--------
9
10libmtp is based on several ancestors:
11
12* libptp2 by Mariusz Woloszyn was the starting point used
13 by Richard A. Low for the initial starter port. You can
14 find it at http://libptp.sourceforge.net/
15
16* libgphoto2 by Mariusz Woloszyn and Marcus Meissner was
17 used at a later stage since it was (is) more actively
18 maintained. libmtp tracks the PTP implementation in
19 libgphoto2 and considers it an upstream project. We will
20 try to submit anything generally useful back to libgphoto2
21 and not make double efforts. In practice this means we
22 use ptp.c, ptp.h and ptp-pack.c verbatim from the libgphoto2
23 source code. If you need to change things in these files,
24 make sure it is so general that libgphoto2 will want to
25 merge it to their codebase too. You find libgphoto2 as part
26 of gPhoto: http://gphoto.sourceforge.net/
27
28* libnjb was a project that Richard and Linus were working
Linus Walleijfcf88912006-06-05 13:23:33 +000029 on before libmtp. When Linus took Richards initial port
Linus Walleij0dd71e92006-05-04 18:47:07 +000030 and made an generic C API he re-used the philosophy and
31 much code from libnjb. Many of the sample programs are for
32 example taken quite literally from libnjb. You find it here:
33 http://libnjb.sourceforge.net/
34
35
Linus Walleijea7d45b2009-02-23 22:26:09 +000036Contacting and Contributing
37---------------------------
38
39See the project page at http://libmtp.sourceforge.net/
40We always need your help. There is a mailinglist and a
41bug report system there.
42
43People who want to discuss MTP devices in fora seem to
44hang out on the forums at AnythingbutiPod:
45http://www.anythingbutipod.com/forum/
46
47
Linus Walleij0dd71e92006-05-04 18:47:07 +000048Compiling programs for libmtp
49-----------------------------
50
51libmtp has support for the pkg-config script by adding a libmtp.pc
52entry in $(prefix)/lib/pkgconfig. To compile a libmtp program,
53"just" write:
54
55gcc -o foo `pkg-config --cflags --libs libmtp` foo.c
56
57This also simplifies compilation using autoconf and pkg-config: just
58write e.g.
59
60PKG_CHECK_MODULES(MTP, libmtp)
61AC_SUBST(MTP_CFLAGS)
62AC_SUBST(MTP_LIBS)
63
64To have libmtp LIBS and CFLAGS defined. Needless to say, this will
65only work if you have pkgconfig installed on your system, but most
66people have nowadays.
67
68If your library is installed in e.g. /usr/local you may have to tell
69this to pkgconfig by setting the PKG_CONFIG_PATH thus:
70
71export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
72
73
74Documentation
75-------------
76
77Read the API documentation that can be generated with doxygen.
78It will be output in doc/html if you have Doxygen properly
79installed. (It will not be created unless you have Doxygen!)
80
81For information about the Media Transfer Protocol, see:
82http://en.wikipedia.org/wiki/Media_Transfer_Protocol
83
Linus Walleij7a83e552008-07-29 21:30:43 +000084The official 1.0 specification for MTP was released by the
85USB Implementers Forum in may, 2008. Prior to this, only a
86proprietary Microsoft version was available, and quite a few
87devices out there still use some aspects of the Microsoft
88version, which deviates from the specified standard. You can
89find the official specification here:
90http://www.usb.org/developers/devclass_docs/MTP_1.0.zip
Linus Walleij0dd71e92006-05-04 18:47:07 +000091
Linus Walleij1b91ca62008-10-17 07:07:56 +000092
93The Examples
94------------
95
Linus Walleijbe8b03b2009-10-16 21:19:35 +000096In the subdirectory "examples" you find a number of
Linus Walleij1b91ca62008-10-17 07:07:56 +000097command-line tools, illustrating the use of libmtp in very
98simple terms.
99
100Please do not complain about the usability or documentation
101of these examples, they look like they do for two reasons:
102
1031. They are examples, not tools. If they were intended for
104 day-to-day usage by commandline freaks, I would have
105 called them "tools" not "examples".
106
1072. The MTP usage paradigm is that a daemon should hook
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000108 the device upon connection, and that it should be
Linus Walleij1b91ca62008-10-17 07:07:56 +0000109 released by unplugging. GUI tools utilizing HAL (hald)
110 and D-Bus do this much better than any commandline
111 program ever can. (See below on bugs.) Specificationwise
112 this is a bug, however it is present in many, many
113 devices.
114
115That said, if you want to pick up and maintain the examples,
116please volunteer.
117
118
Linus Walleija1b66f22007-05-10 20:02:16 +0000119New Devices
120-----------
121
Linus Walleijfcf88912006-06-05 13:23:33 +0000122If you happen upon a device which libmtp claims it cannot
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000123autodetect, please submit the vendor ID and device ID
Linus Walleij9ee29402007-10-31 20:24:48 +0000124(these can be obtained from the "lsusb" and "lsusb -n"
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000125commands run as root) as a bug, patch or feature request
126on the Sourceforge bug tracker at our homepage. If it
127gives a sensible output from "mtp-detect" then please attach
128the result as well as it teach us some stuff about your
129device. If you've done some additional hacking, join our
Linus Walleij9ee29402007-10-31 20:24:48 +0000130mailinglist and post your experiences there.
Linus Walleijda558be2007-03-10 21:42:25 +0000131
Linus Walleija1b66f22007-05-10 20:02:16 +0000132If you want to be able to hack some more and you're not
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000133afraid of C hacking, add an entry for your device's
134vendor/product ID and a descriptive string to the database
Linus Walleij6dc01682007-11-15 21:23:46 +0000135in the file src/music-players.h.
Linus Walleija1b66f22007-05-10 20:02:16 +0000136
137If you want to poke around to see if your device has some
138special pecularities, you can test some special device
Linus Walleij6dc01682007-11-15 21:23:46 +0000139flags (defined in src/device-flags.h) by inserting them
140together with your device entry in src/music-players.h.
Linus Walleija1b66f22007-05-10 20:02:16 +0000141Flags can be tested in isolation or catenated with "|"
142(binary OR). If relatives to your device use a certain
143flag, chances are high that a new device will need it
144too, typically from the same manufacturer.
145
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000146The most common flag that needs to be set is the
Linus Walleija1b66f22007-05-10 20:02:16 +0000147DEVICE_FLAG_UNLOAD_DRIVER that detach any Linux kernel
148drivers that may have attached to the device making
Linus Walleij94f23d52007-08-04 19:37:28 +0000149MTP access impossible. This is however not expected to
150really work: this is a problem being tracked as of
151now (2007-08-04). See the "last resort" solutions below
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000152if you really need to get your dual-mode device to work
Linus Walleij94f23d52007-08-04 19:37:28 +0000153with MTP.
Linus Walleija1b66f22007-05-10 20:02:16 +0000154
Linus Walleijcc2cf972007-11-22 20:23:43 +0000155Another flag which is easy to identify is the
156DEVICE_FLAG_NO_ZERO_READS, which remedies connection
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000157timeouts when getting files, and some timeouts on e.g.
Linus Walleijcc2cf972007-11-22 20:23:43 +0000158successive "mtp-connect" calls.
159
Linus Walleija1b66f22007-05-10 20:02:16 +0000160If your device is very problematic we are curious of how it
Linus Walleijda558be2007-03-10 21:42:25 +0000161works under Windows, so we enjoy reading USB packet sniffs
162that reveal the low-level traffic carried out between
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000163Windows Media Player and your device. This can be done
Linus Walleij61c25682007-09-04 14:46:21 +0000164using e.g.:
165
166* USBsnoop:
167 http://benoit.papillault.free.fr/usbsnoop/
168
169* The trial version of HHD Softwares software-only
170 USB monitor. You need to get a copy of version 2.37 since
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000171 the newer trial versions won't let you carry out the
Linus Walleij61c25682007-09-04 14:46:21 +0000172 needed packet sniffs. (As of 2007-03-10 a copy can be found
173 at: http://www.cobbleware.com/files/usb-monitor-237.exe)
174
Linus Walleijda558be2007-03-10 21:42:25 +0000175There are other USB monitors as well, some more expensive
176alternatives use hardware and even measure electronic
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000177characteristics of the traffic (which is far too much
Linus Walleijda558be2007-03-10 21:42:25 +0000178detail for us).
179
Linus Walleij91fb0282007-09-03 21:16:08 +0000180Device sniffs are an easy read since the PTP/MTP protocol
181is nicely structured. All commands will have a structure such
182as this in the log, we examplify with a object list request:
183
184PTP REQEUST:
185000120: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:25.9843750 +0.0
186Pipe Handle: 0x863ce234 (Endpoint Address: 0x2)
187Send 0x20 bytes to the device:
188 20 00 00 00 01 00 05 98 23 00 00 00 27 03 00 10 ......?#...'...
189 Length TYPE CMD Trans# Param1
190
191 00 00 00 00 02 DC 00 00 00 00 00 00 00 00 00 00 .....Ü..........
192 Param2 Param3 Param4 Param5
193
194[OPTIONAL] DATA PHASE:
195000121: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0156250
196Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
197Get 0x1a bytes from the device:
198 1A 00 00 00 02 00 05 98 23 00 00 00 01 00 00 00 .......?#.......
199 Length TYPE CMD Trans# DATA
200
201 27 03 00 10 02 DC 04 00 00 30 '....Ü...0
202
203RESPONSE:
204000122: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0
205Pipe Handle: 0x863ce214 (Endpoint Address: 0x81)
206Get 0xc bytes from the device:
207 0C 00 00 00 03 00 01 20 23 00 00 00 ....... #...
208 Length TYPE CODE Trans#
209
210* One send (OUT to the device), two reads (IN from the device).
211
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000212* All three byte chunks commands are
213 sent/recieved/recieeved by the function ptp_transaction()
Linus Walleij91fb0282007-09-03 21:16:08 +0000214 in the file ptp.c.
215
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000216* It boils down to ptp_usb_sendreq(), optionally ptp_usb_senddata()
217 or ptp_usb_getdata() and finally ptp_usb_getresp() in the file
Linus Walleij91fb0282007-09-03 21:16:08 +0000218 libusb-glue.c. Notice ptp_usb_sendreq() and ptp_usb_getresp()
219 are ALWAYS called. The TYPE field correspond to this, so the
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000220 TYPES in this case are "COMMAND" (0x0001), "DATA" (0x0002),
Linus Walleij91fb0282007-09-03 21:16:08 +0000221 and "RESPONSE" (0x0003).
222
223* Notice that the byte order is little endian, so you need to read
224 each field from right to left.
225
226* This COMMAND has:
227 CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
228 Transaction# 0x00000023.
229 REQUEST parameters 0x10000327, 0x00000000, 0x0000DC02, 0x00000000
230 0x00000000, in this case it means "get props for object 0x10000327",
231 "any format", "property 0xDC02" (PTP_OPC_ObjectFormat), then two
232 parameters that are always zero (no idea what they mean or their
233 use).
234
235* The DATA has:
236 CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
237 Transaction# 0x00000023.
238 Then comes data 0x00000001, 0x10000327, 0xDC02, 0x0004, 0x3000
239 Which means in this case, (and this is the tricky part) "here
240 you have 1 property", "for object 0x10000327", "it is property
241 0xDC02" (PTP_OPC_ObjectFormat), "which is of type 0x0004"
242 (PTP_DTC_UINT16), "and set to 0x3000" (PTP_OFC_Undefined, it
243 is perfectly valid to have undefined object formats, since it
244 is a legal value defining this).
245
246* This RESPONSE has:
247 CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList.
248 Return Code ("RC") = 0x2001, PTP_RC_OK, all went fine.
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000249 Transaction# 0x00000023.
Linus Walleijfcf88912006-06-05 13:23:33 +0000250
Linus Walleijd05fce62007-09-29 20:17:23 +0000251If you want to compare the Windows behaviour with a similar
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000252operation using libmtp you can go into the src/libusb-glue.c
Linus Walleij6dc01682007-11-15 21:23:46 +0000253file and uncomment the row that reads:
Linus Walleijd05fce62007-09-29 20:17:23 +0000254
255//#define ENABLE_USB_BULK_DEBUG
256
257(I.e. remove the two //.)
258
259This will make libmtp print out a hex dump of every bulk USB
260transaction. The bulk transactions contain all the PTP/MTP layer
261data, which is usually where the problems appear.
262
Linus Walleij6fd2f082006-03-28 07:19:22 +0000263
Linus Walleij8d799eb2009-07-23 22:58:06 +0000264Dual-mode devices does not work - last resort:
265----------------------------------------------
Linus Walleijbd7624c2007-05-28 10:48:54 +0000266
267Some devices that are dual-mode are simply impossible to get
268to work under Linux because the usb-storage(.ko) kernel
269module hook them first, and refuse to release them, even
Linus Walleij94f23d52007-08-04 19:37:28 +0000270when we specify the DEVICE_FLAG_UNLOAD_DRIVER flag. (Maybe
271it DOES release it but the device will immediately be probed
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000272at the USB mass storage interface AGAIN because it
Linus Walleij94f23d52007-08-04 19:37:28 +0000273enumerates.)
Linus Walleijbd7624c2007-05-28 10:48:54 +0000274
Linus Walleij8d799eb2009-07-23 22:58:06 +0000275Here is what some people do:
276
277 1. Plug in the device.
278 2. USB-mass storage folder will open automatically.
279 3. Unmount the device.
280 4. Run mtp-detect. It will most likely fail the first time.
281 5. Run mtp-detect again, it might work this time, or fail. Keep running
282 till it works. 99% it works by the third try.
283 6. Once mtp-detect gives you an "Ok", open either Rhythmbox or Gnomad2,
284 everything should work.
285
Linus Walleije20abaf2007-12-10 11:20:34 +0000286Linux: Try this, if you have a recent 2.6.x Linux kernel,
Linus Walleij584eb8d2007-09-05 19:51:27 +0000287run (as root) something like:
288
289> rmmod usb_storage ; mtp-detect
290
291You can run most any command or a client like gnomad2 or
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000292Amarok immediately after the rmmod command. This works
Linus Walleij584eb8d2007-09-05 19:51:27 +0000293sometimes. Another way:
Linus Walleijbd7624c2007-05-28 10:48:54 +0000294
Linus Walleij94f23d52007-08-04 19:37:28 +0000295* Edit /etc/modprobe.d/blacklist
Linus Walleijbd7624c2007-05-28 10:48:54 +0000296
297* Add the line "blacklist usb-storage"
298
299* Reboot.
300
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000301Now none of you USB disks, flash memory sticks etc will be
Linus Walleijbd7624c2007-05-28 10:48:54 +0000302working (you just disabled them all). However you *can* try
303your device, and it might have started working because there
304is no longer a USB mass storage driver that tries to hook onto
305the mass storage interface of your device.
306
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000307If not even blacklisting works (check with
Linus Walleij94f23d52007-08-04 19:37:28 +0000308"lsmod | grep usb-storage"), there is some problem with
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000309something else and you may need to remove or rename the file
Linus Walleij94f23d52007-08-04 19:37:28 +0000310/lib/modules/<VERSION>/kernel/drivers/usb/storage/usb-storage.ko
311manually.
312
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000313If you find the PerfectSolution(TM) to this dilemma, so you
Linus Walleijbd7624c2007-05-28 10:48:54 +0000314can properly switch for individual devices whether to use it
315as USB mass storage or not, please tell us how you did it. We
316know we cannot use udev, because udev is called after-the-fact:
317the device is already configured for USB mass storage when
318udev is called.
319
Linus Walleije20abaf2007-12-10 11:20:34 +0000320On Mac OS there is another ugly hack:
321
3221. Open up a terminal window
3232. Type:
324sudo mv /System/Library/Extensions/IOUSBMassStorageClass.kext
325/System/Library/Extensions/IOUSBMassStorageClass.kext.disabled
326
327and when prompted enter your password.
328
3293. Restart.
330
331To reverse this change, just reverse the filenames:
332
333sudo mv /System/Library/Extensions/
334IOUSBMassStorageClass.kext.disabled /System/Library/Extensions/
335IOUSBMassStorageClass.kext
336
337and restart.
338
Linus Walleijbd7624c2007-05-28 10:48:54 +0000339
Linus Walleij15def332006-09-19 14:27:02 +0000340Calendar and contact support:
341-----------------------------
Linus Walleijd3bdf762006-02-20 22:21:56 +0000342
Linus Walleij3c16fe42006-04-30 07:53:41 +0000343The Creative Zen series can read VCALENDAR2 (.ics) files
Linus Walleij15def332006-09-19 14:27:02 +0000344and VCard (.vcf) files from programs like for example
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000345Evolution with the following limitations/conditions:
Linus Walleijd3bdf762006-02-20 22:21:56 +0000346
Linus Walleij3c16fe42006-04-30 07:53:41 +0000347- The file must be in DOS (CR/LF) format, use the unix2dos
348 program to convert if needed
Linus Walleij15def332006-09-19 14:27:02 +0000349
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000350- Repeat events in calendar files do not seem to be supported,
Linus Walleij15def332006-09-19 14:27:02 +0000351 entries will only appear once.
352
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000353- Calendar (.ics) files should be stored in the folder "My Organizer"
Linus Walleij15def332006-09-19 14:27:02 +0000354 when sent to the device (this directory should be autodetected
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000355 for use with calendar files, otherwise use the option
Linus Walleij15def332006-09-19 14:27:02 +0000356 -f "My Organizer" to sendfile for this) Apparently this file can
357 also contain tasklists.
358
359- Contact (.vcf) files should be stored in the folder "My Contacts"
360 when sent to the device. (-f "My Contacts")
361
362- Some devices are picky about the name of the calendar and
363 contact files. For example the Zen Microphoto wants:
364
Linus Walleijb1318d12006-09-25 14:59:26 +0000365 Calendar: My Organizer/6651416.ics
366 Contacts: My Organizer/6651416.vcf
367
368
369Syncing in with Evolution and Creative Devices
370----------------------------------------------
371
372Evolution can easily export .ics an .vcf files, but you currently
373need some command-line hacking to get you stuff copied over in
374one direction host -> device. The examples/ directory contains a script
375created for the Creative Zen Microphoto by Nicolas Tetreault.
376
Linus Walleij6e8cef42006-12-03 20:45:04 +0000377
378It's Not Our Bug!
379-----------------
380
381Some MTP devices have strange pecularities. We try to work around
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000382these whenever we can, sometimes we cannot work around it or we
Linus Walleij6e8cef42006-12-03 20:45:04 +0000383cannot test your solution.
384
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000385* Generic MTP/PTP disconnect misbehaviour: we have noticed that
Linus Walleij67038b92008-04-16 15:01:40 +0000386 Windows Media Player apparently never close the session to an MTP
387 device. There is a daemon in Windows that "hooks" the device
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000388 by opening a PTP session to any MTP device, whenever it is
389 plugged in. This daemon proxies any subsequent transactions
Linus Walleij67038b92008-04-16 15:01:40 +0000390 to/from the device and will never close the session, thus
391 Windows simply does not close sessions at all.
392
Linus Walleije2f65662008-12-07 20:44:11 +0000393 Typical sign of this illness: broken pipes on closing sessions,
394 on the main transfer pipes(s) or the interrupt pipe:
395
396 Closing session
397 usb_clear_halt() on INTERRUPT endpoint: Broken pipe
398 OK.
399
Linus Walleij67038b92008-04-16 15:01:40 +0000400 This means that device manufacturers doesn't notice any problems
401 with devices that do not correctly handle closing PTP/MTP
402 sessions, since Windows never do it. The proper way of closing
403 a session in Windows is to unplug the device, simply put.
404
405 Since libmtp actually tries to close sessions, some devices
406 may fail since the close session functionality has never been
407 properly tested, and "it works with Windows" is sort of the
408 testing criteria at some companies.
409
410 You can get Windows-like behaviour on Linux by running a HAL-aware
411 libmtp GUI client like Rhythmbox or Gnomad2, which will "hook"
412 the device when you plug it in, and "release" it if you unplug
413 it.
414
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000415 If this bug in your device annoys you, contact your device
416 manufacturer and ask them to test their product with some libmtp
Linus Walleij67038b92008-04-16 15:01:40 +0000417 program.
418
Linus Walleijc3a6eeb2010-01-30 07:32:41 +0000419* Generic certificate misbehaviour. All devices are actually
420 required to support a device certificate to be able to
421 encrypt Windows Media (WMA/WMV) files. However there are
422 obviously a lot of devices out there which doesn't support
423 this at all but instead crash. Typical printout:
424
425 Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed
426 to get unicode property.
427
Linus Walleijb715ba62008-02-12 23:41:49 +0000428* Generic USB misbehaviour: some devices behave badly under MTP
429 and USB mass storage alike, even down to the lowest layers
430 of USB. You can always discuss such issues at the linux-usb
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000431 mailing list if you're using Linux:
Linus Walleijb715ba62008-02-12 23:41:49 +0000432 http://www.linux-usb.org/mailing.html
433
Linus Walleij76b185d2008-02-12 23:46:14 +0000434 If you have a problem specific to USB mass storage mode, there
435 is a list of strange behaving devices in the Linux kernel:
436 http://lxr.linux.no/linux/drivers/usb/storage/unusual_devs.h
Linus Walleijf7d8df12008-02-13 00:02:17 +0000437 You can discuss this too on the mentioned list, for understanding
438 the quirks, see:
439 http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt
Linus Walleij76b185d2008-02-12 23:46:14 +0000440
Linus Walleijdeddc342008-08-16 23:52:06 +0000441* Kernel bug on Linux. Linux 2.6.16 is generally speaking required
442 to use any MTP device under USB 2.0. This is because the EHCI
443 driver previously did not support zero-length writes to endpoints.
444 It should work in most cases however, or if you connect it
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000445 to an UHCI/OHCI port instead (yielding lower speed). But
Linus Walleijdeddc342008-08-16 23:52:06 +0000446 please just use a recent kernel.
447
Linus Walleij07bb5382008-07-31 20:21:09 +0000448* Zen models AVI file seeking problem: the Zens cannot parse the
449 files for the runlength metadata. Do not transfer file with e.g.
450 mtp-sendfile, use mtp-sendtr and set the length of the track to
451 the apropriate number of seconds and it will work. In graphical
452 clients, use a "track transfer" function to send these AVI files,
453 the Zens need the metadata associated with tracks to play back
454 movies properly. Movies are considered "tracks" in the MTP world.
455
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000456* Some devices that disregard the metadata sent with the MTP
Linus Walleij64e2e982008-08-01 21:51:13 +0000457 commands will parse the files for e.g. ID3 metadata. Some still
458 of these devices expect only ID3v2.3 metadata and will fail with
459 a modern ID3v2,4 tag writer, like many of those found in Linux
460 applications. Windows Media Player use ID3v2.3 only, so many
461 manufacturers only test this version.
462
Linus Walleij6e8cef42006-12-03 20:45:04 +0000463* The Zen Vision:M (possibly more Creative Zens) has a firmware bug
464 that makes it drop the last two characters off a playlist name.
465 It is fixed in later firmware.
466
Linus Walleijc41f2e82007-03-12 22:26:00 +0000467* For Creative Technology devices, there are hard limits on how
468 many files can be put onto the device. For a 30 GiB device (like
469 the Zen Xtra) the limit is 6000, for a 60 GiB device the limit
470 is 15000 files. For further Creative pecularities, see the
471 FAQ sections at www.nomadness.net.
472
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000473* Sandisk sansa c150 and probably several other Sandisk devices
Linus Walleijd24a7ab2007-03-07 21:48:43 +0000474 (and possibly devices from other manufacturers) have a dual
475 mode with MTP and USB mass storage. The device will initially
476 claim to be mass storage so udev will capture is and make the
Linus Walleijda558be2007-03-10 21:42:25 +0000477 use of MTP mode impossible. One way of avoiding it could be to
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000478 be to blacklist the "usb-storage" module in
Linus Walleijd24a7ab2007-03-07 21:48:43 +0000479 /etc/modprobe.c/blacklist with a row like this:
Linus Walleijda558be2007-03-10 21:42:25 +0000480 "blacklist usb-storage". Some have even removed the
481 "usb-storage.ko" (kernel module file) to avoid loading.
Linus Walleijd24a7ab2007-03-07 21:48:43 +0000482
Linus Walleij2242b022009-01-02 01:44:00 +0000483* Sandisk Sansa Fuze has three modes: auto, MTP or mass storage
484 (MSC). Please set it to MTP to avoid problems with libmtp.
485
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000486* The iriver devices (possibly all of them) cannot handle the
487 enhanced GetObjectPropList MTP command (0x9805) properly. So
Linus Walleij6e8cef42006-12-03 20:45:04 +0000488 they have been banned from using it.
489
Linus Walleijda558be2007-03-10 21:42:25 +0000490* iriver devices have problems with older versions of libmtp and
Linus Walleij82265222007-03-04 19:47:08 +0000491 with new devices libmtp does not know of as of yet, since it
492 has an oldstyle USB device controller that cannot handle zero
Linus Walleijda558be2007-03-10 21:42:25 +0000493 writes. (Register your device with us!) All their devices are
494 likely to need a special device flag in the src/libusb-glue.c
495 database.
Linus Walleij82265222007-03-04 19:47:08 +0000496
Linus Walleij6e8cef42006-12-03 20:45:04 +0000497* The Samsung Yepp T9 has several strange characteristics, some
498 that we've managed to work around. (For example it will return
499 multiple PTP packages in a single transaction.)
500
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000501* The early firmware for Philips HDD players is known to be
Linus Walleijf2711b32007-02-26 20:18:40 +0000502 problematic. Please upgrade to as new firmware as you can get.
503 (Yes this requires some kind of Windows Installation I think.)
504
Linus Walleijb5a4f922008-05-11 20:15:00 +0000505* Philips HDD 1630/16 or 1630/17 etc may lock themselves up,
506 turning inresponsive due to internal corruption. This typically
507 gives an error in opening the PTP session. Apparently you can
508 do a "repair" with the firmware utility (Windows only) which
509 will often fix this problem and make the device responsive
510 again.
511
Linus Walleij9340aac2007-10-01 10:02:05 +0000512* Some devices that implement GetObjectPropList (0x9805) will
513 not return the entire object list if you request a list for object
514 0xffffffffu. (But they should.) So they may need the special
515 DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL.
516
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000517* Some (smaller) subset of devices cannot even get all the
Linus Walleij9340aac2007-10-01 10:02:05 +0000518 properties for a single object in one go, these need the
519 DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST. Currently only the
520 iriver devices seem to have this bug.
521
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000522* The Toshiba Gigabeat S (and probably its sibling the
Linus Walleij9340aac2007-10-01 10:02:05 +0000523 Microsoft Zune and other Toshiba devices) will only display
524 album information tags for a song in case there is also
525 an abstract album (created with the album interface) with
526 the exact same name.
Linus Walleijd132d8e2007-04-03 23:24:54 +0000527
Linus Walleij265b9d62007-11-25 20:08:15 +0000528* The Zen Vision:M has an older firmware which is very corrupt,
529 it is incompatible with the Linux USB stack altogether. The
530 kernel dmesg will look something like this, and you have to
531 upgrade the firmware using Windows:
532 usb 4-5: new high speed USB device using ehci_hcd and address 5
533 usb 4-5: configuration #1 chosen from 1 choice
534 usb 4-5: can't set config #1, error -110
Linus Walleijd132d8e2007-04-03 23:24:54 +0000535
Linus Walleij103a78e2008-08-25 20:48:52 +0000536* The Sirus Stiletto does not seem to allow you to copy any files
537 off the device. This may be someone's idea of copy protection.
Linus Walleijb715ba62008-02-12 23:41:49 +0000538
Linus Walleij25a16302009-03-04 13:56:33 +0000539* The Samsung P2 assigns parent folder ID 0 to all unknown file
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000540 types.(i.e. moves them to the root folder)
Linus Walleij1b91ca62008-10-17 07:07:56 +0000541
Linus Walleij7c64a062010-02-06 01:13:08 +0000542* The Sandisk Sansa Clip+ needs a firmware upgrade in earlier
543 versions in order to work properly.
544
Linus Walleijd132d8e2007-04-03 23:24:54 +0000545Lost symbols
546------------
547
548Shared libraries can be troublesome to users not experienced with
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000549them. The following is a condensed version of a generic question
Linus Walleijd132d8e2007-04-03 23:24:54 +0000550that has appeared on the libmtp mailing list from time to time.
551
552> PTP: Opening session
553> Queried Creative Zen Vision:M
554> gnomad2: relocation error: gnomad2: undefined symbol:
555> LIBMTP_Get_Storageinfo
556> (...)
557> Are these type of errors related to libmtp or something else?
558
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000559The problem is of a generic nature, and related to dynamic library
Linus Walleijd132d8e2007-04-03 23:24:54 +0000560loading. It is colloquially known as "dependency hell".
561(http://en.wikipedia.org/wiki/Dependency_hell)
562
563The gnomad2 application calls upon the dynamic linker in Linux to
564resolve the symbol "LIBMTP_Get_Storageinfo" or any other symbol
565(ELF symbol, or link point or whatever you want to call them, a
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000566symbol is a label on a memory address that the linker shall
Linus Walleijd132d8e2007-04-03 23:24:54 +0000567resolve from label to actual address.)
568For generic information on this subject see the INSTALL file and
569this Wikipedia page:
570
571http://en.wikipedia.org/wiki/Library_(computing)
572
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000573When Linux /lib/ld-linux.so.X is called to link the symbols compiled
574into gnomad2 (or any other executable using libmtp), it examines the
575ELF file for the libmtp.so.X file it finds first and cannot resolve
Linus Walleijd132d8e2007-04-03 23:24:54 +0000576the symbol "LIBMTP_Get_Storageinfo" (or whichever symbol you have a
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000577problem witj) from it, since it's probably not there. There are many
Linus Walleijd132d8e2007-04-03 23:24:54 +0000578possible causes of this symbol breakage:
579
5801) You installed precompiled libmtp and gnomad2 packages (RPMs, debs
581 whatever) that do not match up. Typical cause: your gnomad2 package was
582 built against a newer version of libmtp than what's installed on your
583 machine. Another typical cause: you installed a package you found on
584 the web, somewhere, the dependency resolution system did not protest
585 properly (as it should) or you forced it to install anyway, ignoring
586 some warnings.
587
5882) You compiled libmtp and/or gnomad2 from source, installing both or
589 either in /usr/local/lib and /usr/local/bin. This means at compile-time
590 gnomad2 finds the libmtp library in /usr/local/lib but at runtime, it
591 depends on the Linux system wide library loader (/lib/ld-linux.so.X) in
592 order to resolve the symbols. This loader will look into the file
593 /etc/ld.so.conf and/or the folder /etc/ld.so.conf.d in order to find
594 paths to libraries to be used for resolving the symbols. If you have
595 some older version of libmtp in e.g. /usr/lib (typically installed by a
596 package manager) it will take precedence over the new version you just
597 installed in /usr/local/lib and the newly compiled library in
598 /usr/local/lib will *not* be used, resulting in this error message.
599
6003) You really did install the very latest versions (as of writing libmtp
601 0.1.5 and gnomad2 2.8.11) from source and there really is no
602 pre-installed package of either on your machine. In that case I'm
603 totally lost, I have no idea what's causing this.
604
605Typical remedies:
606
6071) If you don't want to mess around with your system and risk these
608 situations, only use pre-packaged software that came with the
609 distribution or its official support channels. If it still breaks,
610 blame your distribution, they're not packaging correctly. Relying on
611 properly packaged software and not installing things yourself *is* the
612 Linux solution to the "dependency hell" problem.
613
6142) Read about dynamically linked library handling until the stuff I wrote
615 about in the previous list sounds like music to your ears, inspect
616 your /lib, /usr/lib, /usr/local/lib, /etc/ld.so.conf and the
617 /etc/ld.so.conf.d, remove all pre-packed versions using RPM, APT,
618 YaST or whatever your distribution uses, compile libmtp and gnomad2
619 (or whatever) from source only and you will be enlighted.
620
621I don't know if this helps you, it's the best answer we can give.
Linus Walleij387e37a2008-10-29 17:22:22 +0000622
623
624API is obscure - I want plain files!
625------------------------------------
626
627PTP/MTP devices does not actually contain "files", they contain
628objects. These objects have file names, but that is actually
629just a name tag on the object.
630
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000631Folders/directories aren't really such entities: they are just
Linus Walleij387e37a2008-10-29 17:22:22 +0000632objects too, albeit objects that can act as parent to other
Linus Walleij8aba06d2008-12-28 08:26:57 +0000633objects. They are called "associations" and are created in atomic
Linus Walleij387e37a2008-10-29 17:22:22 +0000634fashion and even though there is an MTP command to get all the
Linus Walleij8aba06d2008-12-28 08:26:57 +0000635associations of a certain association, this command is optional
636so it is perfectly possible (and most common, actually) to create
637devices where the "folders" (which are actually associations) have
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000638no idea whatsoever of what files they are associated as parents to
Linus Walleij387e37a2008-10-29 17:22:22 +0000639(i.e. which files they contain). This is very easy for device
Linus Walleij8aba06d2008-12-28 08:26:57 +0000640manufacturers to implement, all the association (i.e. finding out
641which files are in a certain folder) has to be done by the MTP
642Initiator / host computer.
Linus Walleij387e37a2008-10-29 17:22:22 +0000643
644Moving a file to a new folder is for example very simple in a
645"real" file system. In PTP/MTP devices it is often not even possible,
646some devices *may* be able to do that. But actually the only
647reliable way of doing that is to upload the file to the host,
Linus Walleij8aba06d2008-12-28 08:26:57 +0000648download it with the new parent, then delete the old file.
Linus Walleij387e37a2008-10-29 17:22:22 +0000649We have played with the idea of implementing this time consuming
650function, perhaps we will.
651
Linus Walleij8aba06d2008-12-28 08:26:57 +0000652Then the issue that in PTP/MTP it is legal for two files to have
653exactly the same path as long as their object IDs differ. A
654folder/association can contain two files with the exact same name.
655(And on the Creative devices this even works, too, though most devices
656implicitly fail at this.) Perhaps one could add some custom hook for
657handling that, so they become /Foo.mp3 and /Foo.mp3(1) or something
658similar, but it's really a bit kludgy.
659
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000660Playlists and albums aren't really files, thinking about
Linus Walleij387e37a2008-10-29 17:22:22 +0000661them as files like the hacks in libgphoto2 is really backwards. They are
662called associations and are more like a symbolic link that links in a
663star-shaped pattern to all the files that are part of the album/playlist.
664Some devices (Samsung) thought that was too complicated and have a
665different way of storing playlists in an UTF-16 encoded .spl-like file
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000666instead! This is why playlists/albums must have their own structs and
Linus Walleij387e37a2008-10-29 17:22:22 +0000667functions.
668
Linus Walleij8aba06d2008-12-28 08:26:57 +0000669Plain file access also assumes to be able to write files of an
670undetermined size, which is simply not possible in a transactional
671file system like PTP/MTP. (See further below.)
672
Linus Walleij387e37a2008-10-29 17:22:22 +0000673
674I Want Streaming!
675-----------------
676
677Streaming reads is easy. Just connect the output file descriptor from
678LIBMTP_Get_File_To_File_Descriptor() (and a similar function for tracks)
679wherever you want.
680
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000681People have connected this to TCP sockets for streaming web servers
682etc, works like a charm. Some devices will even survive if the callback
Linus Walleij387e37a2008-10-29 17:22:22 +0000683functions return non-zero and cancel the download. Some devices will
684lock up and even require a reset if you do that. Devices are poorly
685implemented so that's life. If you want to stream off a device, the
686best idea is always to stream the entire file and discard the stuff
687at the end you don't want. It will incur a delay if you e.g. want to
688skip between tracks, sadly.
689
690Then we get to the complicated things: streaming WRITES...
691
692There is a function:
693LIBMTP_Send_File_From_File_Descriptor() (and similar for tracks)
694which will write a file to a device from a file descriptor, which may
695be a socket or whatever.
696
697HOWEVER: this requires a piece of metadata with the .filesize properly
698set first.
699
700This is not because we think it is funny to require that, the protocol
701requires it. The reason is that PTP/MTP is a transactional file system
702and it wants to be able to deny file transfer if the file won't fit on
703the device, so the transaction never even starts, it's impossible to
704start a transaction without giving file length.
705
706People really want streaming so I tried a lot of hacks to see if they
707would work, such as setting file size to 0xffffffffU or something other
708unnaturally big and then aborting the file transfer when the stream ends.
709It doesn't work: either the device crashes or the file simply disappears
710since the device rolls back all failed transactions.
711
712So this is an inherent limitation of the PTP/MTP protocol.
Linus Walleijbe8b03b2009-10-16 21:19:35 +0000713
714
715I make MTP devices!
716-------------------
717
718If you are a device vendor there is a lot you can do for libmtp:
719
720* Please consider assigning one of your employees as a contact person
721 for libmtp, have them sign up to the libmtp development list and answer
722 questions and post new device ID:s as they are released to our
723 mailing list.
724
725* If you want to help even more, assign someone to look deeper into
726 error reports on your specific devices, understand why your firmware
727 may require some special device flags and what can be done about it.
728
729* Do you have spare devices you can give us? Send them to Richard (Mac
730 support) or Linus (Linux support). (So far nobody did that except for
731 Microsoft who sent us a Zune by proxy!)
732
733Vendors do need help from libmtp too, especially we want to help
734vendors improve their MTP stacks, because they all suffer from the
735same problem: the lack of a proper conformance test has made many devices
736incompliant with the MTP specification as it is published today: most
737devices are just compliant with the Windows MTP stack, and don't work
738out-of-the-box with libmtp. We need someone on the inside to help in
739bug reporting vendors MTP stacks internally so these issues are raised.
740A good way to go toward better MTP compliance is to test with an
741alternative implementation of the stack. In e.g. IETF standardization
742it is compulsory for an RFC to have atleast two independent implementations
743for it to reach the status as standard.
744
745Being compliant with libmtp is also more and more important for
746vendors: libmtp is being deployed in some embedded systems like
747set-top-boxes etc. It will be very irritating for customers if a device
748will not dock properly with some home entertainment equipment just because
749it is based on Linux and libmtp and not the Windows MTP stack.