usbmuxd: fix tethering not working after iPhone restart
authorGeorgi Valkov <gvalkov@gmail.com>
Sat, 20 Apr 2024 23:12:49 +0000 (02:12 +0300)
committerRosen Penev <rosenp@gmail.com>
Sun, 21 Apr 2024 20:45:57 +0000 (13:45 -0700)
If the iPhone restarts while the USB cable is still connected,
tethering does not work. This can be fixed by reconnecting.

Fix: if the hotplug.d script detects that carrier is disabled
(no communication), the USB link is reset, and then the
usbmuxd service is restarted. Tethering starts even before
the iPhone is unlocked. As a side effect, if tethering is not
enabled, the iPhone will ding a second time after 5 seconds.

Add dependency on usbutils for usbreset, remove dependency on librt.

[1] https://github.com/libimobiledevice/usbmuxd/issues/218
[2] https://github.com/openwrt/openwrt/issues/12566#issuecomment-2066305622

Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
utils/usbmuxd/Makefile
utils/usbmuxd/files/usbmuxd.hotplug [new file with mode: 0644]

index 32fbc6857f47cf893c45667d8b713c8985b0384c..e584d9106c683008742e3ff9517c4f36ed166249 100644 (file)
@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
 
 PKG_NAME:=usbmuxd
 PKG_VERSION:=1.1.1
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=https://www.libimobiledevice.org/downloads
@@ -31,7 +31,7 @@ define Package/usbmuxd
   SUBMENU:=libimobiledevice
   TITLE:=USB multiplexing daemon
   URL:=https://www.libimobiledevice.org/
-  DEPENDS:=+librt +libusb-1.0 +libusbmuxd +libopenssl +libimobiledevice
+  DEPENDS:=+libusb-1.0 +libusbmuxd +libopenssl +libimobiledevice +usbutils
 endef
 
 define Package/usbmuxd/description
@@ -50,7 +50,9 @@ endef
 CONFIGURE_ARGS += --with-systemd
 
 define Package/usbmuxd/install
+       $(INSTALL_DIR) $(1)/etc/hotplug.d/usb
        $(INSTALL_DIR) $(1)/etc/init.d
+       $(INSTALL_BIN) ./files/usbmuxd.hotplug $(1)/etc/hotplug.d/usb/40-usbmuxd
        $(INSTALL_BIN) ./files/usbmuxd.init $(1)/etc/init.d/usbmuxd
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/usbmuxd $(1)/usr/sbin/
diff --git a/utils/usbmuxd/files/usbmuxd.hotplug b/utils/usbmuxd/files/usbmuxd.hotplug
new file mode 100644 (file)
index 0000000..84986cc
--- /dev/null
@@ -0,0 +1,24 @@
+case "$ACTION" in
+       bind)
+               dev=/sys$DEVPATH
+
+               [ ! -f /tmp/iPhone.lock ] && [ -d ${dev}/net ] &&
+               {
+                       readlink ${dev}/driver | grep -q 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