Skip to main content

Driver

Struct Driver 

Source
pub struct Driver<D: CaDevice> { /* private fields */ }
Expand description

Drives a CaDevice with the CiStack.

Implementations§

Source§

impl<D: CaDevice> Driver<D>

Source

pub fn new(device: D) -> Self

New driver over device, single transport connection.

Examples found in repository?
examples/mock_cam_session.rs (line 18)
15fn main() -> std::io::Result<()> {
16    // Script a module that accepts the transport connection (C_T_C_Reply).
17    let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
18    let mut driver = Driver::new(dev);
19
20    // Bring the interface up: reset + open the transport connection.
21    driver.init()?;
22    println!("init: sent {} device op(s)", driver.device().ops.len());
23
24    // Pump the device. When readable it reads a frame and feeds the stack;
25    // otherwise it advances the EN 50221 poll cadence by the timeout.
26    for step in 0..5 {
27        let read = driver.pump(Duration::from_millis(100))?;
28        println!("pump {step}: processed_frame={read}");
29    }
30
31    // Anything the host application needs to act on surfaces as a Notification.
32    for note in driver.take_notifications() {
33        match note {
34            Notification::CamReady => println!("note: CAM ready — safe to send ca_pmt"),
35            Notification::ApplicationInfo { menu, .. } => {
36                println!("note: application_information menu={menu:?}")
37            }
38            Notification::CaInfo { ca_system_ids } => {
39                println!("note: ca_info system_ids={ca_system_ids:?}")
40            }
41            other => println!("note: {other:?}"),
42        }
43    }
44
45    // The mock records every device op (writes/ioctls) — handy for assertions.
46    println!("total recorded device ops: {}", driver.device().ops.len());
47    Ok(())
48}
Source

pub fn device(&self) -> &D

Borrow the underlying device (e.g. to inspect a mock’s recorded ops).

Examples found in repository?
examples/mock_cam_session.rs (line 22)
15fn main() -> std::io::Result<()> {
16    // Script a module that accepts the transport connection (C_T_C_Reply).
17    let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
18    let mut driver = Driver::new(dev);
19
20    // Bring the interface up: reset + open the transport connection.
21    driver.init()?;
22    println!("init: sent {} device op(s)", driver.device().ops.len());
23
24    // Pump the device. When readable it reads a frame and feeds the stack;
25    // otherwise it advances the EN 50221 poll cadence by the timeout.
26    for step in 0..5 {
27        let read = driver.pump(Duration::from_millis(100))?;
28        println!("pump {step}: processed_frame={read}");
29    }
30
31    // Anything the host application needs to act on surfaces as a Notification.
32    for note in driver.take_notifications() {
33        match note {
34            Notification::CamReady => println!("note: CAM ready — safe to send ca_pmt"),
35            Notification::ApplicationInfo { menu, .. } => {
36                println!("note: application_information menu={menu:?}")
37            }
38            Notification::CaInfo { ca_system_ids } => {
39                println!("note: ca_info system_ids={ca_system_ids:?}")
40            }
41            other => println!("note: {other:?}"),
42        }
43    }
44
45    // The mock records every device op (writes/ioctls) — handy for assertions.
46    println!("total recorded device ops: {}", driver.device().ops.len());
47    Ok(())
48}
Source

pub fn next_timer(&self) -> Option<Duration>

The poll delay the stack most recently requested, if any.

Source

pub fn take_notifications(&mut self) -> Vec<Notification>

Drain the notifications collected so far.

Examples found in repository?
examples/mock_cam_session.rs (line 32)
15fn main() -> std::io::Result<()> {
16    // Script a module that accepts the transport connection (C_T_C_Reply).
17    let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
18    let mut driver = Driver::new(dev);
19
20    // Bring the interface up: reset + open the transport connection.
21    driver.init()?;
22    println!("init: sent {} device op(s)", driver.device().ops.len());
23
24    // Pump the device. When readable it reads a frame and feeds the stack;
25    // otherwise it advances the EN 50221 poll cadence by the timeout.
26    for step in 0..5 {
27        let read = driver.pump(Duration::from_millis(100))?;
28        println!("pump {step}: processed_frame={read}");
29    }
30
31    // Anything the host application needs to act on surfaces as a Notification.
32    for note in driver.take_notifications() {
33        match note {
34            Notification::CamReady => println!("note: CAM ready — safe to send ca_pmt"),
35            Notification::ApplicationInfo { menu, .. } => {
36                println!("note: application_information menu={menu:?}")
37            }
38            Notification::CaInfo { ca_system_ids } => {
39                println!("note: ca_info system_ids={ca_system_ids:?}")
40            }
41            other => println!("note: {other:?}"),
42        }
43    }
44
45    // The mock records every device op (writes/ioctls) — handy for assertions.
46    println!("total recorded device ops: {}", driver.device().ops.len());
47    Ok(())
48}
Source

pub fn init(&mut self) -> Result<()>

Bring the interface up (reset + open the transport connection).

