From a0c4d8a6fb975d00f3325ef22e1822682ee6bd17 Mon Sep 17 00:00:00 2001 From: Georgi Valkov Date: Sun, 21 Apr 2024 02:12:49 +0300 Subject: [PATCH] usbmuxd: fix tethering not working after iPhone restart 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 --- utils/usbmuxd/Makefile | 6 ++++-- utils/usbmuxd/files/usbmuxd.hotplug | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 utils/usbmuxd/files/usbmuxd.hotplug diff --git a/utils/usbmuxd/Makefile b/utils/usbmuxd/Makefile index 32fbc6857f..e584d9106c 100644 --- a/utils/usbmuxd/Makefile +++ b/utils/usbmuxd/Makefile @@ -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 index 0000000000..84986cc968 --- /dev/null +++ b/utils/usbmuxd/files/usbmuxd.hotplug @@ -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