Skip to main content

matter_kit/clusters/generated/
time_synchronization.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Time Synchronization — cluster 0x0038.
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//! Time Synchronization (cluster `0x0038`, revision 2).
10//!
11//! 24 identifiers, 4 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 = 0x0038;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 2;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "TIMESYNC";
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    /// Server supports time zone.
42    ///
43    /// Code `TZ`, bit 0.
44    pub const TIME_ZONE: u32 = 1 << 0;
45    /// Server supports an NTP or SNTP client.
46    ///
47    /// Code `NTPC`, bit 1.
48    pub const NTP_CLIENT: u32 = 1 << 1;
49    /// Server supports an NTP server role.
50    ///
51    /// Code `NTPS`, bit 2.
52    pub const NTP_SERVER: u32 = 1 << 2;
53    /// Time synchronization client cluster is present.
54    ///
55    /// Code `TSC`, bit 3.
56    pub const TIME_SYNC_CLIENT: u32 = 1 << 3;
57}
58
59/// Every feature bit, with its conformance.
60pub 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
87/// The attribute ids.
88pub mod attribute {
89    use crate::im::AttributeId;
90
91    /// `UTCTime`.
92    pub const UTC_TIME: AttributeId = 0x00;
93    /// `Granularity`.
94    pub const GRANULARITY: AttributeId = 0x01;
95    /// `TimeSource`.
96    pub const TIME_SOURCE: AttributeId = 0x02;
97    /// `TrustedTimeSource`.
98    pub const TRUSTED_TIME_SOURCE: AttributeId = 0x03;
99    /// `DefaultNTP`.
100    pub const DEFAULT_NTP: AttributeId = 0x04;
101    /// `TimeZone`.
102    pub const TIME_ZONE: AttributeId = 0x05;
103    /// `DSTOffset`.
104    pub const DST_OFFSET: AttributeId = 0x06;
105    /// `LocalTime`.
106    pub const LOCAL_TIME: AttributeId = 0x07;
107    /// `TimeZoneDatabase`.
108    pub const TIME_ZONE_DATABASE: AttributeId = 0x08;
109    /// `NTPServerAvailable`.
110    pub const NTP_SERVER_AVAILABLE: AttributeId = 0x09;
111    /// `TimeZoneListMaxSize`.
112    pub const TIME_ZONE_LIST_MAX_SIZE: AttributeId = 0x0A;
113    /// `DSTOffsetListMaxSize`.
114    pub const DST_OFFSET_LIST_MAX_SIZE: AttributeId = 0x0B;
115    /// `SupportsDNSResolve`.
116    pub const SUPPORTS_DNS_RESOLVE: AttributeId = 0x0C;
117}
118
119/// The command ids.
120pub mod command {
121    use crate::im::CommandId;
122
123    /// `SetUTCTime`.
124    pub const SET_UTC_TIME: CommandId = 0x00;
125    /// `SetTrustedTimeSource`.
126    pub const SET_TRUSTED_TIME_SOURCE: CommandId = 0x01;
127    /// `SetTimeZone`.
128    pub const SET_TIME_ZONE: CommandId = 0x02;
129    /// `SetTimeZoneResponse`.
130    pub const SET_TIME_ZONE_RESPONSE: CommandId = 0x03;
131    /// `SetDSTOffset`.
132    pub const SET_DST_OFFSET: CommandId = 0x04;
133    /// `SetDefaultNTP`.
134    pub const SET_DEFAULT_NTP: CommandId = 0x05;
135}
136
137/// The event ids.
138pub mod event {
139    use crate::im::EventId;
140
141    /// `DSTTableEmpty`.
142    pub const DST_TABLE_EMPTY: EventId = 0x00;
143    /// `DSTStatus`.
144    pub const DST_STATUS: EventId = 0x01;
145    /// `TimeZoneStatus`.
146    pub const TIME_ZONE_STATUS: EventId = 0x02;
147    /// `TimeFailure`.
148    pub const TIME_FAILURE: EventId = 0x03;
149    /// `MissingTrustedTimeSource`.
150    pub const MISSING_TRUSTED_TIME_SOURCE: EventId = 0x04;
151}
152
153/// `GranularityEnum`.
154#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
155#[repr(u8)]
156pub enum GranularityEnum {
157    /// This indicates that the node is not currently synchronized with a UTC Time source and its clock is based on the Last Known Good UTC Time only.
158    NoTimeGranularity = 0,
159    /// This indicates the node was synchronized to an upstream source in the past, but sufficient clock drift has occurred such that the clock error is now > 5 seconds.
160    MinutesGranularity = 1,
161    /// This indicates the node is synchronized to an upstream source using a low resolution protocol. UTC Time is accurate to ± 5 seconds.
162    SecondsGranularity = 2,
163    /// This indicates the node is synchronized to an upstream source using high resolution time-synchronization protocol such as NTP, or has built-in GNSS with some amount of jitter applying its GNSS timestamp. UTC Time is accurate to ± 50 ms.
164    MillisecondsGranularity = 3,
165    /// This indicates the node is synchronized to an upstream source using a highly precise time-synchronization protocol such as PTP, or has built-in GNSS. UTC time is accurate to ± 10 μs.
166    MicrosecondsGranularity = 4,
167}
168
169impl GranularityEnum {
170    /// Reads a wire value, or `None` for one this revision does not define.
171    #[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    /// Its wire value.
184    #[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/// `StatusCodeEnum`.
204#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
205#[repr(u8)]
206pub enum StatusCodeEnum {
207    /// Node rejected the attempt to set the UTC time
208    TimeNotAccepted = 2,
209}
210
211impl StatusCodeEnum {
212    /// Reads a wire value, or `None` for one this revision does not define.
213    #[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    /// Its wire value.
222    #[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/// `TimeSourceEnum`.
242#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
243#[repr(u8)]
244pub enum TimeSourceEnum {
245    /// Node is not currently synchronized with a UTC Time source.
246    None = 0,
247    /// Node uses an unlisted time source.
248    Unknown = 1,
249    /// Node received time from a client using the SetUTCTime Command.
250    Admin = 2,
251    /// Synchronized time by querying the Time Synchronization cluster of another Node.
252    NodeTimeCluster = 3,
253    /// SNTP from a server not in the Matter network. NTS is not used.
254    NonMatterSNTP = 4,
255    /// NTP from servers not in the Matter network. None of the servers used NTS.
256    NonMatterNTP = 5,
257    /// SNTP from a server within the Matter network. NTS is not used.
258    MatterSNTP = 6,
259    /// NTP from servers within the Matter network. None of the servers used NTS.
260    MatterNTP = 7,
261    /// NTP from multiple servers in the Matter network and external. None of the servers used NTS.
262    MixedNTP = 8,
263    /// SNTP from a server not in the Matter network. NTS is used.
264    NonMatterSNTPNTS = 9,
265    /// NTP from servers not in the Matter network. NTS is used on at least one server.
266    NonMatterNTPNTS = 10,
267    /// SNTP from a server within the Matter network. NTS is used.
268    MatterSNTPNTS = 11,
269    /// NTP from a server within the Matter network. NTS is used on at least one server.
270    MatterNTPNTS = 12,
271    /// NTP from multiple servers in the Matter network and external. NTS is used on at least one server.
272    MixedNTPNTS = 13,
273    /// Time synchronization comes from a vendor cloud-based source (e.g. "Date" header in authenticated HTTPS connection).
274    CloudSource = 14,
275    /// Time synchronization comes from PTP.
276    PTP = 15,
277    /// Time synchronization comes from a GNSS source.
278    GNSS = 16,
279}
280
281impl TimeSourceEnum {
282    /// Reads a wire value, or `None` for one this revision does not define.
283    #[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    /// Its wire value.
308    #[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/// `TimeZoneDatabaseEnum`.
328#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
329#[repr(u8)]
330pub enum TimeZoneDatabaseEnum {
331    /// Node has a full list of the available time zones
332    Full = 0,
333    /// Node has a partial list of the available time zones
334    Partial = 1,
335    /// Node does not have a time zone database
336    None = 2,
337}
338
339impl TimeZoneDatabaseEnum {
340    /// Reads a wire value, or `None` for one this revision does not define.
341    #[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    /// Its wire value.
352    #[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/// `DSTOffsetStruct`.
372#[derive(Debug, Clone, Copy, PartialEq)]
373pub struct DSTOffsetStruct {
374    /// `Offset`, field 0.
375    pub offset: i32,
376    /// `ValidStarting`, field 1.
377    pub valid_starting: u64,
378    /// `ValidUntil`, field 2.
379    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                // A field this revision does not define. §7.19.2: a receiver
412                // ignores what it does not know rather than refusing the whole
413                // structure, which is what lets a newer peer talk to an older one.
414                _ => 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/// `FabricScopedTrustedTimeSourceStruct`.
427#[derive(Debug, Clone, Copy, PartialEq)]
428pub struct FabricScopedTrustedTimeSourceStruct {
429    /// `NodeID`, field 0.
430    pub node_id: crate::msg::NodeId,
431    /// `Endpoint`, field 1.
432    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                // A field this revision does not define. §7.19.2: a receiver
462                // ignores what it does not know rather than refusing the whole
463                // structure, which is what lets a newer peer talk to an older one.
464                _ => 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/// `TimeZoneStruct`.
475#[derive(Debug, Clone, Copy, PartialEq)]
476pub struct TimeZoneStruct<'a> {
477    /// `Offset`, field 0.
478    pub offset: i32,
479    /// `ValidAt`, field 1.
480    pub valid_at: u64,
481    /// `Name`, field 2.
482    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                // A field this revision does not define. §7.19.2: a receiver
517                // ignores what it does not know rather than refusing the whole
518                // structure, which is what lets a newer peer talk to an older one.
519                _ => 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/// `TrustedTimeSourceStruct`.
531#[derive(Debug, Clone, Copy, PartialEq)]
532pub struct TrustedTimeSourceStruct {
533    /// `FabricIndex`, field 0.
534    pub fabric_index: crate::msg::FabricIndex,
535    /// `NodeID`, field 1.
536    pub node_id: crate::msg::NodeId,
537    /// `Endpoint`, field 2.
538    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                // A field this revision does not define. §7.19.2: a receiver
573                // ignores what it does not know rather than refusing the whole
574                // structure, which is what lets a newer peer talk to an older one.
575                _ => 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/// The fields of `SetUTCTime` (command `0x00`).
587#[derive(Debug, Clone, Copy, PartialEq)]
588pub struct SetUTCTimeFields {
589    /// `UTCTime`, field 0.
590    pub utc_time: u64,
591    /// `Granularity`, field 1.
592    pub granularity: GranularityEnum,
593    /// `TimeSource`, field 2.
594    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                // A field this revision does not define. §7.19.2: a receiver
629                // ignores what it does not know rather than refusing the whole
630                // structure, which is what lets a newer peer talk to an older one.
631                _ => 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/// The fields of `SetTrustedTimeSource` (command `0x01`).
643#[derive(Debug, Clone, Copy, PartialEq)]
644pub struct SetTrustedTimeSourceFields {
645    /// `TrustedTimeSource`, field 0.
646    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                // A field this revision does not define. §7.19.2: a receiver
677                // ignores what it does not know rather than refusing the whole
678                // structure, which is what lets a newer peer talk to an older one.
679                _ => 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/// The fields of `SetTimeZone` (command `0x02`).
690#[derive(Debug, Clone, Copy, PartialEq)]
691pub struct SetTimeZoneFields<'a> {
692    /// `TimeZone`, field 0.
693    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                // A field this revision does not define. §7.19.2: a receiver
722                // ignores what it does not know rather than refusing the whole
723                // structure, which is what lets a newer peer talk to an older one.
724                _ => 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/// The fields of `SetTimeZoneResponse` (command `0x03`).
734#[derive(Debug, Clone, Copy, PartialEq)]
735pub struct SetTimeZoneResponseFields {
736    /// `DSTOffsetRequired`, field 0.
737    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                // A field this revision does not define. §7.19.2: a receiver
764                // ignores what it does not know rather than refusing the whole
765                // structure, which is what lets a newer peer talk to an older one.
766                _ => 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/// The fields of `SetDSTOffset` (command `0x04`).
777#[derive(Debug, Clone, Copy, PartialEq)]
778pub struct SetDSTOffsetFields<'a> {
779    /// `DSTOffset`, field 0.
780    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                // A field this revision does not define. §7.19.2: a receiver
809                // ignores what it does not know rather than refusing the whole
810                // structure, which is what lets a newer peer talk to an older one.
811                _ => 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/// The fields of `SetDefaultNTP` (command `0x05`).
821#[derive(Debug, Clone, Copy, PartialEq)]
822pub struct SetDefaultNTPFields<'a> {
823    /// `DefaultNTP`, field 0.
824    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                // A field this revision does not define. §7.19.2: a receiver
851                // ignores what it does not know rather than refusing the whole
852                // structure, which is what lets a newer peer talk to an older one.
853                _ => 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
862/// Every attribute the specification defines, with its conformance.
863pub 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
1033/// Every command, with its conformance.
1034pub 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
1111/// Every event, with its conformance.
1112pub 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
1170/// The whole cluster, as the specification defines it.
1171pub 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};