Trait axdriver::prelude::NetDriverOps
source · pub trait NetDriverOps<'a>: BaseDriverOps {
// Required methods
fn mac_address(&self) -> EthernetAddress;
fn can_transmit(&self) -> bool;
fn can_receive(&self) -> bool;
fn rx_queue_size(&self) -> usize;
fn tx_queue_size(&self) -> usize;
fn fill_rx_buffers(
&mut self,
buf_pool: &'a NetBufferPool
) -> Result<(), DevError>;
fn prepare_tx_buffer(
&self,
tx_buf: &mut NetBuffer<'_>,
packet_len: usize
) -> Result<(), DevError>;
fn recycle_rx_buffer(
&mut self,
rx_buf: Box<NetBuffer<'a>, Global>
) -> Result<(), DevError>;
fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>;
fn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>;
}
net
only.Expand description
Operations that require a network device (NIC) driver to implement.
'a
indicates the lifetime of the network buffers.
Required Methods§
sourcefn mac_address(&self) -> EthernetAddress
fn mac_address(&self) -> EthernetAddress
The ethernet address of the NIC.
sourcefn can_transmit(&self) -> bool
fn can_transmit(&self) -> bool
Whether can transmit packets.
sourcefn can_receive(&self) -> bool
fn can_receive(&self) -> bool
Whether can receive packets.
sourcefn rx_queue_size(&self) -> usize
fn rx_queue_size(&self) -> usize
Size of the receive queue.
sourcefn tx_queue_size(&self) -> usize
fn tx_queue_size(&self) -> usize
Size of the transmit queue.
sourcefn fill_rx_buffers(
&mut self,
buf_pool: &'a NetBufferPool
) -> Result<(), DevError>
fn fill_rx_buffers( &mut self, buf_pool: &'a NetBufferPool ) -> Result<(), DevError>
Fills the receive queue with buffers.
It should be called once when the driver is initialized.
sourcefn prepare_tx_buffer(
&self,
tx_buf: &mut NetBuffer<'_>,
packet_len: usize
) -> Result<(), DevError>
fn prepare_tx_buffer( &self, tx_buf: &mut NetBuffer<'_>, packet_len: usize ) -> Result<(), DevError>
Prepares a buffer for transmitting.
e.g., fill the header of the packet.
sourcefn recycle_rx_buffer(
&mut self,
rx_buf: Box<NetBuffer<'a>, Global>
) -> Result<(), DevError>
fn recycle_rx_buffer( &mut self, rx_buf: Box<NetBuffer<'a>, Global> ) -> Result<(), DevError>
Gives back the rx_buf
to the receive queue for later receiving.
rx_buf
should be the same as the one returned by
NetDriverOps::receive
.
sourcefn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>
fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> Result<(), DevError>
Transmits a packet in the buffer to the network, and blocks until the request completed.
tx_buf
should be initialized by NetDriverOps::prepare_tx_buffer
.
sourcefn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>
fn receive(&mut self) -> Result<Box<NetBuffer<'a>, Global>, DevError>
Receives a packet from the network and store it in the NetBuffer
,
returns the buffer.
Before receiving, the driver should have already populated some buffers
in the receive queue by NetDriverOps::fill_rx_buffers
or
NetDriverOps::recycle_rx_buffer
.
If currently no incomming packets, returns an error with type
DevError::Again
.