Skip to main content

Crate dvb_ci_runtime

Crate dvb_ci_runtime 

Source
Expand description

EN 50221 DVB Common Interface driver runtime: the device I/O, the TPDU poll loop, SPDU session management and the per-resource state machines that drive a physical Conditional Access Module (CAM), over the dvb-ci wire codecs. It implements CENELEC EN 50221 (February 1997): the Annex A transport and the host-provided Resource Manager, Application Information, Conditional Access Support, Date-Time, MMI and Host Control resources, plus the Linux DVB CA API for real hardware.

It builds on dvb-ci (codecs), dvb-si (PMT and CAT inputs), mpeg-ts and broadcast-common. The core, CiStack, is sans-IO (events in, actions out, the caller owns the clock); Driver runs it against a CaDevice, and CaDescrambler adds the TS data plane. It serves no CI Plus and no Low-Speed Communications, never descrambles itself (the CAM does) and has no no_std claim. Every limit and timeout is the caller’s.

§Quickstart

Bring a slot up against an in-memory CAM and drain the host-facing events:

use std::time::Duration;
use dvb_ci::tpdu::tags;
use dvb_ci_runtime::{
    Driver, DriverBounds, MockCaDevice, Notification, StackBounds, TransportBounds,
};

let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
let bounds = DriverBounds {
    stack: StackBounds {
        transport: TransportBounds {
            poll_interval: Duration::from_millis(100),
            reply_timeout: Duration::from_secs(1),
            max_setup_attempts: 5,
            max_reassembly_len: 2 * 1024 * 1024,
            max_outbound_queue: 64,
        },
        max_sessions: 32,
    },
    max_pending_notifications: 1024,
    slot_ready_grace: Duration::from_secs(12),
    slot_retry: Duration::from_millis(250),
};
let mut driver = Driver::new(dev, bounds);
driver.init()?;
for _ in 0..4 {
    driver.pump(Duration::from_millis(100))?;
}
for note in driver.take_notifications() {
    if let Notification::CamReady = note {
        // now safe to send a ca_pmt
    }
}

§How do I…

§Modules

Host-facing driver: driver (the pump loop and the managed CAS calls), managed (the active-service set, PID routing and re-query), descrambler (turnkey control plus data plane), event (events, actions, host requests, notifications, hot-plug).

Protocol core: stack (the composed sans-IO stack), transport (TPDU poll loop), session (SPDU sessions), resource (the resource state machines).

Devices and diagnostics: device (the control-plane trait, mock and recorder), dataplane (the ciM TS data-plane trait and mock), trace (annotated link traces); the linux module (feature linux, Linux only: the /dev/dvb devices).

§Feature flags

  • linux (off by default): LinuxCaDevice, LinuxCiDataDevice and the ci-probe binary (pulls rustix and clap). Linux only; the portable core needs none of it.

§Spec citations

CENELEC EN 50221 Annex A section A.4 (TPDU transport), section 7.2 (SPDU session layer), section 8 (resources), section 8.4.3.4 and Table 25 (ca_pmt); ISO/IEC 13818-1 section 2.6.16 (CA_descriptor); the Linux linux/dvb/ca.h ABI for the device layer; transcriptions under private/specs-verified/dvb/dvb-ci/.

Re-exports§

pub use dataplane::CiDataDevice;
pub use dataplane::MockCiDataDevice;
pub use dataplane::PartialWrite;
pub use dataplane::partial_write_progress;
pub use descrambler::CaDescrambler;
pub use device::CaDevice;
pub use device::DeviceOp;
pub use device::DeviceOpError;
pub use device::LinkEvent;
pub use device::MAX_CA_FRAME;
pub use device::MockCaDevice;
pub use device::RecordingCaDevice;
pub use device::SlotInfo;
pub use driver::Driver;
pub use driver::DriverBounds;
pub use event::Action;
pub use event::Event;
pub use event::HostRequest;
pub use event::HotPlug;
pub use event::Notification;
pub use linux::CiDataTimings;Linux and linux
pub use linux::LinuxCaDevice;Linux and linux
pub use linux::LinuxCiDataDevice;Linux and linux
pub use managed::CaError;
pub use managed::ManagedCa;
pub use managed::ManagedService;
pub use managed::REQUERY_DEFAULT;
pub use stack::CiStack;
pub use stack::StackBounds;
pub use transport::TransportBounds;

Modules§

dataplane
The CI TS data-plane device: CiDataDevice.
descrambler
Turnkey CAS descrambler — #763 Layer 2.
device
The hardware-abstraction boundary: CaDevice.
driver
The driver — the one place I/O happens. It pumps a CaDevice against the sans-IO CiStack: reads frames in, executes the stack’s Actions (writes/ioctls) out, tracks the requested poll timer, and collects Notifications for the host application.
event
The sans-IO event/action model.
linuxLinux and linux
Linux /dev/dvb/adapterN/caM CaDevice implementation (the linux feature).
managed
Managed CAS-layer state (#763) — the Driver’s owned view of the slot’s active descrambled-service set.
resource
The resource layer — application-layer state machines (ETSI EN 50221 §8), one per resource, driven by the session layer’s APDUs.
session
SPDU session layer — a sans-IO mechanism over the transport layer (ETSI EN 50221 §7.2).
stack
The CI protocol stack — composes the transport + session layers and the resource state machines (Resource Manager, application_information, conditional_access, date_time, mmi, host_control) into one sans-IO core.
trace
Human-readable decoding of CI link frames, for diagnosing live-CAM exchanges (e.g. issue #337).
transport
TPDU transport layer — a sans-IO state machine for the single transport connection per CI slot (ETSI EN 50221 §A.4).