Skip to content

Commit

Permalink
Pass correct if for ipv6 mDNS
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed May 1, 2024
1 parent 931e248 commit a7d75ff
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
6 changes: 3 additions & 3 deletions .github/configs/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Increase a bit these stack sizes as they are too low by default
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=8192
#CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
CONFIG_PTHREAD_TASK_STACK_SIZE_DEFAULT=8192 # For async-io

# Go figure...
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=4096
Expand All @@ -17,4 +17,4 @@ CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_A2DP_ENABLE=n
CONFIG_BT_BLE_42_FEATURES_SUPPORTED=y
CONFIG_BT_BLE_50_FEATURES_SUPPORTED=n
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=n
CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY=y
4 changes: 2 additions & 2 deletions examples/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ fn main() -> Result<(), Error> {

// Run in a higher-prio thread to avoid issues with `async-io` getting
// confused by the low priority of the ESP IDF main task
// Also allocate a large stack as `rs-matter` futures do occupy quite some space
// Also allocate a very large stack (for now) as `rs-matter` futures do occupy quite some space
let thread = std::thread::Builder::new()
.stack_size(60 * 1024)
.stack_size(80 * 1024)
.spawn(run)
.unwrap();

Expand Down
6 changes: 4 additions & 2 deletions src/netif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ where
}
}

pub fn get_ips(netif: &EspNetif) -> Result<(Ipv4Addr, Ipv6Addr), Error> {
pub fn get_ips(netif: &EspNetif) -> Result<(Ipv4Addr, Ipv6Addr, u32), Error> {
let ip_info = netif.get_ip_info()?;

let ipv4: Ipv4Addr = ip_info.ip.octets().into();
Expand Down Expand Up @@ -110,7 +110,9 @@ pub fn get_ips(netif: &EspNetif) -> Result<(Ipv4Addr, Ipv6Addr), Error> {
]
.into();

Ok((ipv4, ipv6))
let interface = netif.get_index();

Ok((ipv4, ipv6, interface))
}

#[cfg(esp_idf_comp_esp_eth_enabled)]
Expand Down
17 changes: 11 additions & 6 deletions src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,19 @@ where
loop {
info!("Waiting for the network to come up...");

let (ipv4, ipv6) = netif
let (ipv4, ipv6, interface) = netif
.wait(sysloop.clone(), |netif| Ok(get_ips(netif).ok()))
.await?;

info!("Got network with IPs: IPv4={ipv4}, IPv6={ipv6}");
info!("Got network with IPs: IPv4={ipv4}, IPv6={ipv6}, if={interface}");

let socket = async_io::Async::<std::net::UdpSocket>::bind(MATTER_SOCKET_BIND_ADDR)?;

let mut main =
pin!(self.run_once(&socket, &socket, nvs.clone(), dev_comm.clone(), &handler));
let mut mdns = pin!(self.run_builtin_mdns(ipv4, ipv6));
let mut mdns = pin!(self.run_builtin_mdns(ipv4, ipv6, interface));
let mut down = pin!(netif.wait(sysloop.clone(), |netif| {
let prev = Some((ipv4, ipv6));
let prev = Some((ipv4, ipv6, interface));
let next = get_ips(netif).ok();

Ok((prev != next).then_some(()))
Expand Down Expand Up @@ -212,7 +212,12 @@ where
Ok(())
}

async fn run_builtin_mdns(&self, ipv4: Ipv4Addr, ipv6: Ipv6Addr) -> Result<(), Error> {
async fn run_builtin_mdns(
&self,
ipv4: Ipv4Addr,
ipv6: Ipv6Addr,
interface: u32,
) -> Result<(), Error> {
use rs_matter::mdns::{
Host, MDNS_IPV4_BROADCAST_ADDR, MDNS_IPV6_BROADCAST_ADDR, MDNS_SOCKET_BIND_ADDR,
};
Expand All @@ -232,7 +237,7 @@ where
ip: ipv4.octets(),
ipv6: Some(ipv6.octets()),
},
Some(0),
Some(interface),
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion src/wifi/mgmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ where
&[AuthMethod::None]
} else {
&[
AuthMethod::WPA2WPA3Personal,
AuthMethod::WPAWPA2Personal,
AuthMethod::WPA2WPA3Personal,
AuthMethod::WEP,
]
};
Expand Down

0 comments on commit a7d75ff

Please sign in to comment.