Merged multi-admin
This commit is contained in:
parent
31034f6e89
commit
2b4919bb56
7 changed files with 31 additions and 37 deletions
|
@ -39,7 +39,7 @@ fn main() {
|
||||||
};
|
};
|
||||||
let dev_att = Box::new(dev_att::HardCodedDevAtt::new());
|
let dev_att = Box::new(dev_att::HardCodedDevAtt::new());
|
||||||
|
|
||||||
let mut matter = core::Matter::new(&dev_info, dev_att, &comm_data).unwrap();
|
let mut matter = core::Matter::new(&dev_info, dev_att, comm_data).unwrap();
|
||||||
let dm = matter.get_data_model();
|
let dm = matter.get_data_model();
|
||||||
{
|
{
|
||||||
let mut node = dm.node.write().unwrap();
|
let mut node = dm.node.write().unwrap();
|
||||||
|
|
|
@ -26,7 +26,7 @@ use crate::{
|
||||||
interaction_model::InteractionModel,
|
interaction_model::InteractionModel,
|
||||||
mdns::Mdns,
|
mdns::Mdns,
|
||||||
pairing::print_pairing_code_and_qr,
|
pairing::print_pairing_code_and_qr,
|
||||||
secure_channel::core::SecureChannel,
|
secure_channel::{core::SecureChannel, pake::PaseMgr, spake2p::VerifierData},
|
||||||
transport,
|
transport,
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
@ -56,17 +56,12 @@ impl Matter {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
dev_det: &BasicInfoConfig,
|
dev_det: &BasicInfoConfig,
|
||||||
dev_att: Box<dyn DevAttDataFetcher>,
|
dev_att: Box<dyn DevAttDataFetcher>,
|
||||||
dev_comm: &CommissioningData,
|
dev_comm: CommissioningData,
|
||||||
) -> Result<Box<Matter>, Error> {
|
) -> Result<Box<Matter>, Error> {
|
||||||
let mdns = Mdns::get()?;
|
let mdns = Mdns::get()?;
|
||||||
mdns.set_values(
|
mdns.set_values(dev_det.vid, dev_det.pid, &dev_det.device_name);
|
||||||
dev_det.vid,
|
|
||||||
dev_det.pid,
|
|
||||||
dev_comm.discriminator,
|
|
||||||
&dev_det.device_name,
|
|
||||||
);
|
|
||||||
|
|
||||||
print_pairing_code_and_qr(dev_det, dev_comm);
|
print_pairing_code_and_qr(dev_det, &dev_comm);
|
||||||
|
|
||||||
let fabric_mgr = Arc::new(FabricMgr::new()?);
|
let fabric_mgr = Arc::new(FabricMgr::new()?);
|
||||||
let acl_mgr = Arc::new(AclMgr::new()?);
|
let acl_mgr = Arc::new(AclMgr::new()?);
|
||||||
|
|
|
@ -381,7 +381,7 @@ impl FabricMgr {
|
||||||
pub fn set_label(&self, index: u8, label: String) -> Result<(), Error> {
|
pub fn set_label(&self, index: u8, label: String) -> Result<(), Error> {
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
let mut mgr = self.inner.write()?;
|
let mut mgr = self.inner.write()?;
|
||||||
if label != "" {
|
if !label.is_empty() {
|
||||||
for i in 1..MAX_SUPPORTED_FABRICS {
|
for i in 1..MAX_SUPPORTED_FABRICS {
|
||||||
if let Some(fabric) = &mgr.fabrics[i] {
|
if let Some(fabric) = &mgr.fabrics[i] {
|
||||||
if fabric.label == label {
|
if fabric.label == label {
|
||||||
|
|
|
@ -30,8 +30,6 @@ pub struct MdnsInner {
|
||||||
vid: u16,
|
vid: u16,
|
||||||
/// Product ID
|
/// Product ID
|
||||||
pid: u16,
|
pid: u16,
|
||||||
/// Discriminator
|
|
||||||
discriminator: u16,
|
|
||||||
/// Device name
|
/// Device name
|
||||||
device_name: String,
|
device_name: String,
|
||||||
}
|
}
|
||||||
|
@ -75,11 +73,10 @@ impl Mdns {
|
||||||
/// Set mDNS service specific values
|
/// Set mDNS service specific values
|
||||||
/// Values like vid, pid, discriminator etc
|
/// Values like vid, pid, discriminator etc
|
||||||
// TODO: More things like device-type etc can be added here
|
// TODO: More things like device-type etc can be added here
|
||||||
pub fn set_values(&self, vid: u16, pid: u16, discriminator: u16, device_name: &str) {
|
pub fn set_values(&self, vid: u16, pid: u16, device_name: &str) {
|
||||||
let mut inner = self.inner.lock().unwrap();
|
let mut inner = self.inner.lock().unwrap();
|
||||||
inner.vid = vid;
|
inner.vid = vid;
|
||||||
inner.pid = pid;
|
inner.pid = pid;
|
||||||
inner.discriminator = discriminator;
|
|
||||||
inner.device_name = device_name.chars().take(32).collect();
|
inner.device_name = device_name.chars().take(32).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,12 +89,12 @@ impl Mdns {
|
||||||
ServiceMode::Commissioned => {
|
ServiceMode::Commissioned => {
|
||||||
sys_publish_service(name, "_matter._tcp", MATTER_PORT, &[])
|
sys_publish_service(name, "_matter._tcp", MATTER_PORT, &[])
|
||||||
}
|
}
|
||||||
ServiceMode::Commissionable => {
|
ServiceMode::Commissionable(discriminator) => {
|
||||||
let inner = self.inner.lock().unwrap();
|
let inner = self.inner.lock().unwrap();
|
||||||
let short = compute_short_discriminator(inner.discriminator);
|
let short = compute_short_discriminator(discriminator);
|
||||||
let serv_type = format!("_matterc._udp,_S{},_L{}", short, inner.discriminator);
|
let serv_type = format!("_matterc._udp,_S{},_L{}", short, discriminator);
|
||||||
|
|
||||||
let str_discriminator = format!("{}", inner.discriminator);
|
let str_discriminator = format!("{}", discriminator);
|
||||||
let txt_kvs = [
|
let txt_kvs = [
|
||||||
["D", &str_discriminator],
|
["D", &str_discriminator],
|
||||||
["CM", "1"],
|
["CM", "1"],
|
||||||
|
|
|
@ -23,7 +23,7 @@ use verhoeff::Verhoeff;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
codec::base38, data_model::cluster_basic_information::BasicInfoConfig, error::Error,
|
codec::base38, data_model::cluster_basic_information::BasicInfoConfig, error::Error,
|
||||||
CommissioningData,
|
secure_channel::spake2p::VerifierOption, CommissioningData,
|
||||||
};
|
};
|
||||||
|
|
||||||
const LONG_BITS: usize = 12;
|
const LONG_BITS: usize = 12;
|
||||||
|
@ -130,10 +130,15 @@ fn compute_pairing_code(comm_data: &CommissioningData) -> String {
|
||||||
|
|
||||||
let CommissioningData {
|
let CommissioningData {
|
||||||
discriminator,
|
discriminator,
|
||||||
passwd,
|
verifier,
|
||||||
..
|
..
|
||||||
} = comm_data;
|
} = comm_data;
|
||||||
|
|
||||||
|
let passwd = match verifier.data {
|
||||||
|
VerifierOption::Password(pwd) => pwd,
|
||||||
|
VerifierOption::Verifier(_) => todo!(),
|
||||||
|
};
|
||||||
|
|
||||||
let mut digits = String::new();
|
let mut digits = String::new();
|
||||||
digits.push_str(&((VID_PID_PRESENT << 2) | (discriminator >> 10) as u8).to_string());
|
digits.push_str(&((VID_PID_PRESENT << 2) | (discriminator >> 10) as u8).to_string());
|
||||||
digits.push_str(&format!(
|
digits.push_str(&format!(
|
||||||
|
@ -233,6 +238,11 @@ fn generate_bit_set(
|
||||||
return Err(Error::BufferTooSmall);
|
return Err(Error::BufferTooSmall);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let passwd = match payload.comm_data.verifier.data {
|
||||||
|
VerifierOption::Password(pwd) => pwd,
|
||||||
|
VerifierOption::Verifier(_) => todo!(),
|
||||||
|
};
|
||||||
|
|
||||||
const VERSION: u64 = 0;
|
const VERSION: u64 = 0;
|
||||||
populate_bits(
|
populate_bits(
|
||||||
bits,
|
bits,
|
||||||
|
@ -285,7 +295,7 @@ fn generate_bit_set(
|
||||||
populate_bits(
|
populate_bits(
|
||||||
bits,
|
bits,
|
||||||
&mut offset,
|
&mut offset,
|
||||||
payload.comm_data.passwd as u64,
|
passwd as u64,
|
||||||
SETUP_PINCODE_FIELD_LENGTH_IN_BITS,
|
SETUP_PINCODE_FIELD_LENGTH_IN_BITS,
|
||||||
total_payload_size_in_bits,
|
total_payload_size_in_bits,
|
||||||
)?;
|
)?;
|
||||||
|
@ -306,22 +316,22 @@ fn generate_bit_set(
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::secure_channel::spake2p::VerifierData;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_compute_pairing_code() {
|
fn can_compute_pairing_code() {
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 123456,
|
verifier: VerifierData::new_with_pw(123456),
|
||||||
discriminator: 250,
|
discriminator: 250,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let pairing_code = compute_pairing_code(&comm_data);
|
let pairing_code = compute_pairing_code(&comm_data);
|
||||||
assert_eq!(pairing_code, "00876800071");
|
assert_eq!(pairing_code, "00876800071");
|
||||||
|
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 34567890,
|
verifier: VerifierData::new_with_pw(34567890),
|
||||||
discriminator: 2976,
|
discriminator: 2976,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let pairing_code = compute_pairing_code(&comm_data);
|
let pairing_code = compute_pairing_code(&comm_data);
|
||||||
assert_eq!(pairing_code, "26318621095");
|
assert_eq!(pairing_code, "26318621095");
|
||||||
|
@ -332,9 +342,8 @@ mod tests {
|
||||||
const QR_CODE: &str = "MT:YNJV7VSC00CMVH7SR00";
|
const QR_CODE: &str = "MT:YNJV7VSC00CMVH7SR00";
|
||||||
|
|
||||||
let comm_data = CommissioningData {
|
let comm_data = CommissioningData {
|
||||||
passwd: 34567890,
|
verifier: VerifierData::new_with_pw(34567890),
|
||||||
discriminator: 2976,
|
discriminator: 2976,
|
||||||
..Default::default()
|
|
||||||
};
|
};
|
||||||
let dev_det = BasicInfoConfig {
|
let dev_det = BasicInfoConfig {
|
||||||
vid: 9050,
|
vid: 9050,
|
||||||
|
|
|
@ -115,7 +115,7 @@ impl CryptoSpake2 for CryptoMbedTLS {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_L(&mut self, l: &[u8]) -> Result<(), Error> {
|
fn set_L(&mut self, l: &[u8]) -> Result<(), Error> {
|
||||||
self.L = EcPoint::from_binary(&mut self.group, l)?;
|
self.L = EcPoint::from_binary(&self.group, l)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,14 +106,7 @@ impl ImEngine {
|
||||||
// Only allow the standard peer node id of the IM Engine
|
// Only allow the standard peer node id of the IM Engine
|
||||||
default_acl.add_subject(IM_ENGINE_PEER_ID).unwrap();
|
default_acl.add_subject(IM_ENGINE_PEER_ID).unwrap();
|
||||||
acl_mgr.add(default_acl).unwrap();
|
acl_mgr.add(default_acl).unwrap();
|
||||||
let dm = DataModel::new(
|
let dm = DataModel::new(&dev_det, dev_att, fabric_mgr, acl_mgr.clone(), pase_mgr).unwrap();
|
||||||
dev_det,
|
|
||||||
dev_att,
|
|
||||||
fabric_mgr.clone(),
|
|
||||||
acl_mgr.clone(),
|
|
||||||
pase_mgr,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut d = dm.node.write().unwrap();
|
let mut d = dm.node.write().unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue