Skip to main content

matter_kit/clusters/generated/
access_control.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Access Control — cluster 0x001F.
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//! Access Control (cluster `0x001F`, revision 3).
10//!
11//! 14 identifiers, 3 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 = 0x001F;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 3;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "ACL";
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    /// Device provides ACL Extension attribute
42    ///
43    /// Code `EXTS`, bit 0.
44    pub const EXTENSION: u32 = 1 << 0;
45    /// Device is managed
46    ///
47    /// Code `MNGD`, bit 1.
48    pub const MANAGED_DEVICE: u32 = 1 << 1;
49    /// Some auxiliary ACL entries may be auto-generated by other features
50    ///
51    /// Code `AUX`, bit 2.
52    pub const AUXILIARY: u32 = 1 << 2;
53}
54
55/// Every feature bit, with its conformance.
56pub const FEATURES: &[Feature] = &[
57    Feature {
58        bit: 0,
59        code: "EXTS",
60        name: "Extension",
61        conform: Conform::OPTIONAL,
62    },
63    Feature {
64        bit: 1,
65        code: "MNGD",
66        name: "ManagedDevice",
67        conform: Conform::DESCRIBED,
68    },
69    Feature {
70        bit: 2,
71        code: "AUX",
72        name: "Auxiliary",
73        conform: Conform {
74            clauses: &[
75                Clause {
76                    verdict: Conformance::Provisional,
77                    when: Condition::Always,
78                },
79                Clause {
80                    verdict: Conformance::Described,
81                    when: Condition::Always,
82                },
83            ],
84        },
85    },
86];
87
88/// The attribute ids.
89pub mod attribute {
90    use crate::im::AttributeId;
91
92    /// `ACL`.
93    pub const ACL: AttributeId = 0x00;
94    /// `Extension`.
95    pub const EXTENSION: AttributeId = 0x01;
96    /// `SubjectsPerAccessControlEntry`.
97    pub const SUBJECTS_PER_ACCESS_CONTROL_ENTRY: AttributeId = 0x02;
98    /// `TargetsPerAccessControlEntry`.
99    pub const TARGETS_PER_ACCESS_CONTROL_ENTRY: AttributeId = 0x03;
100    /// `AccessControlEntriesPerFabric`.
101    pub const ACCESS_CONTROL_ENTRIES_PER_FABRIC: AttributeId = 0x04;
102    /// `CommissioningARL`.
103    pub const COMMISSIONING_ARL: AttributeId = 0x05;
104    /// `ARL`.
105    pub const ARL: AttributeId = 0x06;
106    /// `AuxiliaryACL`.
107    pub const AUXILIARY_ACL: AttributeId = 0x07;
108}
109
110/// The command ids.
111pub mod command {
112    use crate::im::CommandId;
113
114    /// `ReviewFabricRestrictions`.
115    pub const REVIEW_FABRIC_RESTRICTIONS: CommandId = 0x00;
116    /// `ReviewFabricRestrictionsResponse`.
117    pub const REVIEW_FABRIC_RESTRICTIONS_RESPONSE: CommandId = 0x01;
118}
119
120/// The event ids.
121pub mod event {
122    use crate::im::EventId;
123
124    /// `AccessControlEntryChanged`.
125    pub const ACCESS_CONTROL_ENTRY_CHANGED: EventId = 0x00;
126    /// `AccessControlExtensionChanged`.
127    pub const ACCESS_CONTROL_EXTENSION_CHANGED: EventId = 0x01;
128    /// `FabricRestrictionReviewUpdate`.
129    pub const FABRIC_RESTRICTION_REVIEW_UPDATE: EventId = 0x02;
130    /// `AuxiliaryAccessUpdated`.
131    pub const AUXILIARY_ACCESS_UPDATED: EventId = 0x03;
132}
133
134/// `AccessControlAuxiliaryTypeEnum`.
135#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
136#[repr(u8)]
137pub enum AccessControlAuxiliaryTypeEnum {
138    /// This ACL entry exists because of some system reason and is likely non-revocable
139    System = 0,
140    /// Synthesized via Groupcast Cluster administrator-configured group membership
141    Groupcast = 1,
142}
143
144impl AccessControlAuxiliaryTypeEnum {
145    /// Reads a wire value, or `None` for one this revision does not define.
146    #[must_use]
147    pub const fn from_value(value: u8) -> Option<Self> {
148        match value {
149            0 => Some(Self::System),
150            1 => Some(Self::Groupcast),
151            _ => None,
152        }
153    }
154
155    /// Its wire value.
156    #[must_use]
157    pub const fn value(self) -> u8 {
158        self as u8
159    }
160}
161
162impl ToTlv for AccessControlAuxiliaryTypeEnum {
163    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
164        self.value().to_tlv(w, tag)
165    }
166}
167
168impl<'a> FromTlv<'a> for AccessControlAuxiliaryTypeEnum {
169    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
170        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
171        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
172    }
173}
174
175/// `AccessControlEntryAuthModeEnum`.
176#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
177#[repr(u8)]
178pub enum AccessControlEntryAuthModeEnum {
179    /// Passcode authenticated session
180    PASE = 1,
181    /// Certificate authenticated session
182    CASE = 2,
183    /// Group authenticated session
184    Group = 3,
185}
186
187impl AccessControlEntryAuthModeEnum {
188    /// Reads a wire value, or `None` for one this revision does not define.
189    #[must_use]
190    pub const fn from_value(value: u8) -> Option<Self> {
191        match value {
192            1 => Some(Self::PASE),
193            2 => Some(Self::CASE),
194            3 => Some(Self::Group),
195            _ => None,
196        }
197    }
198
199    /// Its wire value.
200    #[must_use]
201    pub const fn value(self) -> u8 {
202        self as u8
203    }
204}
205
206impl ToTlv for AccessControlEntryAuthModeEnum {
207    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
208        self.value().to_tlv(w, tag)
209    }
210}
211
212impl<'a> FromTlv<'a> for AccessControlEntryAuthModeEnum {
213    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
214        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
215        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
216    }
217}
218
219/// `AccessControlEntryPrivilegeEnum`.
220#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
221#[repr(u8)]
222pub enum AccessControlEntryPrivilegeEnum {
223    /// Can read and observe all (except Access Control Cluster)
224    View = 1,
225    /// `ProxyView`.
226    ProxyView = 2,
227    /// View privileges, and can perform the primary function of this Node (except Access Control Cluster)
228    Operate = 3,
229    /// Operate privileges, and can modify persistent configuration of this Node (except Access Control Cluster)
230    Manage = 4,
231    /// Manage privileges, and can observe and modify the Access Control Cluster
232    Administer = 5,
233}
234
235impl AccessControlEntryPrivilegeEnum {
236    /// Reads a wire value, or `None` for one this revision does not define.
237    #[must_use]
238    pub const fn from_value(value: u8) -> Option<Self> {
239        match value {
240            1 => Some(Self::View),
241            2 => Some(Self::ProxyView),
242            3 => Some(Self::Operate),
243            4 => Some(Self::Manage),
244            5 => Some(Self::Administer),
245            _ => None,
246        }
247    }
248
249    /// Its wire value.
250    #[must_use]
251    pub const fn value(self) -> u8 {
252        self as u8
253    }
254}
255
256impl ToTlv for AccessControlEntryPrivilegeEnum {
257    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
258        self.value().to_tlv(w, tag)
259    }
260}
261
262impl<'a> FromTlv<'a> for AccessControlEntryPrivilegeEnum {
263    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
264        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
265        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
266    }
267}
268
269/// `AccessRestrictionTypeEnum`.
270#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
271#[repr(u8)]
272pub enum AccessRestrictionTypeEnum {
273    /// Clients on this fabric are currently forbidden from reading and writing an attribute
274    AttributeAccessForbidden = 0,
275    /// Clients on this fabric are currently forbidden from writing an attribute
276    AttributeWriteForbidden = 1,
277    /// Clients on this fabric are currently forbidden from invoking a command
278    CommandForbidden = 2,
279    /// Clients on this fabric are currently forbidden from reading an event
280    EventForbidden = 3,
281}
282
283impl AccessRestrictionTypeEnum {
284    /// Reads a wire value, or `None` for one this revision does not define.
285    #[must_use]
286    pub const fn from_value(value: u8) -> Option<Self> {
287        match value {
288            0 => Some(Self::AttributeAccessForbidden),
289            1 => Some(Self::AttributeWriteForbidden),
290            2 => Some(Self::CommandForbidden),
291            3 => Some(Self::EventForbidden),
292            _ => None,
293        }
294    }
295
296    /// Its wire value.
297    #[must_use]
298    pub const fn value(self) -> u8 {
299        self as u8
300    }
301}
302
303impl ToTlv for AccessRestrictionTypeEnum {
304    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
305        self.value().to_tlv(w, tag)
306    }
307}
308
309impl<'a> FromTlv<'a> for AccessRestrictionTypeEnum {
310    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
311        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
312        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
313    }
314}
315
316/// `ChangeTypeEnum`.
317#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
318#[repr(u8)]
319pub enum ChangeTypeEnum {
320    /// Entry or extension was changed
321    Changed = 0,
322    /// Entry or extension was added
323    Added = 1,
324    /// Entry or extension was removed
325    Removed = 2,
326}
327
328impl ChangeTypeEnum {
329    /// Reads a wire value, or `None` for one this revision does not define.
330    #[must_use]
331    pub const fn from_value(value: u8) -> Option<Self> {
332        match value {
333            0 => Some(Self::Changed),
334            1 => Some(Self::Added),
335            2 => Some(Self::Removed),
336            _ => None,
337        }
338    }
339
340    /// Its wire value.
341    #[must_use]
342    pub const fn value(self) -> u8 {
343        self as u8
344    }
345}
346
347impl ToTlv for ChangeTypeEnum {
348    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
349        self.value().to_tlv(w, tag)
350    }
351}
352
353impl<'a> FromTlv<'a> for ChangeTypeEnum {
354    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
355        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
356        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
357    }
358}
359
360/// `AccessControlEntryStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
361#[derive(Debug, Clone, Copy, PartialEq)]
362pub struct AccessControlEntryStruct<'a> {
363    /// `Privilege`, field 1.
364    pub privilege: AccessControlEntryPrivilegeEnum,
365    /// `AuthMode`, field 2.
366    pub auth_mode: AccessControlEntryAuthModeEnum,
367    /// `Subjects`, field 3.
368    pub subjects: Nullable<TlvList<'a, u64>>,
369    /// `Targets`, field 4.
370    pub targets: Nullable<TlvList<'a, AccessControlTargetStruct>>,
371    /// `AuxiliaryType`, field 5.
372    pub auxiliary_type: Option<AccessControlAuxiliaryTypeEnum>,
373    /// `FabricIndex`, field 254.
374    pub fabric_index: crate::msg::FabricIndex,
375}
376
377impl<'a> ToTlv for AccessControlEntryStruct<'a> {
378    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
379        w.start_structure(tag)?;
380        self.privilege.to_tlv(w, Tag::Context(1))?;
381        self.auth_mode.to_tlv(w, Tag::Context(2))?;
382        self.subjects.to_tlv(w, Tag::Context(3))?;
383        self.targets.to_tlv(w, Tag::Context(4))?;
384        if let Some(value) = &self.auxiliary_type {
385            value.to_tlv(w, Tag::Context(5))?;
386        }
387        self.fabric_index.to_tlv(w, Tag::Context(254))?;
388        w.end_container()
389    }
390}
391
392impl<'a> FromTlv<'a> for AccessControlEntryStruct<'a> {
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 privilege = None;
398        let mut auth_mode = None;
399        let mut subjects = None;
400        let mut targets = None;
401        let mut auxiliary_type = None;
402        let mut fabric_index = None;
403        loop {
404            let Some(field) = reader.next_element()? else {
405                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
406            };
407            if field.value == Value::EndOfContainer {
408                break;
409            }
410            match field.tag.context() {
411                Some(1) => {
412                    privilege = Some(<AccessControlEntryPrivilegeEnum>::from_tlv(reader, &field)?)
413                }
414                Some(2) => {
415                    auth_mode = Some(<AccessControlEntryAuthModeEnum>::from_tlv(reader, &field)?)
416                }
417                Some(3) => subjects = Some(<Nullable<TlvList<'a, u64>>>::from_tlv(reader, &field)?),
418                Some(4) => {
419                    targets = Some(
420                        <Nullable<TlvList<'a, AccessControlTargetStruct>>>::from_tlv(
421                            reader, &field,
422                        )?,
423                    )
424                }
425                Some(5) => {
426                    auxiliary_type =
427                        Some(<AccessControlAuxiliaryTypeEnum>::from_tlv(reader, &field)?)
428                }
429                Some(254) => {
430                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
431                }
432                // A field this revision does not define. §7.19.2: a receiver
433                // ignores what it does not know rather than refusing the whole
434                // structure, which is what lets a newer peer talk to an older one.
435                _ => reader.skip_value(&field)?,
436            }
437        }
438        Ok(Self {
439            privilege: privilege.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
440            auth_mode: auth_mode.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
441            subjects: subjects.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
442            targets: targets.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
443            auxiliary_type,
444            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
445        })
446    }
447}
448
449/// `AccessControlExtensionStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
450#[derive(Debug, Clone, Copy, PartialEq)]
451pub struct AccessControlExtensionStruct<'a> {
452    /// `Data`, field 1.
453    pub data: &'a [u8],
454    /// `FabricIndex`, field 254.
455    pub fabric_index: crate::msg::FabricIndex,
456}
457
458impl<'a> ToTlv for AccessControlExtensionStruct<'a> {
459    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
460        w.start_structure(tag)?;
461        self.data.to_tlv(w, Tag::Context(1))?;
462        self.fabric_index.to_tlv(w, Tag::Context(254))?;
463        w.end_container()
464    }
465}
466
467impl<'a> FromTlv<'a> for AccessControlExtensionStruct<'a> {
468    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
469        if element.value.container() != Some(ContainerKind::Structure) {
470            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
471        }
472        let mut data = None;
473        let mut fabric_index = None;
474        loop {
475            let Some(field) = reader.next_element()? else {
476                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
477            };
478            if field.value == Value::EndOfContainer {
479                break;
480            }
481            match field.tag.context() {
482                Some(1) => data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
483                Some(254) => {
484                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
485                }
486                // A field this revision does not define. §7.19.2: a receiver
487                // ignores what it does not know rather than refusing the whole
488                // structure, which is what lets a newer peer talk to an older one.
489                _ => reader.skip_value(&field)?,
490            }
491        }
492        Ok(Self {
493            data: data.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
494            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
495        })
496    }
497}
498
499/// `AccessControlTargetStruct`.
500#[derive(Debug, Clone, Copy, PartialEq)]
501pub struct AccessControlTargetStruct {
502    /// `Cluster`, field 0.
503    pub cluster: Nullable<u32>,
504    /// `Endpoint`, field 1.
505    pub endpoint: Nullable<u16>,
506    /// `DeviceType`, field 2.
507    pub device_type: Nullable<u32>,
508}
509
510impl ToTlv for AccessControlTargetStruct {
511    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
512        w.start_structure(tag)?;
513        self.cluster.to_tlv(w, Tag::Context(0))?;
514        self.endpoint.to_tlv(w, Tag::Context(1))?;
515        self.device_type.to_tlv(w, Tag::Context(2))?;
516        w.end_container()
517    }
518}
519
520impl<'a> FromTlv<'a> for AccessControlTargetStruct {
521    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
522        if element.value.container() != Some(ContainerKind::Structure) {
523            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
524        }
525        let mut cluster = None;
526        let mut endpoint = None;
527        let mut device_type = None;
528        loop {
529            let Some(field) = reader.next_element()? else {
530                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
531            };
532            if field.value == Value::EndOfContainer {
533                break;
534            }
535            match field.tag.context() {
536                Some(0) => cluster = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
537                Some(1) => endpoint = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
538                Some(2) => device_type = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
539                // A field this revision does not define. §7.19.2: a receiver
540                // ignores what it does not know rather than refusing the whole
541                // structure, which is what lets a newer peer talk to an older one.
542                _ => reader.skip_value(&field)?,
543            }
544        }
545        Ok(Self {
546            cluster: cluster.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
547            endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
548            device_type: device_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
549        })
550    }
551}
552
553/// `AccessRestrictionEntryStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
554#[derive(Debug, Clone, Copy, PartialEq)]
555pub struct AccessRestrictionEntryStruct<'a> {
556    /// `Endpoint`, field 0.
557    pub endpoint: u16,
558    /// `Cluster`, field 1.
559    pub cluster: u32,
560    /// `Restrictions`, field 2.
561    pub restrictions: TlvList<'a, AccessRestrictionStruct>,
562    /// `FabricIndex`, field 254.
563    pub fabric_index: crate::msg::FabricIndex,
564}
565
566impl<'a> ToTlv for AccessRestrictionEntryStruct<'a> {
567    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
568        w.start_structure(tag)?;
569        self.endpoint.to_tlv(w, Tag::Context(0))?;
570        self.cluster.to_tlv(w, Tag::Context(1))?;
571        self.restrictions.to_tlv(w, Tag::Context(2))?;
572        self.fabric_index.to_tlv(w, Tag::Context(254))?;
573        w.end_container()
574    }
575}
576
577impl<'a> FromTlv<'a> for AccessRestrictionEntryStruct<'a> {
578    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
579        if element.value.container() != Some(ContainerKind::Structure) {
580            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
581        }
582        let mut endpoint = None;
583        let mut cluster = None;
584        let mut restrictions = None;
585        let mut fabric_index = None;
586        loop {
587            let Some(field) = reader.next_element()? else {
588                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
589            };
590            if field.value == Value::EndOfContainer {
591                break;
592            }
593            match field.tag.context() {
594                Some(0) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
595                Some(1) => cluster = Some(<u32>::from_tlv(reader, &field)?),
596                Some(2) => {
597                    restrictions = Some(<TlvList<'a, AccessRestrictionStruct>>::from_tlv(
598                        reader, &field,
599                    )?)
600                }
601                Some(254) => {
602                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
603                }
604                // A field this revision does not define. §7.19.2: a receiver
605                // ignores what it does not know rather than refusing the whole
606                // structure, which is what lets a newer peer talk to an older one.
607                _ => reader.skip_value(&field)?,
608            }
609        }
610        Ok(Self {
611            endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
612            cluster: cluster.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
613            restrictions: restrictions.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
614            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
615        })
616    }
617}
618
619/// `AccessRestrictionStruct`.
620#[derive(Debug, Clone, Copy, PartialEq)]
621pub struct AccessRestrictionStruct {
622    /// `Type`, field 0.
623    pub type_: AccessRestrictionTypeEnum,
624    /// `ID`, field 1.
625    pub id: Nullable<u32>,
626}
627
628impl ToTlv for AccessRestrictionStruct {
629    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
630        w.start_structure(tag)?;
631        self.type_.to_tlv(w, Tag::Context(0))?;
632        self.id.to_tlv(w, Tag::Context(1))?;
633        w.end_container()
634    }
635}
636
637impl<'a> FromTlv<'a> for AccessRestrictionStruct {
638    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
639        if element.value.container() != Some(ContainerKind::Structure) {
640            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
641        }
642        let mut type_ = None;
643        let mut id = None;
644        loop {
645            let Some(field) = reader.next_element()? else {
646                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
647            };
648            if field.value == Value::EndOfContainer {
649                break;
650            }
651            match field.tag.context() {
652                Some(0) => type_ = Some(<AccessRestrictionTypeEnum>::from_tlv(reader, &field)?),
653                Some(1) => id = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
654                // A field this revision does not define. §7.19.2: a receiver
655                // ignores what it does not know rather than refusing the whole
656                // structure, which is what lets a newer peer talk to an older one.
657                _ => reader.skip_value(&field)?,
658            }
659        }
660        Ok(Self {
661            type_: type_.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
662            id: id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
663        })
664    }
665}
666
667/// `CommissioningAccessRestrictionEntryStruct`.
668#[derive(Debug, Clone, Copy, PartialEq)]
669pub struct CommissioningAccessRestrictionEntryStruct<'a> {
670    /// `Endpoint`, field 0.
671    pub endpoint: u16,
672    /// `Cluster`, field 1.
673    pub cluster: u32,
674    /// `Restrictions`, field 2.
675    pub restrictions: TlvList<'a, AccessRestrictionStruct>,
676}
677
678impl<'a> ToTlv for CommissioningAccessRestrictionEntryStruct<'a> {
679    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
680        w.start_structure(tag)?;
681        self.endpoint.to_tlv(w, Tag::Context(0))?;
682        self.cluster.to_tlv(w, Tag::Context(1))?;
683        self.restrictions.to_tlv(w, Tag::Context(2))?;
684        w.end_container()
685    }
686}
687
688impl<'a> FromTlv<'a> for CommissioningAccessRestrictionEntryStruct<'a> {
689    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
690        if element.value.container() != Some(ContainerKind::Structure) {
691            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
692        }
693        let mut endpoint = None;
694        let mut cluster = None;
695        let mut restrictions = None;
696        loop {
697            let Some(field) = reader.next_element()? else {
698                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
699            };
700            if field.value == Value::EndOfContainer {
701                break;
702            }
703            match field.tag.context() {
704                Some(0) => endpoint = Some(<u16>::from_tlv(reader, &field)?),
705                Some(1) => cluster = Some(<u32>::from_tlv(reader, &field)?),
706                Some(2) => {
707                    restrictions = Some(<TlvList<'a, AccessRestrictionStruct>>::from_tlv(
708                        reader, &field,
709                    )?)
710                }
711                // A field this revision does not define. §7.19.2: a receiver
712                // ignores what it does not know rather than refusing the whole
713                // structure, which is what lets a newer peer talk to an older one.
714                _ => reader.skip_value(&field)?,
715            }
716        }
717        Ok(Self {
718            endpoint: endpoint.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
719            cluster: cluster.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
720            restrictions: restrictions.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
721        })
722    }
723}
724
725/// The fields of `ReviewFabricRestrictions` (command `0x00`).
726#[derive(Debug, Clone, Copy, PartialEq)]
727pub struct ReviewFabricRestrictionsFields<'a> {
728    /// `ARL`, field 0.
729    pub arl: TlvList<'a, CommissioningAccessRestrictionEntryStruct<'a>>,
730}
731
732impl<'a> ToTlv for ReviewFabricRestrictionsFields<'a> {
733    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
734        w.start_structure(tag)?;
735        self.arl.to_tlv(w, Tag::Context(0))?;
736        w.end_container()
737    }
738}
739
740impl<'a> FromTlv<'a> for ReviewFabricRestrictionsFields<'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 arl = 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) => {
755                    arl = Some(
756                        <TlvList<'a, CommissioningAccessRestrictionEntryStruct<'a>>>::from_tlv(
757                            reader, &field,
758                        )?,
759                    )
760                }
761                // A field this revision does not define. §7.19.2: a receiver
762                // ignores what it does not know rather than refusing the whole
763                // structure, which is what lets a newer peer talk to an older one.
764                _ => reader.skip_value(&field)?,
765            }
766        }
767        Ok(Self {
768            arl: arl.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
769        })
770    }
771}
772
773/// The fields of `ReviewFabricRestrictionsResponse` (command `0x01`).
774#[derive(Debug, Clone, Copy, PartialEq)]
775pub struct ReviewFabricRestrictionsResponseFields {
776    /// `Token`, field 0.
777    pub token: u64,
778}
779
780impl ToTlv for ReviewFabricRestrictionsResponseFields {
781    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
782        w.start_structure(tag)?;
783        self.token.to_tlv(w, Tag::Context(0))?;
784        w.end_container()
785    }
786}
787
788impl<'a> FromTlv<'a> for ReviewFabricRestrictionsResponseFields {
789    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
790        if element.value.container() != Some(ContainerKind::Structure) {
791            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
792        }
793        let mut token = None;
794        loop {
795            let Some(field) = reader.next_element()? else {
796                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
797            };
798            if field.value == Value::EndOfContainer {
799                break;
800            }
801            match field.tag.context() {
802                Some(0) => token = Some(<u64>::from_tlv(reader, &field)?),
803                // A field this revision does not define. §7.19.2: a receiver
804                // ignores what it does not know rather than refusing the whole
805                // structure, which is what lets a newer peer talk to an older one.
806                _ => reader.skip_value(&field)?,
807            }
808        }
809        Ok(Self {
810            token: token.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
811        })
812    }
813}
814
815/// Every attribute the specification defines, with its conformance.
816pub const ATTRIBUTES: &[Attribute] = &[
817    Attribute {
818        id: 0x0000,
819        name: "ACL",
820        kind: "list[AccessControlEntryStruct]",
821        access: Access::read_write_with(Privilege::Administer, Privilege::Administer)
822            .with_qualities(AccessQualities::FABRIC_SCOPED),
823        qualities: AttributeQualities::empty(),
824        reporting: Reporting::OnChange,
825        conform: Conform::MANDATORY,
826    },
827    Attribute {
828        id: 0x0001,
829        name: "Extension",
830        kind: "list[AccessControlExtensionStruct]",
831        access: Access::read_write_with(Privilege::Administer, Privilege::Administer)
832            .with_qualities(AccessQualities::FABRIC_SCOPED),
833        qualities: AttributeQualities::empty(),
834        reporting: Reporting::OnChange,
835        conform: Conform {
836            clauses: &[Clause {
837                verdict: Conformance::Mandatory,
838                when: Condition::Feature(0),
839            }],
840        },
841    },
842    Attribute {
843        id: 0x0002,
844        name: "SubjectsPerAccessControlEntry",
845        kind: "uint16",
846        access: Access::read_only(Privilege::View),
847        qualities: AttributeQualities::FIXED,
848        reporting: Reporting::OnChange,
849        conform: Conform::MANDATORY,
850    },
851    Attribute {
852        id: 0x0003,
853        name: "TargetsPerAccessControlEntry",
854        kind: "uint16",
855        access: Access::read_only(Privilege::View),
856        qualities: AttributeQualities::FIXED,
857        reporting: Reporting::OnChange,
858        conform: Conform::MANDATORY,
859    },
860    Attribute {
861        id: 0x0004,
862        name: "AccessControlEntriesPerFabric",
863        kind: "uint16",
864        access: Access::read_only(Privilege::View),
865        qualities: AttributeQualities::FIXED,
866        reporting: Reporting::OnChange,
867        conform: Conform::MANDATORY,
868    },
869    Attribute {
870        id: 0x0005,
871        name: "CommissioningARL",
872        kind: "list[CommissioningAccessRestrictionEntryStruct]",
873        access: Access::read_only(Privilege::View),
874        qualities: AttributeQualities::FIXED,
875        reporting: Reporting::OnChange,
876        conform: Conform {
877            clauses: &[Clause {
878                verdict: Conformance::Mandatory,
879                when: Condition::Feature(1),
880            }],
881        },
882    },
883    Attribute {
884        id: 0x0006,
885        name: "ARL",
886        kind: "list[AccessRestrictionEntryStruct]",
887        access: Access::read_only(Privilege::View).with_qualities(AccessQualities::FABRIC_SCOPED),
888        qualities: AttributeQualities::empty(),
889        reporting: Reporting::OnChange,
890        conform: Conform {
891            clauses: &[Clause {
892                verdict: Conformance::Mandatory,
893                when: Condition::Feature(1),
894            }],
895        },
896    },
897    Attribute {
898        id: 0x0007,
899        name: "AuxiliaryACL",
900        kind: "list[AccessControlEntryStruct]",
901        access: Access::read_only(Privilege::Administer)
902            .with_qualities(AccessQualities::FABRIC_SCOPED),
903        qualities: AttributeQualities::empty(),
904        reporting: Reporting::ChangesOmitted,
905        conform: Conform {
906            clauses: &[
907                Clause {
908                    verdict: Conformance::Provisional,
909                    when: Condition::Always,
910                },
911                Clause {
912                    verdict: Conformance::Mandatory,
913                    when: Condition::Feature(2),
914                },
915            ],
916        },
917    },
918];
919
920/// Every command, with its conformance.
921pub const COMMANDS: &[Command] = &[
922    Command {
923        id: 0x00,
924        name: "ReviewFabricRestrictions",
925        to_server: true,
926        response: Some(0x01),
927        access: Access::invoke(Privilege::Administer)
928            .with_qualities(AccessQualities::FABRIC_SCOPED),
929        conform: Conform {
930            clauses: &[Clause {
931                verdict: Conformance::Mandatory,
932                when: Condition::Feature(1),
933            }],
934        },
935    },
936    Command {
937        id: 0x01,
938        name: "ReviewFabricRestrictionsResponse",
939        to_server: false,
940        response: None,
941        access: Access::invoke(Privilege::Operate),
942        conform: Conform {
943            clauses: &[Clause {
944                verdict: Conformance::Mandatory,
945                when: Condition::Feature(1),
946            }],
947        },
948    },
949];
950
951/// Every event, with its conformance.
952pub const EVENTS: &[Event] = &[
953    Event {
954        id: 0x00,
955        name: "AccessControlEntryChanged",
956        priority: EventPriority::Info,
957        access: Access::read_only(Privilege::Administer)
958            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
959        conform: Conform::MANDATORY,
960    },
961    Event {
962        id: 0x01,
963        name: "AccessControlExtensionChanged",
964        priority: EventPriority::Info,
965        access: Access::read_only(Privilege::Administer)
966            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
967        conform: Conform {
968            clauses: &[Clause {
969                verdict: Conformance::Mandatory,
970                when: Condition::Feature(0),
971            }],
972        },
973    },
974    Event {
975        id: 0x02,
976        name: "FabricRestrictionReviewUpdate",
977        priority: EventPriority::Info,
978        access: Access::read_only(Privilege::Administer)
979            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
980        conform: Conform {
981            clauses: &[Clause {
982                verdict: Conformance::Mandatory,
983                when: Condition::Feature(1),
984            }],
985        },
986    },
987    Event {
988        id: 0x03,
989        name: "AuxiliaryAccessUpdated",
990        priority: EventPriority::Info,
991        access: Access::read_only(Privilege::Administer)
992            .with_qualities(AccessQualities::FABRIC_SENSITIVE),
993        conform: Conform {
994            clauses: &[
995                Clause {
996                    verdict: Conformance::Provisional,
997                    when: Condition::Always,
998                },
999                Clause {
1000                    verdict: Conformance::Mandatory,
1001                    when: Condition::Feature(2),
1002                },
1003            ],
1004        },
1005    },
1006];
1007
1008/// The whole cluster, as the specification defines it.
1009pub const CLUSTER: Cluster = Cluster {
1010    id: ID,
1011    name: "Access Control",
1012    revision: REVISION,
1013    pics: "ACL",
1014    derived_from: None,
1015    features: FEATURES,
1016    attributes: ATTRIBUTES,
1017    commands: COMMANDS,
1018    events: EVENTS,
1019};