Skip to content

Commit

Permalink
usb: add support for modes 4 and 5
Browse files Browse the repository at this point in the history
* Mode 4
	USB Ethernet + CDC-NCM
	iOS >= 16.0
* Mode 5
	CDC-NCM Direct only (no usbmux, no USB Ethernet, no PTP)
	iOS >= 17.0
  • Loading branch information
Forst authored and nikias committed Sep 14, 2024
1 parent a2dceac commit df80b73
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ static struct usb_device* find_device(int bus, int address)
/// @param dev
/// @param usbdev
/// @param handle
/// @return 0 - undetermined, 1 - initial, 2 - valeria, 3 - cdc_ncm
/// @return 0 - undetermined, 1 - initial, 2 - valeria, 3 - cdc_ncm, 4 - usbeth+cdc_ncm, 5 - cdc_ncm direct
static int guess_mode(struct libusb_device* dev, struct usb_device *usbdev)
{
int res, j;
Expand All @@ -404,11 +404,21 @@ static int guess_mode(struct libusb_device* dev, struct usb_device *usbdev)
int bus = usbdev->bus;
int address = usbdev->address;

if(devdesc.bNumConfigurations == 1) {
// CDC-NCM Direct
return 5;
}

if(devdesc.bNumConfigurations <= 4) {
// Assume this is initial mode
return 1;
}

if(devdesc.bNumConfigurations == 6) {
// USB Ethernet + CDC-NCM
return 4;
}

if(devdesc.bNumConfigurations != 5) {
// No known modes with more then 5 configurations
return 0;
Expand Down Expand Up @@ -699,7 +709,7 @@ static void get_mode_cb(struct libusb_transfer* transfer)

// Response is 3:3:3:0 for initial mode, 5:3:3:0 otherwise.
usbmuxd_log(LL_INFO, "Received response %i:%i:%i:%i for get_mode request for device %i-%i", data[0], data[1], data[2], data[3], context->bus, context->address);
if(desired_mode >= 1 && desired_mode <= 3 &&
if(desired_mode >= 1 && desired_mode <= 5 &&
guessed_mode > 0 && // do not switch mode if guess failed
guessed_mode != desired_mode) {
usbmuxd_log(LL_WARNING, "Switching device %i-%i mode to %i", context->bus, context->address, desired_mode);
Expand Down

0 comments on commit df80b73

Please sign in to comment.