diff options
| author | Paweł Jan Czochański <[email protected]> | 2023-01-18 09:56:38 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-01-19 14:44:01 +0100 |
| commit | 2eae12b7f1cbe38d850ebf30f23a776323815af6 (patch) | |
| tree | a8723c93f9f18c7080ddb63d07c8bbc12caf1984 | |
| parent | 65ab714fae6315a032e7440f44429ced36d2506e (diff) | |
Update smoltcp to the newest master
| -rw-r--r-- | embassy-net/Cargo.toml | 2 | ||||
| -rw-r--r-- | embassy-net/src/device.rs | 13 | ||||
| -rw-r--r-- | embassy-net/src/lib.rs | 30 |
3 files changed, 18 insertions, 27 deletions
diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index 9214fd17e..a2ef3b4fe 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml | |||
| @@ -51,7 +51,7 @@ atomic-polyfill = { version = "1.0" } | |||
| 51 | [dependencies.smoltcp] | 51 | [dependencies.smoltcp] |
| 52 | version = "0.8.0" | 52 | version = "0.8.0" |
| 53 | git = "https://github.com/smoltcp-rs/smoltcp" | 53 | git = "https://github.com/smoltcp-rs/smoltcp" |
| 54 | rev = "b7a7c4b1c56e8d4c2524c1e3a056c745a13cc09f" | 54 | rev = "7b631c27cefe9b29e322a507c076b4156f477ee2" |
| 55 | default-features = false | 55 | default-features = false |
| 56 | features = [ | 56 | features = [ |
| 57 | "proto-ipv4", | 57 | "proto-ipv4", |
diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 44f7dc7bd..d0c8a62db 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs | |||
| @@ -2,6 +2,7 @@ use core::task::Context; | |||
| 2 | 2 | ||
| 3 | use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken}; | 3 | use embassy_net_driver::{Capabilities, Checksum, Driver, Medium, RxToken, TxToken}; |
| 4 | use smoltcp::phy; | 4 | use smoltcp::phy; |
| 5 | use smoltcp::time::Instant; | ||
| 5 | 6 | ||
| 6 | pub(crate) struct DriverAdapter<'d, 'c, T> | 7 | pub(crate) struct DriverAdapter<'d, 'c, T> |
| 7 | where | 8 | where |
| @@ -19,14 +20,14 @@ where | |||
| 19 | type RxToken<'a> = RxTokenAdapter<T::RxToken<'a>> where Self: 'a; | 20 | type RxToken<'a> = RxTokenAdapter<T::RxToken<'a>> where Self: 'a; |
| 20 | type TxToken<'a> = TxTokenAdapter<T::TxToken<'a>> where Self: 'a; | 21 | type TxToken<'a> = TxTokenAdapter<T::TxToken<'a>> where Self: 'a; |
| 21 | 22 | ||
| 22 | fn receive(&mut self) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { | 23 | fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> { |
| 23 | self.inner | 24 | self.inner |
| 24 | .receive(self.cx.as_deref_mut().unwrap()) | 25 | .receive(self.cx.as_deref_mut().unwrap()) |
| 25 | .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) | 26 | .map(|(rx, tx)| (RxTokenAdapter(rx), TxTokenAdapter(tx))) |
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | /// Construct a transmit token. | 29 | /// Construct a transmit token. |
| 29 | fn transmit(&mut self) -> Option<Self::TxToken<'_>> { | 30 | fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> { |
| 30 | self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter) | 31 | self.inner.transmit(self.cx.as_deref_mut().unwrap()).map(TxTokenAdapter) |
| 31 | } | 32 | } |
| 32 | 33 | ||
| @@ -76,9 +77,9 @@ impl<T> phy::RxToken for RxTokenAdapter<T> | |||
| 76 | where | 77 | where |
| 77 | T: RxToken, | 78 | T: RxToken, |
| 78 | { | 79 | { |
| 79 | fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, f: F) -> smoltcp::Result<R> | 80 | fn consume<R, F>(self, f: F) -> R |
| 80 | where | 81 | where |
| 81 | F: FnOnce(&mut [u8]) -> smoltcp::Result<R>, | 82 | F: FnOnce(&mut [u8]) -> R, |
| 82 | { | 83 | { |
| 83 | self.0.consume(|buf| f(buf)) | 84 | self.0.consume(|buf| f(buf)) |
| 84 | } | 85 | } |
| @@ -92,9 +93,9 @@ impl<T> phy::TxToken for TxTokenAdapter<T> | |||
| 92 | where | 93 | where |
| 93 | T: TxToken, | 94 | T: TxToken, |
| 94 | { | 95 | { |
| 95 | fn consume<R, F>(self, _timestamp: smoltcp::time::Instant, len: usize, f: F) -> smoltcp::Result<R> | 96 | fn consume<R, F>(self, len: usize, f: F) -> R |
| 96 | where | 97 | where |
| 97 | F: FnOnce(&mut [u8]) -> smoltcp::Result<R>, | 98 | F: FnOnce(&mut [u8]) -> R, |
| 98 | { | 99 | { |
| 99 | self.0.consume(len, |buf| f(buf)) | 100 | self.0.consume(len, |buf| f(buf)) |
| 100 | } | 101 | } |
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index e4a4218e3..757d3e27d 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs | |||
| @@ -23,11 +23,11 @@ use embassy_sync::waitqueue::WakerRegistration; | |||
| 23 | use embassy_time::{Instant, Timer}; | 23 | use embassy_time::{Instant, Timer}; |
| 24 | use futures::pin_mut; | 24 | use futures::pin_mut; |
| 25 | use heapless::Vec; | 25 | use heapless::Vec; |
| 26 | #[cfg(feature = "medium-ethernet")] | ||
| 27 | use smoltcp::iface::Routes; | ||
| 26 | #[cfg(feature = "dhcpv4")] | 28 | #[cfg(feature = "dhcpv4")] |
| 27 | use smoltcp::iface::SocketHandle; | 29 | use smoltcp::iface::SocketHandle; |
| 28 | use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage}; | 30 | use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage}; |
| 29 | #[cfg(feature = "medium-ethernet")] | ||
| 30 | use smoltcp::iface::{Neighbor, NeighborCache, Route, Routes}; | ||
| 31 | #[cfg(feature = "dhcpv4")] | 31 | #[cfg(feature = "dhcpv4")] |
| 32 | use smoltcp::socket::dhcpv4; | 32 | use smoltcp::socket::dhcpv4; |
| 33 | // smoltcp reexports | 33 | // smoltcp reexports |
| @@ -45,25 +45,16 @@ use crate::device::DriverAdapter; | |||
| 45 | const LOCAL_PORT_MIN: u16 = 1025; | 45 | const LOCAL_PORT_MIN: u16 = 1025; |
| 46 | const LOCAL_PORT_MAX: u16 = 65535; | 46 | const LOCAL_PORT_MAX: u16 = 65535; |
| 47 | 47 | ||
| 48 | pub struct StackResources<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> { | 48 | pub struct StackResources<const SOCK: usize, const NEIGHBOR: usize> { |
| 49 | addresses: [IpCidr; ADDR], | 49 | addresses: [IpCidr; 5], |
| 50 | sockets: [SocketStorage<'static>; SOCK], | 50 | sockets: [SocketStorage<'static>; SOCK], |
| 51 | |||
| 52 | #[cfg(feature = "medium-ethernet")] | ||
| 53 | routes: [Option<(IpCidr, Route)>; 1], | ||
| 54 | #[cfg(feature = "medium-ethernet")] | ||
| 55 | neighbor_cache: [Option<(IpAddress, Neighbor)>; NEIGHBOR], | ||
| 56 | } | 51 | } |
| 57 | 52 | ||
| 58 | impl<const ADDR: usize, const SOCK: usize, const NEIGHBOR: usize> StackResources<ADDR, SOCK, NEIGHBOR> { | 53 | impl<const SOCK: usize, const NEIGHBOR: usize> StackResources<SOCK, NEIGHBOR> { |
| 59 | pub fn new() -> Self { | 54 | pub fn new() -> Self { |
| 60 | Self { | 55 | Self { |
| 61 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); ADDR], | 56 | addresses: [IpCidr::new(Ipv4Address::UNSPECIFIED.into(), 32); 5], |
| 62 | sockets: [SocketStorage::EMPTY; SOCK], | 57 | sockets: [SocketStorage::EMPTY; SOCK], |
| 63 | #[cfg(feature = "medium-ethernet")] | ||
| 64 | routes: [None; 1], | ||
| 65 | #[cfg(feature = "medium-ethernet")] | ||
| 66 | neighbor_cache: [None; NEIGHBOR], | ||
| 67 | } | 58 | } |
| 68 | } | 59 | } |
| 69 | } | 60 | } |
| @@ -105,21 +96,20 @@ impl<D: Driver + 'static> Stack<D> { | |||
| 105 | pub fn new<const ADDR: usize, const SOCK: usize, const NEIGH: usize>( | 96 | pub fn new<const ADDR: usize, const SOCK: usize, const NEIGH: usize>( |
| 106 | mut device: D, | 97 | mut device: D, |
| 107 | config: ConfigStrategy, | 98 | config: ConfigStrategy, |
| 108 | resources: &'static mut StackResources<ADDR, SOCK, NEIGH>, | 99 | resources: &'static mut StackResources<SOCK, NEIGH>, |
| 109 | random_seed: u64, | 100 | random_seed: u64, |
| 110 | ) -> Self { | 101 | ) -> Self { |
| 111 | #[cfg(feature = "medium-ethernet")] | 102 | #[cfg(feature = "medium-ethernet")] |
| 112 | let medium = device.capabilities().medium; | 103 | let medium = device.capabilities().medium; |
| 113 | 104 | ||
| 114 | let mut b = InterfaceBuilder::new(); | 105 | let mut b = InterfaceBuilder::new(); |
| 115 | b = b.ip_addrs(&mut resources.addresses[..]); | 106 | b = b.ip_addrs(Vec::<IpCidr, 5>::from_iter(resources.addresses)); |
| 116 | b = b.random_seed(random_seed); | 107 | b = b.random_seed(random_seed); |
| 117 | 108 | ||
| 118 | #[cfg(feature = "medium-ethernet")] | 109 | #[cfg(feature = "medium-ethernet")] |
| 119 | if medium == Medium::Ethernet { | 110 | if medium == Medium::Ethernet { |
| 120 | b = b.hardware_addr(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address()))); | 111 | b = b.hardware_addr(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address()))); |
| 121 | b = b.neighbor_cache(NeighborCache::new(&mut resources.neighbor_cache[..])); | 112 | b = b.routes(Routes::new()); |
| 122 | b = b.routes(Routes::new(&mut resources.routes[..])); | ||
| 123 | } | 113 | } |
| 124 | 114 | ||
| 125 | let iface = b.finalize(&mut DriverAdapter { | 115 | let iface = b.finalize(&mut DriverAdapter { |
| @@ -266,7 +256,7 @@ impl<D: Driver + 'static> Inner<D> { | |||
| 266 | cx: Some(cx), | 256 | cx: Some(cx), |
| 267 | inner: &mut self.device, | 257 | inner: &mut self.device, |
| 268 | }; | 258 | }; |
| 269 | if s.iface.poll(timestamp, &mut smoldev, &mut s.sockets).is_err() { | 259 | if !s.iface.poll(timestamp, &mut smoldev, &mut s.sockets) { |
| 270 | // If poll() returns error, it may not be done yet, so poll again later. | 260 | // If poll() returns error, it may not be done yet, so poll again later. |
| 271 | cx.waker().wake_by_ref(); | 261 | cx.waker().wake_by_ref(); |
| 272 | return; | 262 | return; |
