Skip to main content

matter_kit/clusters/generated/
ecosystem_information.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Ecosystem Information — cluster 0x0750.
4//
5// Regenerate with `cargo xtask clusters --dm <checkout>/data_model/1.6`; `cargo xtask check`
6// is the CI gate that keeps this file honest. The XML itself is not vendored here — it
7// carries the CSA's own copyright notice and is not redistributable.
8
9//! Ecosystem Information (cluster `0x0750`, revision 1).
10//!
11//! 2 identifiers, 0 feature bits, and the specification's own conformance for
12//! every element. `CLUSTER` is the whole table.
13
14#![allow(unused_imports)]
15
16use crate::dm::conformance::{Clause, Condition, Conform, Conformance};
17use crate::dm::meta::{EventPriority, Reporting};
18use crate::dm::spec::{Attribute, Cluster, Command, Event, Feature};
19use crate::dm::{Access, AccessQualities, AttributeQualities, Privilege};
20use crate::error::Result;
21use crate::im::{AttributeId, ClusterId, CommandId, EventId};
22use crate::tlv::{
23    ContainerKind, Element, FromTlv, Nullable, Tag, TlvList, TlvReader, TlvWriter, ToTlv, Value,
24};
25
26/// The cluster id.
27pub const ID: ClusterId = 0x0750;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "ECOINFO";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The attribute ids.
40pub mod attribute {
41    use crate::im::AttributeId;
42
43    /// `DeviceDirectory`.
44    pub const DEVICE_DIRECTORY: AttributeId = 0x00;
45    /// `LocationDirectory`.
46    pub const LOCATION_DIRECTORY: AttributeId = 0x01;
47}
48
49/// `DeviceTypeStruct`.
50#[derive(Debug, Clone, Copy, PartialEq)]
51pub struct DeviceTypeStruct {
52    /// `DeviceType`, field 0.
53    pub device_type: u32,
54    /// `Revision`, field 1.
55    pub revision: u16,
56}
57
58impl ToTlv for DeviceTypeStruct {
59    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
60        w.start_structure(tag)?;
61        self.device_type.to_tlv(w, Tag::Context(0))?;
62        self.revision.to_tlv(w, Tag::Context(1))?;
63        w.end_container()
64    }
65}
66
67impl<'a> FromTlv<'a> for DeviceTypeStruct {
68    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
69        if element.value.container() != Some(ContainerKind::Structure) {
70            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
71        }
72        let mut device_type = None;
73        let mut revision = None;
74        loop {
75            let Some(field) = reader.next_element()? else {
76                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
77            };
78            if field.value == Value::EndOfContainer {
79                break;
80            }
81            match field.tag.context() {
82                Some(0) => device_type = Some(<u32>::from_tlv(reader, &field)?),
83                Some(1) => revision = Some(<u16>::from_tlv(reader, &field)?),
84                // A field this revision does not define. §7.19.2: a receiver
85                // ignores what it does not know rather than refusing the whole
86                // structure, which is what lets a newer peer talk to an older one.
87                _ => reader.skip_value(&field)?,
88            }
89        }
90        Ok(Self {
91            device_type: device_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
92            revision: revision.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
93        })
94    }
95}
96
97/// `EcosystemDeviceStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
98#[derive(Debug, Clone, Copy, PartialEq)]
99pub struct EcosystemDeviceStruct<'a> {
100    /// `DeviceName`, field 0.
101    pub device_name: Option<&'a str>,
102    /// `DeviceNameLastEdit`, field 1.
103    pub device_name_last_edit: Option<u64>,
104    /// `BridgedEndpoint`, field 2.
105    pub bridged_endpoint: Option<u16>,
106    /// `OriginalEndpoint`, field 3.
107    pub original_endpoint: Option<u16>,
108    /// `DeviceTypes`, field 4.
109    pub device_types: TlvList<'a, DeviceTypeStruct>,
110    /// `UniqueLocationIDs`, field 5.
111    pub unique_location_i_ds: TlvList<'a, &'a str>,
112    /// `UniqueLocationIDsLastEdit`, field 6.
113    pub unique_location_i_ds_last_edit: u64,
114    /// `FabricIndex`, field 254.
115    pub fabric_index: crate::msg::FabricIndex,
116}
117
118impl<'a> ToTlv for EcosystemDeviceStruct<'a> {
119    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
120        w.start_structure(tag)?;
121        if let Some(value) = &self.device_name {
122            value.to_tlv(w, Tag::Context(0))?;
123        }
124        if let Some(value) = &self.device_name_last_edit {
125            value.to_tlv(w, Tag::Context(1))?;
126        }
127        if let Some(value) = &self.bridged_endpoint {
128            value.to_tlv(w, Tag::Context(2))?;
129        }
130        if let Some(value) = &self.original_endpoint {
131            value.to_tlv(w, Tag::Context(3))?;
132        }
133        self.device_types.to_tlv(w, Tag::Context(4))?;
134        self.unique_location_i_ds.to_tlv(w, Tag::Context(5))?;
135        self.unique_location_i_ds_last_edit
136            .to_tlv(w, Tag::Context(6))?;
137        self.fabric_index.to_tlv(w, Tag::Context(254))?;
138        w.end_container()
139    }
140}
141
142impl<'a> FromTlv<'a> for EcosystemDeviceStruct<'a> {
143    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
144        if element.value.container() != Some(ContainerKind::Structure) {
145            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
146        }
147        let mut device_name = None;
148        let mut device_name_last_edit = None;
149        let mut bridged_endpoint = None;
150        let mut original_endpoint = None;
151        let mut device_types = None;
152        let mut unique_location_i_ds = None;
153        let mut unique_location_i_ds_last_edit = None;
154        let mut fabric_index = None;
155        loop {
156            let Some(field) = reader.next_element()? else {
157                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
158            };
159            if field.value == Value::EndOfContainer {
160                break;
161            }
162            match field.tag.context() {
163                Some(0) => device_name = Some(<&'a str>::from_tlv(reader, &field)?),
164                Some(1) => device_name_last_edit = Some(<u64>::from_tlv(reader, &field)?),
165                Some(2) => bridged_endpoint = Some(<u16>::from_tlv(reader, &field)?),
166                Some(3) => original_endpoint = Some(<u16>::from_tlv(reader, &field)?),
167                Some(4) => {
168                    device_types = Some(<TlvList<'a, DeviceTypeStruct>>::from_tlv(reader, &field)?)
169                }
170                Some(5) => {
171                    unique_location_i_ds = Some(<TlvList<'a, &'a str>>::from_tlv(reader, &field)?)
172                }
173                Some(6) => unique_location_i_ds_last_edit = Some(<u64>::from_tlv(reader, &field)?),
174                Some(254) => {
175                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
176                }
177                // A field this revision does not define. §7.19.2: a receiver
178                // ignores what it does not know rather than refusing the whole
179                // structure, which is what lets a newer peer talk to an older one.
180                _ => reader.skip_value(&field)?,
181            }
182        }
183        Ok(Self {
184            device_name,
185            device_name_last_edit,
186            bridged_endpoint,
187            original_endpoint,
188            device_types: device_types.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
189            unique_location_i_ds: unique_location_i_ds
190                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
191            unique_location_i_ds_last_edit: unique_location_i_ds_last_edit
192                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
193            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
194        })
195    }
196}
197
198/// `EcosystemLocationStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
199#[derive(Debug, Clone, Copy, PartialEq)]
200pub struct EcosystemLocationStruct<'a> {
201    /// `UniqueLocationID`, field 0.
202    pub unique_location_id: &'a str,
203    /// `LocationDescriptor`, field 1.
204    pub location_descriptor: crate::clusters::generated::globals::LocationDescriptorStruct<'a>,
205    /// `LocationDescriptorLastEdit`, field 2.
206    pub location_descriptor_last_edit: u64,
207    /// `FabricIndex`, field 254.
208    pub fabric_index: crate::msg::FabricIndex,
209}
210
211impl<'a> ToTlv for EcosystemLocationStruct<'a> {
212    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
213        w.start_structure(tag)?;
214        self.unique_location_id.to_tlv(w, Tag::Context(0))?;
215        self.location_descriptor.to_tlv(w, Tag::Context(1))?;
216        self.location_descriptor_last_edit
217            .to_tlv(w, Tag::Context(2))?;
218        self.fabric_index.to_tlv(w, Tag::Context(254))?;
219        w.end_container()
220    }
221}
222
223impl<'a> FromTlv<'a> for EcosystemLocationStruct<'a> {
224    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
225        if element.value.container() != Some(ContainerKind::Structure) {
226            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
227        }
228        let mut unique_location_id = None;
229        let mut location_descriptor = None;
230        let mut location_descriptor_last_edit = None;
231        let mut fabric_index = None;
232        loop {
233            let Some(field) = reader.next_element()? else {
234                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
235            };
236            if field.value == Value::EndOfContainer {
237                break;
238            }
239            match field.tag.context() {
240                Some(0) => unique_location_id = Some(<&'a str>::from_tlv(reader, &field)?),
241                Some(1) => location_descriptor = Some(
242                    <crate::clusters::generated::globals::LocationDescriptorStruct<'a>>::from_tlv(
243                        reader, &field,
244                    )?,
245                ),
246                Some(2) => location_descriptor_last_edit = Some(<u64>::from_tlv(reader, &field)?),
247                Some(254) => {
248                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
249                }
250                // A field this revision does not define. §7.19.2: a receiver
251                // ignores what it does not know rather than refusing the whole
252                // structure, which is what lets a newer peer talk to an older one.
253                _ => reader.skip_value(&field)?,
254            }
255        }
256        Ok(Self {
257            unique_location_id: unique_location_id
258                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
259            location_descriptor: location_descriptor
260                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
261            location_descriptor_last_edit: location_descriptor_last_edit
262                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
263            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
264        })
265    }
266}
267
268/// Every attribute the specification defines, with its conformance.
269pub const ATTRIBUTES: &[Attribute] = &[
270    Attribute {
271        id: 0x0000,
272        name: "DeviceDirectory",
273        kind: "list[EcosystemDeviceStruct]",
274        access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
275        qualities: AttributeQualities::NON_VOLATILE,
276        reporting: Reporting::OnChange,
277        conform: Conform::MANDATORY,
278    },
279    Attribute {
280        id: 0x0001,
281        name: "LocationDirectory",
282        kind: "list[EcosystemLocationStruct]",
283        access: Access::read_only(Privilege::Manage).with_qualities(AccessQualities::FABRIC_SCOPED),
284        qualities: AttributeQualities::NON_VOLATILE,
285        reporting: Reporting::OnChange,
286        conform: Conform::MANDATORY,
287    },
288];
289
290/// Every command, with its conformance.
291pub const COMMANDS: &[Command] = &[];
292
293/// Every event, with its conformance.
294pub const EVENTS: &[Event] = &[];
295
296/// The whole cluster, as the specification defines it.
297pub const CLUSTER: Cluster = Cluster {
298    id: ID,
299    name: "Ecosystem Information",
300    revision: REVISION,
301    pics: "ECOINFO",
302    derived_from: None,
303    features: FEATURES,
304    attributes: ATTRIBUTES,
305    commands: COMMANDS,
306    events: EVENTS,
307};