tihmstar / usbmuxd2

A socket daemon written in C++ to multiplex connections from and to iOS devices over USB and WIFI
GNU Lesser General Public License v3.0
181 stars 38 forks source link

Getting failed connection error failed to recv_data on client X with error=client X disconnected! code=6750218 #27

Closed sepsky closed 6 months ago

sepsky commented 11 months ago

Hi, when I try to list devices available to my Raspberry pi (there is an Apple TV 4th gen on the network, and I can confirm it's available on my wifi using another tool (pyATV, using atvremote command).

I've got idevice_id version of 1.3.0-190-g6fc41f5 and successfully installed usbmuxd2. This is what I get when run usbmuxd -V:

[15:15:57.668][3] starting usbmuxd2 version: 0.46-753b79eaf317c56df6c8b1fb6da5847cc54a0bb0-RELEASE
[15:15:57.670][3] Loaded config
usbmuxd2 version: 0.46-753b79eaf317c56df6c8b1fb6da5847cc54a0bb0-RELEASE

One thing I've noticed, even when I have usbmuxd running, with the below information:

[15:02:41.372][3] starting usbmuxd2 version: 0.46-753b79eaf317c56df6c8b1fb6da5847cc54a0bb0-RELEASE
[15:02:41.373][3] Loaded config
[15:02:41.373][3] starting usbmuxd2 version: 0.46-753b79eaf317c56df6c8b1fb6da5847cc54a0bb0-RELEASE
[15:02:41.374][3] Inited ClientManager
[15:02:41.374][3] USBDeviceManager libusb 1.0
[15:02:41.389][3] Registering for libusb hotplug events
[15:02:41.390][3] Inited USBDeviceManager
[15:02:41.398][3] Inited WIFIDeviceManager
[15:02:41.398][4] Initialization complete
... {usbmuxd is waiting here}

I get this when I run service usbmuxd status:

● usbmuxd.service - Socket daemon for the usbmux protocol used by Apple devices
     Loaded: loaded (/lib/systemd/system/usbmuxd.service; disabled; vendor pres>
     Active: inactive (dead)
       Docs: man:usbmuxd(8)

I am getting the failed to recv_data on client X with error=client X disconnected! code=6750218 (X increments everytime I run idevice_id --list, or any of its variation)

Is there anything we need to do with the client? I read somewhere that this might be an issue with Avahi-Client, but my Avahi is running ok, and I can confirm that when I do :

TriggeredBy: ● avahi-daemon.socket
   Main PID: 381 (avahi-daemon)
     Status: "Server startup complete. Host name is {DEVICE_NAME}.local. Local service cookie is 3412524750."
      Tasks: 1 (limit: 3933)
        CPU: 606ms
     CGroup: /system.slice/avahi-daemon.service
             └─381 avahi-daemon: running [DEVICE_NAME.local]

Jul 28 14:11:55 DEVICE_NAME systemd[1]: Started Avahi mDNS/DNS-SD Stack.
Jul 28 14:11:56 DEVICE_NAME avahi-daemon[381]: Server startup complete. Host name is DEVICE_NAME.local. Local service cookie is 3412524750.
Jul 28 14:11:57 DEVICE_NAME avahi-daemon[381]: Service "DEVICE_NAME" (/usr/local/etc/avahi/services/ssh.service) successfully established.
Jul 28 14:11:57 DEVICE_NAME avahi-daemon[381]: Service "DEVICE_NAME" (/usr/local/etc/avahi/services/sftp-ssh.service) successfully established.
Jul 28 14:12:02 DEVICE_NAME avahi-daemon[381]: Joining mDNS multicast group on interface wlan0.IPv6 with address [DEVICE_MAC_ADDRESS].
Jul 28 14:12:02 DEVICE_NAME avahi-daemon[381]: New relevant interface wlan0.IPv6 for mDNS.
Jul 28 14:12:02 DEVICE_NAME avahi-daemon[381]: Registering new address record for [DEVICE_MAC_ADDRESS] on wlan0.*.
Jul 28 14:12:07 DEVICE_NAME avahi-daemon[381]: Joining mDNS multicast group on interface wlan0.IPv4 with address [DEVICE_IP_ADDRESS].
Jul 28 14:12:07 DEVICE_NAME avahi-daemon[381]: New relevant interface wlan0.IPv4 for mDNS.
Jul 28 14:12:07 DEVICE_NAME avahi-daemon[381]: Registering new address record for [DEVICE_IP_ADDRESS] on wlan0.IPv4.

Thanks a lot and if we need any more information, please let me know and I'll find and provide it.

Lakr233 commented 11 months ago

Same thing happens here, haven’t find a solution.

sepsky commented 11 months ago

no not me either. I've tried both wireless (ATV) and lan. Getting the same error every time.

I've tried both:

I have a strong feeling this is because my socket setup and config could be the culprit, but I don't know where to look / What to look. I've been looking into the original usbmuxd to see how that works.

One thing I have managed to do, I've managed to pair with an iPad using cabled connection, similar to what usbmuxd does.

How have you setup your sockets?

Lakr233 commented 11 months ago

I havn't dive into the code, just compile all the libimobiledevice sutff and libplist etc etc my own and try to do a backup over internet. I have the same feeling on it that I mis-configured something.

Will get back to you if I found something worth sharing :)

sepsky commented 11 months ago

OK thanks for that. I've been looking into the sockets and dbus configuration, given that Avahi uses the dbus.

I'll also update with anything I come across. 👍 :)

sepsky commented 11 months ago

Hey @Lakr233 found anything?

I've been looking around, and stumbled upon a few threads and issues indirectly related to this (I think).

So a lot of people complained about libplist and libplist++ causing problems with some tools that comes with libimobiledevice. I wonder if we have the same issue, because when I put a lot of logs in usbmuxd2/usbmuxd2/Client.cpp for what we pass to recv_data and readData methods, I was receiving some bytes (different values). I wonder (🤔) if the reason Client.cpp thinks we don't have any connection (or connection was refused) is because we receive response about discovered devices in plist format, but because libelist isn't configured properly (even though I can run plistutil fine), we can't read what we receive, and thus failing.

I've been trying to compile and install libplist manually, although not with much success because of the pesky:

./configure: line 12782: syntax error near unexpected token `libplist,'
./configure: line 12782: `PKG_CHECK_MODULES(libplist, libplist-2.0 >= $LIBPLIST_VERSION)'

I'm fixing this at the moment, will update.

Lakr233 commented 11 months ago

Hi, I'm currently doing a different approach to get workaround for usbmuxd2 doing my side project. Here is a script for you to take reference if you need it. It's for macOS but should do the job on Linux with a tiny modification I guess.

https://github.com/Lakr233/AppleMobileDevice/blob/main/Resource/Automation/build.sh

Looking forward on your progress. I have asked around and looks like somebody got it work.

sepsky commented 11 months ago

Hi @Lakr233

Thanks for the message and the script. Yeah ok great, I'll go through the script and use it to setup the dependencies etc.

I tried the approach here: https://www.numerousnetworks.co.uk/guides/untether-ios-step-by-step/ I didn't install libplist from apt-get, and had to make some changes to the code to fix a duplicate declaration, as well as the other PLIST_FORMAT issue circulating in the issues. But this also doesn't work. No device is found. I also used the trick they said, to connect the device first using USB to pair, and then detach. However, when I detach, even though a record of the UDID and the item is showing, I can't connect to the device.

That's great news someone else has got it working. I also read that some other people had managed to fix it, but that was in September 2022.

I really think it's just a dependency issue, and one (or some) of the dependencies aren't working well with others. But I'll try your script and will update with the outcome.

tihmstar commented 6 months ago

Code has undergone a major rewrite since this issue was created.