Skip to content

Commit e02b316

Browse files
authored
Merge pull request project-chip#80 from kedars/bugfix/ios_support
Support Attributes of Nw Commissioning Cluster
2 parents 50f18db + 7f8ea83 commit e02b316

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

rs-matter/src/data_model/objects/attribute.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,12 @@ bitflags! {
4040
const READ_PRIVILEGE_MASK = Self::NEED_VIEW.bits | Self::NEED_MANAGE.bits | Self::NEED_OPERATE.bits | Self::NEED_ADMIN.bits;
4141
const WRITE_PRIVILEGE_MASK = Self::NEED_MANAGE.bits | Self::NEED_OPERATE.bits | Self::NEED_ADMIN.bits;
4242
const RV = Self::READ.bits | Self::NEED_VIEW.bits;
43+
const RF = Self::READ.bits | Self::FAB_SCOPED.bits;
44+
const RA = Self::READ.bits | Self::NEED_ADMIN.bits;
4345
const RWVA = Self::READ.bits | Self::WRITE.bits | Self::NEED_VIEW.bits | Self::NEED_ADMIN.bits;
4446
const RWFA = Self::READ.bits | Self::WRITE.bits | Self::FAB_SCOPED.bits | Self::NEED_ADMIN.bits;
4547
const RWVM = Self::READ.bits | Self::WRITE.bits | Self::NEED_VIEW.bits | Self::NEED_MANAGE.bits;
48+
const RWFVM = Self::READ.bits | Self::WRITE.bits | Self::FAB_SCOPED.bits |Self::NEED_VIEW.bits | Self::NEED_MANAGE.bits;
4649
}
4750
}
4851

@@ -79,6 +82,10 @@ bitflags! {
7982
const NULLABLE = 0x08; // Short: X
8083

8184
const SN = Self::SCENE.bits | Self::PERSISTENT.bits;
85+
const S = Self::SCENE.bits;
86+
const N = Self::PERSISTENT.bits;
87+
const F = Self::FIXED.bits;
88+
const X = Self::NULLABLE.bits;
8289
}
8390
}
8491

rs-matter/src/data_model/sdm/nw_commissioning.rs

Lines changed: 125 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,35 @@
1515
* limitations under the License.
1616
*/
1717

18+
use strum::FromRepr;
19+
1820
use crate::{
21+
attribute_enum,
1922
data_model::objects::{
20-
AttrDataEncoder, AttrDetails, ChangeNotifier, Cluster, Dataver, Handler,
21-
NonBlockingHandler, ATTRIBUTE_LIST, FEATURE_MAP,
23+
Access, AttrDataEncoder, AttrDataWriter, AttrDetails, AttrType, Attribute, ChangeNotifier,
24+
Cluster, Dataver, Handler, NonBlockingHandler, Quality, ATTRIBUTE_LIST, FEATURE_MAP,
2225
},
23-
error::{Error, ErrorCode},
26+
error::Error,
27+
tlv::{OctetStr, TLVWriter, TagType, ToTLV},
2428
utils::rand::Rand,
2529
};
2630

2731
pub const ID: u32 = 0x0031;
2832

