Custom protocol
===============

The virtio and serial plugins use a custom protocol to communicate with
the system under tests.


Packet structure:

  0:	byte	Packet type
  1:	byte	Reserved
  2:	word	overall packet length
  4:	word	client ID
  6:	word	transaction ID
  8:		data

All header words are in network byte order (aka big-endian)


Packet types:

        local => system under tests
  'c'           run command
  'i'           insert file
  'e'           extract file
  'q'           quit
  'I'           interrupt command
  'O'		monitor an event source

        system under tests => local
  'M'           major error code
  'm'           minor error code
  'T'           command timeout

            both directions
  'h'		hello packet (used to establish the client ID for all subsequent packets)
  'D'		channel data
  'X'		channel eof
  'K'		keepalive packet
  'P'		procinfo query/response
  'S'		settle request/response

The length includes the 4 bytes of the header.


Packets are encoded as follows:

  hello		uint8: protocol major version
  		uint8: protocol minor version
		uint16: requested keepalive interval
  chan_data	uint16:	channel_id (commands: 0, 1, 2; extract/inject: 0)
  		followed by the payload
  chan_eof	uint16: channel_id (commands: 0, 1, 2; extract/inject: 0)
  inject	string: user
  		string: filename
		uint32: filemode
  extract	string: user
  		string: filename
  run command	string: user
  		string: command
		uint32:	timeout
		uint32:	request_tty (LSB)
		uint32: reserved1
		uint32: reserved2
  quit		<no data>
  intr		string: signal name
		Note: the xid of the intr packet must equal the xid of
		transaction to be interrupted
  major		uint32: status word
  minor		uint32: status word
  keepalive	<no data>

  procinfo query
		uint32: mask of requested data
		Note: the xid of the intr packet must equal the xid of
		transaction to be interrupted

  procinfo response
		TLV*

		A sequence of TLVs encoding individual fields of the
		procinfo struct. A TLV with type 0 ends the list.

		Each TLV is

		uint8: type
		uint8: len
		<data>

  monitor	the name of the event source to monitor
  		This will establish a transaction on both ends.
		Events are transmitted on channel 0 of the
		transaction

  settle	uint32: seq
		This command must be sent on an open transaction
		that was created by a MONITOR command.

  		The client sends a sequence number. The server
		causes the associated event souce to flush out
		all pending events. When done, the server will
		send a settle response, containing the sequence
		number originally sent by the client.

A string is encoded as a NUL terminated sequence of bytes.
16bit words and 32bit words are in network byte order.
