aboutsummaryrefslogtreecommitdiff
path: root/embassy-net
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-net')
-rw-r--r--embassy-net/src/lib.rs36
-rw-r--r--embassy-net/src/tcp.rs4
2 files changed, 19 insertions, 21 deletions
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index 22e7358ac..ec7f10fdd 100644
--- a/embassy-net/src/lib.rs
+++ b/embassy-net/src/lib.rs
@@ -33,14 +33,14 @@ pub use embassy_net_driver as driver;
33use embassy_net_driver::{Driver, LinkState}; 33use embassy_net_driver::{Driver, LinkState};
34use embassy_sync::waitqueue::WakerRegistration; 34use embassy_sync::waitqueue::WakerRegistration;
35use embassy_time::{Instant, Timer}; 35use embassy_time::{Instant, Timer};
36#[allow(unused_imports)]
37use heapless::Vec; 36use heapless::Vec;
38#[cfg(feature = "dns")] 37#[cfg(feature = "dns")]
39pub use smoltcp::config::DNS_MAX_SERVER_COUNT; 38pub use smoltcp::config::DNS_MAX_SERVER_COUNT;
40#[cfg(feature = "multicast")] 39#[cfg(feature = "multicast")]
41pub use smoltcp::iface::MulticastError; 40pub use smoltcp::iface::MulticastError;
42#[allow(unused_imports)] 41#[cfg(any(feature = "dns", feature = "dhcpv4"))]
43use smoltcp::iface::{Interface, SocketHandle, SocketSet, SocketStorage}; 42use smoltcp::iface::SocketHandle;
43use smoltcp::iface::{Interface, SocketSet, SocketStorage};
44use smoltcp::phy::Medium; 44use smoltcp::phy::Medium;
45#[cfg(feature = "dhcpv4")] 45#[cfg(feature = "dhcpv4")]
46use smoltcp::socket::dhcpv4::{self, RetryConfig}; 46use smoltcp::socket::dhcpv4::{self, RetryConfig};
@@ -379,11 +379,11 @@ fn to_smoltcp_hardware_address(addr: driver::HardwareAddress) -> (HardwareAddres
379 379
380impl<'d> Stack<'d> { 380impl<'d> Stack<'d> {
381 fn with<R>(&self, f: impl FnOnce(&Inner) -> R) -> R { 381 fn with<R>(&self, f: impl FnOnce(&Inner) -> R) -> R {
382 f(&*self.inner.borrow()) 382 f(&self.inner.borrow())
383 } 383 }
384 384
385 fn with_mut<R>(&self, f: impl FnOnce(&mut Inner) -> R) -> R { 385 fn with_mut<R>(&self, f: impl FnOnce(&mut Inner) -> R) -> R {
386 f(&mut *self.inner.borrow_mut()) 386 f(&mut self.inner.borrow_mut())
387 } 387 }
388 388
389 /// Get the hardware address of the network interface. 389 /// Get the hardware address of the network interface.
@@ -642,7 +642,7 @@ impl<'d> Stack<'d> {
642} 642}
643 643
644impl Inner { 644impl Inner {
645 #[allow(clippy::absurd_extreme_comparisons, dead_code)] 645 #[allow(clippy::absurd_extreme_comparisons)]
646 pub fn get_local_port(&mut self) -> u16 { 646 pub fn get_local_port(&mut self) -> u16 {
647 let res = self.next_local_port; 647 let res = self.next_local_port;
648 self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 }; 648 self.next_local_port = if res >= LOCAL_PORT_MAX { LOCAL_PORT_MIN } else { res + 1 };
@@ -732,7 +732,7 @@ impl Inner {
732 debug!(" Default gateway: {:?}", config.gateway); 732 debug!(" Default gateway: {:?}", config.gateway);
733 733
734 unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok()); 734 unwrap!(addrs.push(IpCidr::Ipv4(config.address)).ok());
735 gateway_v4 = config.gateway.into(); 735 gateway_v4 = config.gateway;
736 #[cfg(feature = "dns")] 736 #[cfg(feature = "dns")]
737 for s in &config.dns_servers { 737 for s in &config.dns_servers {
738 debug!(" DNS server: {:?}", s); 738 debug!(" DNS server: {:?}", s);
@@ -831,22 +831,19 @@ impl Inner {
831 self.state_waker.wake(); 831 self.state_waker.wake();
832 } 832 }
833 833
834 #[allow(unused_mut)]
835 let mut apply_config = false;
836
837 #[cfg(feature = "dhcpv4")] 834 #[cfg(feature = "dhcpv4")]
838 if let Some(dhcp_handle) = self.dhcp_socket { 835 if let Some(dhcp_handle) = self.dhcp_socket {
839 let socket = self.sockets.get_mut::<dhcpv4::Socket>(dhcp_handle); 836 let socket = self.sockets.get_mut::<dhcpv4::Socket>(dhcp_handle);
840 837
841 if self.link_up { 838 let configure = if self.link_up {
842 if old_link_up != self.link_up { 839 if old_link_up != self.link_up {
843 socket.reset(); 840 socket.reset();
844 } 841 }
845 match socket.poll() { 842 match socket.poll() {
846 None => {} 843 None => false,
847 Some(dhcpv4::Event::Deconfigured) => { 844 Some(dhcpv4::Event::Deconfigured) => {
848 self.static_v4 = None; 845 self.static_v4 = None;
849 apply_config = true; 846 true
850 } 847 }
851 Some(dhcpv4::Event::Configured(config)) => { 848 Some(dhcpv4::Event::Configured(config)) => {
852 self.static_v4 = Some(StaticConfigV4 { 849 self.static_v4 = Some(StaticConfigV4 {
@@ -854,20 +851,21 @@ impl Inner {
854 gateway: config.router, 851 gateway: config.router,
855 dns_servers: config.dns_servers, 852 dns_servers: config.dns_servers,
856 }); 853 });
857 apply_config = true; 854 true
858 } 855 }
859 } 856 }
860 } else if old_link_up { 857 } else if old_link_up {
861 socket.reset(); 858 socket.reset();
862 self.static_v4 = None; 859 self.static_v4 = None;
863 apply_config = true; 860 true
861 } else {
862 false
863 };
864 if configure {
865 self.apply_static_config()
864 } 866 }
865 } 867 }
866 868
867 if apply_config {
868 self.apply_static_config();
869 }
870
871 if let Some(poll_at) = self.iface.poll_at(timestamp, &mut self.sockets) { 869 if let Some(poll_at) = self.iface.poll_at(timestamp, &mut self.sockets) {
872 let t = pin!(Timer::at(instant_from_smoltcp(poll_at))); 870 let t = pin!(Timer::at(instant_from_smoltcp(poll_at)));
873 if t.poll(cx).is_ready() { 871 if t.poll(cx).is_ready() {
diff --git a/embassy-net/src/tcp.rs b/embassy-net/src/tcp.rs
index 150b4b36b..32d374064 100644
--- a/embassy-net/src/tcp.rs
+++ b/embassy-net/src/tcp.rs
@@ -186,7 +186,7 @@ impl<'a> TcpSocket<'a> {
186 }); 186 });
187 187
188 Self { 188 Self {
189 io: TcpIo { stack: stack, handle }, 189 io: TcpIo { stack, handle },
190 } 190 }
191 } 191 }
192 192
@@ -806,7 +806,7 @@ pub mod client {
806 }; 806 };
807 let remote_endpoint = (addr, remote.port()); 807 let remote_endpoint = (addr, remote.port());
808 let mut socket = TcpConnection::new(self.stack, self.state)?; 808 let mut socket = TcpConnection::new(self.stack, self.state)?;
809 socket.socket.set_timeout(self.socket_timeout.clone()); 809 socket.socket.set_timeout(self.socket_timeout);
810 socket 810 socket
811 .socket 811 .socket
812 .connect(remote_endpoint) 812 .connect(remote_endpoint)