diff --git a/embassy-net/Cargo.toml b/embassy-net/Cargo.toml index ca34262d..1854d204 100644 --- a/embassy-net/Cargo.toml +++ b/embassy-net/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" [package.metadata.embassy_docs] src_base = "https://github.com/embassy-rs/embassy/blob/embassy-net-v$VERSION/embassy-net/src/" src_base_git = "https://github.com/embassy-rs/embassy/blob/$COMMIT/embassy-net/src/" -features = ["nightly", "unstable-traits", "defmt", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip"] +features = ["nightly", "unstable-traits", "defmt", "tcp", "udp", "dns", "dhcpv4", "proto-ipv6", "medium-ethernet", "medium-ip", "igmp"] target = "thumbv7em-none-eabi" [features] @@ -27,6 +27,7 @@ dhcpv4 = ["medium-ethernet", "smoltcp/socket-dhcpv4"] proto-ipv6 = ["smoltcp/proto-ipv6"] medium-ethernet = ["smoltcp/medium-ethernet"] medium-ip = ["smoltcp/medium-ip"] +igmp = ["smoltcp/proto-igmp"] [dependencies] diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 4ec1b5a7..7b9d0e77 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -304,6 +304,37 @@ impl Stack { } } +#[cfg(feature = "igmp")] +impl Stack { + pub fn join_multicast_group(&self, addr: T) -> Result + where + T: Into, + { + let addr = addr.into(); + + self.with_mut(|s, i| { + s.iface + .join_multicast_group(&mut i.device, addr, instant_to_smoltcp(Instant::now())) + }) + } + + pub fn leave_multicast_group(&self, addr: T) -> Result + where + T: Into, + { + let addr = addr.into(); + + self.with_mut(|s, i| { + s.iface + .leave_multicast_group(&mut i.device, addr, instant_to_smoltcp(Instant::now())) + }) + } + + pub fn has_multicast_group>(&self, addr: T) -> bool { + self.socket.borrow().iface.has_multicast_group(addr) + } +} + impl SocketStack { #[allow(clippy::absurd_extreme_comparisons, dead_code)] pub fn get_local_port(&mut self) -> u16 {