dvb-ci-runtime
Pure-Rust EN 50221 DVB Common Interface runtime — the driver loop over the
dvb-ci wire codecs.
dvb-ci is no_std and owns the wire layer (TPDU / SPDU / APDU
parse+serialize, CA_PMT building, CI Plus extensions). dvb-ci-runtime adds the
runtime: device I/O, the TPDU poll loop, SPDU session management, and the
per-resource state machines that drive a physical CAM (ETSI EN 50221, TS 101 699).
Design
Everything is written against the CaDevice trait, so the runtime runs against
either a real Linux CA device (/dev/dvb/adapterN/caM, the linux feature) or an
in-memory MockCaDevice. The mock makes the state machines testable without
hardware and enables differential testing against an external reference — drive
both with the same scripted mock CAM, assert the emitted write/ioctl byte
sequences match.
Implemented from the EN 50221 specification.
What's implemented
- Transport (TPDU, §A.4):
Create_T_Chandshake, poll cadence,T_SBdata-available →T_RCV,T_Data_More/Lastreassembly, reply timeout. - Session (SPDU, §7.2): session table;
open_session/create_session/close;session_number+ APDU routing. - Resources (§8): Resource Manager handshake →
CamReady, application_information, conditional_access (ca_pmt/ca_pmt_reply), date_time (MJD + BCD), mmi (surfaces module menus/enquiries). - Descramble helper:
Driver::descramble(pmt)/HostRequest::Descrambleruns the fullca_pmtquery → reply →ok_descramblingsequence, filtered to the CAM's advertised CAIDs (fromca_info). - Devices: in-memory
MockCaDevice+MockCiDataDevice; Linux/dev/dvb/adapterN/caM(control plane) andciM(TS data plane,CiDataDevice— scrambled-in / descrambled-out for separate-CI hardware) behind thelinuxfeature (libc). - Diagnostics:
RecordingCaDevicecaptures the link both ways;trace::decode_frame/decode_logannotate a capture (TPDU → SPDU → APDU) for live-CAM debugging.
The EN 50221 link is polled half-duplex — the host sends one T_Data_Last per
module T_SB. The transport queues outbound SPDUs and releases one per turn (a
real CAM drops a second block sent before it answers the first — #337).
#![deny(unsafe_code)] — the Linux device leaf is the sole #[allow]; the
sans-IO core is unsafe-free. 27 tests, no hardware required.
Roadmap: the host_control resource, MMI answering (menu_answ/answ), and a
differential test harness against an external reference.
Example
use Duration;
use ;
use tags;
// Script a module that accepts the transport connection.
let dev = new;
let mut driver = new;
driver.init?; // reset + open the transport connection
for _ in 0..4
for note in driver.take_notifications
# Ok::
See examples/ for a runnable version.
License
MIT OR Apache-2.0.