Skip to main content

matter_kit/clusters/generated/
general_diagnostics.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// General Diagnostics — cluster 0x0033.
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//! General Diagnostics (cluster `0x0033`, revision 3).
10//!
11//! 20 identifiers, 1 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 = 0x0033;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 3;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "DGGEN";
35
36/// The `FeatureMap` bits (Core §7.13.2).
37///
38/// A feature has conformance of its own: a device may not claim one the
39/// specification forbids it alongside another.
40pub mod feature {
41    /// Support specific testing needs for extended Data Model features
42    ///
43    /// Code `DMTEST`, bit 0.
44    pub const DATA_MODEL_TEST: u32 = 1 << 0;
45}
46
47/// Every feature bit, with its conformance.
48pub const FEATURES: &[Feature] = &[Feature {
49    bit: 0,
50    code: "DMTEST",
51    name: "DataModelTest",
52    conform: Conform::DESCRIBED,
53}];
54
55/// The attribute ids.
56pub mod attribute {
57    use crate::im::AttributeId;
58
59    /// `NetworkInterfaces`.
60    pub const NETWORK_INTERFACES: AttributeId = 0x00;
61    /// `RebootCount`.
62    pub const REBOOT_COUNT: AttributeId = 0x01;
63    /// `UpTime`.
64    pub const UP_TIME: AttributeId = 0x02;
65    /// `TotalOperationalHours`.
66    pub const TOTAL_OPERATIONAL_HOURS: AttributeId = 0x03;
67    /// `BootReason`.
68    pub const BOOT_REASON: AttributeId = 0x04;
69    /// `ActiveHardwareFaults`.
70    pub const ACTIVE_HARDWARE_FAULTS: AttributeId = 0x05;
71    /// `ActiveRadioFaults`.
72    pub const ACTIVE_RADIO_FAULTS: AttributeId = 0x06;
73    /// `ActiveNetworkFaults`.
74    pub const ACTIVE_NETWORK_FAULTS: AttributeId = 0x07;
75    /// `TestEventTriggersEnabled`.
76    pub const TEST_EVENT_TRIGGERS_ENABLED: AttributeId = 0x08;
77    /// `DoNotUse`.
78    pub const DO_NOT_USE: AttributeId = 0x09;
79    /// `DeviceLoadStatus`.
80    pub const DEVICE_LOAD_STATUS: AttributeId = 0x0A;
81}
82
83/// The command ids.
84pub mod command {
85    use crate::im::CommandId;
86
87    /// `TestEventTrigger`.
88    pub const TEST_EVENT_TRIGGER: CommandId = 0x00;
89    /// `TimeSnapshot`.
90    pub const TIME_SNAPSHOT: CommandId = 0x01;
91    /// `TimeSnapshotResponse`.
92    pub const TIME_SNAPSHOT_RESPONSE: CommandId = 0x02;
93    /// `PayloadTestRequest`.
94    pub const PAYLOAD_TEST_REQUEST: CommandId = 0x03;
95    /// `PayloadTestResponse`.
96    pub const PAYLOAD_TEST_RESPONSE: CommandId = 0x04;
97}
98
99/// The event ids.
100pub mod event {
101    use crate::im::EventId;
102
103    /// `HardwareFaultChange`.
104    pub const HARDWARE_FAULT_CHANGE: EventId = 0x00;
105    /// `RadioFaultChange`.
106    pub const RADIO_FAULT_CHANGE: EventId = 0x01;
107    /// `NetworkFaultChange`.
108    pub const NETWORK_FAULT_CHANGE: EventId = 0x02;
109    /// `BootReason`.
110    pub const BOOT_REASON: EventId = 0x03;
111}
112
113/// `BootReasonEnum`.
114#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
115#[repr(u8)]
116pub enum BootReasonEnum {
117    /// The Node is unable to identify the Power-On reason as one of the other provided enumeration values.
118    Unspecified = 0,
119    /// The Node has booted as the result of physical interaction with the device resulting in a reboot.
120    PowerOnReboot = 1,
121    /// The Node has rebooted as the result of a brown-out of the Node's power supply.
122    BrownOutReset = 2,
123    /// The Node has rebooted as the result of a software watchdog timer.
124    SoftwareWatchdogReset = 3,
125    /// The Node has rebooted as the result of a hardware watchdog timer.
126    HardwareWatchdogReset = 4,
127    /// The Node has rebooted as the result of a completed software update.
128    SoftwareUpdateCompleted = 5,
129    /// The Node has rebooted as the result of a software initiated reboot.
130    SoftwareReset = 6,
131}
132
133impl BootReasonEnum {
134    /// Reads a wire value, or `None` for one this revision does not define.
135    #[must_use]
136    pub const fn from_value(value: u8) -> Option<Self> {
137        match value {
138            0 => Some(Self::Unspecified),
139            1 => Some(Self::PowerOnReboot),
140            2 => Some(Self::BrownOutReset),
141            3 => Some(Self::SoftwareWatchdogReset),
142            4 => Some(Self::HardwareWatchdogReset),
143            5 => Some(Self::SoftwareUpdateCompleted),
144            6 => Some(Self::SoftwareReset),
145            _ => None,
146        }
147    }
148
149    /// Its wire value.
150    #[must_use]
151    pub const fn value(self) -> u8 {
152        self as u8
153    }
154}
155
156impl ToTlv for BootReasonEnum {
157    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
158        self.value().to_tlv(w, tag)
159    }
160}
161
162impl<'a> FromTlv<'a> for BootReasonEnum {
163    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
164        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
165        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
166    }
167}
168
169/// `HardwareFaultEnum`.
170#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
171#[repr(u8)]
172pub enum HardwareFaultEnum {
173    /// The Node has encountered an unspecified fault.
174    Unspecified = 0,
175    /// The Node has encountered a fault with at least one of its radios.
176    Radio = 1,
177    /// The Node has encountered a fault with at least one of its sensors.
178    Sensor = 2,
179    /// The Node has encountered an over-temperature fault that is resettable.
180    ResettableOverTemp = 3,
181    /// The Node has encountered an over-temperature fault that is not resettable.
182    NonResettableOverTemp = 4,
183    /// The Node has encountered a fault with at least one of its power sources.
184    PowerSource = 5,
185    /// The Node has encountered a fault with at least one of its visual displays.
186    VisualDisplayFault = 6,
187    /// The Node has encountered a fault with at least one of its audio outputs.
188    AudioOutputFault = 7,
189    /// The Node has encountered a fault with at least one of its user interfaces.
190    UserInterfaceFault = 8,
191    /// The Node has encountered a fault with its non-volatile memory.
192    NonVolatileMemoryError = 9,
193    /// The Node has encountered disallowed physical tampering.
194    TamperDetected = 10,
195}
196
197impl HardwareFaultEnum {
198    /// Reads a wire value, or `None` for one this revision does not define.
199    #[must_use]
200    pub const fn from_value(value: u8) -> Option<Self> {
201        match value {
202            0 => Some(Self::Unspecified),
203            1 => Some(Self::Radio),
204            2 => Some(Self::Sensor),
205            3 => Some(Self::ResettableOverTemp),
206            4 => Some(Self::NonResettableOverTemp),
207            5 => Some(Self::PowerSource),
208            6 => Some(Self::VisualDisplayFault),
209            7 => Some(Self::AudioOutputFault),
210            8 => Some(Self::UserInterfaceFault),
211            9 => Some(Self::NonVolatileMemoryError),
212            10 => Some(Self::TamperDetected),
213            _ => None,
214        }
215    }
216
217    /// Its wire value.
218    #[must_use]
219    pub const fn value(self) -> u8 {
220        self as u8
221    }
222}
223
224impl ToTlv for HardwareFaultEnum {
225    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
226        self.value().to_tlv(w, tag)
227    }
228}
229
230impl<'a> FromTlv<'a> for HardwareFaultEnum {
231    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
232        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
233        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
234    }
235}
236
237/// `InterfaceTypeEnum`.
238#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
239#[repr(u8)]
240pub enum InterfaceTypeEnum {
241    /// Indicates an interface of an unspecified type.
242    Unspecified = 0,
243    /// Indicates a Wi-Fi interface.
244    WiFi = 1,
245    /// Indicates a Ethernet interface.
246    Ethernet = 2,
247    /// Indicates a Cellular interface.
248    Cellular = 3,
249    /// Indicates a Thread interface.
250    Thread = 4,
251}
252
253impl InterfaceTypeEnum {
254    /// Reads a wire value, or `None` for one this revision does not define.
255    #[must_use]
256    pub const fn from_value(value: u8) -> Option<Self> {
257        match value {
258            0 => Some(Self::Unspecified),
259            1 => Some(Self::WiFi),
260            2 => Some(Self::Ethernet),
261            3 => Some(Self::Cellular),
262            4 => Some(Self::Thread),
263            _ => None,
264        }
265    }
266
267    /// Its wire value.
268    #[must_use]
269    pub const fn value(self) -> u8 {
270        self as u8
271    }
272}
273
274impl ToTlv for InterfaceTypeEnum {
275    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
276        self.value().to_tlv(w, tag)
277    }
278}
279
280impl<'a> FromTlv<'a> for InterfaceTypeEnum {
281    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
282        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
283        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
284    }
285}
286
287/// `NetworkFaultEnum`.
288#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
289#[repr(u8)]
290pub enum NetworkFaultEnum {
291    /// The Node has encountered an unspecified fault.
292    Unspecified = 0,
293    /// The Node has encountered a network fault as a result of a hardware failure.
294    HardwareFailure = 1,
295    /// The Node has encountered a network fault as a result of a jammed network.
296    NetworkJammed = 2,
297    /// The Node has encountered a network fault as a result of a failure to establish a connection.
298    ConnectionFailed = 3,
299}
300
301impl NetworkFaultEnum {
302    /// Reads a wire value, or `None` for one this revision does not define.
303    #[must_use]
304    pub const fn from_value(value: u8) -> Option<Self> {
305        match value {
306            0 => Some(Self::Unspecified),
307            1 => Some(Self::HardwareFailure),
308            2 => Some(Self::NetworkJammed),
309            3 => Some(Self::ConnectionFailed),
310            _ => None,
311        }
312    }
313
314    /// Its wire value.
315    #[must_use]
316    pub const fn value(self) -> u8 {
317        self as u8
318    }
319}
320
321impl ToTlv for NetworkFaultEnum {
322    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
323        self.value().to_tlv(w, tag)
324    }
325}
326
327impl<'a> FromTlv<'a> for NetworkFaultEnum {
328    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
329        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
330        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
331    }
332}
333
334/// `RadioFaultEnum`.
335#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
336#[repr(u8)]
337pub enum RadioFaultEnum {
338    /// The Node has encountered an unspecified radio fault.
339    Unspecified = 0,
340    /// The Node has encountered a fault with its Wi-Fi radio.
341    WiFiFault = 1,
342    /// The Node has encountered a fault with its cellular radio.
343    CellularFault = 2,
344    /// The Node has encountered a fault with its 802.15.4 radio.
345    ThreadFault = 3,
346    /// The Node has encountered a fault with its NFC radio.
347    NFCFault = 4,
348    /// The Node has encountered a fault with its BLE radio.
349    BLEFault = 5,
350    /// The Node has encountered a fault with its Ethernet controller.
351    EthernetFault = 6,
352}
353
354impl RadioFaultEnum {
355    /// Reads a wire value, or `None` for one this revision does not define.
356    #[must_use]
357    pub const fn from_value(value: u8) -> Option<Self> {
358        match value {
359            0 => Some(Self::Unspecified),
360            1 => Some(Self::WiFiFault),
361            2 => Some(Self::CellularFault),
362            3 => Some(Self::ThreadFault),
363            4 => Some(Self::NFCFault),
364            5 => Some(Self::BLEFault),
365            6 => Some(Self::EthernetFault),
366            _ => None,
367        }
368    }
369
370    /// Its wire value.
371    #[must_use]
372    pub const fn value(self) -> u8 {
373        self as u8
374    }
375}
376
377impl ToTlv for RadioFaultEnum {
378    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
379        self.value().to_tlv(w, tag)
380    }
381}
382
383impl<'a> FromTlv<'a> for RadioFaultEnum {
384    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
385        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
386        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
387    }
388}
389
390/// `DeviceLoadStruct`.
391#[derive(Debug, Clone, Copy, PartialEq)]
392pub struct DeviceLoadStruct {
393    /// `CurrentSubscriptions`, field 0.
394    pub current_subscriptions: u16,
395    /// `CurrentSubscriptionsForFabric`, field 1.
396    pub current_subscriptions_for_fabric: u16,
397    /// `TotalSubscriptionsEstablished`, field 2.
398    pub total_subscriptions_established: u32,
399    /// `TotalInteractionModelMessagesSent`, field 3.
400    pub total_interaction_model_messages_sent: u32,
401    /// `TotalInteractionModelMessagesReceived`, field 4.
402    pub total_interaction_model_messages_received: u32,
403}
404
405impl ToTlv for DeviceLoadStruct {
406    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
407        w.start_structure(tag)?;
408        self.current_subscriptions.to_tlv(w, Tag::Context(0))?;
409        self.current_subscriptions_for_fabric
410            .to_tlv(w, Tag::Context(1))?;
411        self.total_subscriptions_established
412            .to_tlv(w, Tag::Context(2))?;
413        self.total_interaction_model_messages_sent
414            .to_tlv(w, Tag::Context(3))?;
415        self.total_interaction_model_messages_received
416            .to_tlv(w, Tag::Context(4))?;
417        w.end_container()
418    }
419}
420
421impl<'a> FromTlv<'a> for DeviceLoadStruct {
422    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
423        if element.value.container() != Some(ContainerKind::Structure) {
424            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
425        }
426        let mut current_subscriptions = None;
427        let mut current_subscriptions_for_fabric = None;
428        let mut total_subscriptions_established = None;
429        let mut total_interaction_model_messages_sent = None;
430        let mut total_interaction_model_messages_received = None;
431        loop {
432            let Some(field) = reader.next_element()? else {
433                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
434            };
435            if field.value == Value::EndOfContainer {
436                break;
437            }
438            match field.tag.context() {
439                Some(0) => current_subscriptions = Some(<u16>::from_tlv(reader, &field)?),
440                Some(1) => {
441                    current_subscriptions_for_fabric = Some(<u16>::from_tlv(reader, &field)?)
442                }
443                Some(2) => total_subscriptions_established = Some(<u32>::from_tlv(reader, &field)?),
444                Some(3) => {
445                    total_interaction_model_messages_sent = Some(<u32>::from_tlv(reader, &field)?)
446                }
447                Some(4) => {
448                    total_interaction_model_messages_received =
449                        Some(<u32>::from_tlv(reader, &field)?)
450                }
451                // A field this revision does not define. §7.19.2: a receiver
452                // ignores what it does not know rather than refusing the whole
453                // structure, which is what lets a newer peer talk to an older one.
454                _ => reader.skip_value(&field)?,
455            }
456        }
457        Ok(Self {
458            current_subscriptions: current_subscriptions
459                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
460            current_subscriptions_for_fabric: current_subscriptions_for_fabric
461                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
462            total_subscriptions_established: total_subscriptions_established
463                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
464            total_interaction_model_messages_sent: total_interaction_model_messages_sent
465                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
466            total_interaction_model_messages_received: total_interaction_model_messages_received
467                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
468        })
469    }
470}
471
472/// `NetworkInterface`.
473#[derive(Debug, Clone, Copy, PartialEq)]
474pub struct NetworkInterface<'a> {
475    /// `Name`, field 0.
476    pub name: &'a str,
477    /// `IsOperational`, field 1.
478    pub is_operational: bool,
479    /// `OffPremiseServicesReachableIPv4`, field 2.
480    pub off_premise_services_reachable_i_pv4: Nullable<bool>,
481    /// `OffPremiseServicesReachableIPv6`, field 3.
482    pub off_premise_services_reachable_i_pv6: Nullable<bool>,
483    /// `HardwareAddress`, field 4.
484    pub hardware_address: &'a [u8],
485    /// `IPv4Addresses`, field 5.
486    pub i_pv4_addresses: TlvList<'a, &'a [u8]>,
487    /// `IPv6Addresses`, field 6.
488    pub i_pv6_addresses: TlvList<'a, &'a [u8]>,
489    /// `Type`, field 7.
490    pub type_: InterfaceTypeEnum,
491}
492
493impl<'a> ToTlv for NetworkInterface<'a> {
494    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
495        w.start_structure(tag)?;
496        self.name.to_tlv(w, Tag::Context(0))?;
497        self.is_operational.to_tlv(w, Tag::Context(1))?;
498        self.off_premise_services_reachable_i_pv4
499            .to_tlv(w, Tag::Context(2))?;
500        self.off_premise_services_reachable_i_pv6
501            .to_tlv(w, Tag::Context(3))?;
502        self.hardware_address.to_tlv(w, Tag::Context(4))?;
503        self.i_pv4_addresses.to_tlv(w, Tag::Context(5))?;
504        self.i_pv6_addresses.to_tlv(w, Tag::Context(6))?;
505        self.type_.to_tlv(w, Tag::Context(7))?;
506        w.end_container()
507    }
508}
509
510impl<'a> FromTlv<'a> for NetworkInterface<'a> {
511    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
512        if element.value.container() != Some(ContainerKind::Structure) {
513            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
514        }
515        let mut name = None;
516        let mut is_operational = None;
517        let mut off_premise_services_reachable_i_pv4 = None;
518        let mut off_premise_services_reachable_i_pv6 = None;
519        let mut hardware_address = None;
520        let mut i_pv4_addresses = None;
521        let mut i_pv6_addresses = None;
522        let mut type_ = None;
523        loop {
524            let Some(field) = reader.next_element()? else {
525                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
526            };
527            if field.value == Value::EndOfContainer {
528                break;
529            }
530            match field.tag.context() {
531                Some(0) => name = Some(<&'a str>::from_tlv(reader, &field)?),
532                Some(1) => is_operational = Some(<bool>::from_tlv(reader, &field)?),
533                Some(2) => {
534                    off_premise_services_reachable_i_pv4 =
535                        Some(<Nullable<bool>>::from_tlv(reader, &field)?)
536                }
537                Some(3) => {
538                    off_premise_services_reachable_i_pv6 =
539                        Some(<Nullable<bool>>::from_tlv(reader, &field)?)
540                }
541                Some(4) => hardware_address = Some(<&'a [u8]>::from_tlv(reader, &field)?),
542                Some(5) => {
543                    i_pv4_addresses = Some(<TlvList<'a, &'a [u8]>>::from_tlv(reader, &field)?)
544                }
545                Some(6) => {
546                    i_pv6_addresses = Some(<TlvList<'a, &'a [u8]>>::from_tlv(reader, &field)?)
547                }
548                Some(7) => type_ = Some(<InterfaceTypeEnum>::from_tlv(reader, &field)?),
549                // A field this revision does not define. §7.19.2: a receiver
550                // ignores what it does not know rather than refusing the whole
551                // structure, which is what lets a newer peer talk to an older one.
552                _ => reader.skip_value(&field)?,
553            }
554        }
555        Ok(Self {
556            name: name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
557            is_operational: is_operational
558                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
559            off_premise_services_reachable_i_pv4: off_premise_services_reachable_i_pv4
560                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
561            off_premise_services_reachable_i_pv6: off_premise_services_reachable_i_pv6
562                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
563            hardware_address: hardware_address
564                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
565            i_pv4_addresses: i_pv4_addresses
566                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
567            i_pv6_addresses: i_pv6_addresses
568                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
569            type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
570        })
571    }
572}
573
574/// The fields of `TestEventTrigger` (command `0x00`).
575#[derive(Debug, Clone, Copy, PartialEq)]
576pub struct TestEventTriggerFields<'a> {
577    /// `EnableKey`, field 0.
578    pub enable_key: &'a [u8],
579    /// `EventTrigger`, field 1.
580    pub event_trigger: u64,
581}
582
583impl<'a> ToTlv for TestEventTriggerFields<'a> {
584    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
585        w.start_structure(tag)?;
586        self.enable_key.to_tlv(w, Tag::Context(0))?;
587        self.event_trigger.to_tlv(w, Tag::Context(1))?;
588        w.end_container()
589    }
590}
591
592impl<'a> FromTlv<'a> for TestEventTriggerFields<'a> {
593    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
594        if element.value.container() != Some(ContainerKind::Structure) {
595            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
596        }
597        let mut enable_key = None;
598        let mut event_trigger = None;
599        loop {
600            let Some(field) = reader.next_element()? else {
601                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
602            };
603            if field.value == Value::EndOfContainer {
604                break;
605            }
606            match field.tag.context() {
607                Some(0) => enable_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
608                Some(1) => event_trigger = Some(<u64>::from_tlv(reader, &field)?),
609                // A field this revision does not define. §7.19.2: a receiver
610                // ignores what it does not know rather than refusing the whole
611                // structure, which is what lets a newer peer talk to an older one.
612                _ => reader.skip_value(&field)?,
613            }
614        }
615        Ok(Self {
616            enable_key: enable_key.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
617            event_trigger: event_trigger.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
618        })
619    }
620}
621
622/// The fields of `TimeSnapshotResponse` (command `0x02`).
623#[derive(Debug, Clone, Copy, PartialEq)]
624pub struct TimeSnapshotResponseFields {
625    /// `SystemTimeMs`, field 0.
626    pub system_time_ms: u64,
627    /// `PosixTimeMs`, field 1.
628    pub posix_time_ms: Nullable<u64>,
629}
630
631impl ToTlv for TimeSnapshotResponseFields {
632    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
633        w.start_structure(tag)?;
634        self.system_time_ms.to_tlv(w, Tag::Context(0))?;
635        self.posix_time_ms.to_tlv(w, Tag::Context(1))?;
636        w.end_container()
637    }
638}
639
640impl<'a> FromTlv<'a> for TimeSnapshotResponseFields {
641    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
642        if element.value.container() != Some(ContainerKind::Structure) {
643            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
644        }
645        let mut system_time_ms = None;
646        let mut posix_time_ms = None;
647        loop {
648            let Some(field) = reader.next_element()? else {
649                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
650            };
651            if field.value == Value::EndOfContainer {
652                break;
653            }
654            match field.tag.context() {
655                Some(0) => system_time_ms = Some(<u64>::from_tlv(reader, &field)?),
656                Some(1) => posix_time_ms = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
657                // A field this revision does not define. §7.19.2: a receiver
658                // ignores what it does not know rather than refusing the whole
659                // structure, which is what lets a newer peer talk to an older one.
660                _ => reader.skip_value(&field)?,
661            }
662        }
663        Ok(Self {
664            system_time_ms: system_time_ms
665                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
666            posix_time_ms: posix_time_ms.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
667        })
668    }
669}
670
671/// The fields of `PayloadTestRequest` (command `0x03`).
672#[derive(Debug, Clone, Copy, PartialEq)]
673pub struct PayloadTestRequestFields<'a> {
674    /// `EnableKey`, field 0.
675    pub enable_key: &'a [u8],
676    /// `Value`, field 1.
677    pub value: u8,
678    /// `Count`, field 2.
679    pub count: u16,
680}
681
682impl<'a> ToTlv for PayloadTestRequestFields<'a> {
683    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
684        w.start_structure(tag)?;
685        self.enable_key.to_tlv(w, Tag::Context(0))?;
686        self.value.to_tlv(w, Tag::Context(1))?;
687        self.count.to_tlv(w, Tag::Context(2))?;
688        w.end_container()
689    }
690}
691
692impl<'a> FromTlv<'a> for PayloadTestRequestFields<'a> {
693    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
694        if element.value.container() != Some(ContainerKind::Structure) {
695            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
696        }
697        let mut enable_key = None;
698        let mut value = None;
699        let mut count = None;
700        loop {
701            let Some(field) = reader.next_element()? else {
702                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
703            };
704            if field.value == Value::EndOfContainer {
705                break;
706            }
707            match field.tag.context() {
708                Some(0) => enable_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
709                Some(1) => value = Some(<u8>::from_tlv(reader, &field)?),
710                Some(2) => count = Some(<u16>::from_tlv(reader, &field)?),
711                // A field this revision does not define. §7.19.2: a receiver
712                // ignores what it does not know rather than refusing the whole
713                // structure, which is what lets a newer peer talk to an older one.
714                _ => reader.skip_value(&field)?,
715            }
716        }
717        Ok(Self {
718            enable_key: enable_key.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
719            value: value.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
720            count: count.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
721        })
722    }
723}
724
725/// The fields of `PayloadTestResponse` (command `0x04`).
726#[derive(Debug, Clone, Copy, PartialEq)]
727pub struct PayloadTestResponseFields<'a> {
728    /// `Payload`, field 0.
729    pub payload: &'a [u8],
730}
731
732impl<'a> ToTlv for PayloadTestResponseFields<'a> {
733    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
734        w.start_structure(tag)?;
735        self.payload.to_tlv(w, Tag::Context(0))?;
736        w.end_container()
737    }
738}
739
740impl<'a> FromTlv<'a> for PayloadTestResponseFields<'a> {
741    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
742        if element.value.container() != Some(ContainerKind::Structure) {
743            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
744        }
745        let mut payload = None;
746        loop {
747            let Some(field) = reader.next_element()? else {
748                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
749            };
750            if field.value == Value::EndOfContainer {
751                break;
752            }
753            match field.tag.context() {
754                Some(0) => payload = Some(<&'a [u8]>::from_tlv(reader, &field)?),
755                // A field this revision does not define. §7.19.2: a receiver
756                // ignores what it does not know rather than refusing the whole
757                // structure, which is what lets a newer peer talk to an older one.
758                _ => reader.skip_value(&field)?,
759            }
760        }
761        Ok(Self {
762            payload: payload.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
763        })
764    }
765}
766
767/// Every attribute the specification defines, with its conformance.
768pub const ATTRIBUTES: &[Attribute] = &[
769    Attribute {
770        id: 0x0000,
771        name: "NetworkInterfaces",
772        kind: "list[NetworkInterface]",
773        access: Access::read_only(Privilege::View),
774        qualities: AttributeQualities::empty(),
775        reporting: Reporting::OnChange,
776        conform: Conform::MANDATORY,
777    },
778    Attribute {
779        id: 0x0001,
780        name: "RebootCount",
781        kind: "uint16",
782        access: Access::read_only(Privilege::View),
783        qualities: AttributeQualities::NON_VOLATILE,
784        reporting: Reporting::OnChange,
785        conform: Conform::MANDATORY,
786    },
787    Attribute {
788        id: 0x0002,
789        name: "UpTime",
790        kind: "uint64",
791        access: Access::read_only(Privilege::View),
792        qualities: AttributeQualities::empty(),
793        reporting: Reporting::ChangesOmitted,
794        conform: Conform::MANDATORY,
795    },
796    Attribute {
797        id: 0x0003,
798        name: "TotalOperationalHours",
799        kind: "uint32",
800        access: Access::read_only(Privilege::View),
801        qualities: AttributeQualities::NON_VOLATILE,
802        reporting: Reporting::ChangesOmitted,
803        conform: Conform::OPTIONAL,
804    },
805    Attribute {
806        id: 0x0004,
807        name: "BootReason",
808        kind: "BootReasonEnum",
809        access: Access::read_only(Privilege::View),
810        qualities: AttributeQualities::empty(),
811        reporting: Reporting::OnChange,
812        conform: Conform::OPTIONAL,
813    },
814    Attribute {
815        id: 0x0005,
816        name: "ActiveHardwareFaults",
817        kind: "list[HardwareFaultEnum]",
818        access: Access::read_only(Privilege::View),
819        qualities: AttributeQualities::empty(),
820        reporting: Reporting::OnChange,
821        conform: Conform::OPTIONAL,
822    },
823    Attribute {
824        id: 0x0006,
825        name: "ActiveRadioFaults",
826        kind: "list[RadioFaultEnum]",
827        access: Access::read_only(Privilege::View),
828        qualities: AttributeQualities::empty(),
829        reporting: Reporting::OnChange,
830        conform: Conform::OPTIONAL,
831    },
832    Attribute {
833        id: 0x0007,
834        name: "ActiveNetworkFaults",
835        kind: "list[NetworkFaultEnum]",
836        access: Access::read_only(Privilege::View),
837        qualities: AttributeQualities::empty(),
838        reporting: Reporting::OnChange,
839        conform: Conform::OPTIONAL,
840    },
841    Attribute {
842        id: 0x0008,
843        name: "TestEventTriggersEnabled",
844        kind: "bool",
845        access: Access::read_only(Privilege::View),
846        qualities: AttributeQualities::empty(),
847        reporting: Reporting::OnChange,
848        conform: Conform::MANDATORY,
849    },
850    Attribute {
851        id: 0x0009,
852        name: "DoNotUse",
853        kind: "",
854        access: Access::read_only(Privilege::View),
855        qualities: AttributeQualities::empty(),
856        reporting: Reporting::OnChange,
857        conform: Conform::DISALLOWED,
858    },
859    Attribute {
860        id: 0x000A,
861        name: "DeviceLoadStatus",
862        kind: "DeviceLoadStruct",
863        access: Access::read_only(Privilege::View),
864        qualities: AttributeQualities::empty(),
865        reporting: Reporting::ChangesOmitted,
866        conform: Conform {
867            clauses: &[Clause {
868                verdict: Conformance::Described,
869                when: Condition::Named("comparison"),
870            }],
871        },
872    },
873];
874
875/// Every command, with its conformance.
876pub const COMMANDS: &[Command] = &[
877    Command {
878        id: 0x00,
879        name: "TestEventTrigger",
880        to_server: true,
881        response: None,
882        access: Access::invoke(Privilege::Manage),
883        conform: Conform::MANDATORY,
884    },
885    Command {
886        id: 0x01,
887        name: "TimeSnapshot",
888        to_server: true,
889        response: Some(0x02),
890        access: Access::invoke(Privilege::Operate),
891        conform: Conform::MANDATORY,
892    },
893    Command {
894        id: 0x02,
895        name: "TimeSnapshotResponse",
896        to_server: false,
897        response: None,
898        access: Access::invoke(Privilege::Operate),
899        conform: Conform::MANDATORY,
900    },
901    Command {
902        id: 0x03,
903        name: "PayloadTestRequest",
904        to_server: true,
905        response: Some(0x04),
906        access: Access::invoke(Privilege::Manage),
907        conform: Conform {
908            clauses: &[Clause {
909                verdict: Conformance::Mandatory,
910                when: Condition::Feature(0),
911            }],
912        },
913    },
914    Command {
915        id: 0x04,
916        name: "PayloadTestResponse",
917        to_server: false,
918        response: None,
919        access: Access::invoke(Privilege::Operate),
920        conform: Conform {
921            clauses: &[Clause {
922                verdict: Conformance::Mandatory,
923                when: Condition::Feature(0),
924            }],
925        },
926    },
927];
928
929/// Every event, with its conformance.
930pub const EVENTS: &[Event] = &[
931    Event {
932        id: 0x00,
933        name: "HardwareFaultChange",
934        priority: EventPriority::Critical,
935        access: Access::read_only(Privilege::View),
936        conform: Conform::OPTIONAL,
937    },
938    Event {
939        id: 0x01,
940        name: "RadioFaultChange",
941        priority: EventPriority::Critical,
942        access: Access::read_only(Privilege::View),
943        conform: Conform::OPTIONAL,
944    },
945    Event {
946        id: 0x02,
947        name: "NetworkFaultChange",
948        priority: EventPriority::Critical,
949        access: Access::read_only(Privilege::View),
950        conform: Conform::OPTIONAL,
951    },
952    Event {
953        id: 0x03,
954        name: "BootReason",
955        priority: EventPriority::Critical,
956        access: Access::read_only(Privilege::View),
957        conform: Conform::MANDATORY,
958    },
959];
960
961/// The whole cluster, as the specification defines it.
962pub const CLUSTER: Cluster = Cluster {
963    id: ID,
964    name: "General Diagnostics",
965    revision: REVISION,
966    pics: "DGGEN",
967    derived_from: None,
968    features: FEATURES,
969    attributes: ATTRIBUTES,
970    commands: COMMANDS,
971    events: EVENTS,
972};