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