Skip to content

Commit

Permalink
Root endpoint with Wifi support (project-chip#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jun 5, 2024
1 parent d537824 commit b569815
Show file tree
Hide file tree
Showing 5 changed files with 359 additions and 43 deletions.
4 changes: 2 additions & 2 deletions examples/onoff_light/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fn run() -> Result<(), Error> {
const NODE: Node<'static> = Node {
id: 0,
endpoints: &[
root_endpoint::endpoint(0),
root_endpoint::endpoint(0, root_endpoint::OperNwType::Ethernet),
Endpoint {
id: 1,
device_type: DEV_TYPE_ON_OFF_LIGHT,
Expand All @@ -196,7 +196,7 @@ fn dm_handler<'a>(
) -> impl Metadata + NonBlockingHandler + 'a {
(
NODE,
root_endpoint::handler(0, matter)
root_endpoint::eth_handler(0, matter)
.chain(
1,
descriptor::ID,
Expand Down
147 changes: 109 additions & 38 deletions rs-matter/src/data_model/root_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@ use crate::{

use super::{
cluster_basic_information::{self, BasicInfoCluster, BasicInfoConfig},
objects::{Cluster, EmptyHandler, Endpoint, EndptId},
objects::{Cluster, EmptyHandler, Endpoint, EndptId, HandlerCompat},
sdm::{
admin_commissioning::{self, AdminCommCluster},
dev_att::DevAttDataFetcher,
ethernet_nw_diagnostics::{self, EthNwDiagCluster},
failsafe::FailSafe,
general_commissioning::{self, GenCommCluster},
general_diagnostics::{self, GenDiagCluster},
group_key_management,
group_key_management::GrpKeyMgmtCluster,
group_key_management::{self, GrpKeyMgmtCluster},
noc::{self, NocCluster},
nw_commissioning::{self, EthNwCommCluster},
},
Expand All @@ -30,20 +29,20 @@ use super::{
},
};

pub type RootEndpointHandler<'a> = handler_chain_type!(
DescriptorCluster<'static>,
BasicInfoCluster<'a>,
GenCommCluster<'a>,
EthNwCommCluster,
AdminCommCluster<'a>,
NocCluster<'a>,
AccessControlCluster<'a>,
GenDiagCluster,
EthNwDiagCluster,
GrpKeyMgmtCluster
);
const ETH_NW_CLUSTERS: [Cluster<'static>; 10] = [
descriptor::CLUSTER,
cluster_basic_information::CLUSTER,
general_commissioning::CLUSTER,
nw_commissioning::ETH_CLUSTER,
admin_commissioning::CLUSTER,
noc::CLUSTER,
access_control::CLUSTER,
general_diagnostics::CLUSTER,
ethernet_nw_diagnostics::CLUSTER,
group_key_management::CLUSTER,
];

pub const CLUSTERS: [Cluster<'static>; 10] = [
const WIFI_NW_CLUSTERS: [Cluster<'static>; 10] = [
descriptor::CLUSTER,
cluster_basic_information::CLUSTER,
general_commissioning::CLUSTER,
Expand All @@ -56,15 +55,83 @@ pub const CLUSTERS: [Cluster<'static>; 10] = [
group_key_management::CLUSTER,
];

pub const fn endpoint(id: EndptId) -> Endpoint<'static> {
/// The type of operational network (Ethernet, Wifi or (future) Thread)
/// for which root endpoint meta-data is being requested
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum OperNwType {
Ethernet,
Wifi,
}

/// A utility function to create a root (Endpoint 0) object using the requested operational network type.
pub const fn endpoint(id: EndptId, op_nw_type: OperNwType) -> Endpoint<'static> {
Endpoint {
id,
device_type: super::device_types::DEV_TYPE_ROOT_NODE,
clusters: &CLUSTERS,
clusters: clusters(op_nw_type),
}
}

/// A utility function to return the clusters for a root (Endpoint 0) object using the requested operational network type.
pub const fn clusters(op_nw_type: OperNwType) -> &'static [Cluster<'static>] {
match op_nw_type {
OperNwType::Ethernet => &ETH_NW_CLUSTERS,
OperNwType::Wifi => &WIFI_NW_CLUSTERS,
}
}

pub fn handler<'a, T>(endpoint_id: u16, matter: &'a T) -> RootEndpointHandler<'a>
/// A type alias for a root (Endpoint 0) handler using Ethernet as an operational network
pub type EthRootEndpointHandler<'a> = RootEndpointHandler<'a, EthNwCommCluster, EthNwDiagCluster>;

/// A type representing the type of the root (Endpoint 0) handler
/// which is generic over the operational transport clusters (i.e. Ethernet, Wifi or Thread)
pub type RootEndpointHandler<'a, NWCOMM, NWDIAG> = handler_chain_type!(
NWCOMM,
NWDIAG,
HandlerCompat<descriptor::DescriptorCluster<'a>>,
HandlerCompat<cluster_basic_information::BasicInfoCluster<'a>>,
HandlerCompat<general_commissioning::GenCommCluster<'a>>,
HandlerCompat<admin_commissioning::AdminCommCluster<'a>>,
HandlerCompat<noc::NocCluster<'a>>,
HandlerCompat<access_control::AccessControlCluster<'a>>,
HandlerCompat<general_diagnostics::GenDiagCluster>,
HandlerCompat<group_key_management::GrpKeyMgmtCluster>
);

/// A utility function to instantiate the root (Endpoint 0) handler using Ethernet as the operational network.
pub fn eth_handler<'a, T>(endpoint_id: u16, matter: &'a T) -> EthRootEndpointHandler<'a>
where
T: Borrow<BasicInfoConfig<'a>>
+ Borrow<dyn DevAttDataFetcher + 'a>
+ Borrow<RefCell<PaseMgr>>
+ Borrow<RefCell<FabricMgr>>
+ Borrow<RefCell<AclMgr>>
+ Borrow<RefCell<FailSafe>>
+ Borrow<dyn Mdns + 'a>
+ Borrow<Epoch>
+ Borrow<Rand>
+ 'a,
{
handler(
endpoint_id,
matter,
EthNwCommCluster::new(*matter.borrow()),
ethernet_nw_diagnostics::ID,
EthNwDiagCluster::new(*matter.borrow()),
)
}

/// A utility function to instantiate the root (Endpoint 0) handler.
/// Besides a reference to the main `Matter` object, this function
/// needs user-supplied implementations of the network commissioning
/// and network diagnostics clusters.
pub fn handler<'a, NWCOMM, NWDIAG, T>(
endpoint_id: u16,
matter: &'a T,
nwcomm: NWCOMM,
nwdiag_id: u32,
nwdiag: NWDIAG,
) -> RootEndpointHandler<'a, NWCOMM, NWDIAG>
where
T: Borrow<BasicInfoConfig<'a>>
+ Borrow<dyn DevAttDataFetcher + 'a>
Expand All @@ -88,11 +155,14 @@ where
matter.borrow(),
*matter.borrow(),
*matter.borrow(),
nwcomm,
nwdiag_id,
nwdiag,
)
}

