Skip to content

Commit

Permalink
usb: Set default mode to 3 to include CDC NCM, and fix a log message
Browse files Browse the repository at this point in the history
  • Loading branch information
nikias committed Sep 19, 2023
1 parent 91aa7be commit c7a0dd9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,15 @@ static void get_mode_cb(struct libusb_transfer* transfer)
unsigned char *data = libusb_control_transfer_get_data(transfer);

char* desired_mode_char = getenv(ENV_DEVICE_MODE);
int desired_mode = desired_mode_char ? atoi(desired_mode_char) : 1;
int desired_mode = desired_mode_char ? atoi(desired_mode_char) : 3;

This comment has been minimized.

Copy link
@httpstorm

httpstorm Apr 24, 2024

Contributor

Originally mode 1 was used, where a tethered iPhone appears as an Ethernet interface, handled by the ipheth driver. This has been the default for many years and is known to work on iPhone 3G, 4S, 7 Plus, 11 and newer. Since [1-2] ipheth supports CDC NCM in mode 1, and configures the iPhone to use it.
In mode 3, the Ethernet interface is handled by kmod-usb-net-cdc-ncm. This driver has better performance, but now the iPhone does not provide DHCP or Internet connectivity, so we should revert to mode 1. Am I missing some configuration? Has mode 3 been tested? Analysing the network traffic, shows that both the iPhone and OpenWRT are DHCP clients trying to obtain an address. But the iPhone does not act as a DHCP server. I can set a static IP address on OpenWRT and make it lease 172.20.10.1 to the iPhone. Then I can ping the iPhone and I have IPv4 connectivity. I used this to benchmark the network speed. However the iPhone does not provide Internet connectivity to OpenWRT. Maybe in mode 3, the iPhone is a client meant to receive Internet over USB and therefore it is not a gateway?

Attempts to switch old iPhones, such as 3G and 4S to mode 3 fail. They remain in mode 1 and work correctly using the ipheth driver. No issues here.

Comparison, tested on iPhone 7 Plus and 11

  • mode 1 eth0 kmod-usb-net-ipheth 264 Mbit/s DHCP server, Internet
  • mode 3 usb0 kmod-usb-net-cdc-ncm 304 Mbit/s DHCP client, no Internet

The libimobiledevice packages are compiled from [3], which includes the latest releases or commits (where no recent release is available).

[1] torvalds/linux@a2d274c
[2] openwrt/openwrt@680f873
[3] https://github.com/httpstorm/openwrt.packages/commits/libimobiledevice-2024-04-16/

@nikias @FunkyM @BalkanMadman @rickmark @Blefish @marcan

This comment has been minimized.

Copy link
@mbilker

mbilker Jul 19, 2024

Thank you for this comment. I was trying to use tethering from my iPhone to my Linux laptop and was not getting an connection until I saw this and set the USBMUXD_DEFAULT_DEVICE_MODE environment variable to 1 to use the ipheth interface for tethering.

This comment has been minimized.

Copy link
@httpstorm

httpstorm Jul 19, 2024

Contributor

@mbilker
Thanks, for the confirmation. I opened a support request here #252 hopefully we will receive some comments from the usbmuxd maintainers.

int guessed_mode = guess_mode(context->dev, dev);

// 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 &&
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, context->wIndex);
usbmuxd_log(LL_WARNING, "Switching device %i-%i mode to %i", context->bus, context->address, desired_mode);

context->bRequest = APPLE_VEND_SPECIFIC_SET_MODE;
context->wValue = 0;
Expand Down

1 comment on commit c7a0dd9

@hiepnh0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.