Skip to content

Commit 263279e

Browse files
committed
Make multicast ipv6 optional
1 parent aa2d5df commit 263279e

File tree

5 files changed

+53
-40
lines changed

5 files changed

+53
-40
lines changed

examples/onoff_light/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ fn run() -> Result<(), Error> {
101101
0,
102102
"matter-demo",
103103
ipv4_addr.octets(),
104-
Some(ipv6_addr.octets()),
105-
interface,
104+
Some((ipv6_addr.octets(), interface)),
106105
&dev_det,
107106
matter::MATTER_PORT,
108107
);

matter/Cargo.toml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "matter-iot"
33
version = "0.1.0"
4-
edition = "2018"
4+
edition = "2021"
55
authors = ["Kedar Sovani <[email protected]>"]
66
description = "Native RUST implementation of the Matter (Smart-Home) ecosystem"
77
repository = "https://github.com/kedars/matter-rs"
@@ -17,7 +17,8 @@ path = "src/lib.rs"
1717
[features]
1818
default = ["os", "crypto_rustcrypto"]
1919
os = ["std", "backtrace", "env_logger", "nix", "critical-section/std", "embassy-sync/std", "embassy-time/std"]
20-
std = ["alloc", "rand", "qrcode", "async-io", "esp-idf-sys/std"]
20+
esp-idf = ["std", "crypto_rustcrypto", "esp-idf-sys", "esp-idf-hal", "esp-idf-svc"]
21+
std = ["alloc", "rand", "qrcode", "async-io", "esp-idf-sys?/std", "embassy-time/generic-queue-16"]
2122
backtrace = []
2223
alloc = []
2324
nightly = []
@@ -43,10 +44,11 @@ owo-colors = "3"
4344
time = { version = "0.3", default-features = false }
4445
verhoeff = { version = "1", default-features = false }
4546
embassy-futures = "0.1"
46-
embassy-time = { version = "0.1.1", features = ["generic-queue-8"] }
47+
embassy-time = "0.1.1"
4748
embassy-sync = "0.2"
4849
critical-section = "1.1.1"
4950
domain = { version = "0.7.2", default_features = false, features = ["heapless"] }
51+
portable-atomic = "1"
5052

5153
# embassy-net dependencies
5254
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 }
8486
nix = { version = "0.26", features = ["net"], optional = true }
8587

8688
[target.'cfg(target_os = "espidf")'.dependencies]
87-
esp-idf-sys = { version = "0.33", default-features = false, features = ["native", "binstart"] }
88-
esp-idf-hal = { version = "0.41", features = ["embassy-sync", "critical-section"] }
89-
esp-idf-svc = { version = "0.46", features = ["embassy-time-driver"] }
90-
embedded-svc = "0.25"
89+
esp-idf-sys = { version = "0.33", optional = true, default-features = false, features = ["native", "binstart"] }
90+
esp-idf-hal = { version = "0.41", optional = true, features = ["embassy-sync", "critical-section"] } # TODO: Only necessary for the examples
91+
esp-idf-svc = { version = "0.46", optional = true, features = ["embassy-time-driver"] } # TODO: Only necessary for the examples
9192

9293
[build-dependencies]
9394
embuild = "0.31.2"

matter/src/data_model/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717

18-
use core::sync::atomic::{AtomicU32, Ordering};
18+
use portable_atomic::{AtomicU32, Ordering};
1919

