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) -> DevResult;
    fn prepare_tx_buffer(
        &self,
        tx_buf: &mut NetBuffer<'_>,
        packet_len: usize
    ) -> DevResult;
    fn recycle_rx_buffer(&mut self, rx_buf: NetBufferBox<'a>) -> DevResult;
    fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> DevResult;
    fn receive(&mut self) -> DevResult<NetBufferBox<'a>>;
}
Expand description

Operations that require a network device (NIC) driver to implement.

'a indicates the lifetime of the network buffers.

Required Methods§

source

fn mac_address(&self) -> EthernetAddress

The ethernet address of the NIC.

source

fn can_transmit(&self) -> bool

Whether can transmit packets.

source

fn can_receive(&self) -> bool

Whether can receive packets.

source

fn rx_queue_size(&self) -> usize

Size of the receive queue.

source

fn tx_queue_size(&self) -> usize

Size of the transmit queue.

source

fn fill_rx_buffers(&mut self, buf_pool: &'a NetBufferPool) -> DevResult

Fills the receive queue with buffers.

It should be called once when the driver is initialized.

source

fn prepare_tx_buffer( &self, tx_buf: &mut NetBuffer<'_>, packet_len: usize ) -> DevResult

Prepares a buffer for transmitting.

e.g., fill the header of the packet.

source

fn recycle_rx_buffer(&mut self, rx_buf: NetBufferBox<'a>) -> DevResult

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.

source

fn transmit(&mut self, tx_buf: &NetBuffer<'_>) -> DevResult

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.

source

fn receive(&mut self) -> DevResult<NetBufferBox<'a>>

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.

Implementors§