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
//! DVB Common Interface (CENELEC EN 50221): the host to CICAM wire protocol as
//! typed Rust. The crate parses and builds the transport (TPDU), session
//! (SPDU) and application (APDU) layers, the DVB CI extensions (ETSI TS 101 699)
//! and the CI Plus extension APDUs (ETSI TS 103 205), and builds the `ca_pmt`
//! object a host hands to a Conditional Access Module from a `dvb-si` PMT.
//!
//! It builds on `broadcast-core` (the `Parse`/`Serialize` contract),
//! `broadcast-common`, `dvb-si` (the PMT and `CA_descriptor`) and `mpeg-ts`
//! (`Pid`); `dvb-ci-runtime` drives real devices on top of it. The crate is
//! sans-IO and `no_std` + `alloc`: it never touches a device, implements no
//! CI Plus cryptography and is not a descrambler. Every object round-trips
//! byte for byte, including a non-minimal `length_field` a CAM sent.
//!
//! # Quickstart
//!
//! Build a `ca_info` APDU, then route it by its 3-byte tag without knowing the
//! type in advance:
//!
//! ```rust
//! use broadcast_core::Serialize;
//! use dvb_ci::AnyApdu;
//! use dvb_ci::length::LengthForm;
//! use dvb_ci::objects::ca_info::CaInfo;
//!
//! let info = CaInfo {
//! length_form: LengthForm::Minimal,
//! ca_system_ids: vec![0x0500, 0x0B00],
//! };
//! let wire = info.try_to_bytes()?;
//! assert_eq!(wire, [0x9F, 0x80, 0x31, 0x04, 0x05, 0x00, 0x0B, 0x00]);
//!
//! let any = AnyApdu::parse(&wire)?;
//! assert_eq!(any.name(), "CA_INFO");
//! assert_eq!(any.try_to_bytes()?, wire);
//! # Ok::<(), dvb_ci::Error>(())
//! ```
//!
//! # How do I...
//!
//! - Build a `ca_pmt` from a PMT: [`builder::build_ca_pmt`],
//! `examples/build_ca_pmt.rs`.
//! - Restrict a `ca_pmt` to the CAM's advertised CA system ids:
//! [`builder::build_ca_pmt_for_caids`], no example yet.
//! - Parse any application object by tag and re-serialize it: [`AnyApdu`],
//! `examples/parse_apdu.rs`.
//! - Frame APDUs in a session and find where the body starts:
//! [`spdu::SessionNumber`], `examples/session_apdu.rs`.
//! - Open a session for a resource: [`spdu::OpenSessionRequest`],
//! `examples/session_apdu.rs`.
//! - Identify a resource and tell extension resources apart:
//! [`ResourceId`], [`ci_ext::classify`], `examples/session_apdu.rs`.
//! - Parse a TS 101 699 extension APDU (tags collide, so the resource id comes
//! first): [`ci_ext::CiExtApdu`], no example yet.
//! - Parse a CI Plus APDU: [`ci_plus::CiPlusApdu`], no example yet.
//! - Frame a transport command or response: [`tpdu::CommandTpdu`],
//! [`tpdu::ResponseTpdu`], no example yet.
//!
//! # Modules
//!
//! Application layer: [`objects`] (EN 50221 resource objects: Resource Manager,
//! Application Information, CA Support, Date-Time, Host Control, MMI,
//! Low-Speed Communications), [`any`] (unified tag dispatch), [`tag`] (the
//! 3-byte `apdu_tag`), [`traits`] (the dispatch trait), [`builder`] (`ca_pmt`
//! from a PMT).
//!
//! Extension resources: [`ci_ext`] (ETSI TS 101 699, dispatched by resource
//! id), [`ci_plus`] (ETSI TS 103 205, dispatched by resource id).
//!
//! Lower layers and framing: [`spdu`] (session objects), [`tpdu`] (transport
//! objects), [`length`] (the ASN.1 `length_field` with its coding form
//! preserved), [`resource`] (the 4-octet resource identifier).
//!
//! Shared vocabulary: [`error`] (typed errors).
//!
//! # Feature flags
//!
//! - `std` (default): links `std` and the siblings' `std`; off gives
//! `no_std` + `alloc`.
//! - `serde`: `serde::Serialize` on the public types (not the preserved
//! `length_form` or reserved bits).
//!
//! # Spec citations
//!
//! CENELEC EN 50221 (February 1997): section 7 and Table 1 (`length_field`),
//! section 7.2.4 to 7.2.7 (SPDU), Annex A.4.1 (TPDU), section 8.2.2
//! (`resource_identifier`), section 8.4.3.4 (`ca_pmt`), section 8.8.2 and Table
//! 58 (`apdu_tag`); ETSI TS 101 699 V1.1.1 section 8 and Table 87; ETSI
//! TS 103 205 V1.4.1; transcriptions under
//! `private/specs-verified/dvb/dvb-ci/`.
extern crate alloc;
;
pub use AnyApdu;
pub use ;
pub use ResourceId;
pub use ApduTag;
pub use ApduDef;