From 1f8ddeff95884da404a7fbd74d27e04ca8c99a50 Mon Sep 17 00:00:00 2001 From: mrmacete Date: Fri, 30 Mar 2018 15:38:43 +0200 Subject: Avoid using configuration 5 - this fixes setting configuration for iOS 11 devices inside virtual machines which caused timeout and subsequent reboot of the device when unplugged from USB --- src/usb.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/usb.c b/src/usb.c index b659d90..364930c 100644 --- a/src/usb.c +++ b/src/usb.c @@ -392,13 +392,17 @@ static int usb_device_add(libusb_device* dev) return -1; } + int desired_config = devdesc.bNumConfigurations; + if (desired_config > 4) { + desired_config = 4; + } int current_config = 0; if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { usbmuxd_log(LL_WARNING, "Could not get configuration for device %d-%d: %d", bus, address, res); libusb_close(handle); return -1; } - if (current_config != devdesc.bNumConfigurations) { + if (current_config != desired_config) { struct libusb_config_descriptor *config; if((res = libusb_get_active_config_descriptor(dev, &config)) != 0) { usbmuxd_log(LL_NOTICE, "Could not get old configuration descriptor for device %d-%d: %d", bus, address, res); @@ -420,9 +424,9 @@ static int usb_device_add(libusb_device* dev) libusb_free_config_descriptor(config); } - usbmuxd_log(LL_INFO, "Setting configuration for device %d-%d, from %d to %d", bus, address, current_config, devdesc.bNumConfigurations); - if((res = libusb_set_configuration(handle, devdesc.bNumConfigurations)) != 0) { - usbmuxd_log(LL_WARNING, "Could not set configuration %d for device %d-%d: %d", devdesc.bNumConfigurations, bus, address, res); + usbmuxd_log(LL_INFO, "Setting configuration for device %d-%d, from %d to %d", bus, address, current_config, desired_config); + if((res = libusb_set_configuration(handle, desired_config)) != 0) { + usbmuxd_log(LL_WARNING, "Could not set configuration %d for device %d-%d: %d", desired_config, bus, address, res); libusb_close(handle); return -1; } -- cgit v1.1-32-gdbae