aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-11-02 11:22:40 +0000
committerGitHub <[email protected]>2024-11-02 11:22:40 +0000
commit54dd2af6512b9829232baf1bbd0b431d0770922d (patch)
treed3c835d2ac1b4a81bca60ef9d7f4905c7f2fc07c
parent10a9766046f7f8a2cf1c7b91209432ee15ee22a9 (diff)
parent9634dfd6c119b054e232a886058d015ede5aec00 (diff)
Merge pull request #3488 from kkrolczyk/small_net_fixes
embassy-net: disable multicast filtering
-rw-r--r--embassy-net/src/driver_util.rs4
-rw-r--r--embassy-net/src/lib.rs40
-rw-r--r--embassy-net/src/tcp.rs4
-rw-r--r--embassy-stm32/src/eth/v2/mod.rs3
4 files changed, 26 insertions, 25 deletions
diff --git a/embassy-net/src/driver_util.rs b/embassy-net/src/driver_util.rs
index f51641425..536f4c3d9 100644
--- a/embassy-net/src/driver_util.rs
+++ b/embassy-net/src/driver_util.rs
@@ -84,7 +84,7 @@ where
84 { 84 {
85 self.0.consume(|buf| { 85 self.0.consume(|buf| {
86 #[cfg(feature = "packet-trace")] 86 #[cfg(feature = "packet-trace")]
87 trace!("rx: {:?}", buf); 87 trace!("embassy device rx: {:02x}", buf);
88 f(buf) 88 f(buf)
89 }) 89 })
90 } 90 }
@@ -105,7 +105,7 @@ where
105 self.0.consume(len, |buf| { 105 self.0.consume(len, |buf| {
106 let r = f(buf); 106 let r = f(buf);
107 #[cfg(feature = "packet-trace")] 107 #[cfg(feature = "packet-trace")]
108 trace!("tx: {:?}", buf); 108 trace!("embassy device tx: {:02x}", buf);
109 r 109 r
110 }) 110 })
111 } 111 }
diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs
index a7b7efa87..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.
@@ -391,12 +391,12 @@ impl<'d> Stack<'d> {
391 self.with(|i| i.hardware_address) 391 self.with(|i| i.hardware_address)
392 } 392 }
393 393
394 /// Get whether the link is up. 394 /// Check whether the link is up.
395 pub fn is_link_up(&self) -> bool { 395 pub fn is_link_up(&self) -> bool {
396 self.with(|i| i.link_up) 396 self.with(|i| i.link_up)
397 } 397 }
398 398
399 /// Get whether the network stack has a valid IP configuration. 399 /// Check whether the network stack has a valid IP configuration.
400 /// This is true if the network stack has a static IP configuration or if DHCP has completed 400 /// This is true if the network stack has a static IP configuration or if DHCP has completed
401 pub fn is_config_up(&self) -> bool { 401 pub fn is_config_up(&self) -> bool {
402 let v4_up; 402 let v4_up;
@@ -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)
diff --git a/embassy-stm32/src/eth/v2/mod.rs b/embassy-stm32/src/eth/v2/mod.rs
index b26f08cd9..9dd7f7d95 100644
--- a/embassy-stm32/src/eth/v2/mod.rs
+++ b/embassy-stm32/src/eth/v2/mod.rs
@@ -192,6 +192,9 @@ impl<'d, T: Instance, P: PHY> Ethernet<'d, T, P> {
192 // TODO: Carrier sense ? ECRSFD 192 // TODO: Carrier sense ? ECRSFD
193 }); 193 });
194 194
195 // Disable multicast filter
196 mac.macpfr().modify(|w| w.set_pm(true));
197
195 // Note: Writing to LR triggers synchronisation of both LR and HR into the MAC core, 198 // Note: Writing to LR triggers synchronisation of both LR and HR into the MAC core,
196 // so the LR write must happen after the HR write. 199 // so the LR write must happen after the HR write.
197 mac.maca0hr() 200 mac.maca0hr()