network/device/
loopback.rs1use crate::{GET_KIND, InterfaceKind};
2use file_system::{
3 ControlCommand, ControlCommandIdentifier, DirectBaseOperations, DirectCharacterDevice,
4 IoErrorKind, 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(
14 &self,
15 _cx: &mut core::task::Context<'_>,
16 _: &mut [u8],
17 _: file_system::Size,
18 ) -> core::task::Poll<file_system::Result<usize>> {
19 file_system::ready(|| Err(IoErrorKind::Unsupported))
20 }
21
22 fn write(
23 &self,
24 _cx: &mut core::task::Context<'_>,
25 _: &[u8],
26 _: file_system::Size,
27 ) -> core::task::Poll<file_system::Result<usize>> {
28 file_system::ready(|| Err(IoErrorKind::Unsupported))
29 }
30
31 fn control(
32 &self,
33 _cx: &mut core::task::Context<'_>,
34 command: ControlCommandIdentifier,
35 _: &AnyByLayout,
36 output: &mut AnyByLayout,
37 ) -> core::task::Poll<file_system::Result<()>> {
38 file_system::ready(|| match command {
39 GET_KIND::IDENTIFIER => {
40 let kind = GET_KIND::cast_output(output)?;
41 *kind = InterfaceKind::Ethernet as u8;
42 Ok(())
43 }
44 _ => Err(IoErrorKind::Unsupported),
45 })
46 }
47}
48
49impl MountOperations for LoopbackControllerDevice {}
50
51impl DirectCharacterDevice for LoopbackControllerDevice {}
52
53pub fn create_loopback_device() -> (Loopback, LoopbackControllerDevice) {
54 (Loopback::new(Medium::Ethernet), LoopbackControllerDevice)
55}