diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 9214fd17..a2ef3b4f 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -51,7 +51,7 @@ atomic-polyfill = { version = "1.0" } [dependencies.smoltcp] version = "0.8.0" git = "https://github.com/smoltcp-rs/smoltcp" -rev = "b7a7c4b1c56e8d4c2524c1e3a056c745a13cc09f" +rev = "7b631c27cefe9b29e322a507c076b4156f477ee2" default-features = false features = [ "proto-ipv4", diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 44f7dc7b..d0c8a62d 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -2,6 +2,7 @@ use core::task::Context; use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken}; use smoltcp::phy; +use smoltcp::time::Instant; pub(crate) struct DriverAdapter<'d, 'c, T> where @@ -19,14 +20,14 @@ where type RxToken<'a> = RxTokenAdapter> where Self: 'a; type TxToken<'a> = TxTokenAdapter> where Self: 'a; - fn receive(&mut self) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { + fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { self.inner .receive(self.cx.as_deref_mut().unwrap()) .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) } /// Construct a transmit token. - fn transmit(&mut self) -> Option> { + fn transmit(&mut self, _timestamp: Instant) -> Option> { self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter) } @@ -76,9 +77,9 @@ impl phy::RxToken for RxTokenAdapter where T: RxToken, { - fn consume(self, _timestamp: smoltcp::time::Instant, f: F) -> smoltcp::Result + fn consume(self, f: F) -> R where - F: FnOnce(&mut [u8]) -> smoltcp::Result, + F: FnOnce(&mut [u8]) -> R, { self.0.consume(|buf| f(buf)) } @@ -92,9 +93,9 @@ impl phy::TxToken for TxTokenAdapter where T: TxToken, { - fn consume(self, _timestamp: smoltcp::time::Instant, len: usize, f: F) -> smoltcp::Result + fn consume(self, len: usize, f: F) -> R where - F: FnOnce(&mut [u8]) -> smoltcp::Result, + F: FnOnce(&mut [u8]) -> R, { self.0.consume(len, |buf| f(buf)) } diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index e4a4218e..757d3e27 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -23,11 +23,11 @@ use embassy_sync::waitqueue::WakerRegistration; use embassy_time::{Instant, Timer}; use futures::pin_mut; use heapless::Vec; +#[cfg(feature = "medium-ethernet")] +use smoltcp::iface::Routes; #[cfg(feature = "dhcpv4")] use smoltcp::iface::SocketHandle; use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage}; -#[cfg(feature = "medium-ethernet")] -use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; #[cfg(feature = "dhcpv4")] use smoltcp::socket::dhcpv4; // smoltcp reexports @@ -45,25 +45,16 @@ use crate::device::DriverAdapter; const LOCAL_PORT_MIN: u16 = 1025; const LOCAL_PORT_MAX: u16 = 65535; -pub struct StackResources { - addresses: [IpCidr; ADDR], +pub struct StackResources { + addresses: [IpCidr; 5], sockets: [SocketStorage<'static>; SOCK], - - #[cfg(feature = "medium-ethernet")] - routes: [Option<(IpCidr, Route)>; 1], - #[cfg(feature = "medium-ethernet")] - neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR], } -impl StackResources { +impl StackResources { pub fn new() -> Self { Self { - addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], + addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); 5], sockets: [SocketStorage::EMPTY; SOCK], - #[cfg(feature = "medium-ethernet")] - routes: [None; 1], - #[cfg(feature = "medium-ethernet")] - neighbor_cache: [None; NEIGHBOR], } } } @@ -105,21 +96,20 @@ impl Stack { pub fn new( mut device: D, config: ConfigStrategy, - resources: &'static mut StackResources, + resources: &'static mut StackResources, random_seed: u64, ) -> Self { #[cfg(feature = "medium-ethernet")] let medium = device.capabilities().medium; let mut b = InterfaceBuilder::new(); - b = b.ip_addrs(&mut resources.addresses[..]); + b = b.ip_addrs(Vec::::from_iter(resources.addresses)); b = b.random_seed(random_seed); #[cfg(feature = "medium-ethernet")] if medium == Medium::Ethernet { b = b.hardware_addr(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address()))); - b = b.neighbor_cache(NeighborCache::new(&mut resources.neighbor_cache[..])); - b = b.routes(Routes::new(&mut resources.routes[..])); + b = b.routes(Routes::new()); } let iface = b.finalize(&mut DriverAdapter { @@ -266,7 +256,7 @@ impl Inner { cx: Some(cx), inner: &mut self.device, }; - if s.iface.poll(timestamp, &mut smoldev, &mut s.sockets).is_err() { + if !s.iface.poll(timestamp, &mut smoldev, &mut s.sockets) { // If poll() returns error, it may not be done yet, so poll again later. cx.waker().wake_by_ref(); return;