aboutsummaryrefslogtreecommitdiff
path: root/embassy-net-driver/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-10-16 23:41:58 +0200
committerDario Nieuwenhuis <[email protected]>2023-10-18 05:28:16 +0200
commit3cbc6874247d7b814cab8ec8762bfe2f6f385828 (patch)
treeaac4c615c816f6465559874a98c9d3cf60c21817 /embassy-net-driver/src
parent51708c8ed1962618ac7bc244a3f5e7ceced28182 (diff)
net/driver: remove Medium, make HardwareAddress non_exhaustive.
Diffstat (limited to 'embassy-net-driver/src')
-rw-r--r--embassy-net-driver/src/lib.rs54
1 files changed, 18 insertions, 36 deletions
diff --git a/embassy-net-driver/src/lib.rs b/embassy-net-driver/src/lib.rs
index b64c10000..87f9f6ed1 100644
--- a/embassy-net-driver/src/lib.rs
+++ b/embassy-net-driver/src/lib.rs
@@ -7,12 +7,23 @@ use core::task::Context;
7/// Representation of an hardware address, such as an Ethernet address or an IEEE802.15.4 address. 7/// Representation of an hardware address, such as an Ethernet address or an IEEE802.15.4 address.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)] 8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9#[cfg_attr(feature = "defmt", derive(defmt::Format))] 9#[cfg_attr(feature = "defmt", derive(defmt::Format))]
10#[non_exhaustive]
10pub enum HardwareAddress { 11pub enum HardwareAddress {
11 /// A six-octet Ethernet address 12 /// Ethernet medium, with a A six-octet Ethernet address.
13 ///
14 /// Devices of this type send and receive Ethernet frames,
15 /// and interfaces using it must do neighbor discovery via ARP or NDISC.
16 ///
17 /// Examples of devices of this type are Ethernet, WiFi (802.11), Linux `tap`, and VPNs in tap (layer 2) mode.
12 Ethernet([u8; 6]), 18 Ethernet([u8; 6]),
13 /// An eight-octet IEEE802.15.4 address 19 /// 6LoWPAN over IEEE802.15.4, with an eight-octet address.
14 Ieee802154([u8; 8]), 20 Ieee802154([u8; 8]),
15 /// Indicates that a Driver is IP-native, and has no hardware address 21 /// Indicates that a Driver is IP-native, and has no hardware address.
22 ///
23 /// Devices of this type send and receive IP frames, without an
24 /// Ethernet header. MAC addresses are not used, and no neighbor discovery (ARP, NDISC) is done.
25 ///
26 /// Examples of devices of this type are the Linux `tun`, PPP interfaces, VPNs in tun (layer 3) mode.
16 Ip, 27 Ip,
17} 28}
18 29
@@ -64,6 +75,10 @@ pub trait Driver {
64 fn capabilities(&self) -> Capabilities; 75 fn capabilities(&self) -> Capabilities;
65 76
66 /// Get the device's hardware address. 77 /// Get the device's hardware address.
78 ///
79 /// The returned hardware address also determines the "medium" of this driver. This indicates
80 /// what kind of packet the sent/received bytes are, and determines some behaviors of
81 /// the interface. For example, ARP/NDISC address resolution is only done for Ethernet mediums.
67 fn hardware_address(&self) -> HardwareAddress; 82 fn hardware_address(&self) -> HardwareAddress;
68} 83}
69 84
@@ -124,13 +139,6 @@ pub trait TxToken {
124#[cfg_attr(feature = "defmt", derive(defmt::Format))] 139#[cfg_attr(feature = "defmt", derive(defmt::Format))]
125#[non_exhaustive] 140#[non_exhaustive]
126pub struct Capabilities { 141pub struct Capabilities {
127 /// Medium of the device.
128 ///
129 /// This indicates what kind of packet the sent/received bytes are, and determines
130 /// some behaviors of Interface. For example, ARP/NDISC address resolution is only done
131 /// for Ethernet mediums.
132 pub medium: Medium,
133
134 /// Maximum transmission unit. 142 /// Maximum transmission unit.
135 /// 143 ///
136 /// The network device is unable to send or receive frames larger than the value returned 144 /// The network device is unable to send or receive frames larger than the value returned
@@ -161,32 +169,6 @@ pub struct Capabilities {
161 pub checksum: ChecksumCapabilities, 169 pub checksum: ChecksumCapabilities,
162} 170}
163 171
164/// Type of medium of a device.
165#[derive(Debug, Eq, PartialEq, Copy, Clone)]
166#[cfg_attr(feature = "defmt", derive(defmt::Format))]
167pub enum Medium {
168 /// Ethernet medium. Devices of this type send and receive Ethernet frames,
169 /// and interfaces using it must do neighbor discovery via ARP or NDISC.
170 ///
171 /// Examples of devices of this type are Ethernet, WiFi (802.11), Linux `tap`, and VPNs in tap (layer 2) mode.
172 Ethernet,
173
174 /// IP medium. Devices of this type send and receive IP frames, without an
175 /// Ethernet header. MAC addresses are not used, and no neighbor discovery (ARP, NDISC) is done.
176 ///
177 /// Examples of devices of this type are the Linux `tun`, PPP interfaces, VPNs in tun (layer 3) mode.
178 Ip,
179
180 /// IEEE 802_15_4 medium
181 Ieee802154,
182}
183
184impl Default for Medium {
185 fn default() -> Medium {
186 Medium::Ethernet
187 }
188}
189
190/// A description of checksum behavior for every supported protocol. 172/// A description of checksum behavior for every supported protocol.
191#[derive(Debug, Clone, Default)] 173#[derive(Debug, Clone, Default)]
192#[cfg_attr(feature = "defmt", derive(defmt::Format))] 174#[cfg_attr(feature = "defmt", derive(defmt::Format))]