User Tools

Site Tools


notes:iphone_usbmuxd

This is an old revision of the document!


iPhone usbmuxd

The iPhone and iPod Touch devices have various means of communication with hosts and accessories. This communication is typically over USB excepting analogue video and audio, which themselves vanished with the new Lightning connector. The current devices present several USB configurations each of which has one or more interfaces. The list of configurations on an iPhone 4 and the interfaces presented is shown below:

bConfigurationValue bInterfaceNumber bInterfaceClass bInterfaceSubClass bInterfaceProtocol
PTP
1 0 6: Imaging 1: Still image capture 1: Picture Transfer Protocol
iPod USB Interface
2 0 1: Audio 1: Control device
1 1: Audio 2: Streaming
2 3: HID
PTP + Apple Mobile Device
3 0 6: Imaging 1: Still image capture 1: Picture Transfer Protocol
1 255: Vendor specific 254 2: Apple USB multiplexor
PTP + Apple Mobile Device + Apple USB Ethernet
4 0 6: Imaging 1: Still image capture 1: Picture Transfer Protocol
1 255: Vendor specific 254 2: Apple USB multiplexor
2 255: Vendor specific 253 1

Conventional accessories typically communicate by switching the device into USB configuration 2, which makes audio and HID interfaces available. The HID interface is then used to speak the iPod Accessory Protocol (iAP) using HID reports as a transport for iAP packets. This requires authentication using a chip which Apple provide, however, so they can retain control of the accessory ecosystem.

iTunes communicates using a different method, however, since it has to run on consumer PCs which don't have any special authentication hardware. Configuration 4 contains vendor-specific interfaces which are used to multiplex TCP-like connections over the USB link to connect to services on the device. Here are some useful links about this process:

  • usbmux — an overview of the architecture and some protocol exchanges.
  • Linux usbmuxd — a blog post about the stack used on Linux to communicate with iDevices.
  • usbmuxd README — the README from the above project's repository, which has some more useful information.

To facilitate the operation of usbmuxd the device needs to be put into the appropriate USB configuration. The following is an excerpt from /lib/udev/rules.d/85-usbmuxd.rules (line breaks added for clarity):

# Forces iDevices to the last USB configuration and runs usbmuxd
ACTION=="add", SUBSYSTEM=="usb", OWNER="usbmux",
    ATTR{idVendor}=="05ac", ATTR{idProduct}=="12[9a][0-9a-f]",
    ENV{USBMUX_SUPPORTED}="1", ATTR{bConfigurationValue}!="$attr{bNumConfigurations}",
    ATTR{bConfigurationValue}="$attr{bNumConfigurations}",
    RUN+="/usr/sbin/usbmuxd -u -U usbmux"

The interpretation of this rule is as follows:

  • If a USB device is being added
    • And it has vendor ID of 0x05ac (Apple)
    • And it has a product ID of 0x12[9a][0-9a-f]
    • And its USB configuration isn't currently the highest one available
  • Then perform the following:
    • Change the device's USB configuration to the highest available
    • Set the device owner to the user usbmux
    • Set the environment variable USBMUX_SUPPORTED
    • Run /usr/sbin/usbmuxd -u -U usbmux
notes/iphone_usbmuxd.1349868454.txt.gz · Last modified: 2012/10/12 07:32 (external edit)