Skip to content

Commit

Permalink
Merge pull request #162 from ivmarkov/main
Browse files Browse the repository at this point in the history
Pass explicit DiscoveryCapabilities
  • Loading branch information
andy31415 authored May 15, 2024
2 parents 60bd339 + c3d6d0c commit 5d41b9f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
13 changes: 8 additions & 5 deletions examples/onoff_light/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ fn run() -> Result<(), Error> {
let mut transport = pin!(matter.run(
&socket,
&socket,
Some(CommissioningData {
// TODO: Hard-coded for now
verifier: VerifierData::new_with_pw(123456, *matter.borrow()),
discriminator: 250,
}),
Some((
CommissioningData {
// TODO: Hard-coded for now
verifier: VerifierData::new_with_pw(123456, *matter.borrow()),
discriminator: 250,
},
Default::default(),
)),
));

// NOTE:
Expand Down
15 changes: 6 additions & 9 deletions rs-matter/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use crate::{
pub const MATTER_PORT: u16 = 5540;

/// Device Commissioning Data
#[derive(Debug, Clone)]
pub struct CommissioningData {
/// The data like password or verifier that is required to authenticate
pub verifier: VerifierData,
Expand Down Expand Up @@ -149,16 +150,12 @@ impl<'a> Matter<'a> {
fn start_comissioning(
&self,
dev_comm: CommissioningData,
discovery_capabilities: DiscoveryCapabilities,
buf: &mut [u8],
) -> Result<bool, Error> {
if !self.pase_mgr.borrow().is_pase_session_enabled() && self.fabric_mgr.borrow().is_empty()
{
print_pairing_code_and_qr(
self.dev_det,
&dev_comm,
DiscoveryCapabilities::default(),
buf,
)?;
print_pairing_code_and_qr(self.dev_det, &dev_comm, discovery_capabilities, buf)?;

self.pase_mgr.borrow_mut().enable_pase_session(
dev_comm.verifier,
Expand All @@ -182,17 +179,17 @@ impl<'a> Matter<'a> {
&self,
send: S,
recv: R,
dev_comm: Option<CommissioningData>,
dev_comm: Option<(CommissioningData, DiscoveryCapabilities)>,
) -> Result<(), Error>
where
S: NetworkSend,
R: NetworkReceive,
{
if let Some(dev_comm) = dev_comm {
if let Some((dev_comm, discovery_caps)) = dev_comm {
let buf_access = PacketBufferExternalAccess(&self.transport_mgr.rx);
let mut buf = buf_access.get().await.ok_or(ErrorCode::NoSpace)?;

self.start_comissioning(dev_comm, &mut buf)?;
self.start_comissioning(dev_comm, discovery_caps, &mut buf)?;
}

self.transport_mgr.run(send, recv).await
Expand Down
5 changes: 3 additions & 2 deletions rs-matter/src/pairing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ use self::{
qr::{compute_qr_code_text, print_qr_code},
};

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct DiscoveryCapabilities {
on_ip_network: bool,
ble: bool,
soft_access_point: bool,
}

impl DiscoveryCapabilities {
pub fn new(on_ip_network: bool, ble: bool, soft_access_point: bool) -> Self {
DiscoveryCapabilities {
pub const fn new(on_ip_network: bool, ble: bool, soft_access_point: bool) -> Self {
Self {
on_ip_network,
ble,
soft_access_point,
Expand Down
2 changes: 2 additions & 0 deletions rs-matter/src/secure_channel/spake2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ impl Default for Spake2P {
}
}

#[derive(Debug, Clone)]
pub struct VerifierData {
pub data: VerifierOption,
// For the VerifierOption::Verifier, the following fields only serve
Expand All @@ -94,6 +95,7 @@ pub struct VerifierData {
pub count: u32,
}

#[derive(Debug, Clone)]
pub enum VerifierOption {
/// With Password
Password(u32),
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/tests/common/im_engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl<'a> ImEngine<'a> {
}

fn init_matter(matter: &Matter, local_nodeid: u64, remote_nodeid: u64, cat_ids: &NocCatIds) {
matter.transport_mgr.reset();
matter.transport_mgr.reset().unwrap();

let mut session = ReservedSession::reserve_now(matter).unwrap();

Expand Down

0 comments on commit 5d41b9f

Please sign in to comment.