Make multicast ipv6 optional
This commit is contained in:
parent
aa2d5dfe20
commit
263279e714
5 changed files with 53 additions and 40 deletions
|
@ -101,8 +101,7 @@ fn run() -> Result<(), Error> {
|
||||||
0,
|
0,
|
||||||
"matter-demo",
|
"matter-demo",
|
||||||
ipv4_addr.octets(),
|
ipv4_addr.octets(),
|
||||||
Some(ipv6_addr.octets()),
|
Some((ipv6_addr.octets(), interface)),
|
||||||
interface,
|
|
||||||
&dev_det,
|
&dev_det,
|
||||||
matter::MATTER_PORT,
|
matter::MATTER_PORT,
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
name = "matter-iot"
|
name = "matter-iot"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2018"
|
edition = "2021"
|
||||||
authors = ["Kedar Sovani <kedars@gmail.com>"]
|
authors = ["Kedar Sovani <kedars@gmail.com>"]
|
||||||
description = "Native RUST implementation of the Matter (Smart-Home) ecosystem"
|
description = "Native RUST implementation of the Matter (Smart-Home) ecosystem"
|
||||||
repository = "https://github.com/kedars/matter-rs"
|
repository = "https://github.com/kedars/matter-rs"
|
||||||
|
@ -17,7 +17,8 @@ path = "src/lib.rs"
|
||||||
[features]
|
[features]
|
||||||
default = ["os", "crypto_rustcrypto"]
|
default = ["os", "crypto_rustcrypto"]
|
||||||
os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"]
|
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 = []
|
backtrace = []
|
||||||
alloc = []
|
alloc = []
|
||||||
nightly = []
|
nightly = []
|
||||||
|
@ -43,10 +44,11 @@ owo-colors = "3"
|
||||||
time = { version = "0.3", default-features = false }
|
time = { version = "0.3", default-features = false }
|
||||||
verhoeff = { version = "1", default-features = false }
|
verhoeff = { version = "1", default-features = false }
|
||||||
embassy-futures = "0.1"
|
embassy-futures = "0.1"
|
||||||
embassy-time = { version = "0.1.1", features = ["generic-queue-8"] }
|
embassy-time = "0.1.1"
|
||||||
embassy-sync = "0.2"
|
embassy-sync = "0.2"
|
||||||
critical-section = "1.1.1"
|
critical-section = "1.1.1"
|
||||||
domain = { version = "0.7.2", default_features = false, features = ["heapless"] }
|
domain = { version = "0.7.2", default_features = false, features = ["heapless"] }
|
||||||
|
portable-atomic = "1"
|
||||||
|
|
||||||
# embassy-net dependencies
|
# embassy-net dependencies
|
||||||
embassy-net = { version = "0.1", features = ["udp", "igmp", "proto-ipv6", "medium-ethernet", "medium-ip"], optional = true }
|
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 }
|
nix = { version = "0.26", features = ["net"], optional = true }
|
||||||
|
|
||||||
[target.'cfg(target_os = "espidf")'.dependencies]
|
[target.'cfg(target_os = "espidf")'.dependencies]
|
||||||
esp-idf-sys = { version = "0.33", default-features = false, features = ["native", "binstart"] }
|
esp-idf-sys = { version = "0.33", optional = true, default-features = false, features = ["native", "binstart"] }
|
||||||
esp-idf-hal = { version = "0.41", features = ["embassy-sync", "critical-section"] }
|
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", features = ["embassy-time-driver"] }
|
esp-idf-svc = { version = "0.46", optional = true, features = ["embassy-time-driver"] } # TODO: Only necessary for the examples
|
||||||
embedded-svc = "0.25"
|
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
embuild = "0.31.2"
|
embuild = "0.31.2"
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use portable_atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
use super::objects::*;
|
use super::objects::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -23,8 +23,7 @@ impl<'a> MdnsService<'a> {
|
||||||
_id: u16,
|
_id: u16,
|
||||||
_hostname: &str,
|
_hostname: &str,
|
||||||
_ip: [u8; 4],
|
_ip: [u8; 4],
|
||||||
_ipv6: Option<[u8; 16]>,
|
_ipv6: Option<([u8; 16], u32)>,
|
||||||
_interface: u32,
|
|
||||||
dev_det: &'a BasicInfoConfig<'a>,
|
dev_det: &'a BasicInfoConfig<'a>,
|
||||||
matter_port: u16,
|
matter_port: u16,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
|
|
@ -25,7 +25,7 @@ const PORT: u16 = 5353;
|
||||||
pub struct MdnsService<'a> {
|
pub struct MdnsService<'a> {
|
||||||
host: Host<'a>,
|
host: Host<'a>,
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
interface: u32,
|
interface: Option<u32>,
|
||||||
dev_det: &'a BasicInfoConfig<'a>,
|
dev_det: &'a BasicInfoConfig<'a>,
|
||||||
matter_port: u16,
|
matter_port: u16,
|
||||||
services: RefCell<heapless::Vec<(heapless::String<40>, ServiceMode), 4>>,
|
services: RefCell<heapless::Vec<(heapless::String<40>, ServiceMode), 4>>,
|
||||||
|
@ -38,8 +38,7 @@ impl<'a> MdnsService<'a> {
|
||||||
id: u16,
|
id: u16,
|
||||||
hostname: &'a str,
|
hostname: &'a str,
|
||||||
ip: [u8; 4],
|
ip: [u8; 4],
|
||||||
ipv6: Option<[u8; 16]>,
|
ipv6: Option<([u8; 16], u32)>,
|
||||||
interface: u32,
|
|
||||||
dev_det: &'a BasicInfoConfig<'a>,
|
dev_det: &'a BasicInfoConfig<'a>,
|
||||||
matter_port: u16,
|
matter_port: u16,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
@ -48,9 +47,17 @@ impl<'a> MdnsService<'a> {
|
||||||
id,
|
id,
|
||||||
hostname,
|
hostname,
|
||||||
ip,
|
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,
|
dev_det,
|
||||||
matter_port,
|
matter_port,
|
||||||
services: RefCell::new(heapless::Vec::new()),
|
services: RefCell::new(heapless::Vec::new()),
|
||||||
|
@ -137,8 +144,13 @@ impl<'a> MdnsRunner<'a> {
|
||||||
)
|
)
|
||||||
.await?;
|
.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)
|
||||||
.await?;
|
#[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(
|
udp.join_multicast_v4(
|
||||||
IP_BROADCAST_ADDR,
|
IP_BROADCAST_ADDR,
|
||||||
crate::transport::network::Ipv4Addr::from(self.0.host.ip),
|
crate::transport::network::Ipv4Addr::from(self.0.host.ip),
|
||||||
|
@ -217,35 +229,37 @@ impl<'a> MdnsRunner<'a> {
|
||||||
IpAddr::V4(IP_BROADCAST_ADDR),
|
IpAddr::V4(IP_BROADCAST_ADDR),
|
||||||
IpAddr::V6(IPV6_BROADCAST_ADDR),
|
IpAddr::V6(IPV6_BROADCAST_ADDR),
|
||||||
] {
|
] {
|
||||||
loop {
|
if self.0.interface.is_some() || addr == IpAddr::V4(IP_BROADCAST_ADDR) {
|
||||||
let sent = {
|
loop {
|
||||||
let mut data = tx_pipe.data.lock().await;
|
let sent = {
|
||||||
|
let mut data = tx_pipe.data.lock().await;
|
||||||
|
|
||||||
if data.chunk.is_none() {
|
if data.chunk.is_none() {
|
||||||
let len = self.0.host.broadcast(&self.0, data.buf, 60)?;
|
let len = self.0.host.broadcast(&self.0, data.buf, 60)?;
|
||||||
|
|
||||||
if len > 0 {
|
if len > 0 {
|
||||||
info!("Broadasting mDNS entry to {}:{}", addr, PORT);
|
info!("Broadasting mDNS entry to {}:{}", addr, PORT);
|
||||||
|
|
||||||
data.chunk = Some(Chunk {
|
data.chunk = Some(Chunk {
|
||||||
start: 0,
|
start: 0,
|
||||||
end: len,
|
end: len,
|
||||||
addr: Address::Udp(SocketAddr::new(addr, PORT)),
|
addr: Address::Udp(SocketAddr::new(addr, PORT)),
|
||||||
});
|
});
|
||||||
|
|
||||||
tx_pipe.data_supplied_notification.signal(());
|
tx_pipe.data_supplied_notification.signal(());
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
true
|
if sent {
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
false
|
tx_pipe.data_consumed_notification.wait().await;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if sent {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
tx_pipe.data_consumed_notification.wait().await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue