From 64cba950e55dd5cdd7d6ef13c2dbb03825bc6d01 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 26 Jun 2023 01:59:25 +0200 Subject: [PATCH] Update smoltcp. --- embassy-net/Cargo.toml | 4 ++-- embassy-net/src/device.rs | 3 ++- embassy-net/src/lib.rs | 18 +++++++++++++----- embassy-net/src/udp.rs | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 4ac57257..63947c26 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -38,10 +38,10 @@ igmp = ["smoltcp/proto-igmp"] defmt = { version = "0.3", optional = true } log = { version = "0.4.14", optional = true } -smoltcp = { version = "0.9.0", default-features = false, features = [ +smoltcp = { git = "https://github.com/smoltcp-rs/smoltcp", rev = "803840b5ccac01cc0f108993958f637835f0adbe", default-features = false, features = [ "socket", "async", -]} +] } embassy-net-driver = { version = "0.1.0", path = "../embassy-net-driver" } embassy-hal-common = { version = "0.1.0", path = "../embassy-hal-common" } diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 583cdc87..4513c86d 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -51,8 +51,9 @@ where Medium::Ethernet => phy::Medium::Ethernet, #[cfg(feature = "medium-ip")] Medium::Ip => phy::Medium::Ip, + #[allow(unreachable_patterns)] _ => panic!( - "Unsupported medium {:?}. MAke sure to enable it in embassy-net's Cargo features.", + "Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.", caps.medium ), }; diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 7e8f765f..3e83da7a 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -235,12 +235,19 @@ impl Stack { #[cfg(feature = "medium-ethernet")] let medium = device.capabilities().medium; - let mut iface_cfg = smoltcp::iface::Config::new(); + let hardware_addr = match medium { + #[cfg(feature = "medium-ethernet")] + Medium::Ethernet => HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address())), + #[cfg(feature = "medium-ip")] + Medium::Ip => HardwareAddress::Ip, + #[allow(unreachable_patterns)] + _ => panic!( + "Unsupported medium {:?}. Make sure to enable it in embassy-net's Cargo features.", + medium + ), + }; + let mut iface_cfg = smoltcp::iface::Config::new(hardware_addr); iface_cfg.random_seed = random_seed; - #[cfg(feature = "medium-ethernet")] - if medium == Medium::Ethernet { - iface_cfg.hardware_addr = Some(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address()))); - } let iface = Interface::new( iface_cfg, @@ -248,6 +255,7 @@ impl Stack { inner: &mut device, cx: None, }, + instant_to_smoltcp(Instant::now()), ); let sockets = SocketSet::new(&mut resources.sockets[..]); diff --git a/embassy-net/src/udp.rs b/embassy-net/src/udp.rs index c9843cfe..36f8d06f 100644 --- a/embassy-net/src/udp.rs +++ b/embassy-net/src/udp.rs @@ -104,7 +104,7 @@ impl<'a> UdpSocket<'a> { pub async fn recv_from(&self, buf: &mut [u8]) -> Result<(usize, IpEndpoint), Error> { poll_fn(move |cx| { self.with_mut(|s, _| match s.recv_slice(buf) { - Ok(x) => Poll::Ready(Ok(x)), + Ok((n, meta)) => Poll::Ready(Ok((n, meta.endpoint))), // No data ready Err(udp::RecvError::Exhausted) => { s.register_recv_waker(cx.waker());