simulcrypt
Async Rust implementation of the DVB SimulCrypt head-end protocol (ETSI TS 103 197) for the scrambler (SCS) side:
- ECMG client: channel and stream setup, CW_provision, ECM_response, channel_test keepalive, reconnect with CW replay.
- EMMG server: channel and stream setup, bandwidth allocation,
data_provision over TCP, and over UDP when
EmmgConfig::udpis set. - Control word generation and rotation per crypto period, one CW group shared by any number of CAS.
Scrambling, PSI/SI and TS packetization of ECM/EMM belong to the caller.
Usage
use Duration;
use ;
let simulcrypt = new;
let cas = simulcrypt.add_cas?;
let mut service = simulcrypt.open_service?;
while let Some = service.recv.await
The crate spawns its tasks on the ambient Tokio runtime and does not own
one. add_cas with an already registered id applies the new settings
to that CAS and returns its CasRef: open services keep running, the
ECMG connection restarts and the EMMG channel moves when their settings
change. remove_cas detaches a CAS from open services, which keep
running on their other CAS; close removes every CAS. An EMMG listener
closes with the last CAS on its port.
status reports each CAS: connection state, the last ECMG error (kept
after a reconnect), handshake count and, per stream, readiness, the crypto
period on air and ECM/EMM counters. emmg_status reports each EMMG port:
open connections and UDP datagrams dropped without a reply.
Dropping the last Service of a CAS closes its streams and the ECMG
channel; the CasRef stays valid and reconnects on the next
open_service. An EMMG channel belongs to the connection that set it up
until CHANNEL_CLOSE or disconnect.
With EmmgConfig::udp the EMMG port also accepts data_provision
datagrams on UDP, one message per datagram. Channel and stream setup
stay on TCP: a datagram is delivered only to a stream currently set up
over a TCP connection from the same IP, addressed by its channel and
stream ids or, when they are absent, by client_id and data_id. Anything
else is dropped without a reply.
Examples
Each example reads the ECMG address and service settings from environment
variables (ECMG_HOST, ECMG_PORT, SUPER_CAS_ID, ...) with loopback
defaults. TSDuck tsecmg --port 2222 works as a test ECMG.
Development
Formatting uses unstable options from rustfmt.toml, so rustfmt needs the
nightly toolchain. tests/integration/ runs the crate against fake ECMG
and EMM generator peers on loopback.