Embassy
embassy-net

Crates

git

Versions

default

Flavors

Struct embassy_net::Stack

source ·
pub struct Stack<D: Driver> { /* private fields */ }
Expand description

A network stack.

This is the main entry point for the network stack.

Implementations§

source§

impl<D: Driver> Stack<D>

source

pub fn new<const SOCK: usize>( device: D, config: Config, resources: &'static mut StackResources<SOCK>, random_seed: u64 ) -> Self

Create a new network stack.

source

pub fn hardware_address(&self) -> HardwareAddress

Get the hardware address of the network interface.

Get whether the link is up.

source

pub fn is_config_up(&self) -> bool

Get whether the network stack has a valid IP configuration. This is true if the network stack has a static IP configuration or if DHCP has completed

source

pub async fn wait_config_up(&self)

Wait for the network stack to obtain a valid IP configuration.

§Notes:
  • Ensure Stack::run has been called before using this function.

  • This function may never return (e.g. if no configuration is obtained through DHCP). The caller is supposed to handle a timeout for this case.

§Example
let config = embassy_net::Config::dhcpv4(Default::default());
static RESOURCES: StaticCell<embassy_net::StackResources<2> = StaticCell::new();
static STACK: StaticCell<embassy_net::Stack> = StaticCell::new();
let stack = &*STACK.init(embassy_net::Stack::new(
   device,
   config,
   RESOURCES.init(embassy_net::StackResources::new()),
   seed
));
// Launch network task that runs `stack.run().await`
spawner.spawn(net_task(stack)).unwrap();
// Wait for DHCP config
stack.wait_config_up().await;
// use the network stack
// ...
source

pub fn config_v4(&self) -> Option<StaticConfigV4>

Get the current IPv4 configuration.

If using DHCP, this will be None if DHCP hasn’t been able to acquire an IP address, or Some if it has.

source

pub fn config_v6(&self) -> Option<StaticConfigV6>

Get the current IPv6 configuration.

source

pub fn set_config_v4(&self, config: ConfigV4)

Set the IPv4 configuration.

source

pub fn set_config_v6(&self, config: ConfigV6)

Set the IPv6 configuration.

source

pub async fn run(&self) -> !

Run the network stack.

You must call this in a background task, to process network events.

source

pub async fn dns_query( &self, name: &str, qtype: DnsQueryType ) -> Result<Vec<IpAddress, { smoltcp::config::DNS_MAX_RESULT_COUNT }>, Error>

Make a query for a given name and return the corresponding IP addresses.

source§

impl<D: Driver> Stack<D>

source

pub async fn join_multicast_group<T>( &self, addr: T ) -> Result<bool, MulticastError>
where T: Into<IpAddress>,

Join a multicast group.

source

pub fn poll_join_multicast_group<T>( &self, addr: T, cx: &mut Context<'_> ) -> Poll<Result<bool, MulticastError>>
where T: Into<IpAddress>,

Join a multicast group.

When the send queue is full, this method will return Poll::Pending and register the current task to be notified when the queue has space available.

source

pub async fn leave_multicast_group<T>( &self, addr: T ) -> Result<bool, MulticastError>
where T: Into<IpAddress>,

Leave a multicast group.

source

pub fn poll_leave_multicast_group<T>( &self, addr: T, cx: &mut Context<'_> ) -> Poll<Result<bool, MulticastError>>
where T: Into<IpAddress>,

Leave a multicast group.

When the send queue is full, this method will return Poll::Pending and register the current task to be notified when the queue has space available.

source

pub fn has_multicast_group<T: Into<IpAddress>>(&self, addr: T) -> bool

Get whether the network stack has joined the given multicast group.

Auto Trait Implementations§

§

impl<D> !Freeze for Stack<D>

§

impl<D> !RefUnwindSafe for Stack<D>

§

impl<D> Send for Stack<D>
where D: Send,

§

impl<D> !Sync for Stack<D>

§

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

§

impl<D> !UnwindSafe for Stack<D>

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>,

§

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>,

§

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.