|
@@ -10,7 +10,8 @@ and implementations of it:
|
|
|
* _adapters_ [RawSocket](struct.RawSocket.html) and
|
|
|
[TapInterface](struct.TapInterface.html), to transmit and receive frames
|
|
|
on the host OS.
|
|
|
-
|
|
|
+*/
|
|
|
+# trait for a simple hardware
|
|
@@ -18,7 +19,7 @@ Ethernet controller could look as follows:
|
|
|
|
|
|
```rust
|
|
|
use smoltcp::Result;
|
|
|
-use smoltcp::phy::{self, DeviceCapabilities, Device};
|
|
|
+use smoltcp::phy::{self, DeviceCapabilities, Device, Medium};
|
|
|
use smoltcp::time::Instant;
|
|
|
|
|
|
struct StmPhy {
|
|
@@ -52,6 +53,7 @@ impl<'a> phy::Device<'a> for StmPhy {
|
|
|
let mut caps = DeviceCapabilities::default();
|
|
|
caps.max_transmission_unit = 1536;
|
|
|
caps.max_burst_size = Some(1);
|
|
|
+ caps.medium = Medium::Ethernet;
|
|
|
caps
|
|
|
}
|
|
|
}
|
|
@@ -82,7 +84,7 @@ impl<'a> phy::TxToken for StmPhyTxToken<'a> {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
-*/
|
|
|
+"##)]
|
|
|
|
|
|
use crate::Result;
|
|
|
use crate::time::Instant;
|
|
@@ -192,6 +194,13 @@ impl ChecksumCapabilities {
|
|
|
#[derive(Debug, Clone, Default)]
|
|
|
#[non_exhaustive]
|
|
|
pub struct DeviceCapabilities {
|
|
|
+ /// Medium of the device.
|
|
|
+ ///
|
|
|
+ /// This indicates what kind of packet the sent/received bytes are, and determines
|
|
|
+ /// some behaviors of Interface. For example, ARP/NDISC address resolution is only done
|
|
|
+ /// for Ethernet mediums.
|
|
|
+ pub medium: Medium,
|
|
|
+
|
|
|
/// Maximum transmission unit.
|
|
|
///
|
|
|
/// The network device is unable to send or receive frames larger than the value returned
|
|
@@ -222,6 +231,33 @@ pub struct DeviceCapabilities {
|
|
|
pub checksum: ChecksumCapabilities,
|
|
|
}
|
|
|
|
|
|
+/// Type of medium of a device.
|
|
|
+#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
|
|
+pub enum Medium {
|
|
|
+ /// Ethernet medium. Devices of this type send and receive Ethernet frames,
|
|
|
+ /// and interfaces using it must do neighbor discovery via ARP or NDISC.
|
|
|
+ ///
|
|
|
+ /// Examples of devices of this type are Ethernet, WiFi (802.11), Linux `tap`, and VPNs in tap (layer 2) mode.
|
|
|
+ #[cfg(feature = "ethernet")]
|
|
|
+ Ethernet,
|
|
|
+
|
|
|
+ /// IP medium. Devices of this type send and receive IP frames, without an
|
|
|
+ /// Ethernet header. MAC addresses are not used, and no neighbor discovery (ARP, NDISC) is done.
|
|
|
+ ///
|
|
|
+ /// Examples of devices of this type are the Linux `tun`, PPP interfaces, VPNs in tun (layer 3) mode.
|
|
|
+ Ip,
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+impl Default for Medium {
|
|
|
+ fn default() -> Medium {
|
|
|
+ #[cfg(feature = "ethernet")]
|
|
|
+ return Medium::Ethernet;
|
|
|
+ #[cfg(not(feature = "ethernet"))]
|
|
|
+ return Medium::Ip;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
/// An interface for sending and receiving raw network frames.
|
|
|
///
|
|
|
/// The interface is based on _tokens_, which are types that allow to receive/transmit a
|