diff options
| author | 2021-01-09 04:04:56 +0100 | |
|---|---|---|
| committer | 2021-01-09 04:04:56 +0100 | |
| commit | bf2e2ec054102286ad6ab272be42c21034c136ed (patch) | |
| tree | 66c83b90fe249b48468cd59f5dbe4c03232956bb | |
| parent | 63d1164e736d7419198d1b737d10a9aae85bef98 (diff) | |
| download | usbmuxd-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.
| -rw-r--r-- | src/usb.c | 26 |
1 files changed, 25 insertions, 1 deletions
| @@ -395,7 +395,31 @@ static int usb_device_add(libusb_device* dev) | |||
| 395 | 395 | ||
| 396 | int desired_config = devdesc.bNumConfigurations; | 396 | int desired_config = devdesc.bNumConfigurations; |
| 397 | if (desired_config > 4) { | 397 | if (desired_config > 4) { |
| 398 | desired_config = 4; | 398 | if (desired_config > 5) { |
| 399 | usbmuxd_log(LL_ERROR, "Device %d-%d has more than 5 configurations, but usbmuxd doesn't support that. Choosing configuration 5 instead.", bus, address); | ||
| 400 | desired_config = 5; | ||
| 401 | } | ||
| 402 | /* verify if the configuration 5 is actually usable */ | ||
| 403 | do { | ||
| 404 | struct libusb_config_descriptor *config; | ||
| 405 | const struct libusb_interface_descriptor *intf; | ||
| 406 | if (libusb_get_config_descriptor_by_value(dev, 5, &config) != 0) { | ||
| 407 | usbmuxd_log(LL_WARNING, "Device %d-%d: Failed to get config descriptor for configuration 5, choosing configuration 4 instead.", bus, address); | ||
| 408 | desired_config = 4; | ||
| 409 | break; | ||
| 410 | } | ||
| 411 | if (config->bNumInterfaces != 3) { | ||
| 412 | usbmuxd_log(LL_WARNING, "Device %d-%d: Ignoring possibly bad configuration 5, choosing configuration 4 instead.", bus, address); | ||
| 413 | desired_config = 4; | ||
| 414 | break; | ||
| 415 | } | ||
| 416 | intf = &config->interface[2].altsetting[0]; | ||
| 417 | if (intf->bInterfaceClass != 0xFF || intf->bInterfaceSubClass != 0x2A || intf->bInterfaceProtocol != 0xFF) { | ||
| 418 | usbmuxd_log(LL_WARNING, "Device %d-%d: Ignoring possibly bad configuration 5, choosing configuration 4 instead.", bus, address); | ||
| 419 | desired_config = 4; | ||
| 420 | break; | ||
| 421 | } | ||
| 422 | } while (0); | ||
| 399 | } | 423 | } |
| 400 | int current_config = 0; | 424 | int current_config = 0; |
| 401 | if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { | 425 | if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { |
