Binary Protocol for DVBStreamer
===============================

All integers will be in network byte order (ie big endian)

Authentication will be used for changing channel adding pids/services etc, once a
connection has successfully sent an AUTH message that connection will be allowed
to change channels/add outputs etc.

The primary service is identifyable in the service filters list by the name
"<Primary>".

Common Types
------------

         -----------------------------
STRING = |Length (Uint8)| Characters |
         -----------------------------


IPPORT == STRING Where the string is expected to be in the format (IPv6) [::::]:UDPPort or (IPv4) x.x.x.x:UDPPort.

Message Codes
-------------
1 Character describes type and whether it requires authentication.

AUTH = Authenticate message
Cxxx = Control Messages
Sxxx = Status Messages
Rxxx = Response messages

Message Header
--------------

2 byte Message Code
2 byte Message Length
	-----------------------------------------------                  -
	|Message Code (uint16) | Data Length (uint16) | <--- DATA --->   |
	-----------------------------------------------                  -

Rxxx Standard Response Messages
-------------------------------
RERR = Response Error

	DATA
	-----------------------------------------
	| Code (uint8) | Message string (STRING)|
	-----------------------------------------
Code
----
--CODES-START--=RERR

0x00 = OK            = Success
0x01 = NOTAUTHORISED = Not authorised
0x02 = EXISTS        = Output Already Exists
0x03 = NOTFOUND      = Not found
0x04 = STREAMING     = Already streaming to requested ip:port
0xFF = GENERIC       = Generic Error (see message)

--CODES-END--

AUTH Authentication Message
---------------------------

AUTH = Authenticate

	DATA
	---------------------------------------
	| Username (STRING)| password (STRING)|
	---------------------------------------
	Password is in plain text (not ideal but should be ok for the moment)

	Responses : RERR

INFO Information Message
------------------------
INFO = Information message

	DATA
	----------------------------
	|Field to Retrieve (uint8) |
    ----------------------------

	Responses: RERR (OK, with message string containing the data)

Field IDs
---------
--CODES-START--=INFO

0x00 = NAME          = Name (user defined) of this server
0x01 = FETYPE        = Front End Type
0x02 = AUTHENTICATED = Is connection authenticated = "Authenticated" or "Not authenticated"

0xFE = UPSECS        = Uptime string in seconds ie "61" == 1 Minute 1 Second.
0xFF = UPTIME        = Uptime string "%d days %d hours %d minutes %d seconds"

--CODES-END--

QUOTE Message
-------------

QUOT = Quote a command to execute (like FTP quote)

    DATA
	-------------------
	| Command (STRING)|
	-------------------

	Response: RERR (If not authenticated) or RTXT for the text output from the command.

Cxxx Control Messages
---------------------
CSxx = Control Service messages
CSPS = Control Service Primary Select - Select Primary Service

	DATA
	-----------------------
	|Service Name (STRING)|
	-----------------------

	Responses : RERR

CSSA = Control Service Secondary Add - Add secondary service
CSSD = Control Service Set Destination - Set the destination of a service filter
	DATA
	---------------------------------------------------
	|Service Output Name (STRING)| Output MRL (STRING)|
	---------------------------------------------------

	Responses : RERR (Output already exists, Already Streaming to IP:Port)

CSSS = Control Service Secondary Select - Select a secondary service

	DATA
	-------------------------------------------------------
	| Service Output Name (STRING) | Service Name (STRING)|
	-------------------------------------------------------

	Responses : RERR (No Such Output)

CSSR = Control Service Secondary Remove - Remove secondary service

	DATA
	------------------------------
	|Service Output Name (STRING)|
	------------------------------

	Responses: RERR (No Such Output)

COxx = Control Output messages
COAO = Control Output Add Output - Add a new manual filter
COSD = Control Output Set destination - Set the destination of a manual filter
	DATA
	-------------------------------------------
	| Output Name (STRING)|Output MRL (STRING)|
	-------------------------------------------
	Responses : RERR

CORO = Control Output Remove Output - Remove an manual filter

	DATA
	-----------------------
	| Output Name (STRING)|
	-----------------------
	Responses : RERR

COAP = Control Output Add PIDs - Add pids to an output.
CORP = Control Output remove PIDs - Remove pids from an output.

	DATA
	---------------------------------------------------------     -
	|Output Name (STRING)| PID Count (uint16) |PID (Uint16) | ... |
	---------------------------------------------------------     -

	Responses : RERR

Sxxx Status Messages
--------------------
SSxx = Status Service messages
SSPC = Status Service Primary Current - Return current service name for primary output.

	No Data section

	Responses: RERR (No Service Selected),  RERR (OK, with message string containing the data)

SSSL = Status Service Secondary List - List secondary outputs.

	No Data section

	Responses: RSSL

SOLO = Status Outputs List outputs

	No Data section

	Responses: ROLO

SOLP = Status Output List pids

	DATA
	-----------------------
	| Output Name (STRING)|
	-----------------------

	Responses: RPL, RERR (Output Not found)


SOPC = Status Output Packet Count

	DATA
	-----------------------
	| Output Name (STRING)|
	-----------------------

	Responses: ROPC, RERR (Output Not found)

