network/device/
loopback.rs1use crate::{GET_KIND, InterfaceKind};
2use file_system::{
3 ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectCharacterDevice, Error,
4 MountOperations,
5};
6use shared::AnyByLayout;
7pub use smoltcp::phy::Loopback;
8use smoltcp::phy::Medium;
9
10pub struct LoopbackControllerDevice;
11
12impl DirectBaseOperations for LoopbackControllerDevice {
13 fn read(&self, _: &mut [u8], _: file_system::Size) -> file_system::Result<usize> {
14 Err(Error::UnsupportedOperation)
15 }
16
17 fn write(&self, _: &[u8], _: file_system::Size) -> file_system::Result<usize> {
18 Err(Error::UnsupportedOperation)
19 }
20
21 fn control(
22 &self,
23 command: ControlCommandIdentifier,
24 _: &AnyByLayout,
25 output: &mut AnyByLayout,
26 ) -> file_system::Result<()> {
27 match command {
28 GET_KIND::IDENTIFIER => {
29 let kind = GET_KIND::cast_output(output)?;
30 *kind = InterfaceKind::Ethernet;
31 Ok(())
32 }
33 _ => Err(Error::UnsupportedOperation),
34 }
35 }
36}
37
38impl MountOperations for LoopbackControllerDevice {}
39
40impl DirectCharacterDevice for LoopbackControllerDevice {}
41
42pub fn create_loopback_device() -> (Loopback, LoopbackControllerDevice) {
43 (Loopback::new(Medium::Ethernet), LoopbackControllerDevice)
44}