Skip to main content

matter_kit/clusters/generated/
group_key_management.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Group Key Management — cluster 0x003F.
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//! Group Key Management (cluster `0x003F`, revision 3).
10//!
11//! 11 identifiers, 2 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 = 0x003F;
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 = "GRPKEY";
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    /// The ability to support CacheAndSync security policy and MCSP.
42    ///
43    /// Code `CS`, bit 0.
44    pub const CACHE_AND_SYNC: u32 = 1 << 0;
45    /// The device supports groups using the Groupcast cluster.
46    ///
47    /// Code `GCAST`, bit 1.
48    pub const GROUPCAST: u32 = 1 << 1;
49}
50
51/// Every feature bit, with its conformance.
52pub const FEATURES: &[Feature] = &[
53    Feature {
54        bit: 0,
55        code: "CS",
56        name: "CacheAndSync",
57        conform: Conform {
58            clauses: &[Clause::always(Conformance::Provisional)],
59        },
60    },
61    Feature {
62        bit: 1,
63        code: "GCAST",
64        name: "Groupcast",
65        conform: Conform {
66            clauses: &[
67                Clause {
68                    verdict: Conformance::Provisional,
69                    when: Condition::Always,
70                },
71                Clause {
72                    verdict: Conformance::Optional,
73                    when: Condition::Always,
74                },
75            ],
76        },
77    },
78];
79
80/// The attribute ids.
81pub mod attribute {
82    use crate::im::AttributeId;
83
84    /// `GroupKeyMap`.
85    pub const GROUP_KEY_MAP: AttributeId = 0x00;
86    /// `GroupTable`.
87    pub const GROUP_TABLE: AttributeId = 0x01;
88    /// `MaxGroupsPerFabric`.
89    pub const MAX_GROUPS_PER_FABRIC: AttributeId = 0x02;
90    /// `MaxGroupKeysPerFabric`.
91    pub const MAX_GROUP_KEYS_PER_FABRIC: AttributeId = 0x03;
92    /// `GroupcastAdoption`.
93    pub const GROUPCAST_ADOPTION: AttributeId = 0x04;
94}
95
96/// The command ids.
97pub mod command {
98    use crate::im::CommandId;
99
100    /// `KeySetWrite`.
101    pub const KEY_SET_WRITE: CommandId = 0x00;
102    /// `KeySetRead`.
103    pub const KEY_SET_READ: CommandId = 0x01;
104    /// `KeySetReadResponse`.
105    pub const KEY_SET_READ_RESPONSE: CommandId = 0x02;
106    /// `KeySetRemove`.
107    pub const KEY_SET_REMOVE: CommandId = 0x03;
108    /// `KeySetReadAllIndices`.
109    pub const KEY_SET_READ_ALL_INDICES: CommandId = 0x04;
110    /// `KeySetReadAllIndicesResponse`.
111    pub const KEY_SET_READ_ALL_INDICES_RESPONSE: CommandId = 0x05;
112}
113
114/// `GroupKeyMulticastPolicyEnum`.
115#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
116#[repr(u8)]
117pub enum GroupKeyMulticastPolicyEnum {
118    /// Indicates filtering of multicast messages for a specific Group ID
119    PerGroupID = 0,
120    /// Indicates not filtering of multicast messages
121    AllNodes = 1,
122}
123
124impl GroupKeyMulticastPolicyEnum {
125    /// Reads a wire value, or `None` for one this revision does not define.
126    #[must_use]
127    pub const fn from_value(value: u8) -> Option<Self> {
128        match value {
129            0 => Some(Self::PerGroupID),
130            1 => Some(Self::AllNodes),
131            _ => None,
132        }
133    }
134
135    /// Its wire value.
136    #[must_use]
137    pub const fn value(self) -> u8 {
138        self as u8
139    }
140}
141
142impl ToTlv for GroupKeyMulticastPolicyEnum {
143    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
144        self.value().to_tlv(w, tag)
145    }
146}
147
148impl<'a> FromTlv<'a> for GroupKeyMulticastPolicyEnum {
149    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
150        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
151        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
152    }
153}
154
155/// `GroupKeySecurityPolicyEnum`.
156#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
157#[repr(u8)]
158pub enum GroupKeySecurityPolicyEnum {
159    /// Message counter synchronization using trust-first
160    TrustFirst = 0,
161    /// Message counter synchronization using cache-and-sync
162    CacheAndSync = 1,
163}
164
165impl GroupKeySecurityPolicyEnum {
166    /// Reads a wire value, or `None` for one this revision does not define.
167    #[must_use]
168    pub const fn from_value(value: u8) -> Option<Self> {
169        match value {
170            0 => Some(Self::TrustFirst),
171            1 => Some(Self::CacheAndSync),
172            _ => None,
173        }
174    }
175
176    /// Its wire value.
177    #[must_use]
178    pub const fn value(self) -> u8 {
179        self as u8
180    }
181}
182
183impl ToTlv for GroupKeySecurityPolicyEnum {
184    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
185        self.value().to_tlv(w, tag)
186    }
187}
188
189impl<'a> FromTlv<'a> for GroupKeySecurityPolicyEnum {
190    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
191        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
192        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
193    }
194}
195
196/// `GroupInfoMapStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
197#[derive(Debug, Clone, Copy, PartialEq)]
198pub struct GroupInfoMapStruct<'a> {
199    /// `GroupId`, field 1.
200    pub group_id: crate::msg::GroupId,
201    /// `Endpoints`, field 2.
202    pub endpoints: TlvList<'a, u16>,
203    /// `GroupName`, field 3.
204    pub group_name: Option<&'a str>,
205    /// `FabricIndex`, field 254.
206    pub fabric_index: crate::msg::FabricIndex,
207}
208
209impl<'a> ToTlv for GroupInfoMapStruct<'a> {
210    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
211        w.start_structure(tag)?;
212        self.group_id.to_tlv(w, Tag::Context(1))?;
213        self.endpoints.to_tlv(w, Tag::Context(2))?;
214        if let Some(value) = &self.group_name {
215            value.to_tlv(w, Tag::Context(3))?;
216        }
217        self.fabric_index.to_tlv(w, Tag::Context(254))?;
218        w.end_container()
219    }
220}
221
222impl<'a> FromTlv<'a> for GroupInfoMapStruct<'a> {
223    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
224        if element.value.container() != Some(ContainerKind::Structure) {
225            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
226        }
227        let mut group_id = None;
228        let mut endpoints = None;
229        let mut group_name = None;
230        let mut fabric_index = None;
231        loop {
232            let Some(field) = reader.next_element()? else {
233                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
234            };
235            if field.value == Value::EndOfContainer {
236                break;
237            }
238            match field.tag.context() {
239                Some(1) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
240                Some(2) => endpoints = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
241                Some(3) => group_name = Some(<&'a str>::from_tlv(reader, &field)?),
242                Some(254) => {
243                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
244                }
245                // A field this revision does not define. §7.19.2: a receiver
246                // ignores what it does not know rather than refusing the whole
247                // structure, which is what lets a newer peer talk to an older one.
248                _ => reader.skip_value(&field)?,
249            }
250        }
251        Ok(Self {
252            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
253            endpoints: endpoints.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
254            group_name,
255            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
256        })
257    }
258}
259
260/// `GroupKeyMapStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
261#[derive(Debug, Clone, Copy, PartialEq)]
262pub struct GroupKeyMapStruct {
263    /// `GroupId`, field 1.
264    pub group_id: crate::msg::GroupId,
265    /// `GroupKeySetID`, field 2.
266    pub group_key_set_id: u16,
267    /// `FabricIndex`, field 254.
268    pub fabric_index: crate::msg::FabricIndex,
269}
270
271impl ToTlv for GroupKeyMapStruct {
272    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
273        w.start_structure(tag)?;
274        self.group_id.to_tlv(w, Tag::Context(1))?;
275        self.group_key_set_id.to_tlv(w, Tag::Context(2))?;
276        self.fabric_index.to_tlv(w, Tag::Context(254))?;
277        w.end_container()
278    }
279}
280
281impl<'a> FromTlv<'a> for GroupKeyMapStruct {
282    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
283        if element.value.container() != Some(ContainerKind::Structure) {
284            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
285        }
286        let mut group_id = None;
287        let mut group_key_set_id = None;
288        let mut fabric_index = None;
289        loop {
290            let Some(field) = reader.next_element()? else {
291                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
292            };
293            if field.value == Value::EndOfContainer {
294                break;
295            }
296            match field.tag.context() {
297                Some(1) => group_id = Some(<crate::msg::GroupId>::from_tlv(reader, &field)?),
298                Some(2) => group_key_set_id = Some(<u16>::from_tlv(reader, &field)?),
299                Some(254) => {
300                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
301                }
302                // A field this revision does not define. §7.19.2: a receiver
303                // ignores what it does not know rather than refusing the whole
304                // structure, which is what lets a newer peer talk to an older one.
305                _ => reader.skip_value(&field)?,
306            }
307        }
308        Ok(Self {
309            group_id: group_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
310            group_key_set_id: group_key_set_id
311                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
312            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
313        })
314    }
315}
316
317/// `GroupKeySetStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
318#[derive(Debug, Clone, Copy, PartialEq)]
319pub struct GroupKeySetStruct<'a> {
320    /// `GroupKeySetID`, field 0.
321    pub group_key_set_id: u16,
322    /// `GroupKeySecurityPolicy`, field 1.
323    pub group_key_security_policy: GroupKeySecurityPolicyEnum,
324    /// `EpochKey0`, field 2.
325    pub epoch_key0: Nullable<&'a [u8]>,
326    /// `EpochStartTime0`, field 3.
327    pub epoch_start_time0: Nullable<u64>,
328    /// `EpochKey1`, field 4.
329    pub epoch_key1: Nullable<&'a [u8]>,
330    /// `EpochStartTime1`, field 5.
331    pub epoch_start_time1: Nullable<u64>,
332    /// `EpochKey2`, field 6.
333    pub epoch_key2: Nullable<&'a [u8]>,
334    /// `EpochStartTime2`, field 7.
335    pub epoch_start_time2: Nullable<u64>,
336    /// `GroupKeyMulticastPolicy`, field 8.
337    pub group_key_multicast_policy: Option<GroupKeyMulticastPolicyEnum>,
338    /// `FabricIndex`, field 254.
339    pub fabric_index: crate::msg::FabricIndex,
340}
341
342impl<'a> ToTlv for GroupKeySetStruct<'a> {
343    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
344        w.start_structure(tag)?;
345        self.group_key_set_id.to_tlv(w, Tag::Context(0))?;
346        self.group_key_security_policy.to_tlv(w, Tag::Context(1))?;
347        self.epoch_key0.to_tlv(w, Tag::Context(2))?;
348        self.epoch_start_time0.to_tlv(w, Tag::Context(3))?;
349        self.epoch_key1.to_tlv(w, Tag::Context(4))?;
350        self.epoch_start_time1.to_tlv(w, Tag::Context(5))?;
351        self.epoch_key2.to_tlv(w, Tag::Context(6))?;
352        self.epoch_start_time2.to_tlv(w, Tag::Context(7))?;
353        if let Some(value) = &self.group_key_multicast_policy {
354            value.to_tlv(w, Tag::Context(8))?;
355        }
356        self.fabric_index.to_tlv(w, Tag::Context(254))?;
357        w.end_container()
358    }
359}
360
361impl<'a> FromTlv<'a> for GroupKeySetStruct<'a> {
362    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
363        if element.value.container() != Some(ContainerKind::Structure) {
364            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
365        }
366        let mut group_key_set_id = None;
367        let mut group_key_security_policy = None;
368        let mut epoch_key0 = None;
369        let mut epoch_start_time0 = None;
370        let mut epoch_key1 = None;
371        let mut epoch_start_time1 = None;
372        let mut epoch_key2 = None;
373        let mut epoch_start_time2 = None;
374        let mut group_key_multicast_policy = None;
375        let mut fabric_index = None;
376        loop {
377            let Some(field) = reader.next_element()? else {
378                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
379            };
380            if field.value == Value::EndOfContainer {
381                break;
382            }
383            match field.tag.context() {
384                Some(0) => group_key_set_id = Some(<u16>::from_tlv(reader, &field)?),
385                Some(1) => {
386                    group_key_security_policy =
387                        Some(<GroupKeySecurityPolicyEnum>::from_tlv(reader, &field)?)
388                }
389                Some(2) => epoch_key0 = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?),
390                Some(3) => epoch_start_time0 = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
391                Some(4) => epoch_key1 = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?),
392                Some(5) => epoch_start_time1 = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
393                Some(6) => epoch_key2 = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?),
394                Some(7) => epoch_start_time2 = Some(<Nullable<u64>>::from_tlv(reader, &field)?),
395                Some(8) => {
396                    group_key_multicast_policy =
397                        Some(<GroupKeyMulticastPolicyEnum>::from_tlv(reader, &field)?)
398                }
399                Some(254) => {
400                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
401                }
402                // A field this revision does not define. §7.19.2: a receiver
403                // ignores what it does not know rather than refusing the whole
404                // structure, which is what lets a newer peer talk to an older one.
405                _ => reader.skip_value(&field)?,
406            }
407        }
408        Ok(Self {
409            group_key_set_id: group_key_set_id
410                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
411            group_key_security_policy: group_key_security_policy
412                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
413            epoch_key0: epoch_key0.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
414            epoch_start_time0: epoch_start_time0
415                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
416            epoch_key1: epoch_key1.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
417            epoch_start_time1: epoch_start_time1
418                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
419            epoch_key2: epoch_key2.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
420            epoch_start_time2: epoch_start_time2
421                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
422            group_key_multicast_policy,
423            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
424        })
425    }
426}
427
428/// `GroupcastAdoptionStruct`, fabric-scoped — §7.19.1.9's `FabricIndex` is field 254.
429#[derive(Debug, Clone, Copy, PartialEq)]
430pub struct GroupcastAdoptionStruct {
431    /// `GroupcastAdopted`, field 0.
432    pub groupcast_adopted: bool,
433    /// `FabricIndex`, field 254.
434    pub fabric_index: crate::msg::FabricIndex,
435}
436
437impl ToTlv for GroupcastAdoptionStruct {
438    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
439        w.start_structure(tag)?;
440        self.groupcast_adopted.to_tlv(w, Tag::Context(0))?;
441        self.fabric_index.to_tlv(w, Tag::Context(254))?;
442        w.end_container()
443    }
444}
445
446impl<'a> FromTlv<'a> for GroupcastAdoptionStruct {
447    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
448        if element.value.container() != Some(ContainerKind::Structure) {
449            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
450        }
451        let mut groupcast_adopted = None;
452        let mut fabric_index = None;
453        loop {
454            let Some(field) = reader.next_element()? else {
455                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
456            };
457            if field.value == Value::EndOfContainer {
458                break;
459            }
460            match field.tag.context() {
461                Some(0) => groupcast_adopted = Some(<bool>::from_tlv(reader, &field)?),
462                Some(254) => {
463                    fabric_index = Some(<crate::msg::FabricIndex>::from_tlv(reader, &field)?)
464                }
465                // A field this revision does not define. §7.19.2: a receiver
466                // ignores what it does not know rather than refusing the whole
467                // structure, which is what lets a newer peer talk to an older one.
468                _ => reader.skip_value(&field)?,
469            }
470        }
471        Ok(Self {
472            groupcast_adopted: groupcast_adopted
473                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
474            fabric_index: fabric_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
475        })
476    }
477}
478
479/// The fields of `KeySetWrite` (command `0x00`).
480#[derive(Debug, Clone, Copy, PartialEq)]
481pub struct KeySetWriteFields<'a> {
482    /// `GroupKeySet`, field 0.
483    pub group_key_set: GroupKeySetStruct<'a>,
484}
485
486impl<'a> ToTlv for KeySetWriteFields<'a> {
487    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
488        w.start_structure(tag)?;
489        self.group_key_set.to_tlv(w, Tag::Context(0))?;
490        w.end_container()
491    }
492}
493
494impl<'a> FromTlv<'a> for KeySetWriteFields<'a> {
495    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
496        if element.value.container() != Some(ContainerKind::Structure) {
497            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
498        }
499        let mut group_key_set = None;
500        loop {
501            let Some(field) = reader.next_element()? else {
502                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
503            };
504            if field.value == Value::EndOfContainer {
505                break;
506            }
507            match field.tag.context() {
508                Some(0) => group_key_set = Some(<GroupKeySetStruct<'a>>::from_tlv(reader, &field)?),
509                // A field this revision does not define. §7.19.2: a receiver
510                // ignores what it does not know rather than refusing the whole
511                // structure, which is what lets a newer peer talk to an older one.
512                _ => reader.skip_value(&field)?,
513            }
514        }
515        Ok(Self {
516            group_key_set: group_key_set.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
517        })
518    }
519}
520
521/// The fields of `KeySetRead` (command `0x01`).
522#[derive(Debug, Clone, Copy, PartialEq)]
523pub struct KeySetReadFields {
524    /// `GroupKeySetID`, field 0.
525    pub group_key_set_id: u16,
526}
527
528impl ToTlv for KeySetReadFields {
529    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
530        w.start_structure(tag)?;
531        self.group_key_set_id.to_tlv(w, Tag::Context(0))?;
532        w.end_container()
533    }
534}
535
536impl<'a> FromTlv<'a> for KeySetReadFields {
537    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
538        if element.value.container() != Some(ContainerKind::Structure) {
539            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
540        }
541        let mut group_key_set_id = None;
542        loop {
543            let Some(field) = reader.next_element()? else {
544                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
545            };
546            if field.value == Value::EndOfContainer {
547                break;
548            }
549            match field.tag.context() {
550                Some(0) => group_key_set_id = Some(<u16>::from_tlv(reader, &field)?),
551                // A field this revision does not define. §7.19.2: a receiver
552                // ignores what it does not know rather than refusing the whole
553                // structure, which is what lets a newer peer talk to an older one.
554                _ => reader.skip_value(&field)?,
555            }
556        }
557        Ok(Self {
558            group_key_set_id: group_key_set_id
559                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
560        })
561    }
562}
563
564/// The fields of `KeySetReadResponse` (command `0x02`).
565#[derive(Debug, Clone, Copy, PartialEq)]
566pub struct KeySetReadResponseFields<'a> {
567    /// `GroupKeySet`, field 0.
568    pub group_key_set: GroupKeySetStruct<'a>,
569}
570
571impl<'a> ToTlv for KeySetReadResponseFields<'a> {
572    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
573        w.start_structure(tag)?;
574        self.group_key_set.to_tlv(w, Tag::Context(0))?;
575        w.end_container()
576    }
577}
578
579impl<'a> FromTlv<'a> for KeySetReadResponseFields<'a> {
580    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
581        if element.value.container() != Some(ContainerKind::Structure) {
582            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
583        }
584        let mut group_key_set = None;
585        loop {
586            let Some(field) = reader.next_element()? else {
587                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
588            };
589            if field.value == Value::EndOfContainer {
590                break;
591            }
592            match field.tag.context() {
593                Some(0) => group_key_set = Some(<GroupKeySetStruct<'a>>::from_tlv(reader, &field)?),
594                // A field this revision does not define. §7.19.2: a receiver
595                // ignores what it does not know rather than refusing the whole
596                // structure, which is what lets a newer peer talk to an older one.
597                _ => reader.skip_value(&field)?,
598            }
599        }
600        Ok(Self {
601            group_key_set: group_key_set.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
602        })
603    }
604}
605
606/// The fields of `KeySetRemove` (command `0x03`).
607#[derive(Debug, Clone, Copy, PartialEq)]
608pub struct KeySetRemoveFields {
609    /// `GroupKeySetID`, field 0.
610    pub group_key_set_id: u16,
611}
612
613impl ToTlv for KeySetRemoveFields {
614    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
615        w.start_structure(tag)?;
616        self.group_key_set_id.to_tlv(w, Tag::Context(0))?;
617        w.end_container()
618    }
619}
620
621impl<'a> FromTlv<'a> for KeySetRemoveFields {
622    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
623        if element.value.container() != Some(ContainerKind::Structure) {
624            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
625        }
626        let mut group_key_set_id = None;
627        loop {
628            let Some(field) = reader.next_element()? else {
629                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
630            };
631            if field.value == Value::EndOfContainer {
632                break;
633            }
634            match field.tag.context() {
635                Some(0) => group_key_set_id = Some(<u16>::from_tlv(reader, &field)?),
636                // A field this revision does not define. §7.19.2: a receiver
637                // ignores what it does not know rather than refusing the whole
638                // structure, which is what lets a newer peer talk to an older one.
639                _ => reader.skip_value(&field)?,
640            }
641        }
642        Ok(Self {
643            group_key_set_id: group_key_set_id
644                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
645        })
646    }
647}
648
649/// The fields of `KeySetReadAllIndicesResponse` (command `0x05`).
650#[derive(Debug, Clone, Copy, PartialEq)]
651pub struct KeySetReadAllIndicesResponseFields<'a> {
652    /// `GroupKeySetIDs`, field 0.
653    pub group_key_set_i_ds: TlvList<'a, u16>,
654}
655
656impl<'a> ToTlv for KeySetReadAllIndicesResponseFields<'a> {
657    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
658        w.start_structure(tag)?;
659        self.group_key_set_i_ds.to_tlv(w, Tag::Context(0))?;
660        w.end_container()
661    }
662}
663
664impl<'a> FromTlv<'a> for KeySetReadAllIndicesResponseFields<'a> {
665    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
666        if element.value.container() != Some(ContainerKind::Structure) {
667            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
668        }
669        let mut group_key_set_i_ds = None;
670        loop {
671            let Some(field) = reader.next_element()? else {
672                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
673            };
674            if field.value == Value::EndOfContainer {
675                break;
676            }
677            match field.tag.context() {
678                Some(0) => group_key_set_i_ds = Some(<TlvList<'a, u16>>::from_tlv(reader, &field)?),
679                // A field this revision does not define. §7.19.2: a receiver
680                // ignores what it does not know rather than refusing the whole
681                // structure, which is what lets a newer peer talk to an older one.
682                _ => reader.skip_value(&field)?,
683            }
684        }
685        Ok(Self {
686            group_key_set_i_ds: group_key_set_i_ds
687                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
688        })
689    }
690}
691
692/// Every attribute the specification defines, with its conformance.
693pub const ATTRIBUTES: &[Attribute] = &[
694    Attribute {
695        id: 0x0000,
696        name: "GroupKeyMap",
697        kind: "list[GroupKeyMapStruct]",
698        access: Access::read_write_with(Privilege::View, Privilege::Manage)
699            .with_qualities(AccessQualities::FABRIC_SCOPED),
700        qualities: AttributeQualities::NON_VOLATILE,
701        reporting: Reporting::OnChange,
702        conform: Conform::MANDATORY,
703    },
704    Attribute {
705        id: 0x0001,
706        name: "GroupTable",
707        kind: "list[GroupInfoMapStruct]",
708        access: Access::read_only(Privilege::View).with_qualities(AccessQualities::FABRIC_SCOPED),
709        qualities: AttributeQualities::empty(),
710        reporting: Reporting::OnChange,
711        conform: Conform::MANDATORY,
712    },
713    Attribute {
714        id: 0x0002,
715        name: "MaxGroupsPerFabric",
716        kind: "uint16",
717        access: Access::read_only(Privilege::View),
718        qualities: AttributeQualities::FIXED,
719        reporting: Reporting::OnChange,
720        conform: Conform::MANDATORY,
721    },
722    Attribute {
723        id: 0x0003,
724        name: "MaxGroupKeysPerFabric",
725        kind: "uint16",
726        access: Access::read_only(Privilege::View),
727        qualities: AttributeQualities::FIXED,
728        reporting: Reporting::OnChange,
729        conform: Conform::MANDATORY,
730    },
731    Attribute {
732        id: 0x0004,
733        name: "GroupcastAdoption",
734        kind: "list[GroupcastAdoptionStruct]",
735        access: Access::read_write_with(Privilege::Administer, Privilege::Administer)
736            .with_qualities(AccessQualities::FABRIC_SCOPED),
737        qualities: AttributeQualities::NON_VOLATILE,
738        reporting: Reporting::OnChange,
739        conform: Conform {
740            clauses: &[
741                Clause {
742                    verdict: Conformance::Provisional,
743                    when: Condition::Always,
744                },
745                Clause {
746                    verdict: Conformance::Mandatory,
747                    when: Condition::Feature(1),
748                },
749            ],
750        },
751    },
752];
753
754/// Every command, with its conformance.
755pub const COMMANDS: &[Command] = &[
756    Command {
757        id: 0x00,
758        name: "KeySetWrite",
759        to_server: true,
760        response: None,
761        access: Access::invoke(Privilege::Administer)
762            .with_qualities(AccessQualities::FABRIC_SCOPED),
763        conform: Conform::MANDATORY,
764    },
765    Command {
766        id: 0x01,
767        name: "KeySetRead",
768        to_server: true,
769        response: Some(0x02),
770        access: Access::invoke(Privilege::Administer)
771            .with_qualities(AccessQualities::FABRIC_SCOPED),
772        conform: Conform::MANDATORY,
773    },
774    Command {
775        id: 0x02,
776        name: "KeySetReadResponse",
777        to_server: false,
778        response: None,
779        access: Access::invoke(Privilege::Operate),
780        conform: Conform::MANDATORY,
781    },
782    Command {
783        id: 0x03,
784        name: "KeySetRemove",
785        to_server: true,
786        response: None,
787        access: Access::invoke(Privilege::Administer)
788            .with_qualities(AccessQualities::FABRIC_SCOPED),
789        conform: Conform::MANDATORY,
790    },
791    Command {
792        id: 0x04,
793        name: "KeySetReadAllIndices",
794        to_server: true,
795        response: Some(0x05),
796        access: Access::invoke(Privilege::Administer)
797            .with_qualities(AccessQualities::FABRIC_SCOPED),
798        conform: Conform::MANDATORY,
799    },
800    Command {
801        id: 0x05,
802        name: "KeySetReadAllIndicesResponse",
803        to_server: false,
804        response: None,
805        access: Access::invoke(Privilege::Operate),
806        conform: Conform::MANDATORY,
807    },
808];
809
810/// Every event, with its conformance.
811pub const EVENTS: &[Event] = &[];
812
813/// The whole cluster, as the specification defines it.
814pub const CLUSTER: Cluster = Cluster {
815    id: ID,
816    name: "Group Key Management",
817    revision: REVISION,
818    pics: "GRPKEY",
819    derived_from: None,
820    features: FEATURES,
821    attributes: ATTRIBUTES,
822    commands: COMMANDS,
823    events: EVENTS,
824};