libimobiledevice/usbmuxd

tethering does not work after iPhone reboot until the USB cable is reconnected

httpstorm opened this issue · 0 comments

I use the libimobiledevice and ipheth on my OpenWRT router with iPhone 7 Plus. Pretty much everything works great and tethering starts as soon as I plug the USB cable.

The only issue I have is if I reboot the iPhone, tethering does not start until the USB cable is reconnected. ifconfig eth0 shows all counters as 0. I added tracing code to the ipheth diver, and I see that when USB is connected, ipheth starts, the carrier flag is set, and then everything works, but after rebooting the iPhone, this flag is not set. I can also monitor this flag through sysfs.

Considering the workaround described below, my best guess is that after iPhone reboot, the LTE network is not yet ready when usbmuxd detects the iPhone. LTE and tethering become available about 2 seconds later. Can you please create a fix? I can compile and test it on my OpenWRT router.

Note: On Windows and macOS tethering works after restarting the iPhone. Sometimes I hear the USB connect sound twice, which means that the driver resets the connection to get it working.

Workaround:

/usr/bin/usbreset iPhone
/etc/init.d/usbmuxd restart
# hotplug.d script for OpenWRT to make tethering work after iPhone reboot
# /etc/hotplug.d/usb/40-iPhone
case "$ACTION" in
	bind)
		dev=/sys$DEVPATH

		[ ! -f /tmp/iPhone.lock ] && [ -d ${dev}/net ] &&
		{
			readlink ${dev}/driver | grep ipheth &&
			{
				sleep 5
				carrier_path=${dev}/net/*/carrier
				carrier=`cat ${carrier_path}`

				[ "${carrier}" == "0" ] &&
				{
					touch /tmp/iPhone.lock
					logger -p daemon.error -t iPhone ${carrier_path} = ${carrier}
					logger -p daemon.error -t iPhone `/usr/bin/usbreset iPhone`
					/etc/init.d/usbmuxd restart
					sleep 5 && rm -f /tmp/iPhone.lock &
				}
			}
		}
		;;
esac