STSS = Status TS Stats

	No Data section

	Responses: RTSS

SFES = Status Front End Status

	No Data section

	Responses: RFES

SSL = Status List Services

    DATA
    ---------------------
    | Multiplex (uint32)|
    ---------------------

    Where Multiplex can be the ID of a multiplex to list services on that multiplex,

--CODES-START--=SSLMULTIPLEX

0x00000000 = ALL     = All services
0xffffffff = CURRENT = Current Multiplex

--CODES-END--

    Responses: RSL

SMC = Status Current Multiplex

    No Data section

    Responses: RLM (with only 1 multiplex in)

SML = Status List Multiplexes

    No Data section

    Responses: RLM

SSPL = Status Services List PIDs

	DATA
	-----------------------
	|Service Name (STRING)|
	-----------------------

	Responses : RERR, RLP


Rxxx Response Messages
----------------------
RSSL = Response Service Secondary List

	DATA (header)

	----------------------------------
	| # of Secondary Services (uint8)|
	----------------------------------

	(repeated)
	---------------------------------------------------------------------------
	| Service Output Name (STRING) |Output MRL (STRING)| Service Name (STRING)|
	---------------------------------------------------------------------------


ROLO = Response  Outputs List outputs

	DATA (header)

	---------------------------------
	| # of Secondary Outputs (uint8)|
	---------------------------------

	(repeated)
	------------------------------------------      -
	|Output Name (STRING)|Output MRL (STRING)| .....|
	------------------------------------------      -



RLP = Response List pids

	DATA
	---------------------------------------     --
	| # of PIDs (uint16) | PID 0 (uint16) | ..... |
    ---------------------------------------     --



ROPC = Response Output Packet Count

	DATA
	-------------------------
 	| Packet Count (uint32) |
	-------------------------



RTSS = Response TS Stats

	DATA (PC = Packet count (uint32))
	----------------------------------------------------------
	| bitrate (uint32) | Total PC | PAT PC | PMT PC | SDT PC |
    ----------------------------------------------------------


RFES = Response Front End Status

	DATA

	---------------------------------------------------------------------------
	| Status (uint8) | BER (uint32) | SNR (uint16) | Signal Strength (uint16) |
	---------------------------------------------------------------------------

RLS  = Response Services List

	DATA
	------------------------------------------------     --
	|Services Count (uint16)| Service Name (STRING)| ...  |
	------------------------------------------------     --

RTXT = Response Text

    Entire contents of the packet is printable characters for text output from
    commands.

	DATA
	-----    --
	|Text ... |
	-----    --

RLM = Response Mulitplex List

    DATA
    --------------------------------------------------    -
    | # of multiplexes (uint8)| Multiplex 0 (uint32) |....|
    --------------------------------------------------    -

Message Codes/Names to Values
-----------------------------
--CODES-START--=MSGCODE

0x0000 = INFO = Information message
0x0001 = AUTH = Authenticate
0x0002 = QUOT = Quote command

0x1101 = CSPS = Control Service Primary Select - Select Primary Service
0x1102 = CSSA = Control Service Secondary Add - Add secondary service
0x1103 = CSSS = Control Service Secondary Select - Select a secondary service
0x1104 = CSSR = Control Service Secondary Remove - Remove secondary service
0x1105 = CSSD = Control Service Set Destination - Set the destination of a service filter
0x1201 = COAO = Control Output Add Output - Add a new output destination
0x1202 = CORO = Control Output Remove Output - Remove an output destination
0x1203 = COAP = Control Output Add PIDs - Add pids to an output.
0x1204 = CORP = Control Output remove PIDs - Remove pids from an output.
0x1205 = COSD = Control Output Set destination - Set the destination of a manual filter

0x2101 = SSPS = Status Service Primary Service - Return current service name for primary service output.
0x2102 = SSFL = Status Service Filter List - List service filters outputs.
0x2103 = SSPC = Status Service Packet Count
0x2201 = SOLO = Status Outputs List outputs
0x2202 = SOLP = Status Output List pids
0x2203 = SOPC = Status Output Packet Count
0x2F01 = STSS = Status TS Stats
0x2F02 = SFES = Status Front End Status
0x2F03 = SSL  = Status List Services
0x2F04 = SMC  = Status Current Multiplex
0x2F05 = SML  = Status List Multiplexes
0x2F06 = SSPL = Status Services List PIDs

0xF001 = RSSL = Response Service Secondary List
0xF002 = ROLO = Response Outputs List outputs
0xF003 = RLP  = Response Output List pids
0xF004 = ROPC = Response Output Packet Count
0xF005 = RTSS = Response TS Stats
0xF006 = RFES = Response Front End Status
0xF007 = RLS  = Response Services List
0xF008 = RTXT = Response Text
0xF009 = RLM  = Response Mulitplex List
0xFFFF = RERR = Response Error


--CODES-END--

Script to produce header file
-----------------------------
Use binaryprotocol_cheader.awk to create the msgcodes.h file,
or
Use binaryprotocol_python.awk to create a python file containing all the codes.
