diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-10-16 23:41:58 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-10-18 05:28:16 +0200 |
| commit | 3cbc6874247d7b814cab8ec8762bfe2f6f385828 (patch) | |
| tree | aac4c615c816f6465559874a98c9d3cf60c21817 /embassy-net-driver | |
| parent | 51708c8ed1962618ac7bc244a3f5e7ceced28182 (diff) | |
net/driver: remove Medium, make HardwareAddress non_exhaustive.
Diffstat (limited to 'embassy-net-driver')
| -rw-r--r-- | embassy-net-driver/CHANGELOG.md | 10 | ||||
| -rw-r--r-- | embassy-net-driver/src/lib.rs | 54 |
2 files changed, 23 insertions, 41 deletions
diff --git a/embassy-net-driver/CHANGELOG.md b/embassy-net-driver/CHANGELOG.md index 7be622820..165461eff 100644 --- a/embassy-net-driver/CHANGELOG.md +++ b/embassy-net-driver/CHANGELOG.md | |||
| @@ -5,13 +5,13 @@ All notable changes to this project will be documented in this file. | |||
| 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), |
| 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | 6 | and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). |
| 7 | 7 | ||
| 8 | ## 0.2.0 - 2023-10-15 | 8 | ## 0.2.0 - 2023-10-18 |
| 9 | 9 | ||
| 10 | - Added `Driver::ieee802154_address` | 10 | - Added support for IEEE 802.15.4 mediums. |
| 11 | - Added `Medium::Ieee802154` | 11 | - Added `Driver::hardware_address()`, `HardwareAddress`. |
| 12 | - Removed `Medium` enum. The medium is deduced out of the hardware address. | ||
| 13 | - Removed `Driver::ethernet_address()`. Replacement is `hardware_address()`. | ||
| 12 | 14 | ||
| 13 | ## 0.1.0 - 2023-06-29 | 15 | ## 0.1.0 - 2023-06-29 |
| 14 | 16 | ||
| 15 | - First release | 17 | - First release |
| 16 | |||
| 17 | |||
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] | ||
| 10 | pub enum HardwareAddress { | 11 | pub 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] |
| 126 | pub struct Capabilities { | 141 | pub 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))] | ||
| 167 | pub 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 | |||
| 184 | impl 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))] |
