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 = 0x0038;
28
29pub const REVISION: u16 = 2;
32
33pub const PICS: &str = "TIMESYNC";
35
36pub mod feature {
41 pub const TIME_ZONE: u32 = 1 << 0;
45 pub const NTP_CLIENT: u32 = 1 << 1;
49 pub const NTP_SERVER: u32 = 1 << 2;
53 pub const TIME_SYNC_CLIENT: u32 = 1 << 3;
57}
58
59pub const FEATURES: &[Feature] = &[
61 Feature {
62 bit: 0,
63 code: "TZ",
64 name: "TimeZone",
65 conform: Conform::OPTIONAL,
66 },
67 Feature {
68 bit: 1,
69 code: "NTPC",
70 name: "NTPClient",
71 conform: Conform::OPTIONAL,
72 },
73 Feature {
74 bit: 2,
75 code: "NTPS",
76 name: "NTPServer",
77 conform: Conform::OPTIONAL,
78 },
79 Feature {
80 bit: 3,
81 code: "TSC",
82 name: "TimeSyncClient",
83 conform: Conform::OPTIONAL,
84 },
85];
86
87pub mod attribute {
89 use crate::im::AttributeId;
90
91 pub const UTC_TIME: AttributeId = 0x00;
93 pub const GRANULARITY: AttributeId = 0x01;
95 pub const TIME_SOURCE: AttributeId = 0x02;
97 pub const TRUSTED_TIME_SOURCE: AttributeId = 0x03;
99 pub const DEFAULT_NTP: AttributeId = 0x04;
101 pub const TIME_ZONE: AttributeId = 0x05;
103 pub const DST_OFFSET: AttributeId = 0x06;
105 pub const LOCAL_TIME: AttributeId = 0x07;
107 pub const TIME_ZONE_DATABASE: AttributeId = 0x08;
109 pub const NTP_SERVER_AVAILABLE: AttributeId = 0x09;
111 pub const TIME_ZONE_LIST_MAX_SIZE: AttributeId = 0x0A;
113 pub const DST_OFFSET_LIST_MAX_SIZE: AttributeId = 0x0B;
115 pub const SUPPORTS_DNS_RESOLVE: AttributeId = 0x0C;
117}
118
119pub mod command {
121 use crate::im::CommandId;
122
123 pub const SET_UTC_TIME: CommandId = 0x00;
125 pub const SET_TRUSTED_TIME_SOURCE: CommandId = 0x01;
127 pub const SET_TIME_ZONE: CommandId = 0x02;
129 pub const SET_TIME_ZONE_RESPONSE: CommandId = 0x03;
131 pub const SET_DST_OFFSET: CommandId = 0x04;
133 pub const SET_DEFAULT_NTP: CommandId = 0x05;
135}
136
137pub mod event {
139 use crate::im::EventId;
140
141 pub const DST_TABLE_EMPTY: EventId = 0x00;
143 pub const DST_STATUS: EventId = 0x01;
145 pub const TIME_ZONE_STATUS: EventId = 0x02;
147 pub const TIME_FAILURE: EventId = 0x03;
149 pub const MISSING_TRUSTED_TIME_SOURCE: EventId = 0x04;
151}
152
153#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
155#[repr(u8)]
156pub enum GranularityEnum {
157 NoTimeGranularity = 0,
159 MinutesGranularity = 1,
161 SecondsGranularity = 2,
163 MillisecondsGranularity = 3,
165 MicrosecondsGranularity = 4,
167}
168
169impl GranularityEnum {
170 #[must_use]
172 pub const fn from_value(value: u8) -> Option<Self> {
173 match value {
174 0 => Some(Self::NoTimeGranularity),
175 1 => Some(Self::MinutesGranularity),
176 2 => Some(Self::SecondsGranularity),
177 3 => Some(Self::MillisecondsGranularity),
178 4 => Some(Self::MicrosecondsGranularity),
179 _ => None,
180 }
181 }
182
183 #[must_use]
185 pub const fn value(self) -> u8 {
186 self as u8
187 }
188}
189
190impl ToTlv for GranularityEnum {
191 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
192 self.value().to_tlv(w, tag)
193 }
194}
195
196impl<'a> FromTlv<'a> for GranularityEnum {
197 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
198 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
199 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
200 }
201}
202
203#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
205#[repr(u8)]
206pub enum StatusCodeEnum {
207 TimeNotAccepted = 2,
209}
210
211impl StatusCodeEnum {
212 #[must_use]
214 pub const fn from_value(value: u8) -> Option<Self> {
215 match value {
216 2 => Some(Self::TimeNotAccepted),
217 _ => None,
218 }
219 }
220
221 #[must_use]
223 pub const fn value(self) -> u8 {
224 self as u8
225 }
226}
227
228impl ToTlv for StatusCodeEnum {
229 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
230 self.value().to_tlv(w, tag)
231 }
232}
233
234impl<'a> FromTlv<'a> for StatusCodeEnum {
235 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
236 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
237 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
238 }
239}
240
241#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
243#[repr(u8)]
244pub enum TimeSourceEnum {
245 None = 0,
247 Unknown = 1,
249 Admin = 2,
251 NodeTimeCluster = 3,
253 NonMatterSNTP = 4,
255 NonMatterNTP = 5,
257 MatterSNTP = 6,
259 MatterNTP = 7,
261 MixedNTP = 8,
263 NonMatterSNTPNTS = 9,
265 NonMatterNTPNTS = 10,
267 MatterSNTPNTS = 11,
269 MatterNTPNTS = 12,
271 MixedNTPNTS = 13,
273 CloudSource = 14,
275 PTP = 15,
277 GNSS = 16,
279}
280
281impl TimeSourceEnum {
282 #[must_use]
284 pub const fn from_value(value: u8) -> Option<Self> {
285 match value {
286 0 => Some(Self::None),
287 1 => Some(Self::Unknown),
288 2 => Some(Self::Admin),
289 3 => Some(Self::NodeTimeCluster),
290 4 => Some(Self::NonMatterSNTP),
291 5 => Some(Self::NonMatterNTP),
292 6 => Some(Self::MatterSNTP),
293 7 => Some(Self::MatterNTP),
294 8 => Some(Self::MixedNTP),
295 9 => Some(Self::NonMatterSNTPNTS),
296 10 => Some(Self::NonMatterNTPNTS),
297 11 => Some(Self::MatterSNTPNTS),
298 12 => Some(Self::MatterNTPNTS),
299 13 => Some(Self::MixedNTPNTS),
300 14 => Some(Self::CloudSource),
301 15 => Some(Self::PTP),
302 16 => Some(Self::GNSS),
303 _ => None,
304 }
305 }
306
307 #[must_use]
309 pub const fn value(self) -> u8 {
310 self as u8
311 }
312}
313
314impl ToTlv for TimeSourceEnum {
315 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
316 self.value().to_tlv(w, tag)
317 }
318}
319
320impl<'a> FromTlv<'a> for TimeSourceEnum {
321 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
322 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
323 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
324 }
325}
326
327#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
329#[repr(u8)]
330pub enum TimeZoneDatabaseEnum {
331 Full = 0,
333 Partial = 1,
335 None = 2,
337}
338
339impl TimeZoneDatabaseEnum {
340 #[must_use]
342 pub const fn from_value(value: u8) -> Option<Self> {
343 match value {
344 0 => Some(Self::Full),
345 1 => Some(Self::Partial),
346 2 => Some(Self::None),
347 _ => None,
348 }
349 }
350
351 #[must_use]
353 pub const fn value(self) -> u8 {
354 self as u8
355 }
356}
357
358impl ToTlv for TimeZoneDatabaseEnum {
359 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
360 self.value().to_tlv(w, tag)
361 }
362}
363
364impl<'a> FromTlv<'a> for TimeZoneDatabaseEnum {
365 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
366 let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
367 Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
368 }
369}
370
371#[derive(Debug, Clone, Copy, PartialEq)]
373pub struct DSTOffsetStruct {
374 pub offset: i32,
376 pub valid_starting: u64,
378 pub valid_until: Nullable<u64>,
380}
381
382impl ToTlv for DSTOffsetStruct {
383 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
384 w.start_structure(tag)?;
385 self.offset.to_tlv(w, Tag::Context(0))?;
386 self.valid_starting.to_tlv(w, Tag::Context(1))?;
387 self.valid_until.to_tlv(w, Tag::Context(2))?;
388 w.end_container()
389 }
390}
391
392impl<'a> FromTlv<'a> for DSTOffsetStruct {
393 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
394 if element.value.container() != Some(ContainerKind::Structure) {
395 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
396 }
397 let mut offset = None;
398 let mut valid_starting = None;
399 let mut valid_until = None;
400 loop {
401 let Some(field) = reader.next_element()? else {
402 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
403 };
404 if field.value == Value::EndOfContainer {
405 break;
406 }
407 match field.tag.context() {
408 Some(0) => offset = Some(<i32>::from_tlv(reader, &field)?),
409 Some(1) => valid_starting = Some(<u64>::from_tlv(reader, &field)?),
410 Some(2) => valid_until = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
411 _ => reader.skip_value(&field)?,
415 }
416 }
417 Ok(Self {
418 offset: offset.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
419 valid_starting: valid_starting
420 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
421 valid_until: valid_until.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
422 })
423 }
424}
425
426#[derive(Debug, Clone, Copy, PartialEq)]
428pub struct FabricScopedTrustedTimeSourceStruct {
429 pub node_id: crate::msg::NodeId,
431 pub endpoint: u16,
433}
434
435impl ToTlv for FabricScopedTrustedTimeSourceStruct {
436 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
437 w.start_structure(tag)?;
438 self.node_id.to_tlv(w, Tag::Context(0))?;
439 self.endpoint.to_tlv(w, Tag::Context(1))?;
440 w.end_container()
441 }
442}
443
444impl<'a> FromTlv<'a> for FabricScopedTrustedTimeSourceStruct {
445 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
446 if element.value.container() != Some(ContainerKind::Structure) {
447 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
448 }
449 let mut node_id = None;
450 let mut endpoint = None;
451 loop {
452 let Some(field) = reader.next_element()? else {
453 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
454 };
455 if field.value == Value::EndOfContainer {
456 break;
457 }
458 match field.tag.context() {
459 Some(0) => node_id = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
460 Some(1) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
461 _ => reader.skip_value(&field)?,
465 }
466 }
467 Ok(Self {
468 node_id: node_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
469 endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
470 })
471 }
472}
473
474#[derive(Debug, Clone, Copy, PartialEq)]
476pub struct TimeZoneStruct<'a> {
477 pub offset: i32,
479 pub valid_at: u64,
481 pub name: Option<&'a str>,
483}
484
485impl<'a> ToTlv for TimeZoneStruct<'a> {
486 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
487 w.start_structure(tag)?;
488 self.offset.to_tlv(w, Tag::Context(0))?;
489 self.valid_at.to_tlv(w, Tag::Context(1))?;
490 if let Some(value) = &self.name {
491 value.to_tlv(w, Tag::Context(2))?;
492 }
493 w.end_container()
494 }
495}
496
497impl<'a> FromTlv<'a> for TimeZoneStruct<'a> {
498 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
499 if element.value.container() != Some(ContainerKind::Structure) {
500 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
501 }
502 let mut offset = None;
503 let mut valid_at = None;
504 let mut name = None;
505 loop {
506 let Some(field) = reader.next_element()? else {
507 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
508 };
509 if field.value == Value::EndOfContainer {
510 break;
511 }
512 match field.tag.context() {
513 Some(0) => offset = Some(<i32>::from_tlv(reader, &field)?),
514 Some(1) => valid_at = Some(<u64>::from_tlv(reader, &field)?),
515 Some(2) => name = Some(<&'a str>::from_tlv(reader, &field)?),
516 _ => reader.skip_value(&field)?,
520 }
521 }
522 Ok(Self {
523 offset: offset.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
524 valid_at: valid_at.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
525 name,
526 })
527 }
528}
529
530#[derive(Debug, Clone, Copy, PartialEq)]
532pub struct TrustedTimeSourceStruct {
533 pub fabric_index: crate::msg::FabricIndex,
535 pub node_id: crate::msg::NodeId,
537 pub endpoint: u16,
539}
540
541impl ToTlv for TrustedTimeSourceStruct {
542 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
543 w.start_structure(tag)?;
544 self.fabric_index.to_tlv(w, Tag::Context(0))?;
545 self.node_id.to_tlv(w, Tag::Context(1))?;
546 self.endpoint.to_tlv(w, Tag::Context(2))?;
547 w.end_container()
548 }
549}
550
551impl<'a> FromTlv<'a> for TrustedTimeSourceStruct {
552 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
553 if element.value.container() != Some(ContainerKind::Structure) {
554 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
555 }
556 let mut fabric_index = None;
557 let mut node_id = None;
558 let mut endpoint = None;
559 loop {
560 let Some(field) = reader.next_element()? else {
561 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
562 };
563 if field.value == Value::EndOfContainer {
564 break;
565 }
566 match field.tag.context() {
567 Some(0) => {
568 fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
569 }
570 Some(1) => node_id = Some(<crate::msg::NodeId>::from_tlv(reader, &field)?),
571 Some(2) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
572 _ => reader.skip_value(&field)?,
576 }
577 }
578 Ok(Self {
579 fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
580 node_id: node_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
581 endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
582 })
583 }
584}
585
586#[derive(Debug, Clone, Copy, PartialEq)]
588pub struct SetUTCTimeFields {
589 pub utc_time: u64,
591 pub granularity: GranularityEnum,
593 pub time_source: Option<TimeSourceEnum>,
595}
596
597impl ToTlv for SetUTCTimeFields {
598 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
599 w.start_structure(tag)?;
600 self.utc_time.to_tlv(w, Tag::Context(0))?;
601 self.granularity.to_tlv(w, Tag::Context(1))?;
602 if let Some(value) = &self.time_source {
603 value.to_tlv(w, Tag::Context(2))?;
604 }
605 w.end_container()
606 }
607}
608
609impl<'a> FromTlv<'a> for SetUTCTimeFields {
610 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
611 if element.value.container() != Some(ContainerKind::Structure) {
612 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
613 }
614 let mut utc_time = None;
615 let mut granularity = None;
616 let mut time_source = None;
617 loop {
618 let Some(field) = reader.next_element()? else {
619 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
620 };
621 if field.value == Value::EndOfContainer {
622 break;
623 }
624 match field.tag.context() {
625 Some(0) => utc_time = Some(<u64>::from_tlv(reader, &field)?),
626 Some(1) => granularity = Some(<GranularityEnum>::from_tlv(reader, &field)?),
627 Some(2) => time_source = Some(<TimeSourceEnum>::from_tlv(reader, &field)?),
628 _ => reader.skip_value(&field)?,
632 }
633 }
634 Ok(Self {
635 utc_time: utc_time.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
636 granularity: granularity.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
637 time_source,
638 })
639 }
640}
641
642#[derive(Debug, Clone, Copy, PartialEq)]
644pub struct SetTrustedTimeSourceFields {
645 pub trusted_time_source: Nullable<FabricScopedTrustedTimeSourceStruct>,
647}
648
649impl ToTlv for SetTrustedTimeSourceFields {
650 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
651 w.start_structure(tag)?;
652 self.trusted_time_source.to_tlv(w, Tag::Context(0))?;
653 w.end_container()
654 }
655}
656
657impl<'a> FromTlv<'a> for SetTrustedTimeSourceFields {
658 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
659 if element.value.container() != Some(ContainerKind::Structure) {
660 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
661 }
662 let mut trusted_time_source = None;
663 loop {
664 let Some(field) = reader.next_element()? else {
665 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
666 };
667 if field.value == Value::EndOfContainer {
668 break;
669 }
670 match field.tag.context() {
671 Some(0) => {
672 trusted_time_source = Some(
673 <Nullable<FabricScopedTrustedTimeSourceStruct>>::from_tlv(reader, &field)?,
674 )
675 }
676 _ => reader.skip_value(&field)?,
680 }
681 }
682 Ok(Self {
683 trusted_time_source: trusted_time_source
684 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
685 })
686 }
687}
688
689#[derive(Debug, Clone, Copy, PartialEq)]
691pub struct SetTimeZoneFields<'a> {
692 pub time_zone: TlvList<'a, TimeZoneStruct<'a>>,
694}
695
696impl<'a> ToTlv for SetTimeZoneFields<'a> {
697 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
698 w.start_structure(tag)?;
699 self.time_zone.to_tlv(w, Tag::Context(0))?;
700 w.end_container()
701 }
702}
703
704impl<'a> FromTlv<'a> for SetTimeZoneFields<'a> {
705 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
706 if element.value.container() != Some(ContainerKind::Structure) {
707 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
708 }
709 let mut time_zone = None;
710 loop {
711 let Some(field) = reader.next_element()? else {
712 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
713 };
714 if field.value == Value::EndOfContainer {
715 break;
716 }
717 match field.tag.context() {
718 Some(0) => {
719 time_zone = Some(<TlvList<'a, TimeZoneStruct<'a>>>::from_tlv(reader, &field)?)
720 }
721 _ => reader.skip_value(&field)?,
725 }
726 }
727 Ok(Self {
728 time_zone: time_zone.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
729 })
730 }
731}
732
733#[derive(Debug, Clone, Copy, PartialEq)]
735pub struct SetTimeZoneResponseFields {
736 pub dst_offset_required: bool,
738}
739
740impl ToTlv for SetTimeZoneResponseFields {
741 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
742 w.start_structure(tag)?;
743 self.dst_offset_required.to_tlv(w, Tag::Context(0))?;
744 w.end_container()
745 }
746}
747
748impl<'a> FromTlv<'a> for SetTimeZoneResponseFields {
749 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
750 if element.value.container() != Some(ContainerKind::Structure) {
751 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
752 }
753 let mut dst_offset_required = None;
754 loop {
755 let Some(field) = reader.next_element()? else {
756 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
757 };
758 if field.value == Value::EndOfContainer {
759 break;
760 }
761 match field.tag.context() {
762 Some(0) => dst_offset_required = Some(<bool>::from_tlv(reader, &field)?),
763 _ => reader.skip_value(&field)?,
767 }
768 }
769 Ok(Self {
770 dst_offset_required: dst_offset_required
771 .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
772 })
773 }
774}
775
776#[derive(Debug, Clone, Copy, PartialEq)]
778pub struct SetDSTOffsetFields<'a> {
779 pub dst_offset: TlvList<'a, DSTOffsetStruct>,
781}
782
783impl<'a> ToTlv for SetDSTOffsetFields<'a> {
784 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
785 w.start_structure(tag)?;
786 self.dst_offset.to_tlv(w, Tag::Context(0))?;
787 w.end_container()
788 }
789}
790
791impl<'a> FromTlv<'a> for SetDSTOffsetFields<'a> {
792 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
793 if element.value.container() != Some(ContainerKind::Structure) {
794 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
795 }
796 let mut dst_offset = None;
797 loop {
798 let Some(field) = reader.next_element()? else {
799 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
800 };
801 if field.value == Value::EndOfContainer {
802 break;
803 }
804 match field.tag.context() {
805 Some(0) => {
806 dst_offset = Some(<TlvList<'a, DSTOffsetStruct>>::from_tlv(reader, &field)?)
807 }
808 _ => reader.skip_value(&field)?,
812 }
813 }
814 Ok(Self {
815 dst_offset: dst_offset.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
816 })
817 }
818}
819
820#[derive(Debug, Clone, Copy, PartialEq)]
822pub struct SetDefaultNTPFields<'a> {
823 pub default_ntp: Nullable<&'a str>,
825}
826
827impl<'a> ToTlv for SetDefaultNTPFields<'a> {
828 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
829 w.start_structure(tag)?;
830 self.default_ntp.to_tlv(w, Tag::Context(0))?;
831 w.end_container()
832 }
833}
834
835impl<'a> FromTlv<'a> for SetDefaultNTPFields<'a> {
836 fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
837 if element.value.container() != Some(ContainerKind::Structure) {
838 return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
839 }
840 let mut default_ntp = None;
841 loop {
842 let Some(field) = reader.next_element()? else {
843 return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
844 };
845 if field.value == Value::EndOfContainer {
846 break;
847 }
848 match field.tag.context() {
849 Some(0) => default_ntp = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
850 _ => reader.skip_value(&field)?,
854 }
855 }
856 Ok(Self {
857 default_ntp: default_ntp.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
858 })
859 }
860}
861
862pub const ATTRIBUTES: &[Attribute] = &[
864 Attribute {
865 id: 0x0000,
866 name: "UTCTime",
867 kind: "epoch-us",
868 access: Access::read_only(Privilege::View),
869 qualities: AttributeQualities::NULLABLE,
870 reporting: Reporting::ChangesOmitted,
871 conform: Conform::MANDATORY,
872 },
873 Attribute {
874 id: 0x0001,
875 name: "Granularity",
876 kind: "GranularityEnum",
877 access: Access::read_only(Privilege::View),
878 qualities: AttributeQualities::empty(),
879 reporting: Reporting::OnChange,
880 conform: Conform::MANDATORY,
881 },
882 Attribute {
883 id: 0x0002,
884 name: "TimeSource",
885 kind: "TimeSourceEnum",
886 access: Access::read_only(Privilege::View),
887 qualities: AttributeQualities::empty(),
888 reporting: Reporting::OnChange,
889 conform: Conform::OPTIONAL,
890 },
891 Attribute {
892 id: 0x0003,
893 name: "TrustedTimeSource",
894 kind: "TrustedTimeSourceStruct",
895 access: Access::read_only(Privilege::View),
896 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
897 reporting: Reporting::OnChange,
898 conform: Conform {
899 clauses: &[Clause {
900 verdict: Conformance::Mandatory,
901 when: Condition::Feature(3),
902 }],
903 },
904 },
905 Attribute {
906 id: 0x0004,
907 name: "DefaultNTP",
908 kind: "string",
909 access: Access::read_only(Privilege::View),
910 qualities: AttributeQualities::NULLABLE.union(AttributeQualities::NON_VOLATILE),
911 reporting: Reporting::OnChange,
912 conform: Conform {
913 clauses: &[Clause {
914 verdict: Conformance::Mandatory,
915 when: Condition::Feature(1),
916 }],
917 },
918 },
919 Attribute {
920 id: 0x0005,
921 name: "TimeZone",
922 kind: "list[TimeZoneStruct]",
923 access: Access::read_only(Privilege::View),
924 qualities: AttributeQualities::NON_VOLATILE,
925 reporting: Reporting::OnChange,
926 conform: Conform {
927 clauses: &[Clause {
928 verdict: Conformance::Mandatory,
929 when: Condition::Feature(0),
930 }],
931 },
932 },
933 Attribute {
934 id: 0x0006,
935 name: "DSTOffset",
936 kind: "list[DSTOffsetStruct]",
937 access: Access::read_only(Privilege::View),
938 qualities: AttributeQualities::NON_VOLATILE,
939 reporting: Reporting::OnChange,
940 conform: Conform {
941 clauses: &[Clause {
942 verdict: Conformance::Mandatory,
943 when: Condition::Feature(0),
944 }],
945 },
946 },
947 Attribute {
948 id: 0x0007,
949 name: "LocalTime",
950 kind: "epoch-us",
951 access: Access::read_only(Privilege::View),
952 qualities: AttributeQualities::NULLABLE,
953 reporting: Reporting::ChangesOmitted,
954 conform: Conform {
955 clauses: &[Clause {
956 verdict: Conformance::Mandatory,
957 when: Condition::Feature(0),
958 }],
959 },
960 },
961 Attribute {
962 id: 0x0008,
963 name: "TimeZoneDatabase",
964 kind: "TimeZoneDatabaseEnum",
965 access: Access::read_only(Privilege::View),
966 qualities: AttributeQualities::FIXED,
967 reporting: Reporting::OnChange,
968 conform: Conform {
969 clauses: &[Clause {
970 verdict: Conformance::Mandatory,
971 when: Condition::Feature(0),
972 }],
973 },
974 },
975 Attribute {
976 id: 0x0009,
977 name: "NTPServerAvailable",
978 kind: "bool",
979 access: Access::read_only(Privilege::View),
980 qualities: AttributeQualities::empty(),
981 reporting: Reporting::OnChange,
982 conform: Conform {
983 clauses: &[Clause {
984 verdict: Conformance::Mandatory,
985 when: Condition::Feature(2),
986 }],
987 },
988 },
989 Attribute {
990 id: 0x000A,
991 name: "TimeZoneListMaxSize",
992 kind: "uint8",
993 access: Access::read_only(Privilege::View),
994 qualities: AttributeQualities::FIXED,
995 reporting: Reporting::OnChange,
996 conform: Conform {
997 clauses: &[Clause {
998 verdict: Conformance::Mandatory,
999 when: Condition::Feature(0),
1000 }],
1001 },
1002 },
1003 Attribute {
1004 id: 0x000B,
1005 name: "DSTOffsetListMaxSize",
1006 kind: "uint8",
1007 access: Access::read_only(Privilege::View),
1008 qualities: AttributeQualities::FIXED,
1009 reporting: Reporting::OnChange,
1010 conform: Conform {
1011 clauses: &[Clause {
1012 verdict: Conformance::Mandatory,
1013 when: Condition::Feature(0),
1014 }],
1015 },
1016 },
1017 Attribute {
1018 id: 0x000C,
1019 name: "SupportsDNSResolve",
1020 kind: "bool",
1021 access: Access::read_only(Privilege::View),
1022 qualities: AttributeQualities::FIXED,
1023 reporting: Reporting::OnChange,
1024 conform: Conform {
1025 clauses: &[Clause {
1026 verdict: Conformance::Mandatory,
1027 when: Condition::Feature(1),
1028 }],
1029 },
1030 },
1031];
1032
1033pub const COMMANDS: &[Command] = &[
1035 Command {
1036 id: 0x00,
1037 name: "SetUTCTime",
1038 to_server: true,
1039 response: None,
1040 access: Access::invoke(Privilege::Administer),
1041 conform: Conform::MANDATORY,
1042 },
1043 Command {
1044 id: 0x01,
1045 name: "SetTrustedTimeSource",
1046 to_server: true,
1047 response: None,
1048 access: Access::invoke(Privilege::Administer)
1049 .with_qualities(AccessQualities::FABRIC_SCOPED),
1050 conform: Conform {
1051 clauses: &[Clause {
1052 verdict: Conformance::Mandatory,
1053 when: Condition::Feature(3),
1054 }],
1055 },
1056 },
1057 Command {
1058 id: 0x02,
1059 name: "SetTimeZone",
1060 to_server: true,
1061 response: Some(0x03),
1062 access: Access::invoke(Privilege::Manage),
1063 conform: Conform {
1064 clauses: &[Clause {
1065 verdict: Conformance::Mandatory,
1066 when: Condition::Feature(0),
1067 }],
1068 },
1069 },
1070 Command {
1071 id: 0x03,
1072 name: "SetTimeZoneResponse",
1073 to_server: false,
1074 response: None,
1075 access: Access::invoke(Privilege::Operate),
1076 conform: Conform {
1077 clauses: &[Clause {
1078 verdict: Conformance::Mandatory,
1079 when: Condition::Feature(0),
1080 }],
1081 },
1082 },
1083 Command {
1084 id: 0x04,
1085 name: "SetDSTOffset",
1086 to_server: true,
1087 response: None,
1088 access: Access::invoke(Privilege::Manage),
1089 conform: Conform {
1090 clauses: &[Clause {
1091 verdict: Conformance::Mandatory,
1092 when: Condition::Feature(0),
1093 }],
1094 },
1095 },
1096 Command {
1097 id: 0x05,
1098 name: "SetDefaultNTP",
1099 to_server: true,
1100 response: None,
1101 access: Access::invoke(Privilege::Administer),
1102 conform: Conform {
1103 clauses: &[Clause {
1104 verdict: Conformance::Mandatory,
1105 when: Condition::Feature(1),
1106 }],
1107 },
1108 },
1109];
1110
1111pub const EVENTS: &[Event] = &[
1113 Event {
1114 id: 0x00,
1115 name: "DSTTableEmpty",
1116 priority: EventPriority::Info,
1117 access: Access::read_only(Privilege::View),
1118 conform: Conform {
1119 clauses: &[Clause {
1120 verdict: Conformance::Mandatory,
1121 when: Condition::Feature(0),
1122 }],
1123 },
1124 },
1125 Event {
1126 id: 0x01,
1127 name: "DSTStatus",
1128 priority: EventPriority::Info,
1129 access: Access::read_only(Privilege::View),
1130 conform: Conform {
1131 clauses: &[Clause {
1132 verdict: Conformance::Mandatory,
1133 when: Condition::Feature(0),
1134 }],
1135 },
1136 },
1137 Event {
1138 id: 0x02,
1139 name: "TimeZoneStatus",
1140 priority: EventPriority::Info,
1141 access: Access::read_only(Privilege::View),
1142 conform: Conform {
1143 clauses: &[Clause {
1144 verdict: Conformance::Mandatory,
1145 when: Condition::Feature(0),
1146 }],
1147 },
1148 },
1149 Event {
1150 id: 0x03,
1151 name: "TimeFailure",
1152 priority: EventPriority::Info,
1153 access: Access::read_only(Privilege::View),
1154 conform: Conform::MANDATORY,
1155 },
1156 Event {
1157 id: 0x04,
1158 name: "MissingTrustedTimeSource",
1159 priority: EventPriority::Info,
1160 access: Access::read_only(Privilege::View),
1161 conform: Conform {
1162 clauses: &[Clause {
1163 verdict: Conformance::Mandatory,
1164 when: Condition::Feature(3),
1165 }],
1166 },
1167 },
1168];
1169
1170pub const CLUSTER: Cluster = Cluster {
1172 id: ID,
1173 name: "Time Synchronization",
1174 revision: REVISION,
1175 pics: "TIMESYNC",
1176 derived_from: None,
1177 features: FEATURES,
1178 attributes: ATTRIBUTES,
1179 commands: COMMANDS,
1180 events: EVENTS,
1181};