Skip to main content

ssh_stamp_hal/traits/network/
provider.rs

1// SPDX-FileCopyrightText: 2026 Roman Valls Guimera <brainstorm@nopcode.org>
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5//! Generic network-provider hardware abstraction.
6
7use core::future::Future;
8
9use embassy_net::Stack;
10
11use crate::HalError;
12
13/// A platform that can bring up a network interface.
14///
15/// This is the generic cut beneath [`crate::WifiHal`]: it says nothing about
16/// what radio (if any) is attached and only promises to hand back an
17/// [`embassy_net::Stack`] that is up and usable. Implementations may be
18/// backed by built-in `WiFi`, an externally connected module (SDIO/SPI/USB
19/// `WiFi`, ATWINC, cyw43, ESP-AT companion, CDC-NCM over USB), or a wired
20/// Ethernet PHY.
21///
22/// Transport-specific configuration happens through the extended trait for
23/// that transport (for `WiFi`, see [`crate::WifiHal::configure_ap`]). Call
24/// those configuration methods first, then [`Self::bring_up`].
25///
26/// # Example
27///
28/// ```ignore
29/// async fn start<N: NetworkProviderHal>(net: &mut N) -> Result<Stack<'static>, HalError> {
30///     net.bring_up().await
31/// }
32/// ```
33pub trait NetworkProviderHal {
34    /// Bring the network interface up and wait for the link to become ready.
35    ///
36    /// Returns an [`embassy_net::Stack`] that is ready to open sockets on.
37    /// Implementations typically spawn their driver tasks on the embassy
38    /// executor during this call.
39    ///
40    /// # Errors
41    ///
42    /// Returns [`HalError::Wifi`] (or a future transport-specific variant)
43    /// on link-up, DHCP, or driver-init failure.
44    fn bring_up(&mut self) -> impl Future<Output = Result<Stack<'static>, HalError>>;
45}