1#![no_std]
2
3pub const MTU: usize = 1514;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum NetError {
7 NoPacket,
8 TxQueueFull,
9 BufferTooSmall,
10 NotReady,
11 LinkDown,
12 DeviceNotFound,
13}
14
15impl core::fmt::Display for NetError {
16 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
17 match self {
18 Self::NoPacket => f.write_str("no packet available"),
19 Self::TxQueueFull => f.write_str("transmit queue full"),
20 Self::BufferTooSmall => f.write_str("buffer too small"),
21 Self::NotReady => f.write_str("device not ready"),
22 Self::LinkDown => f.write_str("link down"),
23 Self::DeviceNotFound => f.write_str("device not found"),
24 }
25 }
26}
27
28pub trait NetworkDevice: Send + Sync {
34 fn name(&self) -> &str;
35 fn receive(&self, buf: &mut [u8]) -> Result<usize, NetError>;
36 fn transmit(&self, buf: &[u8]) -> Result<(), NetError>;
37 fn mac_address(&self) -> [u8; 6];
38 fn link_up(&self) -> bool;
39 fn handle_interrupt(&self) {}
40
41 fn poll(&self) {}
45}