33+
#[derive(FromRepr)]
34+
#[repr(u16)]
35+
pub enum Attributes {
36+
MaxNetworks = 0x00,
37+
Networks = 0x01,
38+
ConnectMaxTimeSecs = 0x03,
39+
InterfaceEnabled = 0x04,
40+
LastNetworkingStatus = 0x05,
41+
LastNetworkID = 0x06,
42+
LastConnectErrorValue = 0x07,
43+
}
44+
45+
attribute_enum!(Attributes);
46+
2947
enum FeatureMap {
3048
_Wifi = 0x01,
3149
_Thread = 0x02,
@@ -35,7 +53,33 @@ enum FeatureMap {
3553
pub const CLUSTER: Cluster<'static> = Cluster {
3654
id: ID as _,
3755
feature_map: FeatureMap::Ethernet as _,
38-
attributes: &[FEATURE_MAP, ATTRIBUTE_LIST],
56+
attributes: &[
57+
FEATURE_MAP,
58+
ATTRIBUTE_LIST,
59+
Attribute::new(Attributes::MaxNetworks as u16, Access::RA, Quality::F),
60+
Attribute::new(Attributes::Networks as u16, Access::RA, Quality::NONE),
61+
Attribute::new(
62+
Attributes::ConnectMaxTimeSecs as u16,
63+
Access::RV,
64+
Quality::F,
65+
),
66+
Attribute::new(
67+
Attributes::InterfaceEnabled as u16,
68+
Access::RWVA,
69+
Quality::N,
70+
),
71+
Attribute::new(
72+
Attributes::LastNetworkingStatus as u16,
73+
Access::RA,
74+
Quality::X,
75+
),
76+
Attribute::new(Attributes::LastNetworkID as u16, Access::RA, Quality::X),
77+
Attribute::new(
78+
Attributes::LastConnectErrorValue as u16,
79+
Access::RA,
80+
Quality::X,
81+
),
82+
],
3983
commands: &[],
4084
};
4185

@@ -49,15 +93,90 @@ impl NwCommCluster {
4993
data_ver: Dataver::new(rand),
5094
}
5195
}
96+
97+
fn get_network_info(&self) -> NwMetaInfo<'static> {
98+
// Only single, Ethernet, supported for now
99+
let nw_info = NwInfo {
100+
network_id: OctetStr::new(b"en0"),
101+
connected: true,
102+
};
103+
NwMetaInfo {
104+
nw_info,
105+
connect_max_time_secs: 60,
106+
interface_enabled: true,
107+
last_nw_status: NetworkCommissioningStatus::Success,
108+
}
109+
}
110+
}
111+
112+
#[derive(ToTLV)]
113+
struct NwInfo<'a> {
114+
network_id: OctetStr<'a>,
115+
connected: bool,
116+
}
117+
118+
struct NwMetaInfo<'a> {
119+
nw_info: NwInfo<'a>,
120+
connect_max_time_secs: u8,
121+
interface_enabled: bool,
122+
last_nw_status: NetworkCommissioningStatus,
123+
}
124+
125+
#[allow(dead_code)]
126+
enum NetworkCommissioningStatus {
127+
Success = 0,
128+
OutOfRange = 1,
129+
BoundsExceeded = 2,
130+
NetworkIDNotFound = 3,
131+
DuplicateNetworkID = 4,
132+
NetworkNotFound = 5,
133+
RegulatoryError = 6,
134+
AuthFailure = 7,
135+
UnsupportedSecurity = 8,
136+
OtherConnectionFailure = 9,
137+
IPV6Failed = 10,
138+
IPBindFailed = 11,
139+
UnknownError = 12,
52140
}
53141

54142
impl Handler for NwCommCluster {
55143
fn read(&self, attr: &AttrDetails, encoder: AttrDataEncoder) -> Result<(), Error> {
56-
if let Some(writer) = encoder.with_dataver(self.data_ver.get())? {
144+
let info = self.get_network_info();
145+
if let Some(mut writer) = encoder.with_dataver(self.data_ver.get())? {
57146
if attr.is_system() {
58147
CLUSTER.read(attr.attr_id, writer)
59148
} else {
60-
Err(ErrorCode::AttributeNotFound.into())
149+
match attr.attr_id.try_into()? {
150+
Attributes::MaxNetworks => AttrType::<u8>::new().encode(writer, 1),
151+
Attributes::Networks => {
152+
writer.start_array(AttrDataWriter::TAG)?;
153+
info.nw_info.to_tlv(&mut writer, TagType::Anonymous)?;
154+
writer.end_container()?;
155+
writer.complete()
156+
}
157+
Attributes::ConnectMaxTimeSecs => {
158+
AttrType::<u8>::new().encode(writer, info.connect_max_time_secs)
159+
}
160+
161+
Attributes::InterfaceEnabled => {
162+
AttrType::<bool>::new().encode(writer, info.interface_enabled)
163+
}
164+
165+
Attributes::LastNetworkingStatus => {
166+
AttrType::<u8>::new().encode(writer, info.last_nw_status as u8)
167+
}
168+
169+
Attributes::LastNetworkID => {
170+
info.nw_info
171+
.network_id
172+
.to_tlv(&mut writer, AttrDataWriter::TAG)?;
173+
writer.complete()
174+
}
175+
Attributes::LastConnectErrorValue => {
176+
writer.null(AttrDataWriter::TAG)?;
177+
writer.complete()
178+
}
179+
}
61180
}
62181
} else {
63182
Ok(())

0 commit comments

Comments
 (0)