Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 1 | Building and Installing |
| 2 | ----------------------- |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 3 | |
Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 4 | See the "INSTALL" file. |
| 5 | |
| 6 | |
Linus Walleij | 3f7529c | 2010-07-24 20:33:41 +0000 | [diff] [blame] | 7 | Initiator and Responder |
| 8 | ----------------------- |
| 9 | |
| 10 | libmtp implements an MTP initiator, which means it initiate |
| 11 | MTP sessions with devices. The devices responding are known |
| 12 | as MTP responders. libmtp runs on something with a USB host |
| 13 | controller interface, using libusb to access the host |
| 14 | controller. |
| 15 | |
| 16 | If you're more interested in the MTP responders, gadgets like |
| 17 | MP3 players, mobile phones etc, look into MeeGo:s Buteo Sync: |
| 18 | http://wiki.meego.com/Buteo - these guys are creating a fully |
| 19 | open source MTP responder. |
| 20 | |
| 21 | |
Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 22 | Heritage |
| 23 | -------- |
| 24 | |
| 25 | libmtp is based on several ancestors: |
| 26 | |
| 27 | * libptp2 by Mariusz Woloszyn was the starting point used |
| 28 | by Richard A. Low for the initial starter port. You can |
| 29 | find it at http://libptp.sourceforge.net/ |
| 30 | |
| 31 | * libgphoto2 by Mariusz Woloszyn and Marcus Meissner was |
| 32 | used at a later stage since it was (is) more actively |
| 33 | maintained. libmtp tracks the PTP implementation in |
| 34 | libgphoto2 and considers it an upstream project. We will |
| 35 | try to submit anything generally useful back to libgphoto2 |
| 36 | and not make double efforts. In practice this means we |
| 37 | use ptp.c, ptp.h and ptp-pack.c verbatim from the libgphoto2 |
| 38 | source code. If you need to change things in these files, |
| 39 | make sure it is so general that libgphoto2 will want to |
| 40 | merge it to their codebase too. You find libgphoto2 as part |
| 41 | of gPhoto: http://gphoto.sourceforge.net/ |
| 42 | |
| 43 | * libnjb was a project that Richard and Linus were working |
Linus Walleij | fcf8891 | 2006-06-05 13:23:33 +0000 | [diff] [blame] | 44 | on before libmtp. When Linus took Richards initial port |
Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 45 | and made an generic C API he re-used the philosophy and |
| 46 | much code from libnjb. Many of the sample programs are for |
| 47 | example taken quite literally from libnjb. You find it here: |
| 48 | http://libnjb.sourceforge.net/ |
| 49 | |
| 50 | |
Linus Walleij | ea7d45b | 2009-02-23 22:26:09 +0000 | [diff] [blame] | 51 | Contacting and Contributing |
| 52 | --------------------------- |
| 53 | |
| 54 | See the project page at http://libmtp.sourceforge.net/ |
| 55 | We always need your help. There is a mailinglist and a |
| 56 | bug report system there. |
| 57 | |
| 58 | People who want to discuss MTP devices in fora seem to |
| 59 | hang out on the forums at AnythingbutiPod: |
| 60 | http://www.anythingbutipod.com/forum/ |
| 61 | |
| 62 | |
Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 63 | Compiling programs for libmtp |
| 64 | ----------------------------- |
| 65 | |
| 66 | libmtp has support for the pkg-config script by adding a libmtp.pc |
| 67 | entry in $(prefix)/lib/pkgconfig. To compile a libmtp program, |
| 68 | "just" write: |
| 69 | |
| 70 | gcc -o foo `pkg-config --cflags --libs libmtp` foo.c |
| 71 | |
| 72 | This also simplifies compilation using autoconf and pkg-config: just |
| 73 | write e.g. |
| 74 | |
| 75 | PKG_CHECK_MODULES(MTP, libmtp) |
| 76 | AC_SUBST(MTP_CFLAGS) |
| 77 | AC_SUBST(MTP_LIBS) |
| 78 | |
| 79 | To have libmtp LIBS and CFLAGS defined. Needless to say, this will |
| 80 | only work if you have pkgconfig installed on your system, but most |
| 81 | people have nowadays. |
| 82 | |
| 83 | If your library is installed in e.g. /usr/local you may have to tell |
| 84 | this to pkgconfig by setting the PKG_CONFIG_PATH thus: |
| 85 | |
| 86 | export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig |
| 87 | |
| 88 | |
| 89 | Documentation |
| 90 | ------------- |
| 91 | |
| 92 | Read the API documentation that can be generated with doxygen. |
| 93 | It will be output in doc/html if you have Doxygen properly |
| 94 | installed. (It will not be created unless you have Doxygen!) |
| 95 | |
| 96 | For information about the Media Transfer Protocol, see: |
| 97 | http://en.wikipedia.org/wiki/Media_Transfer_Protocol |
| 98 | |
Linus Walleij | 7a83e55 | 2008-07-29 21:30:43 +0000 | [diff] [blame] | 99 | The official 1.0 specification for MTP was released by the |
| 100 | USB Implementers Forum in may, 2008. Prior to this, only a |
| 101 | proprietary Microsoft version was available, and quite a few |
| 102 | devices out there still use some aspects of the Microsoft |
| 103 | version, which deviates from the specified standard. You can |
| 104 | find the official specification here: |
| 105 | http://www.usb.org/developers/devclass_docs/MTP_1.0.zip |
Linus Walleij | 0dd71e9 | 2006-05-04 18:47:07 +0000 | [diff] [blame] | 106 | |
Linus Walleij | 1b91ca6 | 2008-10-17 07:07:56 +0000 | [diff] [blame] | 107 | |
| 108 | The Examples |
| 109 | ------------ |
| 110 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 111 | In the subdirectory "examples" you find a number of |
Linus Walleij | 1b91ca6 | 2008-10-17 07:07:56 +0000 | [diff] [blame] | 112 | command-line tools, illustrating the use of libmtp in very |
| 113 | simple terms. |
| 114 | |
| 115 | Please do not complain about the usability or documentation |
| 116 | of these examples, they look like they do for two reasons: |
| 117 | |
| 118 | 1. They are examples, not tools. If they were intended for |
| 119 | day-to-day usage by commandline freaks, I would have |
| 120 | called them "tools" not "examples". |
| 121 | |
| 122 | 2. The MTP usage paradigm is that a daemon should hook |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 123 | the device upon connection, and that it should be |
Linus Walleij | 1b91ca6 | 2008-10-17 07:07:56 +0000 | [diff] [blame] | 124 | released by unplugging. GUI tools utilizing HAL (hald) |
| 125 | and D-Bus do this much better than any commandline |
| 126 | program ever can. (See below on bugs.) Specificationwise |
| 127 | this is a bug, however it is present in many, many |
| 128 | devices. |
| 129 | |
| 130 | That said, if you want to pick up and maintain the examples, |
| 131 | please volunteer. |
| 132 | |
| 133 | |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 134 | New Devices |
| 135 | ----------- |
| 136 | |
Linus Walleij | fcf8891 | 2006-06-05 13:23:33 +0000 | [diff] [blame] | 137 | If you happen upon a device which libmtp claims it cannot |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 138 | autodetect, please submit the vendor ID and device ID |
Linus Walleij | 9ee2940 | 2007-10-31 20:24:48 +0000 | [diff] [blame] | 139 | (these can be obtained from the "lsusb" and "lsusb -n" |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 140 | commands run as root) as a bug, patch or feature request |
| 141 | on the Sourceforge bug tracker at our homepage. If it |
| 142 | gives a sensible output from "mtp-detect" then please attach |
| 143 | the result as well as it teach us some stuff about your |
| 144 | device. If you've done some additional hacking, join our |
Linus Walleij | 9ee2940 | 2007-10-31 20:24:48 +0000 | [diff] [blame] | 145 | mailinglist and post your experiences there. |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 146 | |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 147 | If you want to be able to hack some more and you're not |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 148 | afraid of C hacking, add an entry for your device's |
| 149 | vendor/product ID and a descriptive string to the database |
Linus Walleij | 6dc0168 | 2007-11-15 21:23:46 +0000 | [diff] [blame] | 150 | in the file src/music-players.h. |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 151 | |
| 152 | If you want to poke around to see if your device has some |
| 153 | special pecularities, you can test some special device |
Linus Walleij | 6dc0168 | 2007-11-15 21:23:46 +0000 | [diff] [blame] | 154 | flags (defined in src/device-flags.h) by inserting them |
| 155 | together with your device entry in src/music-players.h. |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 156 | Flags can be tested in isolation or catenated with "|" |
| 157 | (binary OR). If relatives to your device use a certain |
| 158 | flag, chances are high that a new device will need it |
| 159 | too, typically from the same manufacturer. |
| 160 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 161 | The most common flag that needs to be set is the |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 162 | DEVICE_FLAG_UNLOAD_DRIVER that detach any Linux kernel |
| 163 | drivers that may have attached to the device making |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 164 | MTP access impossible. This is however not expected to |
| 165 | really work: this is a problem being tracked as of |
| 166 | now (2007-08-04). See the "last resort" solutions below |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 167 | if you really need to get your dual-mode device to work |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 168 | with MTP. |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 169 | |
Linus Walleij | cc2cf97 | 2007-11-22 20:23:43 +0000 | [diff] [blame] | 170 | Another flag which is easy to identify is the |
| 171 | DEVICE_FLAG_NO_ZERO_READS, which remedies connection |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 172 | timeouts when getting files, and some timeouts on e.g. |
Linus Walleij | cc2cf97 | 2007-11-22 20:23:43 +0000 | [diff] [blame] | 173 | successive "mtp-connect" calls. |
| 174 | |
Linus Walleij | a1b66f2 | 2007-05-10 20:02:16 +0000 | [diff] [blame] | 175 | If your device is very problematic we are curious of how it |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 176 | works under Windows, so we enjoy reading USB packet sniffs |
| 177 | that reveal the low-level traffic carried out between |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 178 | Windows Media Player and your device. This can be done |
Linus Walleij | 61c2568 | 2007-09-04 14:46:21 +0000 | [diff] [blame] | 179 | using e.g.: |
| 180 | |
| 181 | * USBsnoop: |
| 182 | http://benoit.papillault.free.fr/usbsnoop/ |
| 183 | |
| 184 | * The trial version of HHD Softwares software-only |
| 185 | USB monitor. You need to get a copy of version 2.37 since |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 186 | the newer trial versions won't let you carry out the |
Linus Walleij | 61c2568 | 2007-09-04 14:46:21 +0000 | [diff] [blame] | 187 | needed packet sniffs. (As of 2007-03-10 a copy can be found |
| 188 | at: http://www.cobbleware.com/files/usb-monitor-237.exe) |
| 189 | |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 190 | There are other USB monitors as well, some more expensive |
| 191 | alternatives use hardware and even measure electronic |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 192 | characteristics of the traffic (which is far too much |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 193 | detail for us). |
| 194 | |
Linus Walleij | 91fb028 | 2007-09-03 21:16:08 +0000 | [diff] [blame] | 195 | Device sniffs are an easy read since the PTP/MTP protocol |
| 196 | is nicely structured. All commands will have a structure such |
| 197 | as this in the log, we examplify with a object list request: |
| 198 | |
| 199 | PTP REQEUST: |
| 200 | 000120: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:25.9843750 +0.0 |
| 201 | Pipe Handle: 0x863ce234 (Endpoint Address: 0x2) |
| 202 | Send 0x20 bytes to the device: |
| 203 | 20 00 00 00 01 00 05 98 23 00 00 00 27 03 00 10 ......?#...'... |
| 204 | Length TYPE CMD Trans# Param1 |
| 205 | |
| 206 | 00 00 00 00 02 DC 00 00 00 00 00 00 00 00 00 00 .....Ü.......... |
| 207 | Param2 Param3 Param4 Param5 |
| 208 | |
| 209 | [OPTIONAL] DATA PHASE: |
| 210 | 000121: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0156250 |
| 211 | Pipe Handle: 0x863ce214 (Endpoint Address: 0x81) |
| 212 | Get 0x1a bytes from the device: |
| 213 | 1A 00 00 00 02 00 05 98 23 00 00 00 01 00 00 00 .......?#....... |
| 214 | Length TYPE CMD Trans# DATA |
| 215 | |
| 216 | 27 03 00 10 02 DC 04 00 00 30 '....Ü...0 |
| 217 | |
| 218 | RESPONSE: |
| 219 | 000122: Bulk or Interrupt Transfer (UP), 03.09.2007 12:49:26.0 +0.0 |
| 220 | Pipe Handle: 0x863ce214 (Endpoint Address: 0x81) |
| 221 | Get 0xc bytes from the device: |
| 222 | 0C 00 00 00 03 00 01 20 23 00 00 00 ....... #... |
| 223 | Length TYPE CODE Trans# |
| 224 | |
| 225 | * One send (OUT to the device), two reads (IN from the device). |
| 226 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 227 | * All three byte chunks commands are |
| 228 | sent/recieved/recieeved by the function ptp_transaction() |
Linus Walleij | 91fb028 | 2007-09-03 21:16:08 +0000 | [diff] [blame] | 229 | in the file ptp.c. |
| 230 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 231 | * It boils down to ptp_usb_sendreq(), optionally ptp_usb_senddata() |
| 232 | or ptp_usb_getdata() and finally ptp_usb_getresp() in the file |
Linus Walleij | 91fb028 | 2007-09-03 21:16:08 +0000 | [diff] [blame] | 233 | libusb-glue.c. Notice ptp_usb_sendreq() and ptp_usb_getresp() |
| 234 | are ALWAYS called. The TYPE field correspond to this, so the |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 235 | TYPES in this case are "COMMAND" (0x0001), "DATA" (0x0002), |
Linus Walleij | 91fb028 | 2007-09-03 21:16:08 +0000 | [diff] [blame] | 236 | and "RESPONSE" (0x0003). |
| 237 | |
| 238 | * Notice that the byte order is little endian, so you need to read |
| 239 | each field from right to left. |
| 240 | |
| 241 | * This COMMAND has: |
| 242 | CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList. |
| 243 | Transaction# 0x00000023. |
| 244 | REQUEST parameters 0x10000327, 0x00000000, 0x0000DC02, 0x00000000 |
| 245 | 0x00000000, in this case it means "get props for object 0x10000327", |
| 246 | "any format", "property 0xDC02" (PTP_OPC_ObjectFormat), then two |
| 247 | parameters that are always zero (no idea what they mean or their |
| 248 | use). |
| 249 | |
| 250 | * The DATA has: |
| 251 | CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList. |
| 252 | Transaction# 0x00000023. |
| 253 | Then comes data 0x00000001, 0x10000327, 0xDC02, 0x0004, 0x3000 |
| 254 | Which means in this case, (and this is the tricky part) "here |
| 255 | you have 1 property", "for object 0x10000327", "it is property |
| 256 | 0xDC02" (PTP_OPC_ObjectFormat), "which is of type 0x0004" |
| 257 | (PTP_DTC_UINT16), "and set to 0x3000" (PTP_OFC_Undefined, it |
| 258 | is perfectly valid to have undefined object formats, since it |
| 259 | is a legal value defining this). |
| 260 | |
| 261 | * This RESPONSE has: |
| 262 | CMD 0x99805, we see in ptp.h that this is PTP_OC_MTP_GetObjPropList. |
| 263 | Return Code ("RC") = 0x2001, PTP_RC_OK, all went fine. |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 264 | Transaction# 0x00000023. |
Linus Walleij | fcf8891 | 2006-06-05 13:23:33 +0000 | [diff] [blame] | 265 | |
Linus Walleij | d05fce6 | 2007-09-29 20:17:23 +0000 | [diff] [blame] | 266 | If you want to compare the Windows behaviour with a similar |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 267 | operation using libmtp you can go into the src/libusb-glue.c |
Linus Walleij | 6dc0168 | 2007-11-15 21:23:46 +0000 | [diff] [blame] | 268 | file and uncomment the row that reads: |
Linus Walleij | d05fce6 | 2007-09-29 20:17:23 +0000 | [diff] [blame] | 269 | |
| 270 | //#define ENABLE_USB_BULK_DEBUG |
| 271 | |
| 272 | (I.e. remove the two //.) |
| 273 | |
| 274 | This will make libmtp print out a hex dump of every bulk USB |
| 275 | transaction. The bulk transactions contain all the PTP/MTP layer |
| 276 | data, which is usually where the problems appear. |
| 277 | |
Linus Walleij | 6fd2f08 | 2006-03-28 07:19:22 +0000 | [diff] [blame] | 278 | |
Darran Kartaschew | a476ae9 | 2011-08-08 09:07:30 +0200 | [diff] [blame] | 279 | Notes to assist with debugging new devices: |
| 280 | ------------------------------------------- |
| 281 | |
| 282 | In debugging new hardware, we highly recommend that you only |
| 283 | use the example mtp-* applications that come with libmtp, as other |
| 284 | applications may have their own bugs that may interfere with your |
| 285 | new device working correctly. Using another application instead of |
| 286 | those that come with libmtp just adds another point of failure. |
| 287 | |
| 288 | For debugging, there are 3 main options: |
| 289 | |
| 290 | 1. Use the env variable: LIBMTP_DEBUG to increase the |
| 291 | verboseness of the debugging output for any application using |
| 292 | libmtp. Relevant codes are: |
| 293 | * 0x00 [0000 0000] : no debug (default) |
| 294 | * 0x01 [0000 0001] : PTP debug |
| 295 | * 0x02 [0000 0010] : Playlist debug |
| 296 | * 0x04 [0000 0100] : USB debug |
| 297 | * 0x08 [0000 1000] : USB data debug |
| 298 | // Codes are hex and binary respectively. Simple add them togther |
| 299 | // to get your desired level of output. |
| 300 | |
| 301 | (Assuming bash) |
| 302 | eg: |
| 303 | $ export LIBMTP_DEBUG=12 |
| 304 | $ mtp-detect |
| 305 | // To get USB debug and USB data debug information. |
| 306 | |
| 307 | $ export LIBMTP_DEBUG=2 |
| 308 | $ mtp-detect |
| 309 | // To get Playlist debug information. |
| 310 | |
| 311 | Also note, an application may also use the LIBMTP_debug() API |
| 312 | function to achieve the same options as listed above. |
| 313 | |
| 314 | 2. Use "strace" on the various mtp-* commands to see where/what |
| 315 | is falling over or getting stuck at. |
| 316 | * On Solaris and FreeBSD, use "truss" or "dtrace" instead on "strace". |
| 317 | * On Mac OS X, use "ktrace" or "dtrace" instead of "strace". |
| 318 | * On OpenBSD and NetBSD, use "ktrace" instead of "strace". |
| 319 | |
| 320 | This will at least help pinpoint where the application is failing, or |
| 321 | a device is reporting incorrect information. (This is extremely helpful |
| 322 | with devices that have odd disconnection requirements). |
| 323 | |
| 324 | The use of these tools may also pinpoint issues with libusb as |
| 325 | implemented by each OS vendor or issues with the MTP implementation |
| 326 | on the new device as well, so please be prepared for either case. |
| 327 | |
| 328 | 3. Use "gdb" or similar debugger to step through the code as it is |
| 329 | run. This is time consuming, and not needed just to pinpoint where |
| 330 | the fault is. |
| 331 | |
| 332 | The use of gdb or another debugger may also miss or actually cause |
| 333 | command and data timing issues with some devices, leading to false |
| 334 | information. So please consider this a last resort option. |
| 335 | |
| 336 | Also please read the "It's Not Our Bug!" section below, as it does |
| 337 | contain some useful information that may assist with your device. |
| 338 | |
| 339 | |
Linus Walleij | 8d799eb | 2009-07-23 22:58:06 +0000 | [diff] [blame] | 340 | Dual-mode devices does not work - last resort: |
| 341 | ---------------------------------------------- |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 342 | |
| 343 | Some devices that are dual-mode are simply impossible to get |
| 344 | to work under Linux because the usb-storage(.ko) kernel |
| 345 | module hook them first, and refuse to release them, even |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 346 | when we specify the DEVICE_FLAG_UNLOAD_DRIVER flag. (Maybe |
| 347 | it DOES release it but the device will immediately be probed |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 348 | at the USB mass storage interface AGAIN because it |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 349 | enumerates.) |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 350 | |
Linus Walleij | 8d799eb | 2009-07-23 22:58:06 +0000 | [diff] [blame] | 351 | Here is what some people do: |
| 352 | |
| 353 | 1. Plug in the device. |
| 354 | 2. USB-mass storage folder will open automatically. |
| 355 | 3. Unmount the device. |
| 356 | 4. Run mtp-detect. It will most likely fail the first time. |
| 357 | 5. Run mtp-detect again, it might work this time, or fail. Keep running |
| 358 | till it works. 99% it works by the third try. |
| 359 | 6. Once mtp-detect gives you an "Ok", open either Rhythmbox or Gnomad2, |
| 360 | everything should work. |
| 361 | |
Linus Walleij | e20abaf | 2007-12-10 11:20:34 +0000 | [diff] [blame] | 362 | Linux: Try this, if you have a recent 2.6.x Linux kernel, |
Linus Walleij | 584eb8d | 2007-09-05 19:51:27 +0000 | [diff] [blame] | 363 | run (as root) something like: |
| 364 | |
| 365 | > rmmod usb_storage ; mtp-detect |
| 366 | |
| 367 | You can run most any command or a client like gnomad2 or |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 368 | Amarok immediately after the rmmod command. This works |
Linus Walleij | 584eb8d | 2007-09-05 19:51:27 +0000 | [diff] [blame] | 369 | sometimes. Another way: |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 370 | |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 371 | * Edit /etc/modprobe.d/blacklist |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 372 | |
| 373 | * Add the line "blacklist usb-storage" |
| 374 | |
| 375 | * Reboot. |
| 376 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 377 | Now none of you USB disks, flash memory sticks etc will be |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 378 | working (you just disabled them all). However you *can* try |
| 379 | your device, and it might have started working because there |
| 380 | is no longer a USB mass storage driver that tries to hook onto |
| 381 | the mass storage interface of your device. |
| 382 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 383 | If not even blacklisting works (check with |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 384 | "lsmod | grep usb-storage"), there is some problem with |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 385 | something else and you may need to remove or rename the file |
Linus Walleij | 94f23d5 | 2007-08-04 19:37:28 +0000 | [diff] [blame] | 386 | /lib/modules/<VERSION>/kernel/drivers/usb/storage/usb-storage.ko |
| 387 | manually. |
| 388 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 389 | If you find the PerfectSolution(TM) to this dilemma, so you |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 390 | can properly switch for individual devices whether to use it |
| 391 | as USB mass storage or not, please tell us how you did it. We |
| 392 | know we cannot use udev, because udev is called after-the-fact: |
| 393 | the device is already configured for USB mass storage when |
| 394 | udev is called. |
| 395 | |
Linus Walleij | e20abaf | 2007-12-10 11:20:34 +0000 | [diff] [blame] | 396 | On Mac OS there is another ugly hack: |
| 397 | |
| 398 | 1. Open up a terminal window |
| 399 | 2. Type: |
| 400 | sudo mv /System/Library/Extensions/IOUSBMassStorageClass.kext |
| 401 | /System/Library/Extensions/IOUSBMassStorageClass.kext.disabled |
| 402 | |
| 403 | and when prompted enter your password. |
| 404 | |
| 405 | 3. Restart. |
| 406 | |
| 407 | To reverse this change, just reverse the filenames: |
| 408 | |
| 409 | sudo mv /System/Library/Extensions/ |
| 410 | IOUSBMassStorageClass.kext.disabled /System/Library/Extensions/ |
| 411 | IOUSBMassStorageClass.kext |
| 412 | |
| 413 | and restart. |
| 414 | |
Linus Walleij | bd7624c | 2007-05-28 10:48:54 +0000 | [diff] [blame] | 415 | |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 416 | Calendar and contact support: |
| 417 | ----------------------------- |
Linus Walleij | d3bdf76 | 2006-02-20 22:21:56 +0000 | [diff] [blame] | 418 | |
Linus Walleij | 3c16fe4 | 2006-04-30 07:53:41 +0000 | [diff] [blame] | 419 | The Creative Zen series can read VCALENDAR2 (.ics) files |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 420 | and VCard (.vcf) files from programs like for example |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 421 | Evolution with the following limitations/conditions: |
Linus Walleij | d3bdf76 | 2006-02-20 22:21:56 +0000 | [diff] [blame] | 422 | |
Linus Walleij | 3c16fe4 | 2006-04-30 07:53:41 +0000 | [diff] [blame] | 423 | - The file must be in DOS (CR/LF) format, use the unix2dos |
| 424 | program to convert if needed |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 425 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 426 | - Repeat events in calendar files do not seem to be supported, |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 427 | entries will only appear once. |
| 428 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 429 | - Calendar (.ics) files should be stored in the folder "My Organizer" |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 430 | when sent to the device (this directory should be autodetected |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 431 | for use with calendar files, otherwise use the option |
Linus Walleij | 15def33 | 2006-09-19 14:27:02 +0000 | [diff] [blame] | 432 | -f "My Organizer" to sendfile for this) Apparently this file can |
| 433 | also contain tasklists. |
| 434 | |
| 435 | - Contact (.vcf) files should be stored in the folder "My Contacts" |
| 436 | when sent to the device. (-f "My Contacts") |
| 437 | |
| 438 | - Some devices are picky about the name of the calendar and |
| 439 | contact files. For example the Zen Microphoto wants: |
| 440 | |
Linus Walleij | b1318d1 | 2006-09-25 14:59:26 +0000 | [diff] [blame] | 441 | Calendar: My Organizer/6651416.ics |
| 442 | Contacts: My Organizer/6651416.vcf |
| 443 | |
| 444 | |
| 445 | Syncing in with Evolution and Creative Devices |
| 446 | ---------------------------------------------- |
| 447 | |
| 448 | Evolution can easily export .ics an .vcf files, but you currently |
| 449 | need some command-line hacking to get you stuff copied over in |
| 450 | one direction host -> device. The examples/ directory contains a script |
| 451 | created for the Creative Zen Microphoto by Nicolas Tetreault. |
| 452 | |
Linus Walleij | 6e8cef4 | 2006-12-03 20:45:04 +0000 | [diff] [blame] | 453 | |
| 454 | It's Not Our Bug! |
| 455 | ----------------- |
| 456 | |
| 457 | Some MTP devices have strange pecularities. We try to work around |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 458 | these whenever we can, sometimes we cannot work around it or we |
Linus Walleij | 6e8cef4 | 2006-12-03 20:45:04 +0000 | [diff] [blame] | 459 | cannot test your solution. |
| 460 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 461 | * Generic MTP/PTP disconnect misbehaviour: we have noticed that |
Linus Walleij | 67038b9 | 2008-04-16 15:01:40 +0000 | [diff] [blame] | 462 | Windows Media Player apparently never close the session to an MTP |
| 463 | device. There is a daemon in Windows that "hooks" the device |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 464 | by opening a PTP session to any MTP device, whenever it is |
| 465 | plugged in. This daemon proxies any subsequent transactions |
Linus Walleij | 67038b9 | 2008-04-16 15:01:40 +0000 | [diff] [blame] | 466 | to/from the device and will never close the session, thus |
| 467 | Windows simply does not close sessions at all. |
| 468 | |
Linus Walleij | e2f6566 | 2008-12-07 20:44:11 +0000 | [diff] [blame] | 469 | Typical sign of this illness: broken pipes on closing sessions, |
| 470 | on the main transfer pipes(s) or the interrupt pipe: |
| 471 | |
| 472 | Closing session |
| 473 | usb_clear_halt() on INTERRUPT endpoint: Broken pipe |
| 474 | OK. |
| 475 | |
Linus Walleij | 67038b9 | 2008-04-16 15:01:40 +0000 | [diff] [blame] | 476 | This means that device manufacturers doesn't notice any problems |
| 477 | with devices that do not correctly handle closing PTP/MTP |
| 478 | sessions, since Windows never do it. The proper way of closing |
| 479 | a session in Windows is to unplug the device, simply put. |
| 480 | |
| 481 | Since libmtp actually tries to close sessions, some devices |
| 482 | may fail since the close session functionality has never been |
| 483 | properly tested, and "it works with Windows" is sort of the |
| 484 | testing criteria at some companies. |
| 485 | |
| 486 | You can get Windows-like behaviour on Linux by running a HAL-aware |
| 487 | libmtp GUI client like Rhythmbox or Gnomad2, which will "hook" |
| 488 | the device when you plug it in, and "release" it if you unplug |
| 489 | it. |
| 490 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 491 | If this bug in your device annoys you, contact your device |
| 492 | manufacturer and ask them to test their product with some libmtp |
Linus Walleij | 67038b9 | 2008-04-16 15:01:40 +0000 | [diff] [blame] | 493 | program. |
| 494 | |
Linus Walleij | c3a6eeb | 2010-01-30 07:32:41 +0000 | [diff] [blame] | 495 | * Generic certificate misbehaviour. All devices are actually |
| 496 | required to support a device certificate to be able to |
| 497 | encrypt Windows Media (WMA/WMV) files. However there are |
| 498 | obviously a lot of devices out there which doesn't support |
| 499 | this at all but instead crash. Typical printout: |
| 500 | |
| 501 | Error 2: PTP Layer error 02ff: get_device_unicode_property(): failed |
| 502 | to get unicode property. |
| 503 | |
Linus Walleij | b715ba6 | 2008-02-12 23:41:49 +0000 | [diff] [blame] | 504 | * Generic USB misbehaviour: some devices behave badly under MTP |
| 505 | and USB mass storage alike, even down to the lowest layers |
| 506 | of USB. You can always discuss such issues at the linux-usb |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 507 | mailing list if you're using Linux: |
Linus Walleij | b715ba6 | 2008-02-12 23:41:49 +0000 | [diff] [blame] | 508 | http://www.linux-usb.org/mailing.html |
| 509 | |
Linus Walleij | 76b185d | 2008-02-12 23:46:14 +0000 | [diff] [blame] | 510 | If you have a problem specific to USB mass storage mode, there |
| 511 | is a list of strange behaving devices in the Linux kernel: |
| 512 | http://lxr.linux.no/linux/drivers/usb/storage/unusual_devs.h |
Linus Walleij | f7d8df1 | 2008-02-13 00:02:17 +0000 | [diff] [blame] | 513 | You can discuss this too on the mentioned list, for understanding |
| 514 | the quirks, see: |
| 515 | http://www2.one-eyed-alien.net/~mdharm/linux-usb/target_offenses.txt |
Linus Walleij | 76b185d | 2008-02-12 23:46:14 +0000 | [diff] [blame] | 516 | |
Linus Walleij | deddc34 | 2008-08-16 23:52:06 +0000 | [diff] [blame] | 517 | * Kernel bug on Linux. Linux 2.6.16 is generally speaking required |
| 518 | to use any MTP device under USB 2.0. This is because the EHCI |
| 519 | driver previously did not support zero-length writes to endpoints. |
| 520 | It should work in most cases however, or if you connect it |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 521 | to an UHCI/OHCI port instead (yielding lower speed). But |
Linus Walleij | deddc34 | 2008-08-16 23:52:06 +0000 | [diff] [blame] | 522 | please just use a recent kernel. |
| 523 | |
Linus Walleij | 07bb538 | 2008-07-31 20:21:09 +0000 | [diff] [blame] | 524 | * Zen models AVI file seeking problem: the Zens cannot parse the |
| 525 | files for the runlength metadata. Do not transfer file with e.g. |
| 526 | mtp-sendfile, use mtp-sendtr and set the length of the track to |
| 527 | the apropriate number of seconds and it will work. In graphical |
| 528 | clients, use a "track transfer" function to send these AVI files, |
| 529 | the Zens need the metadata associated with tracks to play back |
| 530 | movies properly. Movies are considered "tracks" in the MTP world. |
| 531 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 532 | * Some devices that disregard the metadata sent with the MTP |
Linus Walleij | 64e2e98 | 2008-08-01 21:51:13 +0000 | [diff] [blame] | 533 | commands will parse the files for e.g. ID3 metadata. Some still |
| 534 | of these devices expect only ID3v2.3 metadata and will fail with |
| 535 | a modern ID3v2,4 tag writer, like many of those found in Linux |
| 536 | applications. Windows Media Player use ID3v2.3 only, so many |
| 537 | manufacturers only test this version. |
| 538 | |
Linus Walleij | 6e8cef4 | 2006-12-03 20:45:04 +0000 | [diff] [blame] | 539 | * The Zen Vision:M (possibly more Creative Zens) has a firmware bug |
| 540 | that makes it drop the last two characters off a playlist name. |
| 541 | It is fixed in later firmware. |
| 542 | |
Linus Walleij | c41f2e8 | 2007-03-12 22:26:00 +0000 | [diff] [blame] | 543 | * For Creative Technology devices, there are hard limits on how |
| 544 | many files can be put onto the device. For a 30 GiB device (like |
| 545 | the Zen Xtra) the limit is 6000, for a 60 GiB device the limit |
| 546 | is 15000 files. For further Creative pecularities, see the |
| 547 | FAQ sections at www.nomadness.net. |
| 548 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 549 | * Sandisk sansa c150 and probably several other Sandisk devices |
Linus Walleij | d24a7ab | 2007-03-07 21:48:43 +0000 | [diff] [blame] | 550 | (and possibly devices from other manufacturers) have a dual |
| 551 | mode with MTP and USB mass storage. The device will initially |
| 552 | claim to be mass storage so udev will capture is and make the |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 553 | use of MTP mode impossible. One way of avoiding it could be to |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 554 | be to blacklist the "usb-storage" module in |
Linus Walleij | d24a7ab | 2007-03-07 21:48:43 +0000 | [diff] [blame] | 555 | /etc/modprobe.c/blacklist with a row like this: |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 556 | "blacklist usb-storage". Some have even removed the |
| 557 | "usb-storage.ko" (kernel module file) to avoid loading. |
Linus Walleij | d24a7ab | 2007-03-07 21:48:43 +0000 | [diff] [blame] | 558 | |
Linus Walleij | 2242b02 | 2009-01-02 01:44:00 +0000 | [diff] [blame] | 559 | * Sandisk Sansa Fuze has three modes: auto, MTP or mass storage |
| 560 | (MSC). Please set it to MTP to avoid problems with libmtp. |
| 561 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 562 | * The iriver devices (possibly all of them) cannot handle the |
| 563 | enhanced GetObjectPropList MTP command (0x9805) properly. So |
Linus Walleij | 6e8cef4 | 2006-12-03 20:45:04 +0000 | [diff] [blame] | 564 | they have been banned from using it. |
| 565 | |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 566 | * iriver devices have problems with older versions of libmtp and |
Linus Walleij | 8226522 | 2007-03-04 19:47:08 +0000 | [diff] [blame] | 567 | with new devices libmtp does not know of as of yet, since it |
| 568 | has an oldstyle USB device controller that cannot handle zero |
Linus Walleij | da558be | 2007-03-10 21:42:25 +0000 | [diff] [blame] | 569 | writes. (Register your device with us!) All their devices are |
| 570 | likely to need a special device flag in the src/libusb-glue.c |
| 571 | database. |
Linus Walleij | 8226522 | 2007-03-04 19:47:08 +0000 | [diff] [blame] | 572 | |
Linus Walleij | 6e8cef4 | 2006-12-03 20:45:04 +0000 | [diff] [blame] | 573 | * The Samsung Yepp T9 has several strange characteristics, some |
| 574 | that we've managed to work around. (For example it will return |
| 575 | multiple PTP packages in a single transaction.) |
| 576 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 577 | * The early firmware for Philips HDD players is known to be |
Linus Walleij | f2711b3 | 2007-02-26 20:18:40 +0000 | [diff] [blame] | 578 | problematic. Please upgrade to as new firmware as you can get. |
| 579 | (Yes this requires some kind of Windows Installation I think.) |
| 580 | |
Linus Walleij | b5a4f92 | 2008-05-11 20:15:00 +0000 | [diff] [blame] | 581 | * Philips HDD 1630/16 or 1630/17 etc may lock themselves up, |
| 582 | turning inresponsive due to internal corruption. This typically |
| 583 | gives an error in opening the PTP session. Apparently you can |
| 584 | do a "repair" with the firmware utility (Windows only) which |
| 585 | will often fix this problem and make the device responsive |
| 586 | again. |
| 587 | |
Linus Walleij | 9340aac | 2007-10-01 10:02:05 +0000 | [diff] [blame] | 588 | * Some devices that implement GetObjectPropList (0x9805) will |
| 589 | not return the entire object list if you request a list for object |
| 590 | 0xffffffffu. (But they should.) So they may need the special |
| 591 | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST_ALL. |
| 592 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 593 | * Some (smaller) subset of devices cannot even get all the |
Linus Walleij | 9340aac | 2007-10-01 10:02:05 +0000 | [diff] [blame] | 594 | properties for a single object in one go, these need the |
| 595 | DEVICE_FLAG_BROKEN_MTPGETOBJPROPLIST. Currently only the |
| 596 | iriver devices seem to have this bug. |
| 597 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 598 | * The Toshiba Gigabeat S (and probably its sibling the |
Linus Walleij | 9340aac | 2007-10-01 10:02:05 +0000 | [diff] [blame] | 599 | Microsoft Zune and other Toshiba devices) will only display |
| 600 | album information tags for a song in case there is also |
| 601 | an abstract album (created with the album interface) with |
| 602 | the exact same name. |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 603 | |
Linus Walleij | 265b9d6 | 2007-11-25 20:08:15 +0000 | [diff] [blame] | 604 | * The Zen Vision:M has an older firmware which is very corrupt, |
| 605 | it is incompatible with the Linux USB stack altogether. The |
| 606 | kernel dmesg will look something like this, and you have to |
| 607 | upgrade the firmware using Windows: |
| 608 | usb 4-5: new high speed USB device using ehci_hcd and address 5 |
| 609 | usb 4-5: configuration #1 chosen from 1 choice |
| 610 | usb 4-5: can't set config #1, error -110 |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 611 | |
Linus Walleij | 103a78e | 2008-08-25 20:48:52 +0000 | [diff] [blame] | 612 | * The Sirus Stiletto does not seem to allow you to copy any files |
| 613 | off the device. This may be someone's idea of copy protection. |
Linus Walleij | b715ba6 | 2008-02-12 23:41:49 +0000 | [diff] [blame] | 614 | |
Linus Walleij | 25a1630 | 2009-03-04 13:56:33 +0000 | [diff] [blame] | 615 | * The Samsung P2 assigns parent folder ID 0 to all unknown file |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 616 | types.(i.e. moves them to the root folder) |
Linus Walleij | 1b91ca6 | 2008-10-17 07:07:56 +0000 | [diff] [blame] | 617 | |
Linus Walleij | 7c64a06 | 2010-02-06 01:13:08 +0000 | [diff] [blame] | 618 | * The Sandisk Sansa Clip+ needs a firmware upgrade in earlier |
| 619 | versions in order to work properly. |
| 620 | |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 621 | Lost symbols |
| 622 | ------------ |
| 623 | |
| 624 | Shared libraries can be troublesome to users not experienced with |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 625 | them. The following is a condensed version of a generic question |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 626 | that has appeared on the libmtp mailing list from time to time. |
| 627 | |
| 628 | > PTP: Opening session |
| 629 | > Queried Creative Zen Vision:M |
| 630 | > gnomad2: relocation error: gnomad2: undefined symbol: |
| 631 | > LIBMTP_Get_Storageinfo |
| 632 | > (...) |
| 633 | > Are these type of errors related to libmtp or something else? |
| 634 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 635 | The problem is of a generic nature, and related to dynamic library |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 636 | loading. It is colloquially known as "dependency hell". |
| 637 | (http://en.wikipedia.org/wiki/Dependency_hell) |
| 638 | |
| 639 | The gnomad2 application calls upon the dynamic linker in Linux to |
| 640 | resolve the symbol "LIBMTP_Get_Storageinfo" or any other symbol |
| 641 | (ELF symbol, or link point or whatever you want to call them, a |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 642 | symbol is a label on a memory address that the linker shall |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 643 | resolve from label to actual address.) |
| 644 | For generic information on this subject see the INSTALL file and |
| 645 | this Wikipedia page: |
| 646 | |
| 647 | http://en.wikipedia.org/wiki/Library_(computing) |
| 648 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 649 | When Linux /lib/ld-linux.so.X is called to link the symbols compiled |
| 650 | into gnomad2 (or any other executable using libmtp), it examines the |
| 651 | ELF file for the libmtp.so.X file it finds first and cannot resolve |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 652 | the symbol "LIBMTP_Get_Storageinfo" (or whichever symbol you have a |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 653 | problem witj) from it, since it's probably not there. There are many |
Linus Walleij | d132d8e | 2007-04-03 23:24:54 +0000 | [diff] [blame] | 654 | possible causes of this symbol breakage: |
| 655 | |
| 656 | 1) You installed precompiled libmtp and gnomad2 packages (RPMs, debs |
| 657 | whatever) that do not match up. Typical cause: your gnomad2 package was |
| 658 | built against a newer version of libmtp than what's installed on your |
| 659 | machine. Another typical cause: you installed a package you found on |
| 660 | the web, somewhere, the dependency resolution system did not protest |
| 661 | properly (as it should) or you forced it to install anyway, ignoring |
| 662 | some warnings. |
| 663 | |
| 664 | 2) You compiled libmtp and/or gnomad2 from source, installing both or |
| 665 | either in /usr/local/lib and /usr/local/bin. This means at compile-time |
| 666 | gnomad2 finds the libmtp library in /usr/local/lib but at runtime, it |
| 667 | depends on the Linux system wide library loader (/lib/ld-linux.so.X) in |
| 668 | order to resolve the symbols. This loader will look into the file |
| 669 | /etc/ld.so.conf and/or the folder /etc/ld.so.conf.d in order to find |
| 670 | paths to libraries to be used for resolving the symbols. If you have |
| 671 | some older version of libmtp in e.g. /usr/lib (typically installed by a |
| 672 | package manager) it will take precedence over the new version you just |
| 673 | installed in /usr/local/lib and the newly compiled library in |
| 674 | /usr/local/lib will *not* be used, resulting in this error message. |
| 675 | |
| 676 | 3) You really did install the very latest versions (as of writing libmtp |
| 677 | 0.1.5 and gnomad2 2.8.11) from source and there really is no |
| 678 | pre-installed package of either on your machine. In that case I'm |
| 679 | totally lost, I have no idea what's causing this. |
| 680 | |
| 681 | Typical remedies: |
| 682 | |
| 683 | 1) If you don't want to mess around with your system and risk these |
| 684 | situations, only use pre-packaged software that came with the |
| 685 | distribution or its official support channels. If it still breaks, |
| 686 | blame your distribution, they're not packaging correctly. Relying on |
| 687 | properly packaged software and not installing things yourself *is* the |
| 688 | Linux solution to the "dependency hell" problem. |
| 689 | |
| 690 | 2) Read about dynamically linked library handling until the stuff I wrote |
| 691 | about in the previous list sounds like music to your ears, inspect |
| 692 | your /lib, /usr/lib, /usr/local/lib, /etc/ld.so.conf and the |
| 693 | /etc/ld.so.conf.d, remove all pre-packed versions using RPM, APT, |
| 694 | YaST or whatever your distribution uses, compile libmtp and gnomad2 |
| 695 | (or whatever) from source only and you will be enlighted. |
| 696 | |
| 697 | I don't know if this helps you, it's the best answer we can give. |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 698 | |
| 699 | |
| 700 | API is obscure - I want plain files! |
| 701 | ------------------------------------ |
| 702 | |
| 703 | PTP/MTP devices does not actually contain "files", they contain |
| 704 | objects. These objects have file names, but that is actually |
| 705 | just a name tag on the object. |
| 706 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 707 | Folders/directories aren't really such entities: they are just |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 708 | objects too, albeit objects that can act as parent to other |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 709 | objects. They are called "associations" and are created in atomic |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 710 | fashion and even though there is an MTP command to get all the |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 711 | associations of a certain association, this command is optional |
| 712 | so it is perfectly possible (and most common, actually) to create |
| 713 | devices where the "folders" (which are actually associations) have |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 714 | no idea whatsoever of what files they are associated as parents to |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 715 | (i.e. which files they contain). This is very easy for device |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 716 | manufacturers to implement, all the association (i.e. finding out |
| 717 | which files are in a certain folder) has to be done by the MTP |
| 718 | Initiator / host computer. |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 719 | |
| 720 | Moving a file to a new folder is for example very simple in a |
| 721 | "real" file system. In PTP/MTP devices it is often not even possible, |
| 722 | some devices *may* be able to do that. But actually the only |
| 723 | reliable way of doing that is to upload the file to the host, |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 724 | download it with the new parent, then delete the old file. |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 725 | We have played with the idea of implementing this time consuming |
| 726 | function, perhaps we will. |
| 727 | |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 728 | Then the issue that in PTP/MTP it is legal for two files to have |
| 729 | exactly the same path as long as their object IDs differ. A |
| 730 | folder/association can contain two files with the exact same name. |
| 731 | (And on the Creative devices this even works, too, though most devices |
| 732 | implicitly fail at this.) Perhaps one could add some custom hook for |
| 733 | handling that, so they become /Foo.mp3 and /Foo.mp3(1) or something |
| 734 | similar, but it's really a bit kludgy. |
| 735 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 736 | Playlists and albums aren't really files, thinking about |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 737 | them as files like the hacks in libgphoto2 is really backwards. They are |
| 738 | called associations and are more like a symbolic link that links in a |
| 739 | star-shaped pattern to all the files that are part of the album/playlist. |
| 740 | Some devices (Samsung) thought that was too complicated and have a |
| 741 | different way of storing playlists in an UTF-16 encoded .spl-like file |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 742 | instead! This is why playlists/albums must have their own structs and |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 743 | functions. |
| 744 | |
Linus Walleij | 8aba06d | 2008-12-28 08:26:57 +0000 | [diff] [blame] | 745 | Plain file access also assumes to be able to write files of an |
| 746 | undetermined size, which is simply not possible in a transactional |
| 747 | file system like PTP/MTP. (See further below.) |
| 748 | |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 749 | |
| 750 | I Want Streaming! |
| 751 | ----------------- |
| 752 | |
| 753 | Streaming reads is easy. Just connect the output file descriptor from |
| 754 | LIBMTP_Get_File_To_File_Descriptor() (and a similar function for tracks) |
| 755 | wherever you want. |
| 756 | |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 757 | People have connected this to TCP sockets for streaming web servers |
| 758 | etc, works like a charm. Some devices will even survive if the callback |
Linus Walleij | 387e37a | 2008-10-29 17:22:22 +0000 | [diff] [blame] | 759 | functions return non-zero and cancel the download. Some devices will |
| 760 | lock up and even require a reset if you do that. Devices are poorly |
| 761 | implemented so that's life. If you want to stream off a device, the |
| 762 | best idea is always to stream the entire file and discard the stuff |
| 763 | at the end you don't want. It will incur a delay if you e.g. want to |
| 764 | skip between tracks, sadly. |
| 765 | |
| 766 | Then we get to the complicated things: streaming WRITES... |
| 767 | |
| 768 | There is a function: |
| 769 | LIBMTP_Send_File_From_File_Descriptor() (and similar for tracks) |
| 770 | which will write a file to a device from a file descriptor, which may |
| 771 | be a socket or whatever. |
| 772 | |
| 773 | HOWEVER: this requires a piece of metadata with the .filesize properly |
| 774 | set first. |
| 775 | |
| 776 | This is not because we think it is funny to require that, the protocol |
| 777 | requires it. The reason is that PTP/MTP is a transactional file system |
| 778 | and it wants to be able to deny file transfer if the file won't fit on |
| 779 | the device, so the transaction never even starts, it's impossible to |
| 780 | start a transaction without giving file length. |
| 781 | |
| 782 | People really want streaming so I tried a lot of hacks to see if they |
| 783 | would work, such as setting file size to 0xffffffffU or something other |
| 784 | unnaturally big and then aborting the file transfer when the stream ends. |
| 785 | It doesn't work: either the device crashes or the file simply disappears |
| 786 | since the device rolls back all failed transactions. |
| 787 | |
| 788 | So this is an inherent limitation of the PTP/MTP protocol. |
Linus Walleij | be8b03b | 2009-10-16 21:19:35 +0000 | [diff] [blame] | 789 | |
| 790 | |
| 791 | I make MTP devices! |
| 792 | ------------------- |
| 793 | |
| 794 | If you are a device vendor there is a lot you can do for libmtp: |
| 795 | |
| 796 | * Please consider assigning one of your employees as a contact person |
| 797 | for libmtp, have them sign up to the libmtp development list and answer |
| 798 | questions and post new device ID:s as they are released to our |
| 799 | mailing list. |
| 800 | |
| 801 | * If you want to help even more, assign someone to look deeper into |
| 802 | error reports on your specific devices, understand why your firmware |
| 803 | may require some special device flags and what can be done about it. |
| 804 | |
| 805 | * Do you have spare devices you can give us? Send them to Richard (Mac |
| 806 | support) or Linus (Linux support). (So far nobody did that except for |
| 807 | Microsoft who sent us a Zune by proxy!) |
| 808 | |
| 809 | Vendors do need help from libmtp too, especially we want to help |
| 810 | vendors improve their MTP stacks, because they all suffer from the |
| 811 | same problem: the lack of a proper conformance test has made many devices |
| 812 | incompliant with the MTP specification as it is published today: most |
| 813 | devices are just compliant with the Windows MTP stack, and don't work |
| 814 | out-of-the-box with libmtp. We need someone on the inside to help in |
| 815 | bug reporting vendors MTP stacks internally so these issues are raised. |
| 816 | A good way to go toward better MTP compliance is to test with an |
| 817 | alternative implementation of the stack. In e.g. IETF standardization |
| 818 | it is compulsory for an RFC to have atleast two independent implementations |
| 819 | for it to reach the status as standard. |
| 820 | |
| 821 | Being compliant with libmtp is also more and more important for |
| 822 | vendors: libmtp is being deployed in some embedded systems like |
| 823 | set-top-boxes etc. It will be very irritating for customers if a device |
| 824 | will not dock properly with some home entertainment equipment just because |
| 825 | it is based on Linux and libmtp and not the Windows MTP stack. |
Linus Walleij | 5f5c69f | 2011-06-26 14:34:13 +0200 | [diff] [blame] | 826 | |
| 827 | Autodetect with gudev |
| 828 | --------------------- |
| 829 | |
| 830 | Previously you would use HAL to detect devices being plugged in. Nowadays |
| 831 | we use udev directly, or though the GNOME libgudev library. LIBMTPs |
| 832 | default udev rules export the proper properties to detect any MTP device |
| 833 | automatically, here is a verbose example derived from gnomad2: |
| 834 | |
| 835 | #define G_UDEV_API_IS_SUBJECT_TO_CHANGE |
| 836 | #include <gudev/gudev.h> |
| 837 | const char * const gudev_subsystems[] = { "usb", NULL }; |
| 838 | GUdevClient *gudev_client; |
| 839 | guint uevent_id; |
| 840 | guint uevent_bus_hooked = 0; |
| 841 | guint uevent_device_hooked = 0; |
| 842 | |
| 843 | |
| 844 | static void uevent_cb(GUdevClient *client, const char *action, GUdevDevice *device, void *data) |
| 845 | { |
| 846 | guint64 devicenum; |
| 847 | guint vendor; |
| 848 | guint model; |
| 849 | guint busnum; |
| 850 | guint devnum; |
| 851 | guint mtpdevice; |
| 852 | |
| 853 | devicenum = (guint64) g_udev_device_get_device_number(device); |
| 854 | g_print("%s event for %s (%"G_GINT64_MODIFIER"x)", action, |
| 855 | g_udev_device_get_sysfs_path (device), devicenum); |
| 856 | |
| 857 | /* get device info */ |
| 858 | vendor = get_property_as_int(device, "ID_VENDOR_ID", 16); |
| 859 | model = get_property_as_int(device, "ID_MODEL_ID", 16); |
| 860 | busnum = get_property_as_int(device, "BUSNUM", 10); |
| 861 | devnum = get_property_as_int(device, "DEVNUM", 10); |
| 862 | mtpdevice = get_property_as_int(device, "ID_MTP_DEVICE", 10); |
| 863 | |
| 864 | if (vendor == 0 || model == 0) { |
| 865 | g_print("couldn't get vendor or model ID for device at (%x:%x)\n", |
| 866 | busnum, devnum); |
| 867 | return; |
| 868 | } else { |
| 869 | g_print("vendor = %x, model = %x, bus = %x, device = %x\n", |
| 870 | vendor, model, busnum, devnum); |
| 871 | } |
| 872 | |
| 873 | if (mtpdevice) { |
| 874 | g_print("device is MTP compliant\n"); |
| 875 | |
| 876 | if (g_str_equal(action, "add") && |
| 877 | uevent_bus_hooked == 0 && |
| 878 | uevent_device_hooked == 0) { |
| 879 | g_print(MTP device plugged in!\n"); |
| 880 | uevent_bus_hooked = busnum; |
| 881 | uevent_device_hooked = devnum; |
| 882 | scan_jukebox(NULL); |
| 883 | } else if (g_str_equal (action, "remove") && |
| 884 | uevent_bus_hooked == busnum && |
| 885 | uevent_device_hooked == devnum) { |
| 886 | g_print("MTP device removed!\n"); |
| 887 | uevent_bus_hooked = 0; |
| 888 | uevent_device_hooked = 0; |
| 889 | } |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | |
| 894 | |
| 895 | (...) |
| 896 | /* |
| 897 | * Monitor udev device events - we're only really interested in events |
| 898 | * for USB devices. |
| 899 | */ |
| 900 | gudev_client = g_udev_client_new(gudev_subsystems); |
| 901 | uevent_id = g_signal_connect_object(gudev_client, |
| 902 | "uevent", |
| 903 | G_CALLBACK(uevent_cb), |
| 904 | NULL, 0); |