Author Topic: MTP plugin for Netdrive?  (Read 23952 times)

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2092
  • Karma: +159/-0
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #15 on: July 04, 2016, 11:20:19 am »
Hi Guys,

Thanks, Dave! New log attached. I added the line <HANG> at the point the hang occurs.

OK - this is the same as I'm seeing here. That's actually useful, as it save me wasting a bunch of time trying new usb stacks, etc.

I just wish I knew what was different back when I had this kinda working back in 2013 :) I suspect some change in the libusb code trying to fix issues with either lsusb or cups.

I''ll try get back onto this when I have some free time again.

Cheers,

Paul

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #16 on: October 26, 2016, 05:14:24 pm »
I bought a Moto E (2nd gen) and once again the documentation claimed it works as a mass storage device (MSD) but there are no settings to allow it.
So first I test PTP mode, camerdarie sees photos fine on it, unlike my cheap tablet.
I then recompiled libmtp with the latest libusb and MTP mode also works, at least for one shot. I can turn off MTP mode and turn it back on and once again it seems to work for one shot.
I then retested with Paul's build and it seems to work the same. I have to figure out how to transfer a file with the example programs but it does list all the files using mtp-files.exe.
I'll continue playing it tonight.
BTW, tablet is still the same so I don't think using the latest Lars USB drivers did the trick, just slightly different implementation.
Here's the log from mtp-detect.

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2092
  • Karma: +159/-0
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #17 on: October 27, 2016, 10:14:52 am »
Hey Dave,

I bought a Moto E (2nd gen) and once again the documentation claimed it works as a mass storage device (MSD) but there are no settings to allow it.
So first I test PTP mode, camerdarie sees photos fine on it, unlike my cheap tablet.
I then recompiled libmtp with the latest libusb and MTP mode also works, at least for one shot. I can turn off MTP mode and turn it back on and once again it seems to work for one shot.
I then retested with Paul's build and it seems to work the same. I have to figure out how to transfer a file with the example programs but it does list all the files using mtp-files.exe.
I'll continue playing it tonight.
BTW, tablet is still the same so I don't think using the latest Lars USB drivers did the trick, just slightly different implementation.
Here's the log from mtp-detect.

I need to find some time to get back onto this project.... I have 3 weeks vacation over Christmas, hopefully then :)

Cheers,

Paul

Wim Brul

  • Sr. Member
  • ****
  • Posts: 295
  • Karma: +25/-0
    • View Profile
    • Wim's home page
Re: MTP plugin for Netdrive?
« Reply #18 on: October 27, 2016, 12:17:21 pm »
I looked into detect.log and I see starting on line 1883 :

Code: [Select]
libusb: 2.459000 debug [libusb_open] open 1.2
libusb: 2.459000 debug [os2_open] unable to open device - id= 22b8/2e82  rc= ff0c
libusb: 2.459000 debug [os2_open] open: rc = ff0c, fd -1
libusb: 2.459000 debug [os2_open] open, set device configuration: rc = ff37, fd -1

FF0C= ERROR_I24_GEN_FAILURE. The open fails because it has already been opened before.
FF37= ERROR_DEV_NOT_EXIST. The set configuration fails because of the invalid fd (-1) value.
I suspect that it would have worked with the  fd value (35651590) of the outstanding open.

I wonder about the event reported in line 43:

Code: [Select]
libusb_detach_kernel_driver() failed, continuing anyway...: Error 0

May be thIs is causing the problem? 

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #19 on: October 27, 2016, 04:27:28 pm »
The kernel driver seems harmless, the code from libusb1-glue.c
Code: [Select]
  /*
   * If this device is known to be wrongfully claimed by other kernel
   * drivers (such as mass storage), then try to unload it to make it
   * accessible from user space.
   */
  if (FLAG_UNLOAD_DRIVER(ptp_usb) &&
      libusb_kernel_driver_active(device_handle, ptp_usb->interface)
  ) {
      if (LIBUSB_SUCCESS != libusb_detach_kernel_driver(device_handle, ptp_usb->interface)) {
        perror("libusb_detach_kernel_driver() failed, continuing anyway...");
      }
  }

