summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2021-01-09 04:04:56 +0100
committerGravatar Nikias Bassen2021-01-09 04:04:56 +0100
commitbf2e2ec054102286ad6ab272be42c21034c136ed (patch)
tree66c83b90fe249b48468cd59f5dbe4c03232956bb /src
parent63d1164e736d7419198d1b737d10a9aae85bef98 (diff)
downloadusbmuxd-bf2e2ec054102286ad6ab272be42c21034c136ed.tar.gz
usbmuxd-bf2e2ec054102286ad6ab272be42c21034c136ed.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/usb.c26
1 files changed, 25 insertions, 1 deletions
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, &current_config)) != 0) {