#[allow(clippy::too_many_arguments)]
pub fn wrap<'a>(
fn wrap<'a, NWCOMM, NWDIAG>(
endpoint_id: u16,
basic_info: &'a BasicInfoConfig<'a>,
dev_att: &'a dyn DevAttDataFetcher,
Expand All @@ -103,52 +173,53 @@ pub fn wrap<'a>(
mdns: &'a dyn Mdns,
epoch: Epoch,
rand: Rand,
) -> RootEndpointHandler<'a> {
nwcomm: NWCOMM,
nwdiag_id: u32,
nwdiag: NWDIAG,
) -> RootEndpointHandler<'a, NWCOMM, NWDIAG> {
EmptyHandler
.chain(
endpoint_id,
group_key_management::ID,
GrpKeyMgmtCluster::new(rand),
)
.chain(
endpoint_id,
ethernet_nw_diagnostics::ID,
EthNwDiagCluster::new(rand),
HandlerCompat(GrpKeyMgmtCluster::new(rand)),
)
.chain(
endpoint_id,
general_diagnostics::ID,
GenDiagCluster::new(rand),
HandlerCompat(GenDiagCluster::new(rand)),
)
.chain(
endpoint_id,
access_control::ID,
AccessControlCluster::new(acl, rand),
HandlerCompat(AccessControlCluster::new(acl, rand)),
)
.chain(
endpoint_id,
noc::ID,
NocCluster::new(dev_att, fabric, acl, failsafe, mdns, epoch, rand),
HandlerCompat(NocCluster::new(
dev_att, fabric, acl, failsafe, mdns, epoch, rand,
)),
)
.chain(
endpoint_id,
admin_commissioning::ID,
AdminCommCluster::new(pase, mdns, rand),
HandlerCompat(AdminCommCluster::new(pase, mdns, rand)),
)
.chain(
endpoint_id,
nw_commissioning::ID,
EthNwCommCluster::new(rand),
general_commissioning::ID,
HandlerCompat(GenCommCluster::new(failsafe, false, rand)),
)
.chain(
endpoint_id,
general_commissioning::ID,
GenCommCluster::new(failsafe, true, rand),
cluster_basic_information::ID,
HandlerCompat(BasicInfoCluster::new(basic_info, rand)),
)
.chain(
endpoint_id,
cluster_basic_information::ID,
BasicInfoCluster::new(basic_info, rand),
descriptor::ID,
HandlerCompat(DescriptorCluster::new(rand)),
)
.chain(endpoint_id, descriptor::ID, DescriptorCluster::new(rand))
.chain(endpoint_id, nwdiag_id, nwdiag)
.chain(endpoint_id, nw_commissioning::ID, nwcomm)
}
1 change: 1 addition & 0 deletions rs-matter/src/data_model/sdm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ pub mod general_diagnostics;
pub mod group_key_management;
pub mod noc;
pub mod nw_commissioning;
pub mod wifi_nw_diagnostics;
Loading

0 comments on commit b569815

Please sign in to comment.