Skip to content

Commit faf3c60

Browse files
committed
Placeholder clusters that show in 'server-list' to make iOS happy
1 parent 96ceaa4 commit faf3c60

File tree

5 files changed

+497
-2
lines changed

5 files changed

+497
-2
lines changed

rs-matter/src/data_model/root_endpoint.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ use super::{
1515
sdm::{
1616
admin_commissioning::{self, AdminCommCluster},
1717
dev_att::DevAttDataFetcher,
18+
ethernet_nw_diagnostics::{self, EthNwDiagCluster},
1819
failsafe::FailSafe,
1920
general_commissioning::{self, GenCommCluster},
21+
general_diagnostics::{self, GenDiagCluster},
22+
group_key_management,
23+
group_key_management::GrpKeyMgmtCluster,
2024
noc::{self, NocCluster},
2125
nw_commissioning::{self, NwCommCluster},
2226
},
@@ -33,17 +37,23 @@ pub type RootEndpointHandler<'a> = handler_chain_type!(
3337
NwCommCluster,
3438
AdminCommCluster<'a>,
3539
NocCluster<'a>,
36-
AccessControlCluster<'a>
40+
AccessControlCluster<'a>,
41+
GenDiagCluster,
42+
EthNwDiagCluster,
43+
GrpKeyMgmtCluster
3744
);
3845