2020
use super::objects::*;
2121
use crate::{

matter/src/mdns/astro.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ impl<'a> MdnsService<'a> {
2323
_id: u16,
2424
_hostname: &str,
2525
_ip: [u8; 4],
26-
_ipv6: Option<[u8; 16]>,
27-
_interface: u32,
26+
_ipv6: Option<([u8; 16], u32)>,
2827
dev_det: &'a BasicInfoConfig<'a>,
2928
matter_port: u16,
3029
) -> Self {

matter/src/mdns/builtin.rs

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const PORT: u16 = 5353;
2525
pub struct MdnsService<'a> {
2626
host: Host<'a>,
2727
#[allow(unused)]
28-
interface: u32,
28+
interface: Option<u32>,
2929
dev_det: &'a BasicInfoConfig<'a>,
3030
matter_port: u16,
3131
services: RefCell<heapless::Vec<(heapless::String<40>, ServiceMode), 4>>,
@@ -38,8 +38,7 @@ impl<'a> MdnsService<'a> {
3838
id: u16,
3939
hostname: &'a str,
4040
ip: [u8; 4],
41-
ipv6: Option<[u8; 16]>,
42-
interface: u32,
41+
ipv6: Option<([u8; 16], u32)>,
4342
dev_det: &'a BasicInfoConfig<'a>,
4443
matter_port: u16,
4544
) -> Self {
@@ -48,9 +47,17 @@ impl<'a> MdnsService<'a> {
4847
id,
4948
hostname,
5049
ip,
51-
ipv6,
50+
ipv6: if let Some((ipv6, _)) = ipv6 {
51+
Some(ipv6)
52+
} else {
53+
None
54+
},
55+
},
56+
interface: if let Some((_, interface)) = ipv6 {
57+
Some(interface)
58+
} else {
59+
None
5260
},
53-
interface,
5461
dev_det,
5562
matter_port,
5663
services: RefCell::new(heapless::Vec::new()),
@@ -137,8 +144,13 @@ impl<'a> MdnsRunner<'a> {
137144
)
138145
.await?;
139146

140-
udp.join_multicast_v6(IPV6_BROADCAST_ADDR, self.0.interface)
141-
.await?;
147+
// V6 multicast does not work with smoltcp yet (see https://github.com/smoltcp-rs/smoltcp/pull/602)
148+
#[cfg(not(feature = "embassy-net"))]
149+
if let Some(interface) = self.0.interface {
150+
udp.join_multicast_v6(IPV6_BROADCAST_ADDR, interface)
151+
.await?;
152+
}
153+
142154
udp.join_multicast_v4(
143155
IP_BROADCAST_ADDR,
144156
crate::transport::network::Ipv4Addr::from(self.0.host.ip),
@@ -217,35 +229,37 @@ impl<'a> MdnsRunner<'a> {
217229
IpAddr::V4(IP_BROADCAST_ADDR),
218230
IpAddr::V6(IPV6_BROADCAST_ADDR),
219231
] {
220-
loop {
221-
let sent = {
222-
let mut data = tx_pipe.data.lock().await;
232+
if self.0.interface.is_some() || addr == IpAddr::V4(IP_BROADCAST_ADDR) {
233+
loop {
234+
let sent = {
235+
let mut data = tx_pipe.data.lock().await;
223236

224-
if data.chunk.is_none() {
225-
let len = self.0.host.broadcast(&self.0, data.buf, 60)?;
237+
if data.chunk.is_none() {
238+
let len = self.0.host.broadcast(&self.0, data.buf, 60)?;
226239

227-
if len > 0 {
228-
info!("Broadasting mDNS entry to {}:{}", addr, PORT);
240+
if len > 0 {
241+
info!("Broadasting mDNS entry to {}:{}", addr, PORT);
242+
243+
data.chunk = Some(Chunk {
244+
start: 0,
245+
end: len,
246+
addr: Address::Udp(SocketAddr::new(addr, PORT)),
247+
});
229248

230-
data.chunk = Some(Chunk {
231-
start: 0,
232-
end: len,
233-
addr: Address::Udp(SocketAddr::new(addr, PORT)),
234-
});
249+
tx_pipe.data_supplied_notification.signal(());
250+
}
235251

236-
tx_pipe.data_supplied_notification.signal(());
252+
true
253+
} else {
254+
false
237255
}
256+
};
238257

239-
true
258+
if sent {
259+
break;
240260
} else {
241-
false
261+
tx_pipe.data_consumed_notification.wait().await;
242262
}
243-
};
244-
245-
if sent {
246-
break;
247-
} else {
248-
tx_pipe.data_consumed_notification.wait().await;
249263
}
250264
}
251265
}

0 commit comments

Comments
 (0)