USB/IP protocol

PRELIMINARY DRAFT, MAY CONTAIN MISTAKES!28 Jun 2011

The USB/IP protocol follows a server/client architecture. The server exports theUSB devices and the clients imports them. The device driver for the exportedUSB device runs on the client machine.

The client may ask for the list of the exported USB devices. To get the list theclient opens a TCP/IP connection towards the server, and sends an OP_REQ_DEVLISTpacket on top of the TCP/IP connection (so the actual OP_REQ_DEVLIST may be sentin one or more pieces at the low level transport layer). The server sends backthe OP_REP_DEVLIST packet which lists the exported USB devices. Finally theTCP/IP connection is closed.

virtual host controller                                 usb host     "client"                                           "server" (imports USB devices)                             (exports USB devices)         |                                                 |         |                  OP_REQ_DEVLIST                 |         | ----------------------------------------------> |         |                                                 |         |                  OP_REP_DEVLIST                 |         | <---------------------------------------------- |         |                                                 |

Once the client knows the list of exported USB devices it may decide to use oneof them. First the client opens a TCP/IP connection towards the server andsends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If theimport was successful the TCP/IP connection remains open and will be usedto transfer the URB traffic between the client and the server. The client maysend two types of packets: the USBIP_CMD_SUBMIT to submit an URB, andUSBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of theserver may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively.

virtual host controller                                 usb host     "client"                                           "server" (imports USB devices)                             (exports USB devices)         |                                                 |         |                  OP_REQ_IMPORT                  |         | ----------------------------------------------> |         |                                                 |         |                  OP_REP_IMPORT                  |         | <---------------------------------------------- |         |                                                 |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = n)         |         | ----------------------------------------------> |         |                                                 |         |            USBIP_RET_SUBMIT(seqnum = n)         |         | <---------------------------------------------- |         |                        .                        |         |                        :                        |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = m)         |         | ----------------------------------------------> |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = m+1)       |         | ----------------------------------------------> |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = m+2)       |         | ----------------------------------------------> |         |                                                 |         |            USBIP_RET_SUBMIT(seqnum = m)         |         | <---------------------------------------------- |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = m+3)       |         | ----------------------------------------------> |         |                                                 |         |            USBIP_RET_SUBMIT(seqnum = m+1)       |         | <---------------------------------------------- |         |                                                 |         |            USBIP_CMD_SUBMIT(seqnum = m+4)       |         | ----------------------------------------------> |         |                                                 |         |            USBIP_RET_SUBMIT(seqnum = m+2)       |         | <---------------------------------------------- |         |                        .                        |         |                        :                        |         |                                                 |         |               USBIP_CMD_UNLINK                  |         | ----------------------------------------------> |         |                                                 |         |               USBIP_RET_UNLINK                  |         | <---------------------------------------------- |         |                                                 |

The fields are in network (big endian) byte order meaning that the most significantbyte (MSB) is stored at the lowest address.

OP_REQ_DEVLIST:
Retrieve the list of exported USB devices.
OffsetLengthValueDescription
020x0100Binary-coded decimal USBIP version number: v1.0.0
220x8005Command code: Retrieve the list of exported USBdevices.
440x00000000Status: unused, shall be set to 0
OP_REP_DEVLIST:
Reply with the list of exported USB devices.
OffsetLengthValueDescription
020x0100Binary-coded decimal USBIP version number: v1.0.0.
220x0005Reply code: The list of exported USB devices.
440x00000000Status: 0 for OK
84nNumber of exported devices: 0 means no exporteddevices.
0x0C  From now on the exported n devices are described,if any. If no devices are exported the messageends with the previous “number of exporteddevices” field.
 256 path: Path of the device on the host exporting theUSB device, string closed with zero byte, e.g.“/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2”The unused bytes shall be filled with zerobytes.
0x10C32 busid: Bus ID of the exported device, stringclosed with zero byte, e.g. “3-2”. The unusedbytes shall be filled with zero bytes.
0x12C4 busnum
0x1304 devnum
0x1344 speed
0x1382 idVendor
0x13A2 idProduct
0x13C2 bcdDevice
0x13E1 bDeviceClass
0x13F1 bDeviceSubClass
0x1401 bDeviceProtocol
0x1411 bConfigurationValue
0x1421 bNumConfigurations
0x1431 bNumInterfaces
0x144 m_0From now on each interface is described, alltogether bNumInterfaces times, with thethe following 4 fields:
 1 bInterfaceClass
