1// Copyright 2022 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
45use super::*;
6use std::sync::atomic::Ordering;
78/// Error type indicating that a platform reset has been requested.
9#[derive(thiserror::Error, Debug, Hash)]
10#[error("PlatformResetRequested")]
11pub struct PlatformResetRequested {}
1213impl PlatformBacking {
14fn on_plat_reset(&self, instance: Option<&ot::Instance>) {
15#[no_mangle]
16unsafe extern "C" fn otPlatReset(instance: *mut otsys::otInstance) {
17 PlatformBacking::on_plat_reset(
18// SAFETY: Must only be called from OpenThread thread,
19PlatformBacking::as_ref(),
20// SAFETY: `instance` must be a pointer to a valid `otInstance`,
21 // which is guaranteed by the caller.
22ot::Instance::ref_from_ot_ptr(instance),
23 )
24 }
2526if let Some(instance) = instance {
27 instance.thread_set_enabled(false).unwrap();
28 instance.ip6_set_enabled(false).unwrap();
29 }
30// end the stream
31self.is_platform_reset_requested.store(true, Ordering::SeqCst);
32info!("on_plat_reset for {:?}", instance);
33 }
34}