Trait embassy_net_driver::Driver
source · pub trait Driver {
type RxToken<'a>: RxToken
where Self: 'a;
type TxToken<'a>: TxToken
where Self: 'a;
// Required methods
fn receive(
&mut self,
cx: &mut Context<'_>
) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>;
fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>;
fn link_state(&mut self, cx: &mut Context<'_>) -> LinkState;
fn capabilities(&self) -> Capabilities;
fn hardware_address(&self) -> HardwareAddress;
}
Expand description
Main embassy-net
driver API.
This is essentially an interface for sending and receiving raw network frames.
The interface is based on tokens, which are types that allow to receive/transmit a
single packet. The receive
and transmit
functions only construct such tokens, the
real sending/receiving operation are performed when the tokens are consumed.
Required Associated Types§
Required Methods§
sourcefn receive(
&mut self,
cx: &mut Context<'_>
) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>
fn receive( &mut self, cx: &mut Context<'_> ) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)>
Construct a token pair consisting of one receive token and one transmit token.
If there is a packet ready to be received, this function must return Some
.
If there isn’t, it must return None
, and wake cx.waker()
when a packet is ready.
The additional transmit token makes it possible to generate a reply packet based on the contents of the received packet. For example, this makes it possible to handle arbitrarily large ICMP echo (“ping”) requests, where the all received bytes need to be sent back, without heap allocation.
sourcefn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>
fn transmit(&mut self, cx: &mut Context<'_>) -> Option<Self::TxToken<'_>>
Construct a transmit token.
If there is free space in the transmit buffer to transmit a packet, this function must return Some
.
If there isn’t, it must return None
, and wake cx.waker()
when space becomes available.
Note that TxToken::consume
is infallible, so it is not allowed to return a token
if there is no free space and fail later.
sourcefn link_state(&mut self, cx: &mut Context<'_>) -> LinkState
fn link_state(&mut self, cx: &mut Context<'_>) -> LinkState
Get the link state.
This function must return the current link state of the device, and wake cx.waker()
when
the link state changes.
sourcefn capabilities(&self) -> Capabilities
fn capabilities(&self) -> Capabilities
Get a description of device capabilities.
sourcefn hardware_address(&self) -> HardwareAddress
fn hardware_address(&self) -> HardwareAddress
Get the device’s hardware address.
The returned hardware address also determines the “medium” of this driver. This indicates what kind of packet the sent/received bytes are, and determines some behaviors of the interface. For example, ARP/NDISC address resolution is only done for Ethernet mediums.