• Blog
Picture

It's the Simple Things

How to detect Iphone/Ipad connection

7/28/2017

0 Comments

 
UsbMuxd protocol

What is UsbMuxd ?

It's a protocol used by Iphone/Ipad to comunicate via USB with the computer, for example Itunes.
It's almost like a TCP connection on the device.

How does it work ?
  • You first have to open a connection with the usbmuxd driver on the computer.For windows this driver is installed with itunes.
For mac it's already there.
  • Then you have to open a tcp connection :For windows on "localhost:27015"
For mac on "/var/run/usbmuxd"
  • When the connection is established you can start sending request.
Request is composed of a header and Plist format.

The header contains 16 bytes.
4 bytes for the lenghts of the whole msg (16 + the plist size)
4 bytes for a version always 1
4 bytes for a request always 8
4 bytes for a tag always 1 ....

Plist format is an xml key/value format.
For example if you want to start listening on device connection/disconnection you have to send :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MessageType</key>
<string>Listen</string>
<key>ClientVersionString</key>
<string>mogaleaf-usbmux-driver</string>
<key>ProgName</key>
<string>mogaleaf-usbmux-driver</string>
</dict>
</plist>


When an Iphone is plugged on the device driver will sent you notification :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DeviceID</key>
<integer>3</integer>
<key>MessageType</key>
<string>Attached</string>
<key>Properties</key>
<dict>
<key>ConnectionType</key>
<string>USB</string>
<key>DeviceID</key>
<integer>3</integer>
<key>LocationID</key>
<integer>0</integer>
<key>ProductID</key>
<integer>4776</integer>
<key>SerialNumber</key>
<string>aa5b2be5e67b91e327846994dab3f93019e22342</string>
</dict>
</dict>
</plist>


For a disconnection:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DeviceID</key>
<integer>3</integer>
<key>MessageType</key>
<string>Detached</string>
</dict>
</plist>

  • When you get your deviceId you can request a connection for an open port on the device.
Port 62078 is always opened to listen for itunes connection.
So if you want to connect to that port, you will open a new connection on my usbmuxd first, then send a connection request for that port.
You will receive a result message telling me if my connection is established. If so you can start communication.

Message to request a connection on port 62078:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MessageType</key>
<string>Connect</string>
<key>ClientVersionString</key>
<string>mogaleaf-usbmux-driver</string>
<key>ProgName</key>
<string>mogaleaf-usbmux-driver</string>
<key>DeviceID</key>
<integer>4</integer>
<key>PortNumber</key>
<integer>32498</integer>
</dict>
</plist>


(Port has to be in network endian, that's why the value is changed)

Result message :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>MessageType</key>
<string>Result</string>
<key>Number</key>
<integer>0</integer>
</dict>
</plist>


0 -> OK 
Other than 0 -> problem

When 0 connection is established and communication is possible on the tcp socket.

Java API :

API in java






0 Comments



Leave a Reply.

    Author

    Cécile Thiebaut

    Archives

    July 2017
    March 2012

    Categories

    All
    DRIVER
    Gwt
    IOT
    Java

    RSS Feed

Powered by Create your own unique website with customizable templates.
  • Blog