1#![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
26pub const ID: ClusterId = 0x0033;
28
29pub const REVISION: u16 = 3;
32
33pub const PICS: &str = "DGGEN";
35
36pub mod feature {
41 pub const DATA_MODEL_TEST: u32 = 1 << 0;
45}
46
47pub const FEATURES: &[Feature] = &[Feature {
49 bit: 0,
50 code: "DMTEST",
51 name: "DataModelTest",
52 conform: Conform::DESCRIBED,
53}];
54
55pub mod attribute {
57 use crate::im::AttributeId;
58
59 pub const NETWORK_INTERFACES: AttributeId = 0x00;
61 pub const REBOOT_COUNT: AttributeId = 0x01;
63 pub const UP_TIME: AttributeId = 0x02;
65 pub const TOTAL_OPERATIONAL_HOURS: AttributeId = 0x03;
67 pub const BOOT_REASON: AttributeId = 0x04;
69 pub const ACTIVE_HARDWARE_FAULTS: AttributeId = 0x05;
71 pub const ACTIVE_RADIO_FAULTS: AttributeId = 0x06;
73 pub const ACTIVE_NETWORK_FAULTS: AttributeId = 0x07;
75 pub const TEST_EVENT_TRIGGERS_ENABLED: AttributeId = 0x08;
77 pub const DO_NOT_USE: AttributeId = 0x09;
79 pub const DEVICE_LOAD_STATUS: AttributeId = 0x0A;
81}
82
83pub mod command {
85 use crate::im::CommandId;
86
87 pub const TEST_EVENT_TRIGGER: CommandId = 0x00;
89 pub const TIME_SNAPSHOT: CommandId = 0x01;
91 pub const TIME_SNAPSHOT_RESPONSE: CommandId = 0x02;
93 pub const PAYLOAD_TEST_REQUEST: CommandId = 0x03;
95 pub const PAYLOAD_TEST_RESPONSE: CommandId = 0x04;
97}
98
99pub mod event {
101 use crate::im::EventId;
102
103 pub const HARDWARE_FAULT_CHANGE: EventId = 0x00;
105 pub const RADIO_FAULT_CHANGE: EventId = 0x01;
107 pub const NETWORK_FAULT_CHANGE: EventId = 0x02;
109 pub const BOOT_REASON: EventId = 0x03;
111}
112
113#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
115#[repr(u8)]
116pub enum BootReasonEnum {
117 Unspecified = 0,
119 PowerOnReboot = 1,
121 BrownOutReset = 2,
123 SoftwareWatchdogReset = 3,
125 HardwareWatchdogReset = 4,
127 SoftwareUpdateCompleted = 5,
129 SoftwareReset = 6,
131}
132
133impl BootReasonEnum {
134 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
171#[repr(u8)]
172pub enum HardwareFaultEnum {
173 Unspecified = 0,
175 Radio = 1,
177 Sensor = 2,
179 ResettableOverTemp = 3,
181 NonResettableOverTemp = 4,
183 PowerSource = 5,
185 VisualDisplayFault = 6,
187 AudioOutputFault = 7,
189 UserInterfaceFault = 8,
191 NonVolatileMemoryError = 9,
193 TamperDetected = 10,
195}
196
197impl HardwareFaultEnum {
198 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
239#[repr(u8)]
240pub enum InterfaceTypeEnum {
241 Unspecified = 0,
243 WiFi = 1,
245 Ethernet = 2,
247 Cellular = 3,
249 Thread = 4,
251}
252
253impl InterfaceTypeEnum {
254 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
289#[repr(u8)]
290pub enum NetworkFaultEnum {
291 Unspecified = 0,
293 HardwareFailure = 1,
295 NetworkJammed = 2,
297 ConnectionFailed = 3,
299}
300
301impl NetworkFaultEnum {
302 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
336#[repr(u8)]
337pub enum RadioFaultEnum {
338 Unspecified = 0,
340 WiFiFault = 1,
342 CellularFault = 2,
344 ThreadFault = 3,
346 NFCFault = 4,
348 BLEFault = 5,
350 EthernetFault = 6,
352}
353
354impl RadioFaultEnum {
355 #[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 #[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#[derive(Debug, Clone, Copy, PartialEq)]
392pub struct DeviceLoadStruct {
393 pub current_subscriptions: u16,
395 pub current_subscriptions_for_fabric: u16,
397 pub total_subscriptions_established: u32,
399 pub total_interaction_model_messages_sent: u32,
401 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
474pub struct NetworkInterface<'a> {
475 pub name: &'a str,
477 pub is_operational: bool,
479 pub off_premise_services_reachable_i_pv4: Nullable<bool>,
481 pub off_premise_services_reachable_i_pv6: Nullable<bool>,
483 pub hardware_address: &'a [u8],
485 pub i_pv4_addresses: TlvList<'a, &'a [u8]>,
487 pub i_pv6_addresses: TlvList<'a, &'a [u8]>,
489 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
576pub struct TestEventTriggerFields<'a> {
577 pub enable_key: &'a [u8],
579 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
624pub struct TimeSnapshotResponseFields {
625 pub system_time_ms: u64,
627 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
673pub struct PayloadTestRequestFields<'a> {
674 pub enable_key: &'a [u8],
676 pub value: u8,
678 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 _ => 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#[derive(Debug, Clone, Copy, PartialEq)]
727pub struct PayloadTestResponseFields<'a> {
728 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 _ => reader.skip_value(&field)?,
759 }
760 }
761 Ok(Self {
762 payload: payload.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
763 })
764 }
765}
766
767pub 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
875pub 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
929pub 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
961pub 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};