1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//! 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:
//!
//! ```rust
//! 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
//! }
//! }
//! # Ok::<(), std::io::Error>(())
//! ```
//!
//! # How do I...
//!
//! - Drive a CAM from a loop: [`Driver`] (`init`, `pump`, `take_notifications`),
//! `examples/mock_cam_session.rs`.
//! - Run the protocol with no device, thread or clock: [`CiStack`], [`Event`],
//! [`Action`], `examples/sans_io_core.rs`.
//! - React to CAM insertion and removal: [`HotPlug`],
//! [`Driver::pump_hotplug`], `examples/hot_plug.rs`.
//! - Capture and read an annotated link trace:
//! [`device::RecordingCaDevice`], [`trace::decode_log`],
//! `examples/trace_session.rs`.
//! - Push scrambled TS through the CAM and read it back descrambled:
//! [`CaDescrambler`], [`MockCiDataDevice`], `examples/descrambler_feed.rs`.
//! - Descramble a service from its PMT and track the active set:
//! [`Driver::add_service`], [`Driver::set_cat`], no example yet.
//! - Answer a CAM menu or enquiry: [`Driver::mmi_menu_answer`],
//! [`Driver::mmi_enquiry_answer`], no example yet.
//! - Test without hardware: [`MockCaDevice`], `examples/mock_cam_session.rs`.
//! - Talk to a real slot on Linux: the `linux` module (`LinuxCaDevice`,
//! `LinuxCiDataDevice`) and the `ci-probe` binary, both behind feature
//! `linux`; no example yet.
//!
//! # 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/`.
// The portable core is unsafe-free; only the optional Linux device leaf
// (`#[allow(unsafe_code)]` in `linux`) uses ioctls, so this is `deny`, not
// `forbid`.
;
pub use ;
pub use CaDescrambler;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use TransportBounds;