0x1451 bInterfaceSubClass
0x1461 bInterfaceProtocol
0x1471 padding byte for alignment, shall be set to zero
0xC +i*0x138 +m_(i-1)*4  The second exported USB device starts at i=1with the busid field.
OP_REQ_IMPORT:
Request to import (attach) a remote USB device.
OffsetLengthValueDescription
020x0100Binary-coded decimal USBIP version number: v1.0.0
220x8003Command code: import a remote USB device.
440x00000000Status: unused, shall be set to 0
832 busid: the busid of the exported device on theremote host. The possible values are takenfrom the message field OP_REP_DEVLIST.busid.A string closed with zero, the unused bytesshall be filled with zeros.
OP_REP_IMPORT:
Reply to import (attach) a remote USB device.
OffsetLengthValueDescription
020x0100Binary-coded decimal USBIP version number: v1.0.0
220x0003Reply code: Reply to import.
440x00000000

Status:

  • 0 for OK
  • 1 for error
8  From now on comes the details of the importeddevice, if the previous status field was OK (0),otherwise the reply ends with the status field.
 256 path: Path of the device on the host exporting theUSB device, string closed with zero byte, e.g.“/sys/devices/pci0000:00/0000:00:1d.1/usb3/3-2”The unused bytes shall be filled with zerobytes.
0x10832 busid: Bus ID of the exported device, stringclosed with zero byte, e.g. “3-2”. The unusedbytes shall be filled with zero bytes.
0x1284 busnum
0x12C4 devnum
0x1304 speed
0x1342 idVendor
0x1362 idProduct
0x1382 bcdDevice
0x1391 bDeviceClass
0x13A1 bDeviceSubClass
0x13B1 bDeviceProtocol
0x13C1 bConfigurationValue
0x13D1 bNumConfigurations
0x13E1 bNumInterfaces
USBIP_CMD_SUBMIT:
Submit an URB
OffsetLengthValueDescription
040x00000001command: Submit an URB
44 seqnum: the sequence number of the URB to submit
84 devid
0xC4 

direction:

  • 0: USBIP_DIR_OUT
  • 1: USBIP_DIR_IN
0x104 ep: endpoint number, possible values are: 0…15
0x144 transfer_flags: possible values depend on theURB transfer type, see below
0x184 transfer_buffer_length
0x1C4 start_frame: specify the selected frame totransmit an ISO frame, ignored if URB_ISO_ASAPis specified at transfer_flags
0x204 number_of_packets: number of ISO packets
0x244 interval: maximum time for the request on theserver-side host controller
0x288 setup: data bytes for USB setup, filled withzeros if not used
0x30  URB data. For ISO transfers the padding betweeneach ISO packets is not transmitted.
Allowed transfer_flagsvaluecontrolinterruptbulkisochronous
URB_SHORT_NOT_OK0x00000001only inonly inonly inno
URB_ISO_ASAP0x00000002nononoyes
URB_NO_TRANSFER_DMA_MAP0x00000004yesyesyesyes
URB_ZERO_PACKET0x00000040nonoonly outno
URB_NO_INTERRUPT0x00000080yesyesyesyes
URB_FREE_BUFFER0x00000100yesyesyesyes
URB_DIR_MASK0x00000200yesyesyesyes
USBIP_RET_SUBMIT:
Reply for submitting an URB
OffsetLengthValueDescription
040x00000003command
44 seqnum: URB sequence number
84 devid
0xC4 

direction:

  • 0: USBIP_DIR_OUT
  • 1: USBIP_DIR_IN
0x104 ep: endpoint number
0x144 status: zero for successful URB transaction,otherwise some kind of error happened.
0x184nactual_length: number of URB data bytes
0x1C4 start_frame: for an ISO frame the actuallyselected frame for transmit.
0x204 number_of_packets
0x244 error_count
0x288 setup: data bytes for USB setup, filled withzeros if not used
0x30n URB data bytes. For ISO transfers the paddingbetween each ISO packets is not transmitted.
USBIP_CMD_UNLINK:
Unlink an URB
OffsetLengthValueDescription
040x00000002command: URB unlink command
44 

seqnum: URB sequence number to unlink:

FIXME:
is this so?
84 devid
0xC4 

direction:

  • 0: USBIP_DIR_OUT
  • 1: USBIP_DIR_IN
0x104 ep: endpoint number: zero
0x144 seqnum: the URB sequence number given previouslyat USBIP_CMD_SUBMIT.seqnum field
0x30n URB data bytes. For ISO transfers the paddingbetween each ISO packets is not transmitted.
USBIP_RET_UNLINK:
Reply for URB unlink
OffsetLengthValueDescription
040x00000004command: reply for the URB unlink command
44 seqnum: the unlinked URB sequence number
84 devid
0xC4 

direction:

  • 0: USBIP_DIR_OUT
  • 1: USBIP_DIR_IN
0x104 ep: endpoint number
0x144 

status: This is the value contained in theurb->status in the URB completition handler.

FIXME:
a better explanation needed.
0x30n URB data bytes. For ISO transfers the paddingbetween each ISO packets is not transmitted.