//----------------------------------------------------------------------------
//
// TSDuck - The MPEG Transport Stream Toolkit
// Copyright (c) 2005-2025, Thierry Lelegard
// BSD-2-Clause license, see LICENSE.txt file or https://tsduck.io/license
//
//----------------------------------------------------------------------------

<<<
=== tsecmg

[.cmd-header]
Minimal generic DVB SimulCrypt-compliant ECMG

This utility behaves as a DVB SimulCrypt compliant ECMG.
It can be used to debug system integration, replacing any standard ECM Generator.
Most DVB SimulCrypt parameters can be adjusted from the command line to test the behaviour of an SCS.

This fake ECMG can be used with the `tsp` plugin named `scrambler` to build an end-to-end demo of a DVB SimulCrypt system.

This fake ECMG accepts all Super_CAS_Id values.
All ECM requests are instantaneously responded.
The returned ECM is a fake one.
The fake ECM's are TLV messages containing the access criteria and the control words as sent by the SCS in clear format.

*Warning*: It is obvious that this ECMG shall never be used on a production system since
it returns ECM's with clear control words.

[.usage]
Usage

[source,shell]
----
$ tsecmg [options]
----

[.usage]
Network options

[.opt]
*--no-reuse-port*

[.optdoc]
Disable the reuse port socket option.
Do not use unless completely necessary.

[.opt]
*-o* +
*--once*

[.optdoc]
Accept only one client and exit at the end of the session.

[.opt]
*-p* _value_ +
*--port* _value_

[.optdoc]
TCP port number of the ECMG server.
Default: 2222.

[.usage]
DVB SimulCrypt options

[.opt]
*--ac-delay-start* _value_

[.optdoc]
This option sets the DVB SimulCrypt option AC_delay_start, in milliseconds.
By default, use the same value as `--delay-start`.

[.opt]
*--ac-delay-stop* _value_

[.optdoc]
This option sets the DVB SimulCrypt option AC_delay_stop, in milliseconds.
By default, use the same value as `--delay-stop`.

[.opt]
*--comp-time* _value_

[.optdoc]
This option specifies the computation time of an ECM.
The clear ECM's which are generated by this ECMG take no time to generate.
But, in order to emulate the behaviour of a real ECMG,
this parameter forces a delay of the specified duration before returning an ECM.

[.opt]
*-c* _value_ +
*--cw-per-ecm* _value_

[.optdoc]
Specify the required number of control words per ECM.
This option sets the DVB SimulCrypt option CW_per_msg.
It also set lead_CW to CW_per_msg - 1.
By default, use 2 control words per ECM, the current one and next one.

[.opt]
*--delay-start* _value_

[.optdoc]
This option sets the DVB SimulCrypt option delay_start, in milliseconds.
Default: 200 ms.

[.opt]
*--delay-stop* _value_

[.optdoc]
This option sets the DVB SimulCrypt option delay_stop, in milliseconds.
Default: 200 ms.

[.opt]
*--ecmg-scs-version* _value_

[.optdoc]
Specifies the version of the ECMG{d-arrow}SCS DVB SimulCrypt protocol.
Valid values are 2 and 3. The default is 2.

[.opt]
*--max-comp-time* _value_

[.optdoc]
Specify the maximum ECM computation time in milliseconds.
This option sets the DVB SimulCrypt option max_comp_time.

[.optdoc]
By default, use the value of `--comp-time` (which is zero by default) plus 100 milliseconds.

[.opt]
*-r* _value_ +
*--repetition* _value_

[.optdoc]
This option sets the DVB SimulCrypt option ECM_rep_period, the requested repetition period of ECM's, in milliseconds.

[.optdoc]
The default is 100 milliseconds.

[.opt]
*-s* +
*--section-mode*

[.optdoc]
Return ECM's in section format.
This option sets the DVB SimulCrypt parameter section_TSpkt_flag to zero.

[.optdoc]
By default, ECM's are returned in TS packet format.

[.opt]
*--transition-delay-start* _value_

[.optdoc]
This option sets the DVB SimulCrypt option transition_delay_start, in milliseconds.
Default: -500 milliseconds.

[.opt]
*--transition-delay-stop* _value_

[.optdoc]
This option sets the DVB SimulCrypt option transition_delay_stop, in milliseconds.
Default: 0 ms.

include::{docdir}/opt/group-dvbsim-log.adoc[tags=!*;ecmg]
include::{docdir}/opt/group-asynchronous-log.adoc[tags=!*;short-t]
include::{docdir}/opt/group-common-commands.adoc[tags=!*]