39-
pub const CLUSTERS: [Cluster<'static>; 7] = [
46+
pub const CLUSTERS: [Cluster<'static>; 10] = [
4047
descriptor::CLUSTER,
4148
cluster_basic_information::CLUSTER,
4249
general_commissioning::CLUSTER,
4350
nw_commissioning::CLUSTER,
4451
admin_commissioning::CLUSTER,
4552
noc::CLUSTER,
4653
access_control::CLUSTER,
54+
general_diagnostics::CLUSTER,
55+
ethernet_nw_diagnostics::CLUSTER,
56+
group_key_management::CLUSTER,
4757
];
4858

4959
pub const fn endpoint(id: EndptId) -> Endpoint<'static> {
@@ -95,6 +105,21 @@ pub fn wrap<'a>(
95105
rand: Rand,
96106
) -> RootEndpointHandler<'a> {
97107
EmptyHandler
108+
.chain(
109+
endpoint_id,
110+
group_key_management::ID,
111+
GrpKeyMgmtCluster::new(rand),
112+
)
113+
.chain(
114+
endpoint_id,
115+
ethernet_nw_diagnostics::ID,
116+
EthNwDiagCluster::new(rand),
117+
)
118+
.chain(
119+
endpoint_id,
120+
general_diagnostics::ID,
121+
GenDiagCluster::new(rand),
122+
)
98123
.chain(
99124
endpoint_id,
100125
access_control::ID,
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use core::convert::TryInto;
19+
20+
use crate::{
21+
attribute_enum, cmd_enter, command_enum, data_model::objects::AttrType, data_model::objects::*,
22+
error::Error, tlv::TLVElement, transport::exchange::Exchange, utils::rand::Rand,
23+
};
24+
use log::info;
25+
use strum::{EnumDiscriminants, FromRepr};
26+
27+
pub const ID: u32 = 0x0037;
28+
29+
#[derive(FromRepr, EnumDiscriminants)]
30+
#[repr(u16)]
31+
pub enum Attributes {
32+
PacketRxCount(AttrType<u64>) = 0x02,
33+
PacketTxCount(AttrType<u64>) = 0x03,
34+
}
35+
36+
attribute_enum!(Attributes);
37+
38+
#[derive(FromRepr, EnumDiscriminants)]
39+
#[repr(u32)]
40+
pub enum Commands {
41+
ResetCounts = 0x0,
42+
}
43+
44+
command_enum!(Commands);
45+
46+
pub const CLUSTER: Cluster<'static> = Cluster {
47+
id: ID as _,
48+
feature_map: 0,
49+
attributes: &[
50+
FEATURE_MAP,
51+
ATTRIBUTE_LIST,
52+
Attribute::new(
53+
AttributesDiscriminants::PacketRxCount as u16,
54+
Access::RV,
55+
Quality::NONE,
56+
),
57+
Attribute::new(
58+
AttributesDiscriminants::PacketTxCount as u16,
59+
Access::RV,
60+
Quality::FIXED,
61+
),
62+
],
63+
commands: &[CommandsDiscriminants::ResetCounts as _],
64+
};
65+
66+
pub struct EthNwDiagCluster {
67+
data_ver: Dataver,
68+
}
69+
70+
impl EthNwDiagCluster {
71+
pub fn new(rand: Rand) -> Self {
72+
Self {
73+
data_ver: Dataver::new(rand),
74+
}
75+
}
76+
77+
pub fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
78+
if let Some(writer) = encoder.with_dataver(self.data_ver.get())? {
79+
if attr.is_system() {
80+
CLUSTER.read(attr.attr_id, writer)
81+
} else {
82+
match attr.attr_id.try_into()? {
83+
Attributes::PacketRxCount(codec) => codec.encode(writer, 1),
84+
Attributes::PacketTxCount(codec) => codec.encode(writer, 1),
85+
}
86+
}
87+
} else {
88+
Ok(())
89+
}
90+
}
91+
92+
pub fn write(&self, _attr: &AttrDetails, data: AttrData) -> Result<(), Error> {
93+
let _data = data.with_dataver(self.data_ver.get())?;
94+
95+
self.data_ver.changed();
96+
97+
Ok(())
98+
}
99+
100+
pub fn invoke(
101+
&self,
102+
_exchange: &Exchange,
103+
cmd: &CmdDetails,
104+
_data: &TLVElement,
105+
_encoder: CmdDataEncoder,
106+
) -> Result<(), Error> {
107+
match cmd.cmd_id.try_into()? {
108+
Commands::ResetCounts => {
109+
cmd_enter!("ResetCounts: Not yet supported");
110+
}
111+
}
112+
113+
self.data_ver.changed();
114+
115+
Ok(())
116+
}
117+
}
118+
119+
impl Handler for EthNwDiagCluster {
120+
fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
121+
EthNwDiagCluster::read(self, attr, encoder)
122+
}
123+
124+
fn write(&self, attr: &AttrDetails, data: AttrData) -> Result<(), Error> {
125+
EthNwDiagCluster::write(self, attr, data)
126+
}
127+
128+
fn invoke(
129+
&self,
130+
exchange: &Exchange,
131+
cmd: &CmdDetails,
132+
data: &TLVElement,
133+
encoder: CmdDataEncoder,
134+
) -> Result<(), Error> {
135+
EthNwDiagCluster::invoke(self, exchange, cmd, data, encoder)
136+
}
137+
}
138+
139+
// TODO: Might be removed once the `on` member is externalized
140+
impl NonBlockingHandler for EthNwDiagCluster {}
141+
142+
impl ChangeNotifier<()> for EthNwDiagCluster {
143+
fn consume_change(&mut self) -> Option<()> {
144+
self.data_ver.consume_change(())
145+
}
146+
}
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
use core::convert::TryInto;
19+
20+
use crate::{
21+
attribute_enum, cmd_enter, command_enum,
22+
data_model::objects::AttrType,
23+
data_model::objects::*,
24+
error::{Error, ErrorCode},
25+
tlv::TLVElement,
26+
transport::exchange::Exchange,
27+
utils::rand::Rand,
28+
};
29+
use log::info;
30+
use strum::{EnumDiscriminants, FromRepr};
31+
32+
pub const ID: u32 = 0x0033;
33+
34+
#[derive(FromRepr, EnumDiscriminants)]
35+
#[repr(u16)]
36+
pub enum Attributes {
37+
NetworkInterfaces(()) = 0x00,
38+
RebootCount(AttrType<u16>) = 0x01,
39+
TestEventTriggersEnabled(AttrType<bool>) = 0x08,
40+
}
41+
42+
attribute_enum!(Attributes);
43+
44+
#[derive(FromRepr, EnumDiscriminants)]
45+
#[repr(u32)]
46+
pub enum Commands {
47+
TestEventTrigger = 0x0,
48+
}
49+
50+
command_enum!(Commands);
51+
52+
pub const CLUSTER: Cluster<'static> = Cluster {
53+
id: ID as _,
54+
feature_map: 0,
55+
attributes: &[
56+
FEATURE_MAP,
57+
ATTRIBUTE_LIST,
58+
Attribute::new(
59+
AttributesDiscriminants::NetworkInterfaces as u16,
60+
Access::RV,
61+
Quality::NONE,
62+
),
63+
Attribute::new(
64+
AttributesDiscriminants::RebootCount as u16,
65+
Access::RV,
66+
Quality::PERSISTENT,
67+
),
68+
Attribute::new(
69+
AttributesDiscriminants::TestEventTriggersEnabled as u16,
70+
Access::RV,
71+
Quality::NONE,
72+
),
73+
],
74+
commands: &[CommandsDiscriminants::TestEventTrigger as _],
75+
};
76+
77+
pub struct GenDiagCluster {
78+
data_ver: Dataver,
79+
}
80+
81+
impl GenDiagCluster {
82+
pub fn new(rand: Rand) -> Self {
83+
Self {
84+
data_ver: Dataver::new(rand),
85+
}
86+
}
87+
88+
pub fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
89+
if let Some(writer) = encoder.with_dataver(self.data_ver.get())? {
90+
if attr.is_system() {
91+
CLUSTER.read(attr.attr_id, writer)
92+
} else {
93+
match attr.attr_id.try_into()? {
94+
Attributes::RebootCount(codec) => codec.encode(writer, 1),
95+
_ => Err(ErrorCode::AttributeNotFound.into()),
96+
}
97+
}
98+
} else {
99+
Ok(())
100+
}
101+
}
102+
103+
pub fn write(&self, _attr: &AttrDetails, data: AttrData) -> Result<(), Error> {
104+
let _data = data.with_dataver(self.data_ver.get())?;
105+
106+
self.data_ver.changed();
107+
108+
Ok(())
109+
}
110+
111+
pub fn invoke(
112+
&self,
113+
_exchange: &Exchange,
114+
cmd: &CmdDetails,
115+
_data: &TLVElement,
116+
_encoder: CmdDataEncoder,
117+
) -> Result<(), Error> {
118+
match cmd.cmd_id.try_into()? {
119+
Commands::TestEventTrigger => {
120+
cmd_enter!("TestEventTrigger: Not yet supported");
121+
}
122+
}
123+
124+
self.data_ver.changed();
125+
126+
Ok(())
127+
}
128+
}
129+
130+
impl Handler for GenDiagCluster {
131+
fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
132+
GenDiagCluster::read(self, attr, encoder)
133+
}
134+
135+
fn write(&self, attr: &AttrDetails, data: AttrData) -> Result<(), Error> {
136+
GenDiagCluster::write(self, attr, data)
137+
}
138+
139+
fn invoke(
140+
&self,
141+
exchange: &Exchange,
142+
cmd: &CmdDetails,
143+
data: &TLVElement,
144+
encoder: CmdDataEncoder,
145+
) -> Result<(), Error> {
146+
GenDiagCluster::invoke(self, exchange, cmd, data, encoder)
147+
}
148+
}
149+
150+
// TODO: Might be removed once the `on` member is externalized
151+
impl NonBlockingHandler for GenDiagCluster {}
152+
153+
impl ChangeNotifier<()> for GenDiagCluster {
154+
fn consume_change(&mut self) -> Option<()> {
155+
self.data_ver.consume_change(())
156+
}
157+
}

0 commit comments

Comments
 (0)