1use crate::Error;
3
4#[derive(Debug, PartialEq, Eq)]
15#[cfg_attr(feature = "defmt", derive(defmt::Format))]
16pub struct UiccLink(());
17
18impl UiccLink {
19 pub async fn new() -> Result<Self, Error> {
21 if unsafe { !nrfxlib_sys::nrf_modem_is_initialized() } {
22 return Err(Error::ModemNotInitialized);
23 }
24
25 crate::MODEM_RUNTIME_STATE.activate_uicc().await?;
26
27 Ok(Self(()))
28 }
29
30 pub async fn deactivate(self) -> Result<(), Error> {
34 core::mem::forget(self);
35 let result = crate::MODEM_RUNTIME_STATE.deactivate_uicc().await;
36
37 if result.is_err() {
38 crate::MODEM_RUNTIME_STATE.set_error_active();
39 }
40
41 result
42 }
43}
44
45impl Drop for UiccLink {
46 fn drop(&mut self) {
47 #[cfg(feature = "defmt")]
48 defmt::warn!(
49 "Turning off UICC synchronously. Use async function `deactivate` to avoid blocking and to get more guarantees that the modem is actually shut off."
50 );
51
52 if let Err(_e) = crate::MODEM_RUNTIME_STATE.deactivate_uicc_blocking() {
53 #[cfg(feature = "defmt")]
54 defmt::error!("Could not turn off the UICC: {}", _e);
55 crate::MODEM_RUNTIME_STATE.set_error_active();
56 }
57 }
58}