xref: /DragonOS/kernel/src/driver/net/mod.rs (revision 79ad6e5ba4cf7fd624dfa91a1de35d7e60bdda43)
1 use alloc::string::String;
2 use smoltcp::{
3     iface,
4     wire::{self, EthernetAddress},
5 };
6 
7 use super::base::device::Device;
8 use crate::libs::spinlock::SpinLock;
9 use system_error::SystemError;
10 
11 mod dma;
12 pub mod e1000e;
13 pub mod irq_handle;
14 pub mod loopback;
15 pub mod virtio_net;
16 
17 pub trait NetDevice: Device {
18     /// @brief 获取网卡的MAC地址
19     fn mac(&self) -> EthernetAddress;
20 
21     fn name(&self) -> String;
22 
23     /// @brief 获取网卡的id
24     fn nic_id(&self) -> usize;
25 
26     fn poll(&self, sockets: &mut iface::SocketSet) -> Result<(), SystemError>;
27 
28     fn update_ip_addrs(&self, ip_addrs: &[wire::IpCidr]) -> Result<(), SystemError>;
29 
30     /// @brief 获取smoltcp的网卡接口类型
31     fn inner_iface(&self) -> &SpinLock<smoltcp::iface::Interface>;
32     // fn as_any_ref(&'static self) -> &'static dyn core::any::Any;
33 }
34