openthread_fuchsia/backing/
mod.rsuse futures::prelude::*;
use openthread::prelude::*;
use spinel_pack::prelude::*;
use fuchsia_async as fasync;
use futures::channel::mpsc as fmpsc;
use lowpan_driver_common::spinel::*;
use std::cell::{Cell, RefCell};
use std::sync::atomic::AtomicBool;
use std::sync::mpsc;
use std::time::Duration;
#[allow(unused_imports)]
use tracing::{debug, error, info, trace, warn};
mod alarm;
mod infra_if;
mod nat64;
mod radio;
mod reset;
mod resolver;
mod trel;
mod udp;
pub(crate) use alarm::*;
pub(crate) use infra_if::InfraIfInstance;
pub(crate) use nat64::{Nat64Instance, Nat64PlatformInstance};
use openthread::ot::NetifIdentifier;
pub(crate) use reset::PlatformResetRequested;
pub(crate) use resolver::*;
pub(crate) use udp::*;
pub(super) struct PlatformBacking {
pub(super) ot_to_rcp_sender: RefCell<mpsc::Sender<Vec<u8>>>,
pub(super) rcp_to_ot_receiver: RefCell<mpsc::Receiver<Vec<u8>>>,
pub(super) alarm: AlarmInstance,
pub(super) netif_index_thread: Option<ot::NetifIndex>,
pub(super) netif_index_backbone: Option<ot::NetifIndex>,
pub(super) trel: RefCell<Option<trel::TrelInstance>>,
pub(super) infra_if: Option<InfraIfInstance>,
pub(super) is_platform_reset_requested: AtomicBool,
pub(super) nat64: Nat64Instance,
pub(super) resolver: Resolver,
}
impl PlatformBacking {
unsafe fn glob() -> &'static mut Option<PlatformBacking> {
static mut SINGLETON_BACKING: Option<PlatformBacking> = None;
#[allow(static_mut_refs)]
&mut SINGLETON_BACKING
}
pub(super) unsafe fn as_ref() -> &'static PlatformBacking {
Self::glob().as_ref().expect("Platform is uninitialized")
}
pub(super) unsafe fn set_singleton(backing: PlatformBacking) {
assert!(Self::glob().replace(backing).is_none(), "Tried to make two Platform instances");
}
pub(super) unsafe fn drop_singleton() {
assert!(Self::glob().take().is_some(), "Tried to drop singleton that was never allocated");
}
}
impl PlatformBacking {
fn lookup_netif_index(&self, id: ot::NetifIdentifier) -> Option<ot::NetifIndex> {
match id {
NetifIdentifier::Backbone => self.netif_index_backbone,
NetifIdentifier::Thread => self.netif_index_thread,
NetifIdentifier::Unspecified => Some(ot::NETIF_INDEX_UNSPECIFIED),
}
}
}