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 {
18 match self {
19 Self::NoPacket => f.write_str("no packet available"),
20 Self::TxQueueFull => f.write_str("transmit queue full"),
21 Self::BufferTooSmall => f.write_str("buffer too small"),
22 Self::NotReady => f.write_str("device not ready"),
23 Self::LinkDown => f.write_str("link down"),
24 Self::DeviceNotFound => f.write_str("device not found"),
25 }
26 }
27}
28
29pub trait NetworkDevice: Send + Sync {
35 fn name(&self) -> &str;
37 fn receive(&self, buf: &mut [u8]) -> Result<usize, NetError>;
39 fn transmit(&self, buf: &[u8]) -> Result<(), NetError>;
41 fn mac_address(&self) -> [u8; 6];
43 fn link_up(&self) -> bool;
45 fn handle_interrupt(&self) {}
47}