Skip to main content

matter_kit/clusters/generated/
thread_network_directory.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Thread Network Directory — cluster 0x0453.
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//! Thread Network Directory (cluster `0x0453`, revision 1).
10//!
11//! 7 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 = 0x0453;
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 = "THNETDIR";
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    /// `PreferredExtendedPanID`.
44    pub const PREFERRED_EXTENDED_PAN_ID: AttributeId = 0x00;
45    /// `ThreadNetworks`.
46    pub const THREAD_NETWORKS: AttributeId = 0x01;
47    /// `ThreadNetworkTableSize`.
48    pub const THREAD_NETWORK_TABLE_SIZE: AttributeId = 0x02;
49}
50
51/// The command ids.
52pub mod command {
53    use crate::im::CommandId;
54
55    /// `AddNetwork`.
56    pub const ADD_NETWORK: CommandId = 0x00;
57    /// `RemoveNetwork`.
58    pub const REMOVE_NETWORK: CommandId = 0x01;
59    /// `GetOperationalDataset`.
60    pub const GET_OPERATIONAL_DATASET: CommandId = 0x02;
61    /// `OperationalDatasetResponse`.
62    pub const OPERATIONAL_DATASET_RESPONSE: CommandId = 0x03;
63}
64
65/// `ThreadNetworkStruct`.
66#[derive(Debug, Clone, Copy, PartialEq)]
67pub struct ThreadNetworkStruct<'a> {
68    /// `ExtendedPanID`, field 0.
69    pub extended_pan_id: &'a [u8],
70    /// `NetworkName`, field 1.
71    pub network_name: &'a str,
72    /// `Channel`, field 2.
73    pub channel: u16,
74    /// `ActiveTimestamp`, field 3.
75    pub active_timestamp: u64,
76}
77
78impl<'a> ToTlv for ThreadNetworkStruct<'a> {
79    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
80        w.start_structure(tag)?;
81        self.extended_pan_id.to_tlv(w, Tag::Context(0))?;
82        self.network_name.to_tlv(w, Tag::Context(1))?;
83        self.channel.to_tlv(w, Tag::Context(2))?;
84        self.active_timestamp.to_tlv(w, Tag::Context(3))?;
85        w.end_container()
86    }
87}
88
89impl<'a> FromTlv<'a> for ThreadNetworkStruct<'a> {
90    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
91        if element.value.container() != Some(ContainerKind::Structure) {
92            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
93        }
94        let mut extended_pan_id = None;
95        let mut network_name = None;
96        let mut channel = None;
97        let mut active_timestamp = None;
98        loop {
99            let Some(field) = reader.next_element()? else {
100                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
101            };
102            if field.value == Value::EndOfContainer {
103                break;
104            }
105            match field.tag.context() {
106                Some(0) => extended_pan_id = Some(<&'a [u8]>::from_tlv(reader, &field)?),
107                Some(1) => network_name = Some(<&'a str>::from_tlv(reader, &field)?),
108                Some(2) => channel = Some(<u16>::from_tlv(reader, &field)?),
109                Some(3) => active_timestamp = Some(<u64>::from_tlv(reader, &field)?),
110                // A field this revision does not define. §7.19.2: a receiver
111                // ignores what it does not know rather than refusing the whole
112                // structure, which is what lets a newer peer talk to an older one.
113                _ => reader.skip_value(&field)?,
114            }
115        }
116        Ok(Self {
117            extended_pan_id: extended_pan_id
118                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
119            network_name: network_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
120            channel: channel.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
121            active_timestamp: active_timestamp
122                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
123        })
124    }
125}
126
127/// The fields of `AddNetwork` (command `0x00`).
128#[derive(Debug, Clone, Copy, PartialEq)]
129pub struct AddNetworkFields<'a> {
130    /// `OperationalDataset`, field 0.
131    pub operational_dataset: &'a [u8],
132}
133
134impl<'a> ToTlv for AddNetworkFields<'a> {
135    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
136        w.start_structure(tag)?;
137        self.operational_dataset.to_tlv(w, Tag::Context(0))?;
138        w.end_container()
139    }
140}
141
142impl<'a> FromTlv<'a> for AddNetworkFields<'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 operational_dataset = None;
148        loop {
149            let Some(field) = reader.next_element()? else {
150                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
151            };
152            if field.value == Value::EndOfContainer {
153                break;
154            }
155            match field.tag.context() {
156                Some(0) => operational_dataset = Some(<&'a [u8]>::from_tlv(reader, &field)?),
157                // A field this revision does not define. §7.19.2: a receiver
158                // ignores what it does not know rather than refusing the whole
159                // structure, which is what lets a newer peer talk to an older one.
160                _ => reader.skip_value(&field)?,
161            }
162        }
163        Ok(Self {
164            operational_dataset: operational_dataset
165                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
166        })
167    }
168}
169
170/// The fields of `RemoveNetwork` (command `0x01`).
171#[derive(Debug, Clone, Copy, PartialEq)]
172pub struct RemoveNetworkFields<'a> {
173    /// `ExtendedPanID`, field 0.
174    pub extended_pan_id: &'a [u8],
175}
176
177impl<'a> ToTlv for RemoveNetworkFields<'a> {
178    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
179        w.start_structure(tag)?;
180        self.extended_pan_id.to_tlv(w, Tag::Context(0))?;
181        w.end_container()
182    }
183}
184
185impl<'a> FromTlv<'a> for RemoveNetworkFields<'a> {
186    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
187        if element.value.container() != Some(ContainerKind::Structure) {
188            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
189        }
190        let mut extended_pan_id = None;
191        loop {
192            let Some(field) = reader.next_element()? else {
193                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
194            };
195            if field.value == Value::EndOfContainer {
196                break;
197            }
198            match field.tag.context() {
199                Some(0) => extended_pan_id = Some(<&'a [u8]>::from_tlv(reader, &field)?),
200                // A field this revision does not define. §7.19.2: a receiver
201                // ignores what it does not know rather than refusing the whole
202                // structure, which is what lets a newer peer talk to an older one.
203                _ => reader.skip_value(&field)?,
204            }
205        }
206        Ok(Self {
207            extended_pan_id: extended_pan_id
208                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
209        })
210    }
211}
212
213/// The fields of `GetOperationalDataset` (command `0x02`).
214#[derive(Debug, Clone, Copy, PartialEq)]
215pub struct GetOperationalDatasetFields<'a> {
216    /// `ExtendedPanID`, field 0.
217    pub extended_pan_id: &'a [u8],
218}
219
220impl<'a> ToTlv for GetOperationalDatasetFields<'a> {
221    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
222        w.start_structure(tag)?;
223        self.extended_pan_id.to_tlv(w, Tag::Context(0))?;
224        w.end_container()
225    }
226}
227
228impl<'a> FromTlv<'a> for GetOperationalDatasetFields<'a> {
229    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
230        if element.value.container() != Some(ContainerKind::Structure) {
231            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
232        }
233        let mut extended_pan_id = None;
234        loop {
235            let Some(field) = reader.next_element()? else {
236                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
237            };
238            if field.value == Value::EndOfContainer {
239                break;
240            }
241            match field.tag.context() {
242                Some(0) => extended_pan_id = Some(<&'a [u8]>::from_tlv(reader, &field)?),
243                // A field this revision does not define. §7.19.2: a receiver
244                // ignores what it does not know rather than refusing the whole
245                // structure, which is what lets a newer peer talk to an older one.
246                _ => reader.skip_value(&field)?,
247            }
248        }
249        Ok(Self {
250            extended_pan_id: extended_pan_id
251                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
252        })
253    }
254}
255
256/// The fields of `OperationalDatasetResponse` (command `0x03`).
257#[derive(Debug, Clone, Copy, PartialEq)]
258pub struct OperationalDatasetResponseFields<'a> {
259    /// `OperationalDataset`, field 0.
260    pub operational_dataset: &'a [u8],
261}
262
263impl<'a> ToTlv for OperationalDatasetResponseFields<'a> {
264    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
265        w.start_structure(tag)?;
266        self.operational_dataset.to_tlv(w, Tag::Context(0))?;
267        w.end_container()
268    }
269}
270
271impl<'a> FromTlv<'a> for OperationalDatasetResponseFields<'a> {
272    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
273        if element.value.container() != Some(ContainerKind::Structure) {
274            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
275        }
276        let mut operational_dataset = None;
277        loop {
278            let Some(field) = reader.next_element()? else {
279                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
280            };
281            if field.value == Value::EndOfContainer {
282                break;
283            }
284            match field.tag.context() {
285                Some(0) => operational_dataset = Some(<&'a [u8]>::from_tlv(reader, &field)?),
286                // A field this revision does not define. §7.19.2: a receiver
287                // ignores what it does not know rather than refusing the whole
288                // structure, which is what lets a newer peer talk to an older one.
289                _ => reader.skip_value(&field)?,
290            }
291        }
292        Ok(Self {
293            operational_dataset: operational_dataset
294                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
295        })
296    }
297}
298
299/// Every attribute the specification defines, with its conformance.
300pub const ATTRIBUTES: &[Attribute] = &[
301    Attribute {
302        id: 0x0000,
303        name: "PreferredExtendedPanID",
304        kind: "octstr",
305        access: Access::read_write_with(Privilege::View, Privilege::Manage),
306        qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
307        reporting: Reporting::OnChange,
308        conform: Conform::MANDATORY,
309    },
310    Attribute {
311        id: 0x0001,
312        name: "ThreadNetworks",
313        kind: "list[ThreadNetworkStruct]",
314        access: Access::read_only(Privilege::View),
315        qualities: AttributeQualities::NON_VOLATILE,
316        reporting: Reporting::OnChange,
317        conform: Conform::MANDATORY,
318    },
319    Attribute {
320        id: 0x0002,
321        name: "ThreadNetworkTableSize",
322        kind: "uint8",
323        access: Access::read_only(Privilege::View),
324        qualities: AttributeQualities::FIXED,
325        reporting: Reporting::OnChange,
326        conform: Conform::MANDATORY,
327    },
328];
329
330/// Every command, with its conformance.
331pub const COMMANDS: &[Command] = &[
332    Command {
333        id: 0x00,
334        name: "AddNetwork",
335        to_server: true,
336        response: None,
337        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
338        conform: Conform::MANDATORY,
339    },
340    Command {
341        id: 0x01,
342        name: "RemoveNetwork",
343        to_server: true,
344        response: None,
345        access: Access::invoke(Privilege::Manage).with_qualities(AccessQualities::TIMED),
346        conform: Conform::MANDATORY,
347    },
348    Command {
349        id: 0x02,
350        name: "GetOperationalDataset",
351        to_server: true,
352        response: Some(0x03),
353        access: Access::invoke(Privilege::Manage),
354        conform: Conform::MANDATORY,
355    },
356    Command {
357        id: 0x03,
358        name: "OperationalDatasetResponse",
359        to_server: false,
360        response: None,
361        access: Access::invoke(Privilege::Operate),
362        conform: Conform::MANDATORY,
363    },
364];
365
366/// Every event, with its conformance.
367pub const EVENTS: &[Event] = &[];
368
369/// The whole cluster, as the specification defines it.
370pub const CLUSTER: Cluster = Cluster {
371    id: ID,
372    name: "Thread Network Directory",
373    revision: REVISION,
374    pics: "THNETDIR",
375    derived_from: None,
376    features: FEATURES,
377    attributes: ATTRIBUTES,
378    commands: COMMANDS,
379    events: EVENTS,
380};