net: update smoltcp.
This commit is contained in:
parent
fe15a7beee
commit
78c2c1709b
@ -51,7 +51,7 @@ atomic-polyfill = { version = "1.0" }
|
|||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
git = "https://github.com/smoltcp-rs/smoltcp"
|
git = "https://github.com/smoltcp-rs/smoltcp"
|
||||||
rev = "7b631c27cefe9b29e322a507c076b4156f477ee2"
|
rev = "5740b765749b95c18aace5de8dc21cab75ba33d4"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = [
|
features = [
|
||||||
"proto-ipv4",
|
"proto-ipv4",
|
||||||
|
@ -23,11 +23,9 @@ use embassy_sync::waitqueue::WakerRegistration;
|
|||||||
use embassy_time::{Instant, Timer};
|
use embassy_time::{Instant, Timer};
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
#[cfg(feature = "medium-ethernet")]
|
|
||||||
use smoltcp::iface::Routes;
|
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
use smoltcp::iface::SocketHandle;
|
use smoltcp::iface::SocketHandle;
|
||||||
use smoltcp::iface::{Interface, InterfaceBuilder, SocketSet, SocketStorage};
|
use smoltcp::iface::{Interface, SocketSet, SocketStorage};
|
||||||
#[cfg(feature = "dhcpv4")]
|
#[cfg(feature = "dhcpv4")]
|
||||||
use smoltcp::socket::dhcpv4;
|
use smoltcp::socket::dhcpv4;
|
||||||
use smoltcp::socket::dhcpv4::RetryConfig;
|
use smoltcp::socket::dhcpv4::RetryConfig;
|
||||||
@ -111,7 +109,7 @@ struct Inner<D: Driver> {
|
|||||||
|
|
||||||
pub(crate) struct SocketStack {
|
pub(crate) struct SocketStack {
|
||||||
pub(crate) sockets: SocketSet<'static>,
|
pub(crate) sockets: SocketSet<'static>,
|
||||||
pub(crate) iface: Interface<'static>,
|
pub(crate) iface: Interface,
|
||||||
pub(crate) waker: WakerRegistration,
|
pub(crate) waker: WakerRegistration,
|
||||||
next_local_port: u16,
|
next_local_port: u16,
|
||||||
}
|
}
|
||||||
@ -126,19 +124,20 @@ impl<D: Driver + 'static> Stack<D> {
|
|||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
let medium = device.capabilities().medium;
|
let medium = device.capabilities().medium;
|
||||||
|
|
||||||
let mut b = InterfaceBuilder::new();
|
let mut iface_cfg = smoltcp::iface::Config::new();
|
||||||
b = b.random_seed(random_seed);
|
iface_cfg.random_seed = random_seed;
|
||||||
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
b = b.hardware_addr(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address())));
|
iface_cfg.hardware_addr = Some(HardwareAddress::Ethernet(EthernetAddress(device.ethernet_address())));
|
||||||
b = b.routes(Routes::new());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let iface = b.finalize(&mut DriverAdapter {
|
let iface = Interface::new(
|
||||||
inner: &mut device,
|
iface_cfg,
|
||||||
cx: None,
|
&mut DriverAdapter {
|
||||||
});
|
inner: &mut device,
|
||||||
|
cx: None,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
let sockets = SocketSet::new(&mut resources.sockets[..]);
|
let sockets = SocketSet::new(&mut resources.sockets[..]);
|
||||||
|
|
||||||
@ -226,7 +225,13 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
debug!("Acquired IP configuration:");
|
debug!("Acquired IP configuration:");
|
||||||
|
|
||||||
debug!(" IP address: {}", config.address);
|
debug!(" IP address: {}", config.address);
|
||||||
self.set_ipv4_addr(s, config.address);
|
s.iface.update_ip_addrs(|addrs| {
|
||||||
|
if addrs.is_empty() {
|
||||||
|
addrs.push(IpCidr::Ipv4(config.address)).unwrap();
|
||||||
|
} else {
|
||||||
|
addrs[0] = IpCidr::Ipv4(config.address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
@ -258,7 +263,7 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
let medium = self.device.capabilities().medium;
|
let medium = self.device.capabilities().medium;
|
||||||
|
|
||||||
debug!("Lost IP configuration");
|
debug!("Lost IP configuration");
|
||||||
self.set_ipv4_addr(s, Ipv4Cidr::new(Ipv4Address::UNSPECIFIED, 0));
|
s.iface.update_ip_addrs(|ip_addrs| ip_addrs.clear());
|
||||||
#[cfg(feature = "medium-ethernet")]
|
#[cfg(feature = "medium-ethernet")]
|
||||||
if medium == Medium::Ethernet {
|
if medium == Medium::Ethernet {
|
||||||
s.iface.routes_mut().remove_default_ipv4_route();
|
s.iface.routes_mut().remove_default_ipv4_route();
|
||||||
@ -266,13 +271,6 @@ impl<D: Driver + 'static> Inner<D> {
|
|||||||
self.config = None
|
self.config = None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_ipv4_addr(&mut self, s: &mut SocketStack, cidr: Ipv4Cidr) {
|
|
||||||
s.iface.update_ip_addrs(|addrs| {
|
|
||||||
let dest = addrs.iter_mut().next().unwrap();
|
|
||||||
*dest = IpCidr::Ipv4(cidr);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
fn poll(&mut self, cx: &mut Context<'_>, s: &mut SocketStack) {
|
||||||
s.waker.register(cx.waker());
|
s.waker.register(cx.waker());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user