hermit/drivers/net/
mod.rs

1#[cfg(all(target_arch = "riscv64", feature = "gem-net"))]
2pub mod gem;
3#[cfg(all(target_arch = "x86_64", feature = "rtl8139"))]
4pub mod rtl8139;
5#[cfg(not(all(target_arch = "x86_64", feature = "rtl8139")))]
6pub mod virtio;
7
8use smoltcp::phy::ChecksumCapabilities;
9
10#[allow(unused_imports)]
11use crate::arch::kernel::core_local::*;
12use crate::drivers::Driver;
13use crate::executor::device::{RxToken, TxToken};
14
15/// A trait for accessing the network interface
16pub(crate) trait NetworkDriver: Driver {
17	/// Returns smoltcp's checksum capabilities
18	fn get_checksums(&self) -> ChecksumCapabilities {
19		ChecksumCapabilities::default()
20	}
21	/// Returns the mac address of the device.
22	fn get_mac_address(&self) -> [u8; 6];
23	/// Returns the current MTU of the device.
24	fn get_mtu(&self) -> u16;
25	/// Get buffer with the received packet
26	fn receive_packet(&mut self) -> Option<(RxToken, TxToken)>;
27	/// Send packet with the size `len`
28	fn send_packet<R, F>(&mut self, len: usize, f: F) -> R
29	where
30		F: FnOnce(&mut [u8]) -> R;
31	/// Check if a packet is available
32	#[allow(dead_code)]
33	fn has_packet(&self) -> bool;
34	/// Enable / disable the polling mode of the network interface
35	fn set_polling_mode(&mut self, value: bool);
36	/// Handle interrupt and check if a packet is available
37	fn handle_interrupt(&mut self);
38}