Further experimentation shows that it doesn't always lose the device but need to do more experiments.
It would be nice to be able to transfer files over USB as currently I move the micro-sd card over to my computer to move files or use ftp. Ftp is slow for lots of small files and I'd like to make the SD card part of the main storage, which means reformatting it in such a way that it won't work for mass storage.

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2092
  • Karma: +159/-0
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #20 on: October 28, 2016, 03:20:09 am »
Hi Wim,

I looked into detect.log and I see starting on line 1883 :

Code: [Select]
libusb: 2.459000 debug [libusb_open] open 1.2
libusb: 2.459000 debug [os2_open] unable to open device - id= 22b8/2e82  rc= ff0c
libusb: 2.459000 debug [os2_open] open: rc = ff0c, fd -1
libusb: 2.459000 debug [os2_open] open, set device configuration: rc = ff37, fd -1

FF0C= ERROR_I24_GEN_FAILURE. The open fails because it has already been opened before.
FF37= ERROR_DEV_NOT_EXIST. The set configuration fails because of the invalid fd (-1) value.
I suspect that it would have worked with the  fd value (35651590) of the outstanding open.

I wonder about the event reported in line 43:

Code: [Select]
libusb_detach_kernel_driver() failed, continuing anyway...: Error 0

May be thIs is causing the problem?

The comment about ff0c is useful. Probably (it's been a while since I looked at libusb), os2_open is setting fd to -1 based on rc not being 0. There probably needs to be a case where there are other acceptable rc's that should not indicate an error.

afair libusb_detach_kernel_driver is just a stub.

Cheers,

Paul

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #21 on: October 28, 2016, 05:21:36 am »
I also successfully transferred a few files to the phone. While it takes a while (a minute or more) to make contact, once the file is transferring, it is very quick, much quicker then transferring using FAT32. Repeat file copying works fine without having to reset the device.
Have to copy mtp.connect.exe to mtp.sendfiles.exe (also mtp-delfiles.exe mtp-newfolder.exe mtp-sendtr.exe) as they are symlinked on make install.
This is using my build. The only patching I did was fix a bashism in configure and added __OS2__ to a couple of places where O_BINARY was set for windows.

Paul Smedley

  • Hero Member
  • *****
  • Posts: 2092
  • Karma: +159/-0
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #22 on: October 28, 2016, 10:36:51 am »
Hi Guys,

Hi Wim,

I looked into detect.log and I see starting on line 1883 :

Code: [Select]
libusb: 2.459000 debug [libusb_open] open 1.2
libusb: 2.459000 debug [os2_open] unable to open device - id= 22b8/2e82  rc= ff0c
libusb: 2.459000 debug [os2_open] open: rc = ff0c, fd -1
libusb: 2.459000 debug [os2_open] open, set device configuration: rc = ff37, fd -1

FF0C= ERROR_I24_GEN_FAILURE. The open fails because it has already been opened before.
FF37= ERROR_DEV_NOT_EXIST. The set configuration fails because of the invalid fd (-1) value.
I suspect that it would have worked with the  fd value (35651590) of the outstanding open.

I wonder about the event reported in line 43:

Code: [Select]
libusb_detach_kernel_driver() failed, continuing anyway...: Error 0

May be thIs is causing the problem?

The comment about ff0c is useful. Probably (it's been a while since I looked at libusb), os2_open is setting fd to -1 based on rc not being 0. There probably needs to be a case where there are other acceptable rc's that should not indicate an error.

http://smedley.id.au/tmp/libusb10.zip ignores ff0c - perhaps it will help with your tablet Dave?

[code
   rc = UsbOpen( (PUSBHANDLE)&usbhandle,
      (USHORT)dpriv->ddesc.idVendor,
      (USHORT)dpriv->ddesc.idProduct,
      (USHORT)dpriv->ddesc.bcdDevice,
      (USHORT)USB_OPEN_FIRST_UNUSED);

   if (rc && rc != ERROR_I24_GEN_FAILURE) {
      usbi_dbg( "unable to open device - id= %x/%x  rc= %x",
         dpriv->ddesc.idVendor,
         dpriv->ddesc.idProduct, (int)rc);
      usbhandle = -1;
      rtn = -1;
   }
[/code]

Cheers,

Paul

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: MTP plugin for Netdrive?
« Reply #23 on: October 28, 2016, 05:39:00 pm »
Not much different. Log attached.