Examples found in repository?
examples/mock_cam_session.rs (line 21)
15fn main() -> std::io::Result<()> {
16    // Script a module that accepts the transport connection (C_T_C_Reply).
17    let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
18    let mut driver = Driver::new(dev);
19
20    // Bring the interface up: reset + open the transport connection.
21    driver.init()?;
22    println!("init: sent {} device op(s)", driver.device().ops.len());
23
24    // Pump the device. When readable it reads a frame and feeds the stack;
25    // otherwise it advances the EN 50221 poll cadence by the timeout.
26    for step in 0..5 {
27        let read = driver.pump(Duration::from_millis(100))?;
28        println!("pump {step}: processed_frame={read}");
29    }
30
31    // Anything the host application needs to act on surfaces as a Notification.
32    for note in driver.take_notifications() {
33        match note {
34            Notification::CamReady => println!("note: CAM ready — safe to send ca_pmt"),
35            Notification::ApplicationInfo { menu, .. } => {
36                println!("note: application_information menu={menu:?}")
37            }
38            Notification::CaInfo { ca_system_ids } => {
39                println!("note: ca_info system_ids={ca_system_ids:?}")
40            }
41            other => println!("note: {other:?}"),
42        }
43    }
44
45    // The mock records every device op (writes/ioctls) — handy for assertions.
46    println!("total recorded device ops: {}", driver.device().ops.len());
47    Ok(())
48}
Source

pub fn send_ca_pmt(&mut self, ca_pmt: &[u8]) -> Result<()>

Request the module descramble the services in ca_pmt (a serialized ca_pmt APDU body, e.g. from dvb_ci::build_ca_pmt).

Source

pub fn descramble(&mut self, pmt_section: &[u8]) -> Result<()>

Descramble the services in a PMT section: the stack filters the PMT’s CA_descriptors to the CAM’s advertised CAIDs, sends a ca_pmt query, and auto-sends ok_descrambling once the ca_pmt_reply confirms it. Drive pump afterwards to exchange the reply; the outcome surfaces as Notification::CaPmtReply. Call after the CAM is ready and its ca_info has been received (otherwise no CAID filter is applied).

Source

pub fn mmi_menu_answer(&mut self, choice_ref: u8) -> Result<()>

Answer an MMI menu/list by 1-based choice_ref (0 = back/cancel).

Source

pub fn mmi_enquiry_answer(&mut self, text: &[u8]) -> Result<()>

Answer an MMI enquiry with the user’s input (EN 300 468 Annex A bytes).

Source

pub fn mmi_cancel(&mut self) -> Result<()>

Abort the current MMI dialogue (answ with answ_id = cancel).

Source

pub fn enter_menu(&mut self) -> Result<()>

Ask the module to open its MMI menu (enter_menu) — e.g. to read card / entitlement info from the module’s own menus.

Source

pub fn pump(&mut self, timeout: Duration) -> Result<bool>

One pump step: if the device is readable within timeout, read a frame and feed it; otherwise advance the stack’s timers by timeout (driving the poll cadence). Returns whether a frame was processed.

Examples found in repository?
examples/mock_cam_session.rs (line 27)
15fn main() -> std::io::Result<()> {
16    // Script a module that accepts the transport connection (C_T_C_Reply).
17    let dev = MockCaDevice::new([vec![tags::C_T_C_REPLY, 0x01, 0x01]]);
18    let mut driver = Driver::new(dev);
19
20    // Bring the interface up: reset + open the transport connection.
21    driver.init()?;
22    println!("init: sent {} device op(s)", driver.device().ops.len());
23
24    // Pump the device. When readable it reads a frame and feeds the stack;
25    // otherwise it advances the EN 50221 poll cadence by the timeout.
26    for step in 0..5 {
27        let read = driver.pump(Duration::from_millis(100))?;
28        println!("pump {step}: processed_frame={read}");
29    }
30
31    // Anything the host application needs to act on surfaces as a Notification.
32    for note in driver.take_notifications() {
33        match note {
34            Notification::CamReady => println!("note: CAM ready — safe to send ca_pmt"),
35            Notification::ApplicationInfo { menu, .. } => {
36                println!("note: application_information menu={menu:?}")
37            }
38            Notification::CaInfo { ca_system_ids } => {
39                println!("note: ca_info system_ids={ca_system_ids:?}")
40            }
41            other => println!("note: {other:?}"),
42        }
43    }
44
45    // The mock records every device op (writes/ioctls) — handy for assertions.
46    println!("total recorded device ops: {}", driver.device().ops.len());
47    Ok(())
48}

Auto Trait Implementations§

§

impl<D> !RefUnwindSafe for Driver<D>

§

impl<D> !Send for Driver<D>

§

impl<D> !Sync for Driver<D>

§

impl<D> !UnwindSafe for Driver<D>

§

impl<D> Freeze for Driver<D>
where D: Freeze,

§

impl<D> Unpin for Driver<D>
where D: Unpin,

§

impl<D> UnsafeUnpin for Driver<D>
where D: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.