From bf2e2ec054102286ad6ab272be42c21034c136ed Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sat, 9 Jan 2021 04:04:56 +0100 Subject: usb: Allow configuration 5 after verifying it is actualy usable VMware on macOS somehow exposes a bad configuration 5 for iDevices. Trying to use it breaks things and can end up in a kernel panic on the device. The code change introduced with this commit tries its best to make sure the USB configuration 5 is not 'bad' before switching to it, and otherwise falling back to configuration 4. --- src/usb.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/usb.c b/src/usb.c index 39917ef..571a822 100644 --- a/src/usb.c +++ b/src/usb.c @@ -395,7 +395,31 @@ static int usb_device_add(libusb_device* dev) int desired_config = devdesc.bNumConfigurations; if (desired_config > 4) { - desired_config = 4; + if (desired_config > 5) { + usbmuxd_log(LL_ERROR, "Device %d-%d has more than 5 configurations, but usbmuxd doesn't support that. Choosing configuration 5 instead.", bus, address); + desired_config = 5; + } + /* verify if the configuration 5 is actually usable */ + do { + struct libusb_config_descriptor *config; + const struct libusb_interface_descriptor *intf; + if (libusb_get_config_descriptor_by_value(dev, 5, &config) != 0) { + usbmuxd_log(LL_WARNING, "Device %d-%d: Failed to get config descriptor for configuration 5, choosing configuration 4 instead.", bus, address); + desired_config = 4; + break; + } + if (config->bNumInterfaces != 3) { + usbmuxd_log(LL_WARNING, "Device %d-%d: Ignoring possibly bad configuration 5, choosing configuration 4 instead.", bus, address); + desired_config = 4; + break; + } + intf = &config->interface[2].altsetting[0]; + if (intf->bInterfaceClass != 0xFF || intf->bInterfaceSubClass != 0x2A || intf->bInterfaceProtocol != 0xFF) { + usbmuxd_log(LL_WARNING, "Device %d-%d: Ignoring possibly bad configuration 5, choosing configuration 4 instead.", bus, address); + desired_config = 4; + break; + } + } while (0); } int current_config = 0; if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { -- cgit v1.1-32-gdbae