Make multicast ipv6 optional

This commit is contained in:
ivmarkov 2023-07-18 10:20:40 +00:00
parent aa2d5dfe20
commit 263279e714
5 changed files with 53 additions and 40 deletions

View file

@ -101,8 +101,7 @@ fn run() -> Result<(), Error> {
0,
"matter-demo",
ipv4_addr.octets(),
Some(ipv6_addr.octets()),
interface,
Some((ipv6_addr.octets(), interface)),
&dev_det,
matter::MATTER_PORT,
);

View file

@ -1,7 +1,7 @@
[package]
name = "matter-iot"
version = "0.1.0"
edition = "2018"
edition = "2021"
authors = ["Kedar Sovani <kedars@gmail.com>"]
description = "Native RUST implementation of the Matter (Smart-Home) ecosystem"
repository = "https://github.com/kedars/matter-rs"
@ -17,7 +17,8 @@ path = "src/lib.rs"
[features]
default = ["os", "crypto_rustcrypto"]
os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"]
std = ["alloc", "rand", "qrcode", "async-io", "esp-idf-sys/std"]
esp-idf = ["std", "crypto_rustcrypto", "esp-idf-sys", "esp-idf-hal", "esp-idf-svc"]
std = ["alloc", "rand", "qrcode", "async-io", "esp-idf-sys?/std", "embassy-time/generic-queue-16"]
backtrace = []
alloc = []
nightly = []
@ -43,10 +44,11 @@ owo-colors = "3"
time = { version = "0.3", default-features = false }
verhoeff = { version = "1", default-features = false }
embassy-futures = "0.1"
embassy-time = { version = "0.1.1", features = ["generic-queue-8"] }
embassy-time = "0.1.1"
embassy-sync = "0.2"
critical-section = "1.1.1"
domain = { version = "0.7.2", default_features = false, features = ["heapless"] }
portable-atomic = "1"
# embassy-net dependencies
embassy-net = { version = "0.1", features = ["udp", "igmp", "proto-ipv6", "medium-ethernet", "medium-ip"], optional = true }
@ -84,10 +86,9 @@ env_logger = { version = "0.10.0", optional = true }
nix = { version = "0.26", features = ["net"], optional = true }
[target.'cfg(target_os = "espidf")'.dependencies]
esp-idf-sys = { version = "0.33", default-features = false, features = ["native", "binstart"] }
esp-idf-hal = { version = "0.41", features = ["embassy-sync", "critical-section"] }
esp-idf-svc = { version = "0.46", features = ["embassy-time-driver"] }
embedded-svc = "0.25"
esp-idf-sys = { version = "0.33", optional = true, default-features = false, features = ["native", "binstart"] }
esp-idf-hal = { version = "0.41", optional = true, features = ["embassy-sync", "critical-section"] } # TODO: Only necessary for the examples
esp-idf-svc = { version = "0.46", optional = true, features = ["embassy-time-driver"] } # TODO: Only necessary for the examples
[build-dependencies]
embuild = "0.31.2"

View file

@ -15,7 +15,7 @@
* limitations under the License.
*/
use core::sync::atomic::{AtomicU32, Ordering};
use portable_atomic::{AtomicU32, Ordering};
use super::objects::*;
use crate::{

View file

@ -23,8 +23,7 @@ impl<'a> MdnsService<'a> {
_id: u16,
_hostname: &str,
_ip: [u8; 4],
_ipv6: Option<[u8; 16]>,
_interface: u32,
_ipv6: Option<([u8; 16], u32)>,
dev_det: &'a BasicInfoConfig<'a>,
matter_port: u16,
) -> Self {

View file

@ -25,7 +25,7 @@ const PORT: u16 = 5353;
pub struct MdnsService<'a> {
host: Host<'a>,
#[allow(unused)]
interface: u32,
interface: Option<u32>,
dev_det: &'a BasicInfoConfig<'a>,
matter_port: u16,
services: RefCell<heapless::Vec<(heapless::String<40>, ServiceMode), 4>>,
@ -38,8 +38,7 @@ impl<'a> MdnsService<'a> {
id: u16,
hostname: &'a str,
ip: [u8; 4],
ipv6: Option<[u8; 16]>,
interface: u32,
ipv6: Option<([u8; 16], u32)>,
dev_det: &'a BasicInfoConfig<'a>,
matter_port: u16,
) -> Self {
@ -48,9 +47,17 @@ impl<'a> MdnsService<'a> {
id,
hostname,
ip,
ipv6,
ipv6: if let Some((ipv6, _)) = ipv6 {
Some(ipv6)
} else {
None
},
},
interface: if let Some((_, interface)) = ipv6 {
Some(interface)
} else {
None
},
interface,
dev_det,
matter_port,
services: RefCell::new(heapless::Vec::new()),
@ -137,8 +144,13 @@ impl<'a> MdnsRunner<'a> {
)
.await?;
udp.join_multicast_v6(IPV6_BROADCAST_ADDR, self.0.interface)
// V6 multicast does not work with smoltcp yet (see https://github.com/smoltcp-rs/smoltcp/pull/602)
#[cfg(not(feature = "embassy-net"))]
if let Some(interface) = self.0.interface {
udp.join_multicast_v6(IPV6_BROADCAST_ADDR, interface)
.await?;
}
udp.join_multicast_v4(
IP_BROADCAST_ADDR,
crate::transport::network::Ipv4Addr::from(self.0.host.ip),
@ -217,6 +229,7 @@ impl<'a> MdnsRunner<'a> {
IpAddr::V4(IP_BROADCAST_ADDR),
IpAddr::V6(IPV6_BROADCAST_ADDR),
] {
if self.0.interface.is_some() || addr == IpAddr::V4(IP_BROADCAST_ADDR) {
loop {
let sent = {
let mut data = tx_pipe.data.lock().await;
@ -251,6 +264,7 @@ impl<'a> MdnsRunner<'a> {
}
}
}
}
#[allow(clippy::await_holding_refcell_ref)]
async fn respond(&self, rx_pipe: &Pipe<'_>, tx_pipe: &Pipe<'_>) -> Result<(), Error> {