Skip to main content

matter_kit/clusters/generated/
door_lock.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// Door Lock — cluster 0x0101.
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//! Door Lock (cluster `0x0101`, revision 10).
10//!
11//! 79 identifiers, 13 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 = 0x0101;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 10;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "DRLK";
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    /// Lock supports PIN credentials (via keypad, or over-the-air)
42    ///
43    /// Code `PIN`, bit 0.
44    pub const PIN_CREDENTIAL: u32 = 1 << 0;
45    /// Lock supports RFID credentials
46    ///
47    /// Code `RID`, bit 1.
48    pub const RFID_CREDENTIAL: u32 = 1 << 1;
49    /// Lock supports finger related credentials (fingerprint, finger vein)
50    ///
51    /// Code `FGP`, bit 2.
52    pub const FINGER_CREDENTIALS: u32 = 1 << 2;
53    /// Lock supports week day user access schedules
54    ///
55    /// Code `WDSCH`, bit 4.
56    pub const WEEK_DAY_ACCESS_SCHEDULES: u32 = 1 << 4;
57    /// Lock supports a door position sensor that indicates door's state
58    ///
59    /// Code `DPS`, bit 5.
60    pub const DOOR_POSITION_SENSOR: u32 = 1 << 5;
61    /// Lock supports face related credentials (face, iris, retina)
62    ///
63    /// Code `FACE`, bit 6.
64    pub const FACE_CREDENTIALS: u32 = 1 << 6;
65    /// PIN codes over-the-air supported for lock/unlock operations
66    ///
67    /// Code `COTA`, bit 7.
68    pub const CREDENTIAL_OVER_THE_AIR_ACCESS: u32 = 1 << 7;
69    /// Lock supports the user commands and database
70    ///
71    /// Code `USR`, bit 8.
72    pub const USER: u32 = 1 << 8;
73    /// Lock supports year day user access schedules
74    ///
75    /// Code `YDSCH`, bit 10.
76    pub const YEAR_DAY_ACCESS_SCHEDULES: u32 = 1 << 10;
77    /// Lock supports holiday schedules
78    ///
79    /// Code `HDSCH`, bit 11.
80    pub const HOLIDAY_SCHEDULES: u32 = 1 << 11;
81    /// Lock supports unbolting
82    ///
83    /// Code `UBOLT`, bit 12.
84    pub const UNBOLTING: u32 = 1 << 12;
85    /// Lock supports Aliro credential provisioning as defined in Aliro
86    ///
87    /// Code `ALIRO`, bit 13.
88    pub const ALIRO_PROVISIONING: u32 = 1 << 13;
89    /// Lock supports the Bluetooth LE + UWB Access Control Flow as defined in Aliro
90    ///
91    /// Code `ALBU`, bit 14.
92    pub const ALIRO_BLEUWB: u32 = 1 << 14;
93}
94
95/// Every feature bit, with its conformance.
96pub const FEATURES: &[Feature] = &[
97    Feature {
98        bit: 0,
99        code: "PIN",
100        name: "PINCredential",
101        conform: Conform::OPTIONAL,
102    },
103    Feature {
104        bit: 1,
105        code: "RID",
106        name: "RFIDCredential",
107        conform: Conform {
108            clauses: &[
109                Clause {
110                    verdict: Conformance::Provisional,
111                    when: Condition::Always,
112                },
113                Clause {
114                    verdict: Conformance::Optional,
115                    when: Condition::Always,
116                },
117            ],
118        },
119    },
120    Feature {
121        bit: 2,
122        code: "FGP",
123        name: "FingerCredentials",
124        conform: Conform {
125            clauses: &[
126                Clause {
127                    verdict: Conformance::Provisional,
128                    when: Condition::Always,
129                },
130                Clause {
131                    verdict: Conformance::Optional,
132                    when: Condition::Always,
133                },
134            ],
135        },
136    },
137    Feature {
138        bit: 4,
139        code: "WDSCH",
140        name: "WeekDayAccessSchedules",
141        conform: Conform::OPTIONAL,
142    },
143    Feature {
144        bit: 5,
145        code: "DPS",
146        name: "DoorPositionSensor",
147        conform: Conform::OPTIONAL,
148    },
149    Feature {
150        bit: 6,
151        code: "FACE",
152        name: "FaceCredentials",
153        conform: Conform {
154            clauses: &[
155                Clause {
156                    verdict: Conformance::Provisional,
157                    when: Condition::Always,
158                },
159                Clause {
160                    verdict: Conformance::Optional,
161                    when: Condition::Always,
162                },
163            ],
164        },
165    },
166    Feature {
167        bit: 7,
168        code: "COTA",
169        name: "CredentialOverTheAirAccess",
170        conform: Conform::OPTIONAL,
171    },
172    Feature {
173        bit: 8,
174        code: "USR",
175        name: "User",
176        conform: Conform {
177            clauses: &[Clause {
178                verdict: Conformance::Mandatory,
179                when: Condition::Any(&[
180                    Condition::Feature(0),
181                    Condition::Feature(1),
182                    Condition::Feature(2),
183                    Condition::Feature(6),
184                    Condition::Feature(13),
185                ]),
186            }],
187        },
188    },
189    Feature {
190        bit: 10,
191        code: "YDSCH",
192        name: "YearDayAccessSchedules",
193        conform: Conform::OPTIONAL,
194    },
195    Feature {
196        bit: 11,
197        code: "HDSCH",
198        name: "HolidaySchedules",
199        conform: Conform::OPTIONAL,
200    },
201    Feature {
202        bit: 12,
203        code: "UBOLT",
204        name: "Unbolting",
205        conform: Conform::OPTIONAL,
206    },
207    Feature {
208        bit: 13,
209        code: "ALIRO",
210        name: "AliroProvisioning",
211        conform: Conform::OPTIONAL,
212    },
213    Feature {
214        bit: 14,
215        code: "ALBU",
216        name: "AliroBLEUWB",
217        conform: Conform {
218            clauses: &[Clause {
219                verdict: Conformance::Optional,
220                when: Condition::Feature(13),
221            }],
222        },
223    },
224];
225
226/// The attribute ids.
227pub mod attribute {
228    use crate::im::AttributeId;
229
230    /// `LockState`.
231    pub const LOCK_STATE: AttributeId = 0x00;
232    /// `LockType`.
233    pub const LOCK_TYPE: AttributeId = 0x01;
234    /// `ActuatorEnabled`.
235    pub const ACTUATOR_ENABLED: AttributeId = 0x02;
236    /// `DoorState`.
237    pub const DOOR_STATE: AttributeId = 0x03;
238    /// `DoorOpenEvents`.
239    pub const DOOR_OPEN_EVENTS: AttributeId = 0x04;
240    /// `DoorClosedEvents`.
241    pub const DOOR_CLOSED_EVENTS: AttributeId = 0x05;
242    /// `OpenPeriod`.
243    pub const OPEN_PERIOD: AttributeId = 0x06;
244    /// `NumberOfTotalUsersSupported`.
245    pub const NUMBER_OF_TOTAL_USERS_SUPPORTED: AttributeId = 0x11;
246    /// `NumberOfPINUsersSupported`.
247    pub const NUMBER_OF_PIN_USERS_SUPPORTED: AttributeId = 0x12;
248    /// `NumberOfRFIDUsersSupported`.
249    pub const NUMBER_OF_RFID_USERS_SUPPORTED: AttributeId = 0x13;
250    /// `NumberOfWeekDaySchedulesSupportedPerUser`.
251    pub const NUMBER_OF_WEEK_DAY_SCHEDULES_SUPPORTED_PER_USER: AttributeId = 0x14;
252    /// `NumberOfYearDaySchedulesSupportedPerUser`.
253    pub const NUMBER_OF_YEAR_DAY_SCHEDULES_SUPPORTED_PER_USER: AttributeId = 0x15;
254    /// `NumberOfHolidaySchedulesSupported`.
255    pub const NUMBER_OF_HOLIDAY_SCHEDULES_SUPPORTED: AttributeId = 0x16;
256    /// `MaxPINCodeLength`.
257    pub const MAX_PIN_CODE_LENGTH: AttributeId = 0x17;
258    /// `MinPINCodeLength`.
259    pub const MIN_PIN_CODE_LENGTH: AttributeId = 0x18;
260    /// `MaxRFIDCodeLength`.
261    pub const MAX_RFID_CODE_LENGTH: AttributeId = 0x19;
262    /// `MinRFIDCodeLength`.
263    pub const MIN_RFID_CODE_LENGTH: AttributeId = 0x1A;
264    /// `CredentialRulesSupport`.
265    pub const CREDENTIAL_RULES_SUPPORT: AttributeId = 0x1B;
266    /// `NumberOfCredentialsSupportedPerUser`.
267    pub const NUMBER_OF_CREDENTIALS_SUPPORTED_PER_USER: AttributeId = 0x1C;
268    /// `Language`.
269    pub const LANGUAGE: AttributeId = 0x21;
270    /// `LEDSettings`.
271    pub const LED_SETTINGS: AttributeId = 0x22;
272    /// `AutoRelockTime`.
273    pub const AUTO_RELOCK_TIME: AttributeId = 0x23;
274    /// `SoundVolume`.
275    pub const SOUND_VOLUME: AttributeId = 0x24;
276    /// `OperatingMode`.
277    pub const OPERATING_MODE: AttributeId = 0x25;
278    /// `SupportedOperatingModes`.
279    pub const SUPPORTED_OPERATING_MODES: AttributeId = 0x26;
280    /// `DefaultConfigurationRegister`.
281    pub const DEFAULT_CONFIGURATION_REGISTER: AttributeId = 0x27;
282    /// `EnableLocalProgramming`.
283    pub const ENABLE_LOCAL_PROGRAMMING: AttributeId = 0x28;
284    /// `EnableOneTouchLocking`.
285    pub const ENABLE_ONE_TOUCH_LOCKING: AttributeId = 0x29;
286    /// `EnableInsideStatusLED`.
287    pub const ENABLE_INSIDE_STATUS_LED: AttributeId = 0x2A;
288    /// `EnablePrivacyModeButton`.
289    pub const ENABLE_PRIVACY_MODE_BUTTON: AttributeId = 0x2B;
290    /// `LocalProgrammingFeatures`.
291    pub const LOCAL_PROGRAMMING_FEATURES: AttributeId = 0x2C;
292    /// `WrongCodeEntryLimit`.
293    pub const WRONG_CODE_ENTRY_LIMIT: AttributeId = 0x30;
294    /// `UserCodeTemporaryDisableTime`.
295    pub const USER_CODE_TEMPORARY_DISABLE_TIME: AttributeId = 0x31;
296    /// `SendPINOverTheAir`.
297    pub const SEND_PIN_OVER_THE_AIR: AttributeId = 0x32;
298    /// `RequirePINforRemoteOperation`.
299    pub const REQUIRE_PI_NFOR_REMOTE_OPERATION: AttributeId = 0x33;
300    /// `SecurityLevel`.
301    pub const SECURITY_LEVEL: AttributeId = 0x34;
302    /// `ExpiringUserTimeout`.
303    pub const EXPIRING_USER_TIMEOUT: AttributeId = 0x35;
304    /// `AliroReaderVerificationKey`.
305    pub const ALIRO_READER_VERIFICATION_KEY: AttributeId = 0x80;
306    /// `AliroReaderGroupIdentifier`.
307    pub const ALIRO_READER_GROUP_IDENTIFIER: AttributeId = 0x81;
308    /// `AliroReaderGroupSubIdentifier`.
309    pub const ALIRO_READER_GROUP_SUB_IDENTIFIER: AttributeId = 0x82;
310    /// `AliroExpeditedTransactionSupportedProtocolVersions`.
311    pub const ALIRO_EXPEDITED_TRANSACTION_SUPPORTED_PROTOCOL_VERSIONS: AttributeId = 0x83;
312    /// `AliroGroupResolvingKey`.
313    pub const ALIRO_GROUP_RESOLVING_KEY: AttributeId = 0x84;
314    /// `AliroSupportedBLEUWBProtocolVersions`.
315    pub const ALIRO_SUPPORTED_BLEUWB_PROTOCOL_VERSIONS: AttributeId = 0x85;
316    /// `AliroBLEAdvertisingVersion`.
317    pub const ALIRO_BLE_ADVERTISING_VERSION: AttributeId = 0x86;
318    /// `NumberOfAliroCredentialIssuerKeysSupported`.
319    pub const NUMBER_OF_ALIRO_CREDENTIAL_ISSUER_KEYS_SUPPORTED: AttributeId = 0x87;
320    /// `NumberOfAliroEndpointKeysSupported`.
321    pub const NUMBER_OF_ALIRO_ENDPOINT_KEYS_SUPPORTED: AttributeId = 0x88;
322}
323
324/// The command ids.
325pub mod command {
326    use crate::im::CommandId;
327
328    /// `LockDoor`.
329    pub const LOCK_DOOR: CommandId = 0x00;
330    /// `UnlockDoor`.
331    pub const UNLOCK_DOOR: CommandId = 0x01;
332    /// `Toggle`.
333    pub const TOGGLE: CommandId = 0x02;
334    /// `UnlockWithTimeout`.
335    pub const UNLOCK_WITH_TIMEOUT: CommandId = 0x03;
336    /// `SetWeekDaySchedule`.
337    pub const SET_WEEK_DAY_SCHEDULE: CommandId = 0x0B;
338    /// `GetWeekDaySchedule`.
339    pub const GET_WEEK_DAY_SCHEDULE: CommandId = 0x0C;
340    /// `GetWeekDayScheduleResponse`.
341    pub const GET_WEEK_DAY_SCHEDULE_RESPONSE: CommandId = 0x0C;
342    /// `ClearWeekDaySchedule`.
343    pub const CLEAR_WEEK_DAY_SCHEDULE: CommandId = 0x0D;
344    /// `SetYearDaySchedule`.
345    pub const SET_YEAR_DAY_SCHEDULE: CommandId = 0x0E;
346    /// `GetYearDaySchedule`.
347    pub const GET_YEAR_DAY_SCHEDULE: CommandId = 0x0F;
348    /// `GetYearDayScheduleResponse`.
349    pub const GET_YEAR_DAY_SCHEDULE_RESPONSE: CommandId = 0x0F;
350    /// `ClearYearDaySchedule`.
351    pub const CLEAR_YEAR_DAY_SCHEDULE: CommandId = 0x10;
352    /// `SetHolidaySchedule`.
353    pub const SET_HOLIDAY_SCHEDULE: CommandId = 0x11;
354    /// `GetHolidaySchedule`.
355    pub const GET_HOLIDAY_SCHEDULE: CommandId = 0x12;
356    /// `GetHolidayScheduleResponse`.
357    pub const GET_HOLIDAY_SCHEDULE_RESPONSE: CommandId = 0x12;
358    /// `ClearHolidaySchedule`.
359    pub const CLEAR_HOLIDAY_SCHEDULE: CommandId = 0x13;
360    /// `SetUser`.
361    pub const SET_USER: CommandId = 0x1A;
362    /// `GetUser`.
363    pub const GET_USER: CommandId = 0x1B;
364    /// `GetUserResponse`.
365    pub const GET_USER_RESPONSE: CommandId = 0x1C;
366    /// `ClearUser`.
367    pub const CLEAR_USER: CommandId = 0x1D;
368    /// `SetCredential`.
369    pub const SET_CREDENTIAL: CommandId = 0x22;
370    /// `SetCredentialResponse`.
371    pub const SET_CREDENTIAL_RESPONSE: CommandId = 0x23;
372    /// `GetCredentialStatus`.
373    pub const GET_CREDENTIAL_STATUS: CommandId = 0x24;
374    /// `GetCredentialStatusResponse`.
375    pub const GET_CREDENTIAL_STATUS_RESPONSE: CommandId = 0x25;
376    /// `ClearCredential`.
377    pub const CLEAR_CREDENTIAL: CommandId = 0x26;
378    /// `UnboltDoor`.
379    pub const UNBOLT_DOOR: CommandId = 0x27;
380    /// `SetAliroReaderConfig`.
381    pub const SET_ALIRO_READER_CONFIG: CommandId = 0x28;
382    /// `ClearAliroReaderConfig`.
383    pub const CLEAR_ALIRO_READER_CONFIG: CommandId = 0x29;
384}
385
386/// The event ids.
387pub mod event {
388    use crate::im::EventId;
389
390    /// `DoorLockAlarm`.
391    pub const DOOR_LOCK_ALARM: EventId = 0x00;
392    /// `DoorStateChange`.
393    pub const DOOR_STATE_CHANGE: EventId = 0x01;
394    /// `LockOperation`.
395    pub const LOCK_OPERATION: EventId = 0x02;
396    /// `LockOperationError`.
397    pub const LOCK_OPERATION_ERROR: EventId = 0x03;
398    /// `LockUserChange`.
399    pub const LOCK_USER_CHANGE: EventId = 0x04;
400}
401
402/// `AlarmCodeEnum`.
403#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
404#[repr(u8)]
405pub enum AlarmCodeEnum {
406    /// Locking Mechanism Jammed
407    LockJammed = 0,
408    /// Lock Reset to Factory Defaults
409    LockFactoryReset = 1,
410    /// Lock Radio Power Cycled
411    LockRadioPowerCycled = 3,
412    /// Tamper Alarm - wrong code entry limit
413    WrongCodeEntryLimit = 4,
414    /// Tamper Alarm - front escutcheon removed from main
415    FrontEsceutcheonRemoved = 5,
416    /// Forced Door Open under Door Locked Condition
417    DoorForcedOpen = 6,
418    /// Door ajar
419    DoorAjar = 7,
420    /// Force User SOS alarm
421    ForcedUser = 8,
422}
423
424impl AlarmCodeEnum {
425    /// Reads a wire value, or `None` for one this revision does not define.
426    #[must_use]
427    pub const fn from_value(value: u8) -> Option<Self> {
428        match value {
429            0 => Some(Self::LockJammed),
430            1 => Some(Self::LockFactoryReset),
431            3 => Some(Self::LockRadioPowerCycled),
432            4 => Some(Self::WrongCodeEntryLimit),
433            5 => Some(Self::FrontEsceutcheonRemoved),
434            6 => Some(Self::DoorForcedOpen),
435            7 => Some(Self::DoorAjar),
436            8 => Some(Self::ForcedUser),
437            _ => None,
438        }
439    }
440
441    /// Its wire value.
442    #[must_use]
443    pub const fn value(self) -> u8 {
444        self as u8
445    }
446}
447
448impl ToTlv for AlarmCodeEnum {
449    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
450        self.value().to_tlv(w, tag)
451    }
452}
453
454impl<'a> FromTlv<'a> for AlarmCodeEnum {
455    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
456        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
457        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
458    }
459}
460
461/// `CredentialRuleEnum`.
462#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
463#[repr(u8)]
464pub enum CredentialRuleEnum {
465    /// Only one credential is required for lock operation
466    Single = 0,
467    /// Any two credentials are required for lock operation
468    Dual = 1,
469    /// Any three credentials are required for lock operation
470    Tri = 2,
471}
472
473impl CredentialRuleEnum {
474    /// Reads a wire value, or `None` for one this revision does not define.
475    #[must_use]
476    pub const fn from_value(value: u8) -> Option<Self> {
477        match value {
478            0 => Some(Self::Single),
479            1 => Some(Self::Dual),
480            2 => Some(Self::Tri),
481            _ => None,
482        }
483    }
484
485    /// Its wire value.
486    #[must_use]
487    pub const fn value(self) -> u8 {
488        self as u8
489    }
490}
491
492impl ToTlv for CredentialRuleEnum {
493    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
494        self.value().to_tlv(w, tag)
495    }
496}
497
498impl<'a> FromTlv<'a> for CredentialRuleEnum {
499    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
500        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
501        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
502    }
503}
504
505/// `CredentialTypeEnum`.
506#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
507#[repr(u8)]
508pub enum CredentialTypeEnum {
509    /// Programming PIN code credential type
510    ProgrammingPIN = 0,
511    /// PIN code credential type
512    PIN = 1,
513    /// RFID identifier credential type
514    RFID = 2,
515    /// Fingerprint identifier credential type
516    Fingerprint = 3,
517    /// Finger vein identifier credential type
518    FingerVein = 4,
519    /// Face identifier credential type
520    Face = 5,
521    /// A Credential Issuer public key as defined in Aliro
522    AliroCredentialIssuerKey = 6,
523    /// An Endpoint public key as defined in Aliro which can be evicted if space is needed for another endpoint key
524    AliroEvictableEndpointKey = 7,
525    /// An Endpoint public key as defined in Aliro which cannot be evicted if space is needed for another endpoint key
526    AliroNonEvictableEndpointKey = 8,
527}
528
529impl CredentialTypeEnum {
530    /// Reads a wire value, or `None` for one this revision does not define.
531    #[must_use]
532    pub const fn from_value(value: u8) -> Option<Self> {
533        match value {
534            0 => Some(Self::ProgrammingPIN),
535            1 => Some(Self::PIN),
536            2 => Some(Self::RFID),
537            3 => Some(Self::Fingerprint),
538            4 => Some(Self::FingerVein),
539            5 => Some(Self::Face),
540            6 => Some(Self::AliroCredentialIssuerKey),
541            7 => Some(Self::AliroEvictableEndpointKey),
542            8 => Some(Self::AliroNonEvictableEndpointKey),
543            _ => None,
544        }
545    }
546
547    /// Its wire value.
548    #[must_use]
549    pub const fn value(self) -> u8 {
550        self as u8
551    }
552}
553
554impl ToTlv for CredentialTypeEnum {
555    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
556        self.value().to_tlv(w, tag)
557    }
558}
559
560impl<'a> FromTlv<'a> for CredentialTypeEnum {
561    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
562        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
563        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
564    }
565}
566
567/// `DataOperationTypeEnum`.
568#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
569#[repr(u8)]
570pub enum DataOperationTypeEnum {
571    /// Data is being added or was added
572    Add = 0,
573    /// Data is being cleared or was cleared
574    Clear = 1,
575    /// Data is being modified or was modified
576    Modify = 2,
577}
578
579impl DataOperationTypeEnum {
580    /// Reads a wire value, or `None` for one this revision does not define.
581    #[must_use]
582    pub const fn from_value(value: u8) -> Option<Self> {
583        match value {
584            0 => Some(Self::Add),
585            1 => Some(Self::Clear),
586            2 => Some(Self::Modify),
587            _ => None,
588        }
589    }
590
591    /// Its wire value.
592    #[must_use]
593    pub const fn value(self) -> u8 {
594        self as u8
595    }
596}
597
598impl ToTlv for DataOperationTypeEnum {
599    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
600        self.value().to_tlv(w, tag)
601    }
602}
603
604impl<'a> FromTlv<'a> for DataOperationTypeEnum {
605    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
606        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
607        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
608    }
609}
610
611/// `DoorStateEnum`.
612#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
613#[repr(u8)]
614pub enum DoorStateEnum {
615    /// Door state is open
616    DoorOpen = 0,
617    /// Door state is closed
618    DoorClosed = 1,
619    /// Door state is jammed
620    DoorJammed = 2,
621    /// Door state is currently forced open
622    DoorForcedOpen = 3,
623    /// Door state is invalid for unspecified reason
624    DoorUnspecifiedError = 4,
625    /// Door state is ajar
626    DoorAjar = 5,
627}
628
629impl DoorStateEnum {
630    /// Reads a wire value, or `None` for one this revision does not define.
631    #[must_use]
632    pub const fn from_value(value: u8) -> Option<Self> {
633        match value {
634            0 => Some(Self::DoorOpen),
635            1 => Some(Self::DoorClosed),
636            2 => Some(Self::DoorJammed),
637            3 => Some(Self::DoorForcedOpen),
638            4 => Some(Self::DoorUnspecifiedError),
639            5 => Some(Self::DoorAjar),
640            _ => None,
641        }
642    }
643
644    /// Its wire value.
645    #[must_use]
646    pub const fn value(self) -> u8 {
647        self as u8
648    }
649}
650
651impl ToTlv for DoorStateEnum {
652    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
653        self.value().to_tlv(w, tag)
654    }
655}
656
657impl<'a> FromTlv<'a> for DoorStateEnum {
658    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
659        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
660        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
661    }
662}
663
664/// `EventTypeEnum`.
665#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
666#[repr(u8)]
667pub enum EventTypeEnum {
668    /// Event type is operation
669    Operation = 0,
670    /// Event type is programming
671    Programming = 1,
672    /// Event type is alarm
673    Alarm = 2,
674}
675
676impl EventTypeEnum {
677    /// Reads a wire value, or `None` for one this revision does not define.
678    #[must_use]
679    pub const fn from_value(value: u8) -> Option<Self> {
680        match value {
681            0 => Some(Self::Operation),
682            1 => Some(Self::Programming),
683            2 => Some(Self::Alarm),
684            _ => None,
685        }
686    }
687
688    /// Its wire value.
689    #[must_use]
690    pub const fn value(self) -> u8 {
691        self as u8
692    }
693}
694
695impl ToTlv for EventTypeEnum {
696    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
697        self.value().to_tlv(w, tag)
698    }
699}
700
701impl<'a> FromTlv<'a> for EventTypeEnum {
702    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
703        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
704        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
705    }
706}
707
708/// `LEDSettingEnum`.
709#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
710#[repr(u8)]
711pub enum LEDSettingEnum {
712    /// Never use LED for signalization
713    NoLEDSignal = 0,
714    /// Use LED signalization except for access allowed events
715    NoLEDSignalAccessAllowed = 1,
716    /// Use LED signalization for all events
717    LEDSignalAll = 2,
718}
719
720impl LEDSettingEnum {
721    /// Reads a wire value, or `None` for one this revision does not define.
722    #[must_use]
723    pub const fn from_value(value: u8) -> Option<Self> {
724        match value {
725            0 => Some(Self::NoLEDSignal),
726            1 => Some(Self::NoLEDSignalAccessAllowed),
727            2 => Some(Self::LEDSignalAll),
728            _ => None,
729        }
730    }
731
732    /// Its wire value.
733    #[must_use]
734    pub const fn value(self) -> u8 {
735        self as u8
736    }
737}
738
739impl ToTlv for LEDSettingEnum {
740    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
741        self.value().to_tlv(w, tag)
742    }
743}
744
745impl<'a> FromTlv<'a> for LEDSettingEnum {
746    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
747        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
748        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
749    }
750}
751
752/// `LockDataTypeEnum`.
753#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
754#[repr(u8)]
755pub enum LockDataTypeEnum {
756    /// Unspecified or manufacturer specific lock user data added, cleared, or modified.
757    Unspecified = 0,
758    /// Lock programming PIN code was added, cleared, or modified.
759    ProgrammingCode = 1,
760    /// Lock user index was added, cleared, or modified.
761    UserIndex = 2,
762    /// Lock user week day schedule was added, cleared, or modified.
763    WeekDaySchedule = 3,
764    /// Lock user year day schedule was added, cleared, or modified.
765    YearDaySchedule = 4,
766    /// Lock holiday schedule was added, cleared, or modified.
767    HolidaySchedule = 5,
768    /// Lock user PIN code was added, cleared, or modified.
769    PIN = 6,
770    /// Lock user RFID code was added, cleared, or modified.
771    RFID = 7,
772    /// Lock user fingerprint was added, cleared, or modified.
773    Fingerprint = 8,
774    /// Lock user finger-vein information was added, cleared, or modified.
775    FingerVein = 9,
776    /// Lock user face information was added, cleared, or modified.
777    Face = 10,
778    /// An Aliro credential issuer key credential was added, cleared, or modified.
779    AliroCredentialIssuerKey = 11,
780    /// An Aliro endpoint key credential which can be evicted credential was added, cleared, or modified.
781    AliroEvictableEndpointKey = 12,
782    /// An Aliro endpoint key credential which cannot be evicted was added, cleared, or modified.
783    AliroNonEvictableEndpointKey = 13,
784}
785
786impl LockDataTypeEnum {
787    /// Reads a wire value, or `None` for one this revision does not define.
788    #[must_use]
789    pub const fn from_value(value: u8) -> Option<Self> {
790        match value {
791            0 => Some(Self::Unspecified),
792            1 => Some(Self::ProgrammingCode),
793            2 => Some(Self::UserIndex),
794            3 => Some(Self::WeekDaySchedule),
795            4 => Some(Self::YearDaySchedule),
796            5 => Some(Self::HolidaySchedule),
797            6 => Some(Self::PIN),
798            7 => Some(Self::RFID),
799            8 => Some(Self::Fingerprint),
800            9 => Some(Self::FingerVein),
801            10 => Some(Self::Face),
802            11 => Some(Self::AliroCredentialIssuerKey),
803            12 => Some(Self::AliroEvictableEndpointKey),
804            13 => Some(Self::AliroNonEvictableEndpointKey),
805            _ => None,
806        }
807    }
808
809    /// Its wire value.
810    #[must_use]
811    pub const fn value(self) -> u8 {
812        self as u8
813    }
814}
815
816impl ToTlv for LockDataTypeEnum {
817    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
818        self.value().to_tlv(w, tag)
819    }
820}
821
822impl<'a> FromTlv<'a> for LockDataTypeEnum {
823    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
824        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
825        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
826    }
827}
828
829/// `LockOperationTypeEnum`.
830#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
831#[repr(u8)]
832pub enum LockOperationTypeEnum {
833    /// Lock operation
834    Lock = 0,
835    /// Unlock operation
836    Unlock = 1,
837    /// Triggered by keypad entry for user with User Type set to Non Access User
838    NonAccessUserEvent = 2,
839    /// Triggered by using a user with UserType set to Forced User
840    ForcedUserEvent = 3,
841    /// Unlatch operation
842    Unlatch = 4,
843}
844
845impl LockOperationTypeEnum {
846    /// Reads a wire value, or `None` for one this revision does not define.
847    #[must_use]
848    pub const fn from_value(value: u8) -> Option<Self> {
849        match value {
850            0 => Some(Self::Lock),
851            1 => Some(Self::Unlock),
852            2 => Some(Self::NonAccessUserEvent),
853            3 => Some(Self::ForcedUserEvent),
854            4 => Some(Self::Unlatch),
855            _ => None,
856        }
857    }
858
859    /// Its wire value.
860    #[must_use]
861    pub const fn value(self) -> u8 {
862        self as u8
863    }
864}
865
866impl ToTlv for LockOperationTypeEnum {
867    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
868        self.value().to_tlv(w, tag)
869    }
870}
871
872impl<'a> FromTlv<'a> for LockOperationTypeEnum {
873    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
874        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
875        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
876    }
877}
878
879/// `LockStateEnum`.
880#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
881#[repr(u8)]
882pub enum LockStateEnum {
883    /// Lock state is not fully locked
884    NotFullyLocked = 0,
885    /// Lock state is fully locked
886    Locked = 1,
887    /// Lock state is fully unlocked
888    Unlocked = 2,
889    /// Lock state is fully unlocked and the latch is pulled
890    Unlatched = 3,
891}
892
893impl LockStateEnum {
894    /// Reads a wire value, or `None` for one this revision does not define.
895    #[must_use]
896    pub const fn from_value(value: u8) -> Option<Self> {
897        match value {
898            0 => Some(Self::NotFullyLocked),
899            1 => Some(Self::Locked),
900            2 => Some(Self::Unlocked),
901            3 => Some(Self::Unlatched),
902            _ => None,
903        }
904    }
905
906    /// Its wire value.
907    #[must_use]
908    pub const fn value(self) -> u8 {
909        self as u8
910    }
911}
912
913impl ToTlv for LockStateEnum {
914    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
915        self.value().to_tlv(w, tag)
916    }
917}
918
919impl<'a> FromTlv<'a> for LockStateEnum {
920    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
921        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
922        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
923    }
924}
925
926/// `LockTypeEnum`.
927#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
928#[repr(u8)]
929pub enum LockTypeEnum {
930    /// Physical lock type is dead bolt
931    DeadBolt = 0,
932    /// Physical lock type is magnetic
933    Magnetic = 1,
934    /// Physical lock type is other
935    Other = 2,
936    /// Physical lock type is mortise
937    Mortise = 3,
938    /// Physical lock type is rim
939    Rim = 4,
940    /// Physical lock type is latch bolt
941    LatchBolt = 5,
942    /// Physical lock type is cylindrical lock
943    CylindricalLock = 6,
944    /// Physical lock type is tubular lock
945    TubularLock = 7,
946    /// Physical lock type is interconnected lock
947    InterconnectedLock = 8,
948    /// Physical lock type is dead latch
949    DeadLatch = 9,
950    /// Physical lock type is door furniture
951    DoorFurniture = 10,
952    /// Physical lock type is euro cylinder
953    Eurocylinder = 11,
954}
955
956impl LockTypeEnum {
957    /// Reads a wire value, or `None` for one this revision does not define.
958    #[must_use]
959    pub const fn from_value(value: u8) -> Option<Self> {
960        match value {
961            0 => Some(Self::DeadBolt),
962            1 => Some(Self::Magnetic),
963            2 => Some(Self::Other),
964            3 => Some(Self::Mortise),
965            4 => Some(Self::Rim),
966            5 => Some(Self::LatchBolt),
967            6 => Some(Self::CylindricalLock),
968            7 => Some(Self::TubularLock),
969            8 => Some(Self::InterconnectedLock),
970            9 => Some(Self::DeadLatch),
971            10 => Some(Self::DoorFurniture),
972            11 => Some(Self::Eurocylinder),
973            _ => None,
974        }
975    }
976
977    /// Its wire value.
978    #[must_use]
979    pub const fn value(self) -> u8 {
980        self as u8
981    }
982}
983
984impl ToTlv for LockTypeEnum {
985    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
986        self.value().to_tlv(w, tag)
987    }
988}
989
990impl<'a> FromTlv<'a> for LockTypeEnum {
991    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
992        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
993        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
994    }
995}
996
997/// `OperatingModeEnum`.
998#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
999#[repr(u8)]
1000pub enum OperatingModeEnum {
1001    /// `Normal`.
1002    Normal = 0,
1003    /// `Vacation`.
1004    Vacation = 1,
1005    /// `Privacy`.
1006    Privacy = 2,
1007    /// `NoRemoteLockUnlock`.
1008    NoRemoteLockUnlock = 3,
1009    /// `Passage`.
1010    Passage = 4,
1011}
1012
1013impl OperatingModeEnum {
1014    /// Reads a wire value, or `None` for one this revision does not define.
1015    #[must_use]
1016    pub const fn from_value(value: u8) -> Option<Self> {
1017        match value {
1018            0 => Some(Self::Normal),
1019            1 => Some(Self::Vacation),
1020            2 => Some(Self::Privacy),
1021            3 => Some(Self::NoRemoteLockUnlock),
1022            4 => Some(Self::Passage),
1023            _ => None,
1024        }
1025    }
1026
1027    /// Its wire value.
1028    #[must_use]
1029    pub const fn value(self) -> u8 {
1030        self as u8
1031    }
1032}
1033
1034impl ToTlv for OperatingModeEnum {
1035    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1036        self.value().to_tlv(w, tag)
1037    }
1038}
1039
1040impl<'a> FromTlv<'a> for OperatingModeEnum {
1041    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1042        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1043        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1044    }
1045}
1046
1047/// `OperationErrorEnum`.
1048#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1049#[repr(u8)]
1050pub enum OperationErrorEnum {
1051    /// Lock/unlock error caused by unknown or unspecified source
1052    Unspecified = 0,
1053    /// Lock/unlock error caused by invalid PIN, RFID, fingerprint or other credential
1054    InvalidCredential = 1,
1055    /// Lock/unlock error caused by disabled USER or credential
1056    DisabledUserDenied = 2,
1057    /// Lock/unlock error caused by schedule restriction
1058    Restricted = 3,
1059    /// Lock/unlock error caused by insufficient battery power left to safely actuate the lock
1060    InsufficientBattery = 4,
1061}
1062
1063impl OperationErrorEnum {
1064    /// Reads a wire value, or `None` for one this revision does not define.
1065    #[must_use]
1066    pub const fn from_value(value: u8) -> Option<Self> {
1067        match value {
1068            0 => Some(Self::Unspecified),
1069            1 => Some(Self::InvalidCredential),
1070            2 => Some(Self::DisabledUserDenied),
1071            3 => Some(Self::Restricted),
1072            4 => Some(Self::InsufficientBattery),
1073            _ => None,
1074        }
1075    }
1076
1077    /// Its wire value.
1078    #[must_use]
1079    pub const fn value(self) -> u8 {
1080        self as u8
1081    }
1082}
1083
1084impl ToTlv for OperationErrorEnum {
1085    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1086        self.value().to_tlv(w, tag)
1087    }
1088}
1089
1090impl<'a> FromTlv<'a> for OperationErrorEnum {
1091    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1092        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1093        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1094    }
1095}
1096
1097/// `OperationSourceEnum`.
1098#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1099#[repr(u8)]
1100pub enum OperationSourceEnum {
1101    /// Lock/unlock operation came from unspecified source
1102    Unspecified = 0,
1103    /// Lock/unlock operation came from manual operation (key, thumbturn, handle, etc).
1104    Manual = 1,
1105    /// Lock/unlock operation came from proprietary remote source (e.g. vendor app/cloud)
1106    ProprietaryRemote = 2,
1107    /// Lock/unlock operation came from keypad
1108    Keypad = 3,
1109    /// Lock/unlock operation came from lock automatically (e.g. relock timer)
1110    Auto = 4,
1111    /// Lock/unlock operation came from lock button (e.g. one touch or button)
1112    Button = 5,
1113    /// Lock/unlock operation came from lock due to a schedule
1114    Schedule = 6,
1115    /// Lock/unlock operation came from remote node
1116    Remote = 7,
1117    /// Lock/unlock operation came from RFID card
1118    RFID = 8,
1119    /// Lock/unlock operation came from biometric source (e.g. face, fingerprint/fingervein)
1120    Biometric = 9,
1121    /// Lock/unlock operation came from an interaction defined in Aliro, or user change operation was a step-up credential provisioning as defined in Aliro
1122    Aliro = 10,
1123}
1124
1125impl OperationSourceEnum {
1126    /// Reads a wire value, or `None` for one this revision does not define.
1127    #[must_use]
1128    pub const fn from_value(value: u8) -> Option<Self> {
1129        match value {
1130            0 => Some(Self::Unspecified),
1131            1 => Some(Self::Manual),
1132            2 => Some(Self::ProprietaryRemote),
1133            3 => Some(Self::Keypad),
1134            4 => Some(Self::Auto),
1135            5 => Some(Self::Button),
1136            6 => Some(Self::Schedule),
1137            7 => Some(Self::Remote),
1138            8 => Some(Self::RFID),
1139            9 => Some(Self::Biometric),
1140            10 => Some(Self::Aliro),
1141            _ => None,
1142        }
1143    }
1144
1145    /// Its wire value.
1146    #[must_use]
1147    pub const fn value(self) -> u8 {
1148        self as u8
1149    }
1150}
1151
1152impl ToTlv for OperationSourceEnum {
1153    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1154        self.value().to_tlv(w, tag)
1155    }
1156}
1157
1158impl<'a> FromTlv<'a> for OperationSourceEnum {
1159    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1160        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1161        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1162    }
1163}
1164
1165/// `SoundVolumeEnum`.
1166#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1167#[repr(u8)]
1168pub enum SoundVolumeEnum {
1169    /// Silent Mode
1170    Silent = 0,
1171    /// Low Volume
1172    Low = 1,
1173    /// High Volume
1174    High = 2,
1175    /// Medium Volume
1176    Medium = 3,
1177}
1178
1179impl SoundVolumeEnum {
1180    /// Reads a wire value, or `None` for one this revision does not define.
1181    #[must_use]
1182    pub const fn from_value(value: u8) -> Option<Self> {
1183        match value {
1184            0 => Some(Self::Silent),
1185            1 => Some(Self::Low),
1186            2 => Some(Self::High),
1187            3 => Some(Self::Medium),
1188            _ => None,
1189        }
1190    }
1191
1192    /// Its wire value.
1193    #[must_use]
1194    pub const fn value(self) -> u8 {
1195        self as u8
1196    }
1197}
1198
1199impl ToTlv for SoundVolumeEnum {
1200    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1201        self.value().to_tlv(w, tag)
1202    }
1203}
1204
1205impl<'a> FromTlv<'a> for SoundVolumeEnum {
1206    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1207        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1208        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1209    }
1210}
1211
1212/// `StatusCodeEnum`.
1213#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1214#[repr(u8)]
1215pub enum StatusCodeEnum {
1216    /// Entry would cause a duplicate credential/ID.
1217    DUPLICATE = 2,
1218    /// Entry would replace an occupied slot.
1219    OCCUPIED = 3,
1220}
1221
1222impl StatusCodeEnum {
1223    /// Reads a wire value, or `None` for one this revision does not define.
1224    #[must_use]
1225    pub const fn from_value(value: u8) -> Option<Self> {
1226        match value {
1227            2 => Some(Self::DUPLICATE),
1228            3 => Some(Self::OCCUPIED),
1229            _ => None,
1230        }
1231    }
1232
1233    /// Its wire value.
1234    #[must_use]
1235    pub const fn value(self) -> u8 {
1236        self as u8
1237    }
1238}
1239
1240impl ToTlv for StatusCodeEnum {
1241    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1242        self.value().to_tlv(w, tag)
1243    }
1244}
1245
1246impl<'a> FromTlv<'a> for StatusCodeEnum {
1247    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1248        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1249        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1250    }
1251}
1252
1253/// `UserStatusEnum`.
1254#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1255#[repr(u8)]
1256pub enum UserStatusEnum {
1257    /// The user ID is available
1258    Available = 0,
1259    /// The user ID is occupied and enabled
1260    OccupiedEnabled = 1,
1261    /// The user ID is occupied and disabled
1262    OccupiedDisabled = 3,
1263}
1264
1265impl UserStatusEnum {
1266    /// Reads a wire value, or `None` for one this revision does not define.
1267    #[must_use]
1268    pub const fn from_value(value: u8) -> Option<Self> {
1269        match value {
1270            0 => Some(Self::Available),
1271            1 => Some(Self::OccupiedEnabled),
1272            3 => Some(Self::OccupiedDisabled),
1273            _ => None,
1274        }
1275    }
1276
1277    /// Its wire value.
1278    #[must_use]
1279    pub const fn value(self) -> u8 {
1280        self as u8
1281    }
1282}
1283
1284impl ToTlv for UserStatusEnum {
1285    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1286        self.value().to_tlv(w, tag)
1287    }
1288}
1289
1290impl<'a> FromTlv<'a> for UserStatusEnum {
1291    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1292        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1293        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1294    }
1295}
1296
1297/// `UserTypeEnum`.
1298#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
1299#[repr(u8)]
1300pub enum UserTypeEnum {
1301    /// The user ID type is unrestricted
1302    UnrestrictedUser = 0,
1303    /// The user ID type is schedule
1304    YearDayScheduleUser = 1,
1305    /// The user ID type is schedule
1306    WeekDayScheduleUser = 2,
1307    /// The user ID type is programming
1308    ProgrammingUser = 3,
1309    /// The user ID type is non access
1310    NonAccessUser = 4,
1311    /// The user ID type is forced
1312    ForcedUser = 5,
1313    /// The user ID type is disposable
1314    DisposableUser = 6,
1315    /// The user ID type is expiring
1316    ExpiringUser = 7,
1317    /// The user ID type is schedule restricted
1318    ScheduleRestrictedUser = 8,
1319    /// The user ID type is remote only
1320    RemoteOnlyUser = 9,
1321}
1322
1323impl UserTypeEnum {
1324    /// Reads a wire value, or `None` for one this revision does not define.
1325    #[must_use]
1326    pub const fn from_value(value: u8) -> Option<Self> {
1327        match value {
1328            0 => Some(Self::UnrestrictedUser),
1329            1 => Some(Self::YearDayScheduleUser),
1330            2 => Some(Self::WeekDayScheduleUser),
1331            3 => Some(Self::ProgrammingUser),
1332            4 => Some(Self::NonAccessUser),
1333            5 => Some(Self::ForcedUser),
1334            6 => Some(Self::DisposableUser),
1335            7 => Some(Self::ExpiringUser),
1336            8 => Some(Self::ScheduleRestrictedUser),
1337            9 => Some(Self::RemoteOnlyUser),
1338            _ => None,
1339        }
1340    }
1341
1342    /// Its wire value.
1343    #[must_use]
1344    pub const fn value(self) -> u8 {
1345        self as u8
1346    }
1347}
1348
1349impl ToTlv for UserTypeEnum {
1350    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1351        self.value().to_tlv(w, tag)
1352    }
1353}
1354
1355impl<'a> FromTlv<'a> for UserTypeEnum {
1356    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1357        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1358        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1359    }
1360}
1361
1362bitflags::bitflags! {
1363    /// `AlarmMaskBitmap`.
1364    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1365    pub struct AlarmMaskBitmap: u8 {
1366        /// Locking Mechanism Jammed
1367        const LOCK_JAMMED = 1 << 0;
1368        /// Lock Reset to Factory Defaults
1369        const LOCK_FACTORY_RESET = 1 << 1;
1370        /// RF Module Power Cycled
1371        const LOCK_RADIO_POWER_CYCLED = 1 << 3;
1372        /// Tamper Alarm - wrong code entry limit
1373        const WRONG_CODE_ENTRY_LIMIT = 1 << 4;
1374        /// Tamper Alarm - front escutcheon removed from main
1375        const FRONT_ESCUTCHEON_REMOVED = 1 << 5;
1376        /// Forced Door Open under Door Locked Condition
1377        const DOOR_FORCED_OPEN = 1 << 6;
1378    }
1379}
1380
1381impl ToTlv for AlarmMaskBitmap {
1382    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1383        self.bits().to_tlv(w, tag)
1384    }
1385}
1386
1387impl<'a> FromTlv<'a> for AlarmMaskBitmap {
1388    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1389        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1390        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1391    }
1392}
1393
1394bitflags::bitflags! {
1395    /// `ConfigurationRegisterBitmap`.
1396    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1397    pub struct ConfigurationRegisterBitmap: u8 {
1398        /// The state of local programming functionality
1399        const LOCAL_PROGRAMMING = 1 << 0;
1400        /// The state of the keypad interface
1401        const KEYPAD_INTERFACE = 1 << 1;
1402        /// The state of the remote interface
1403        const REMOTE_INTERFACE = 1 << 2;
1404        /// Sound volume is set to Silent value
1405        const SOUND_VOLUME = 1 << 5;
1406        /// Auto relock time it set to 0
1407        const AUTO_RELOCK_TIME = 1 << 6;
1408        /// LEDs is disabled
1409        const LED_SETTINGS = 1 << 7;
1410    }
1411}
1412
1413impl ToTlv for ConfigurationRegisterBitmap {
1414    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1415        self.bits().to_tlv(w, tag)
1416    }
1417}
1418
1419impl<'a> FromTlv<'a> for ConfigurationRegisterBitmap {
1420    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1421        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1422        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1423    }
1424}
1425
1426bitflags::bitflags! {
1427    /// `CredentialRulesBitmap`.
1428    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1429    pub struct CredentialRulesBitmap: u8 {
1430        /// Only one credential is required for lock operation
1431        const SINGLE = 1 << 0;
1432        /// Any two credentials are required for lock operation
1433        const DUAL = 1 << 1;
1434        /// Any three credentials are required for lock operation
1435        const TRI = 1 << 2;
1436    }
1437}
1438
1439impl ToTlv for CredentialRulesBitmap {
1440    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1441        self.bits().to_tlv(w, tag)
1442    }
1443}
1444
1445impl<'a> FromTlv<'a> for CredentialRulesBitmap {
1446    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1447        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1448        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1449    }
1450}
1451
1452bitflags::bitflags! {
1453    /// `DaysMaskBitmap`.
1454    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1455    pub struct DaysMaskBitmap: u8 {
1456        /// Schedule is applied on Sunday
1457        const SUNDAY = 1 << 0;
1458        /// Schedule is applied on Monday
1459        const MONDAY = 1 << 1;
1460        /// Schedule is applied on Tuesday
1461        const TUESDAY = 1 << 2;
1462        /// Schedule is applied on Wednesday
1463        const WEDNESDAY = 1 << 3;
1464        /// Schedule is applied on Thursday
1465        const THURSDAY = 1 << 4;
1466        /// Schedule is applied on Friday
1467        const FRIDAY = 1 << 5;
1468        /// Schedule is applied on Saturday
1469        const SATURDAY = 1 << 6;
1470    }
1471}
1472
1473impl ToTlv for DaysMaskBitmap {
1474    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1475        self.bits().to_tlv(w, tag)
1476    }
1477}
1478
1479impl<'a> FromTlv<'a> for DaysMaskBitmap {
1480    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1481        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1482        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1483    }
1484}
1485
1486bitflags::bitflags! {
1487    /// `LocalProgrammingFeaturesBitmap`.
1488    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1489    pub struct LocalProgrammingFeaturesBitmap: u8 {
1490        /// The state of the ability to add users, credentials or schedules on the device
1491        const ADD_USERS_CREDENTIALS_SCHEDULES = 1 << 0;
1492        /// The state of the ability to modify users, credentials or schedules on the device
1493        const MODIFY_USERS_CREDENTIALS_SCHEDULES = 1 << 1;
1494        /// The state of the ability to clear users, credentials or schedules on the device
1495        const CLEAR_USERS_CREDENTIALS_SCHEDULES = 1 << 2;
1496        /// The state of the ability to adjust settings on the device
1497        const ADJUST_SETTINGS = 1 << 3;
1498    }
1499}
1500
1501impl ToTlv for LocalProgrammingFeaturesBitmap {
1502    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1503        self.bits().to_tlv(w, tag)
1504    }
1505}
1506
1507impl<'a> FromTlv<'a> for LocalProgrammingFeaturesBitmap {
1508    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1509        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1510        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1511    }
1512}
1513
1514bitflags::bitflags! {
1515    /// `OperatingModesBitmap`.
1516    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
1517    pub struct OperatingModesBitmap: u8 {
1518        /// Normal operation mode
1519        const NORMAL = 1 << 0;
1520        /// Vacation operation mode
1521        const VACATION = 1 << 1;
1522        /// Privacy operation mode
1523        const PRIVACY = 1 << 2;
1524        /// No remote lock and unlock operation mode
1525        const NO_REMOTE_LOCK_UNLOCK = 1 << 3;
1526        /// Passage operation mode
1527        const PASSAGE = 1 << 4;
1528    }
1529}
1530
1531impl ToTlv for OperatingModesBitmap {
1532    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1533        self.bits().to_tlv(w, tag)
1534    }
1535}
1536
1537impl<'a> FromTlv<'a> for OperatingModesBitmap {
1538    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1539        let bits = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
1540        Self::from_bits(bits).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
1541    }
1542}
1543
1544/// `CredentialStruct`.
1545#[derive(Debug, Clone, Copy, PartialEq)]
1546pub struct CredentialStruct {
1547    /// `CredentialType`, field 0.
1548    pub credential_type: CredentialTypeEnum,
1549    /// `CredentialIndex`, field 1.
1550    pub credential_index: u16,
1551}
1552
1553impl ToTlv for CredentialStruct {
1554    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1555        w.start_structure(tag)?;
1556        self.credential_type.to_tlv(w, Tag::Context(0))?;
1557        self.credential_index.to_tlv(w, Tag::Context(1))?;
1558        w.end_container()
1559    }
1560}
1561
1562impl<'a> FromTlv<'a> for CredentialStruct {
1563    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1564        if element.value.container() != Some(ContainerKind::Structure) {
1565            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1566        }
1567        let mut credential_type = None;
1568        let mut credential_index = None;
1569        loop {
1570            let Some(field) = reader.next_element()? else {
1571                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1572            };
1573            if field.value == Value::EndOfContainer {
1574                break;
1575            }
1576            match field.tag.context() {
1577                Some(0) => credential_type = Some(<CredentialTypeEnum>::from_tlv(reader, &field)?),
1578                Some(1) => credential_index = Some(<u16>::from_tlv(reader, &field)?),
1579                // A field this revision does not define. §7.19.2: a receiver
1580                // ignores what it does not know rather than refusing the whole
1581                // structure, which is what lets a newer peer talk to an older one.
1582                _ => reader.skip_value(&field)?,
1583            }
1584        }
1585        Ok(Self {
1586            credential_type: credential_type
1587                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1588            credential_index: credential_index
1589                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1590        })
1591    }
1592}
1593
1594/// The fields of `LockDoor` (command `0x00`).
1595#[derive(Debug, Clone, Copy, PartialEq)]
1596pub struct LockDoorFields<'a> {
1597    /// `PINCode`, field 0.
1598    pub pin_code: Option<&'a [u8]>,
1599}
1600
1601impl<'a> ToTlv for LockDoorFields<'a> {
1602    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1603        w.start_structure(tag)?;
1604        if let Some(value) = &self.pin_code {
1605            value.to_tlv(w, Tag::Context(0))?;
1606        }
1607        w.end_container()
1608    }
1609}
1610
1611impl<'a> FromTlv<'a> for LockDoorFields<'a> {
1612    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1613        if element.value.container() != Some(ContainerKind::Structure) {
1614            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1615        }
1616        let mut pin_code = None;
1617        loop {
1618            let Some(field) = reader.next_element()? else {
1619                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1620            };
1621            if field.value == Value::EndOfContainer {
1622                break;
1623            }
1624            match field.tag.context() {
1625                Some(0) => pin_code = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1626                // A field this revision does not define. §7.19.2: a receiver
1627                // ignores what it does not know rather than refusing the whole
1628                // structure, which is what lets a newer peer talk to an older one.
1629                _ => reader.skip_value(&field)?,
1630            }
1631        }
1632        Ok(Self { pin_code })
1633    }
1634}
1635
1636/// The fields of `UnlockDoor` (command `0x01`).
1637#[derive(Debug, Clone, Copy, PartialEq)]
1638pub struct UnlockDoorFields<'a> {
1639    /// `PINCode`, field 0.
1640    pub pin_code: Option<&'a [u8]>,
1641}
1642
1643impl<'a> ToTlv for UnlockDoorFields<'a> {
1644    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1645        w.start_structure(tag)?;
1646        if let Some(value) = &self.pin_code {
1647            value.to_tlv(w, Tag::Context(0))?;
1648        }
1649        w.end_container()
1650    }
1651}
1652
1653impl<'a> FromTlv<'a> for UnlockDoorFields<'a> {
1654    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1655        if element.value.container() != Some(ContainerKind::Structure) {
1656            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1657        }
1658        let mut pin_code = None;
1659        loop {
1660            let Some(field) = reader.next_element()? else {
1661                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1662            };
1663            if field.value == Value::EndOfContainer {
1664                break;
1665            }
1666            match field.tag.context() {
1667                Some(0) => pin_code = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1668                // A field this revision does not define. §7.19.2: a receiver
1669                // ignores what it does not know rather than refusing the whole
1670                // structure, which is what lets a newer peer talk to an older one.
1671                _ => reader.skip_value(&field)?,
1672            }
1673        }
1674        Ok(Self { pin_code })
1675    }
1676}
1677
1678/// The fields of `UnlockWithTimeout` (command `0x03`).
1679#[derive(Debug, Clone, Copy, PartialEq)]
1680pub struct UnlockWithTimeoutFields<'a> {
1681    /// `Timeout`, field 0.
1682    pub timeout: u16,
1683    /// `PINCode`, field 1.
1684    pub pin_code: Option<&'a [u8]>,
1685}
1686
1687impl<'a> ToTlv for UnlockWithTimeoutFields<'a> {
1688    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1689        w.start_structure(tag)?;
1690        self.timeout.to_tlv(w, Tag::Context(0))?;
1691        if let Some(value) = &self.pin_code {
1692            value.to_tlv(w, Tag::Context(1))?;
1693        }
1694        w.end_container()
1695    }
1696}
1697
1698impl<'a> FromTlv<'a> for UnlockWithTimeoutFields<'a> {
1699    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1700        if element.value.container() != Some(ContainerKind::Structure) {
1701            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1702        }
1703        let mut timeout = None;
1704        let mut pin_code = None;
1705        loop {
1706            let Some(field) = reader.next_element()? else {
1707                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1708            };
1709            if field.value == Value::EndOfContainer {
1710                break;
1711            }
1712            match field.tag.context() {
1713                Some(0) => timeout = Some(<u16>::from_tlv(reader, &field)?),
1714                Some(1) => pin_code = Some(<&'a [u8]>::from_tlv(reader, &field)?),
1715                // A field this revision does not define. §7.19.2: a receiver
1716                // ignores what it does not know rather than refusing the whole
1717                // structure, which is what lets a newer peer talk to an older one.
1718                _ => reader.skip_value(&field)?,
1719            }
1720        }
1721        Ok(Self {
1722            timeout: timeout.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1723            pin_code,
1724        })
1725    }
1726}
1727
1728/// The fields of `SetWeekDaySchedule` (command `0x0B`).
1729#[derive(Debug, Clone, Copy, PartialEq)]
1730pub struct SetWeekDayScheduleFields {
1731    /// `WeekDayIndex`, field 0.
1732    pub week_day_index: u8,
1733    /// `UserIndex`, field 1.
1734    pub user_index: u16,
1735    /// `DaysMask`, field 2.
1736    pub days_mask: DaysMaskBitmap,
1737    /// `StartHour`, field 3.
1738    pub start_hour: u8,
1739    /// `StartMinute`, field 4.
1740    pub start_minute: u8,
1741    /// `EndHour`, field 5.
1742    pub end_hour: u8,
1743    /// `EndMinute`, field 6.
1744    pub end_minute: u8,
1745}
1746
1747impl ToTlv for SetWeekDayScheduleFields {
1748    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1749        w.start_structure(tag)?;
1750        self.week_day_index.to_tlv(w, Tag::Context(0))?;
1751        self.user_index.to_tlv(w, Tag::Context(1))?;
1752        self.days_mask.to_tlv(w, Tag::Context(2))?;
1753        self.start_hour.to_tlv(w, Tag::Context(3))?;
1754        self.start_minute.to_tlv(w, Tag::Context(4))?;
1755        self.end_hour.to_tlv(w, Tag::Context(5))?;
1756        self.end_minute.to_tlv(w, Tag::Context(6))?;
1757        w.end_container()
1758    }
1759}
1760
1761impl<'a> FromTlv<'a> for SetWeekDayScheduleFields {
1762    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1763        if element.value.container() != Some(ContainerKind::Structure) {
1764            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1765        }
1766        let mut week_day_index = None;
1767        let mut user_index = None;
1768        let mut days_mask = None;
1769        let mut start_hour = None;
1770        let mut start_minute = None;
1771        let mut end_hour = None;
1772        let mut end_minute = None;
1773        loop {
1774            let Some(field) = reader.next_element()? else {
1775                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1776            };
1777            if field.value == Value::EndOfContainer {
1778                break;
1779            }
1780            match field.tag.context() {
1781                Some(0) => week_day_index = Some(<u8>::from_tlv(reader, &field)?),
1782                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
1783                Some(2) => days_mask = Some(<DaysMaskBitmap>::from_tlv(reader, &field)?),
1784                Some(3) => start_hour = Some(<u8>::from_tlv(reader, &field)?),
1785                Some(4) => start_minute = Some(<u8>::from_tlv(reader, &field)?),
1786                Some(5) => end_hour = Some(<u8>::from_tlv(reader, &field)?),
1787                Some(6) => end_minute = Some(<u8>::from_tlv(reader, &field)?),
1788                // A field this revision does not define. §7.19.2: a receiver
1789                // ignores what it does not know rather than refusing the whole
1790                // structure, which is what lets a newer peer talk to an older one.
1791                _ => reader.skip_value(&field)?,
1792            }
1793        }
1794        Ok(Self {
1795            week_day_index: week_day_index
1796                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1797            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1798            days_mask: days_mask.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1799            start_hour: start_hour.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1800            start_minute: start_minute.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1801            end_hour: end_hour.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1802            end_minute: end_minute.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1803        })
1804    }
1805}
1806
1807/// The fields of `GetWeekDaySchedule` (command `0x0C`).
1808#[derive(Debug, Clone, Copy, PartialEq)]
1809pub struct GetWeekDayScheduleFields {
1810    /// `WeekDayIndex`, field 0.
1811    pub week_day_index: u8,
1812    /// `UserIndex`, field 1.
1813    pub user_index: u16,
1814}
1815
1816impl ToTlv for GetWeekDayScheduleFields {
1817    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1818        w.start_structure(tag)?;
1819        self.week_day_index.to_tlv(w, Tag::Context(0))?;
1820        self.user_index.to_tlv(w, Tag::Context(1))?;
1821        w.end_container()
1822    }
1823}
1824
1825impl<'a> FromTlv<'a> for GetWeekDayScheduleFields {
1826    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1827        if element.value.container() != Some(ContainerKind::Structure) {
1828            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1829        }
1830        let mut week_day_index = None;
1831        let mut user_index = None;
1832        loop {
1833            let Some(field) = reader.next_element()? else {
1834                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1835            };
1836            if field.value == Value::EndOfContainer {
1837                break;
1838            }
1839            match field.tag.context() {
1840                Some(0) => week_day_index = Some(<u8>::from_tlv(reader, &field)?),
1841                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
1842                // A field this revision does not define. §7.19.2: a receiver
1843                // ignores what it does not know rather than refusing the whole
1844                // structure, which is what lets a newer peer talk to an older one.
1845                _ => reader.skip_value(&field)?,
1846            }
1847        }
1848        Ok(Self {
1849            week_day_index: week_day_index
1850                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1851            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1852        })
1853    }
1854}
1855
1856/// The fields of `GetWeekDayScheduleResponse` (command `0x0C`).
1857#[derive(Debug, Clone, Copy, PartialEq)]
1858pub struct GetWeekDayScheduleResponseFields {
1859    /// `WeekDayIndex`, field 0.
1860    pub week_day_index: u8,
1861    /// `UserIndex`, field 1.
1862    pub user_index: u16,
1863    /// `Status`, field 2.
1864    pub status: u8,
1865    /// `DaysMask`, field 3.
1866    pub days_mask: Option<DaysMaskBitmap>,
1867    /// `StartHour`, field 4.
1868    pub start_hour: Option<u8>,
1869    /// `StartMinute`, field 5.
1870    pub start_minute: Option<u8>,
1871    /// `EndHour`, field 6.
1872    pub end_hour: Option<u8>,
1873    /// `EndMinute`, field 7.
1874    pub end_minute: Option<u8>,
1875}
1876
1877impl ToTlv for GetWeekDayScheduleResponseFields {
1878    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1879        w.start_structure(tag)?;
1880        self.week_day_index.to_tlv(w, Tag::Context(0))?;
1881        self.user_index.to_tlv(w, Tag::Context(1))?;
1882        self.status.to_tlv(w, Tag::Context(2))?;
1883        if let Some(value) = &self.days_mask {
1884            value.to_tlv(w, Tag::Context(3))?;
1885        }
1886        if let Some(value) = &self.start_hour {
1887            value.to_tlv(w, Tag::Context(4))?;
1888        }
1889        if let Some(value) = &self.start_minute {
1890            value.to_tlv(w, Tag::Context(5))?;
1891        }
1892        if let Some(value) = &self.end_hour {
1893            value.to_tlv(w, Tag::Context(6))?;
1894        }
1895        if let Some(value) = &self.end_minute {
1896            value.to_tlv(w, Tag::Context(7))?;
1897        }
1898        w.end_container()
1899    }
1900}
1901
1902impl<'a> FromTlv<'a> for GetWeekDayScheduleResponseFields {
1903    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1904        if element.value.container() != Some(ContainerKind::Structure) {
1905            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1906        }
1907        let mut week_day_index = None;
1908        let mut user_index = None;
1909        let mut status = None;
1910        let mut days_mask = None;
1911        let mut start_hour = None;
1912        let mut start_minute = None;
1913        let mut end_hour = None;
1914        let mut end_minute = None;
1915        loop {
1916            let Some(field) = reader.next_element()? else {
1917                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1918            };
1919            if field.value == Value::EndOfContainer {
1920                break;
1921            }
1922            match field.tag.context() {
1923                Some(0) => week_day_index = Some(<u8>::from_tlv(reader, &field)?),
1924                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
1925                Some(2) => status = Some(<u8>::from_tlv(reader, &field)?),
1926                Some(3) => days_mask = Some(<DaysMaskBitmap>::from_tlv(reader, &field)?),
1927                Some(4) => start_hour = Some(<u8>::from_tlv(reader, &field)?),
1928                Some(5) => start_minute = Some(<u8>::from_tlv(reader, &field)?),
1929                Some(6) => end_hour = Some(<u8>::from_tlv(reader, &field)?),
1930                Some(7) => end_minute = Some(<u8>::from_tlv(reader, &field)?),
1931                // A field this revision does not define. §7.19.2: a receiver
1932                // ignores what it does not know rather than refusing the whole
1933                // structure, which is what lets a newer peer talk to an older one.
1934                _ => reader.skip_value(&field)?,
1935            }
1936        }
1937        Ok(Self {
1938            week_day_index: week_day_index
1939                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1940            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1941            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1942            days_mask,
1943            start_hour,
1944            start_minute,
1945            end_hour,
1946            end_minute,
1947        })
1948    }
1949}
1950
1951/// The fields of `ClearWeekDaySchedule` (command `0x0D`).
1952#[derive(Debug, Clone, Copy, PartialEq)]
1953pub struct ClearWeekDayScheduleFields {
1954    /// `WeekDayIndex`, field 0.
1955    pub week_day_index: u8,
1956    /// `UserIndex`, field 1.
1957    pub user_index: u16,
1958}
1959
1960impl ToTlv for ClearWeekDayScheduleFields {
1961    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
1962        w.start_structure(tag)?;
1963        self.week_day_index.to_tlv(w, Tag::Context(0))?;
1964        self.user_index.to_tlv(w, Tag::Context(1))?;
1965        w.end_container()
1966    }
1967}
1968
1969impl<'a> FromTlv<'a> for ClearWeekDayScheduleFields {
1970    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
1971        if element.value.container() != Some(ContainerKind::Structure) {
1972            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
1973        }
1974        let mut week_day_index = None;
1975        let mut user_index = None;
1976        loop {
1977            let Some(field) = reader.next_element()? else {
1978                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
1979            };
1980            if field.value == Value::EndOfContainer {
1981                break;
1982            }
1983            match field.tag.context() {
1984                Some(0) => week_day_index = Some(<u8>::from_tlv(reader, &field)?),
1985                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
1986                // A field this revision does not define. §7.19.2: a receiver
1987                // ignores what it does not know rather than refusing the whole
1988                // structure, which is what lets a newer peer talk to an older one.
1989                _ => reader.skip_value(&field)?,
1990            }
1991        }
1992        Ok(Self {
1993            week_day_index: week_day_index
1994                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1995            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
1996        })
1997    }
1998}
1999
2000/// The fields of `SetYearDaySchedule` (command `0x0E`).
2001#[derive(Debug, Clone, Copy, PartialEq)]
2002pub struct SetYearDayScheduleFields {
2003    /// `YearDayIndex`, field 0.
2004    pub year_day_index: u8,
2005    /// `UserIndex`, field 1.
2006    pub user_index: u16,
2007    /// `LocalStartTime`, field 2.
2008    pub local_start_time: u32,
2009    /// `LocalEndTime`, field 3.
2010    pub local_end_time: u32,
2011}
2012
2013impl ToTlv for SetYearDayScheduleFields {
2014    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2015        w.start_structure(tag)?;
2016        self.year_day_index.to_tlv(w, Tag::Context(0))?;
2017        self.user_index.to_tlv(w, Tag::Context(1))?;
2018        self.local_start_time.to_tlv(w, Tag::Context(2))?;
2019        self.local_end_time.to_tlv(w, Tag::Context(3))?;
2020        w.end_container()
2021    }
2022}
2023
2024impl<'a> FromTlv<'a> for SetYearDayScheduleFields {
2025    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2026        if element.value.container() != Some(ContainerKind::Structure) {
2027            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2028        }
2029        let mut year_day_index = None;
2030        let mut user_index = None;
2031        let mut local_start_time = None;
2032        let mut local_end_time = None;
2033        loop {
2034            let Some(field) = reader.next_element()? else {
2035                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2036            };
2037            if field.value == Value::EndOfContainer {
2038                break;
2039            }
2040            match field.tag.context() {
2041                Some(0) => year_day_index = Some(<u8>::from_tlv(reader, &field)?),
2042                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2043                Some(2) => local_start_time = Some(<u32>::from_tlv(reader, &field)?),
2044                Some(3) => local_end_time = Some(<u32>::from_tlv(reader, &field)?),
2045                // A field this revision does not define. §7.19.2: a receiver
2046                // ignores what it does not know rather than refusing the whole
2047                // structure, which is what lets a newer peer talk to an older one.
2048                _ => reader.skip_value(&field)?,
2049            }
2050        }
2051        Ok(Self {
2052            year_day_index: year_day_index
2053                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2054            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2055            local_start_time: local_start_time
2056                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2057            local_end_time: local_end_time
2058                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2059        })
2060    }
2061}
2062
2063/// The fields of `GetYearDaySchedule` (command `0x0F`).
2064#[derive(Debug, Clone, Copy, PartialEq)]
2065pub struct GetYearDayScheduleFields {
2066    /// `YearDayIndex`, field 0.
2067    pub year_day_index: u8,
2068    /// `UserIndex`, field 1.
2069    pub user_index: u16,
2070}
2071
2072impl ToTlv for GetYearDayScheduleFields {
2073    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2074        w.start_structure(tag)?;
2075        self.year_day_index.to_tlv(w, Tag::Context(0))?;
2076        self.user_index.to_tlv(w, Tag::Context(1))?;
2077        w.end_container()
2078    }
2079}
2080
2081impl<'a> FromTlv<'a> for GetYearDayScheduleFields {
2082    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2083        if element.value.container() != Some(ContainerKind::Structure) {
2084            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2085        }
2086        let mut year_day_index = None;
2087        let mut user_index = None;
2088        loop {
2089            let Some(field) = reader.next_element()? else {
2090                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2091            };
2092            if field.value == Value::EndOfContainer {
2093                break;
2094            }
2095            match field.tag.context() {
2096                Some(0) => year_day_index = Some(<u8>::from_tlv(reader, &field)?),
2097                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2098                // A field this revision does not define. §7.19.2: a receiver
2099                // ignores what it does not know rather than refusing the whole
2100                // structure, which is what lets a newer peer talk to an older one.
2101                _ => reader.skip_value(&field)?,
2102            }
2103        }
2104        Ok(Self {
2105            year_day_index: year_day_index
2106                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2107            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2108        })
2109    }
2110}
2111
2112/// The fields of `GetYearDayScheduleResponse` (command `0x0F`).
2113#[derive(Debug, Clone, Copy, PartialEq)]
2114pub struct GetYearDayScheduleResponseFields {
2115    /// `YearDayIndex`, field 0.
2116    pub year_day_index: u8,
2117    /// `UserIndex`, field 1.
2118    pub user_index: u16,
2119    /// `Status`, field 2.
2120    pub status: u8,
2121    /// `LocalStartTime`, field 3.
2122    pub local_start_time: Option<u32>,
2123    /// `LocalEndTime`, field 4.
2124    pub local_end_time: Option<u32>,
2125}
2126
2127impl ToTlv for GetYearDayScheduleResponseFields {
2128    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2129        w.start_structure(tag)?;
2130        self.year_day_index.to_tlv(w, Tag::Context(0))?;
2131        self.user_index.to_tlv(w, Tag::Context(1))?;
2132        self.status.to_tlv(w, Tag::Context(2))?;
2133        if let Some(value) = &self.local_start_time {
2134            value.to_tlv(w, Tag::Context(3))?;
2135        }
2136        if let Some(value) = &self.local_end_time {
2137            value.to_tlv(w, Tag::Context(4))?;
2138        }
2139        w.end_container()
2140    }
2141}
2142
2143impl<'a> FromTlv<'a> for GetYearDayScheduleResponseFields {
2144    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2145        if element.value.container() != Some(ContainerKind::Structure) {
2146            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2147        }
2148        let mut year_day_index = None;
2149        let mut user_index = None;
2150        let mut status = None;
2151        let mut local_start_time = None;
2152        let mut local_end_time = None;
2153        loop {
2154            let Some(field) = reader.next_element()? else {
2155                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2156            };
2157            if field.value == Value::EndOfContainer {
2158                break;
2159            }
2160            match field.tag.context() {
2161                Some(0) => year_day_index = Some(<u8>::from_tlv(reader, &field)?),
2162                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2163                Some(2) => status = Some(<u8>::from_tlv(reader, &field)?),
2164                Some(3) => local_start_time = Some(<u32>::from_tlv(reader, &field)?),
2165                Some(4) => local_end_time = Some(<u32>::from_tlv(reader, &field)?),
2166                // A field this revision does not define. §7.19.2: a receiver
2167                // ignores what it does not know rather than refusing the whole
2168                // structure, which is what lets a newer peer talk to an older one.
2169                _ => reader.skip_value(&field)?,
2170            }
2171        }
2172        Ok(Self {
2173            year_day_index: year_day_index
2174                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2175            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2176            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2177            local_start_time,
2178            local_end_time,
2179        })
2180    }
2181}
2182
2183/// The fields of `ClearYearDaySchedule` (command `0x10`).
2184#[derive(Debug, Clone, Copy, PartialEq)]
2185pub struct ClearYearDayScheduleFields {
2186    /// `YearDayIndex`, field 0.
2187    pub year_day_index: u8,
2188    /// `UserIndex`, field 1.
2189    pub user_index: u16,
2190}
2191
2192impl ToTlv for ClearYearDayScheduleFields {
2193    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2194        w.start_structure(tag)?;
2195        self.year_day_index.to_tlv(w, Tag::Context(0))?;
2196        self.user_index.to_tlv(w, Tag::Context(1))?;
2197        w.end_container()
2198    }
2199}
2200
2201impl<'a> FromTlv<'a> for ClearYearDayScheduleFields {
2202    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2203        if element.value.container() != Some(ContainerKind::Structure) {
2204            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2205        }
2206        let mut year_day_index = None;
2207        let mut user_index = None;
2208        loop {
2209            let Some(field) = reader.next_element()? else {
2210                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2211            };
2212            if field.value == Value::EndOfContainer {
2213                break;
2214            }
2215            match field.tag.context() {
2216                Some(0) => year_day_index = Some(<u8>::from_tlv(reader, &field)?),
2217                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2218                // A field this revision does not define. §7.19.2: a receiver
2219                // ignores what it does not know rather than refusing the whole
2220                // structure, which is what lets a newer peer talk to an older one.
2221                _ => reader.skip_value(&field)?,
2222            }
2223        }
2224        Ok(Self {
2225            year_day_index: year_day_index
2226                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2227            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2228        })
2229    }
2230}
2231
2232/// The fields of `SetHolidaySchedule` (command `0x11`).
2233#[derive(Debug, Clone, Copy, PartialEq)]
2234pub struct SetHolidayScheduleFields {
2235    /// `HolidayIndex`, field 0.
2236    pub holiday_index: u8,
2237    /// `LocalStartTime`, field 1.
2238    pub local_start_time: u32,
2239    /// `LocalEndTime`, field 2.
2240    pub local_end_time: u32,
2241    /// `OperatingMode`, field 3.
2242    pub operating_mode: OperatingModeEnum,
2243}
2244
2245impl ToTlv for SetHolidayScheduleFields {
2246    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2247        w.start_structure(tag)?;
2248        self.holiday_index.to_tlv(w, Tag::Context(0))?;
2249        self.local_start_time.to_tlv(w, Tag::Context(1))?;
2250        self.local_end_time.to_tlv(w, Tag::Context(2))?;
2251        self.operating_mode.to_tlv(w, Tag::Context(3))?;
2252        w.end_container()
2253    }
2254}
2255
2256impl<'a> FromTlv<'a> for SetHolidayScheduleFields {
2257    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2258        if element.value.container() != Some(ContainerKind::Structure) {
2259            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2260        }
2261        let mut holiday_index = None;
2262        let mut local_start_time = None;
2263        let mut local_end_time = None;
2264        let mut operating_mode = None;
2265        loop {
2266            let Some(field) = reader.next_element()? else {
2267                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2268            };
2269            if field.value == Value::EndOfContainer {
2270                break;
2271            }
2272            match field.tag.context() {
2273                Some(0) => holiday_index = Some(<u8>::from_tlv(reader, &field)?),
2274                Some(1) => local_start_time = Some(<u32>::from_tlv(reader, &field)?),
2275                Some(2) => local_end_time = Some(<u32>::from_tlv(reader, &field)?),
2276                Some(3) => operating_mode = Some(<OperatingModeEnum>::from_tlv(reader, &field)?),
2277                // A field this revision does not define. §7.19.2: a receiver
2278                // ignores what it does not know rather than refusing the whole
2279                // structure, which is what lets a newer peer talk to an older one.
2280                _ => reader.skip_value(&field)?,
2281            }
2282        }
2283        Ok(Self {
2284            holiday_index: holiday_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2285            local_start_time: local_start_time
2286                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2287            local_end_time: local_end_time
2288                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2289            operating_mode: operating_mode
2290                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2291        })
2292    }
2293}
2294
2295/// The fields of `GetHolidaySchedule` (command `0x12`).
2296#[derive(Debug, Clone, Copy, PartialEq)]
2297pub struct GetHolidayScheduleFields {
2298    /// `HolidayIndex`, field 0.
2299    pub holiday_index: u8,
2300}
2301
2302impl ToTlv for GetHolidayScheduleFields {
2303    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2304        w.start_structure(tag)?;
2305        self.holiday_index.to_tlv(w, Tag::Context(0))?;
2306        w.end_container()
2307    }
2308}
2309
2310impl<'a> FromTlv<'a> for GetHolidayScheduleFields {
2311    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2312        if element.value.container() != Some(ContainerKind::Structure) {
2313            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2314        }
2315        let mut holiday_index = None;
2316        loop {
2317            let Some(field) = reader.next_element()? else {
2318                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2319            };
2320            if field.value == Value::EndOfContainer {
2321                break;
2322            }
2323            match field.tag.context() {
2324                Some(0) => holiday_index = Some(<u8>::from_tlv(reader, &field)?),
2325                // A field this revision does not define. §7.19.2: a receiver
2326                // ignores what it does not know rather than refusing the whole
2327                // structure, which is what lets a newer peer talk to an older one.
2328                _ => reader.skip_value(&field)?,
2329            }
2330        }
2331        Ok(Self {
2332            holiday_index: holiday_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2333        })
2334    }
2335}
2336
2337/// The fields of `GetHolidayScheduleResponse` (command `0x12`).
2338#[derive(Debug, Clone, Copy, PartialEq)]
2339pub struct GetHolidayScheduleResponseFields {
2340    /// `HolidayIndex`, field 0.
2341    pub holiday_index: u8,
2342    /// `Status`, field 1.
2343    pub status: u8,
2344    /// `LocalStartTime`, field 2.
2345    pub local_start_time: Option<Nullable<u32>>,
2346    /// `LocalEndTime`, field 3.
2347    pub local_end_time: Option<Nullable<u32>>,
2348    /// `OperatingMode`, field 4.
2349    pub operating_mode: Option<Nullable<OperatingModeEnum>>,
2350}
2351
2352impl ToTlv for GetHolidayScheduleResponseFields {
2353    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2354        w.start_structure(tag)?;
2355        self.holiday_index.to_tlv(w, Tag::Context(0))?;
2356        self.status.to_tlv(w, Tag::Context(1))?;
2357        if let Some(value) = &self.local_start_time {
2358            value.to_tlv(w, Tag::Context(2))?;
2359        }
2360        if let Some(value) = &self.local_end_time {
2361            value.to_tlv(w, Tag::Context(3))?;
2362        }
2363        if let Some(value) = &self.operating_mode {
2364            value.to_tlv(w, Tag::Context(4))?;
2365        }
2366        w.end_container()
2367    }
2368}
2369
2370impl<'a> FromTlv<'a> for GetHolidayScheduleResponseFields {
2371    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2372        if element.value.container() != Some(ContainerKind::Structure) {
2373            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2374        }
2375        let mut holiday_index = None;
2376        let mut status = None;
2377        let mut local_start_time = None;
2378        let mut local_end_time = None;
2379        let mut operating_mode = None;
2380        loop {
2381            let Some(field) = reader.next_element()? else {
2382                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2383            };
2384            if field.value == Value::EndOfContainer {
2385                break;
2386            }
2387            match field.tag.context() {
2388                Some(0) => holiday_index = Some(<u8>::from_tlv(reader, &field)?),
2389                Some(1) => status = Some(<u8>::from_tlv(reader, &field)?),
2390                Some(2) => local_start_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
2391                Some(3) => local_end_time = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
2392                Some(4) => {
2393                    operating_mode = Some(<Nullable<OperatingModeEnum>>::from_tlv(reader, &field)?)
2394                }
2395                // A field this revision does not define. §7.19.2: a receiver
2396                // ignores what it does not know rather than refusing the whole
2397                // structure, which is what lets a newer peer talk to an older one.
2398                _ => reader.skip_value(&field)?,
2399            }
2400        }
2401        Ok(Self {
2402            holiday_index: holiday_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2403            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2404            local_start_time,
2405            local_end_time,
2406            operating_mode,
2407        })
2408    }
2409}
2410
2411/// The fields of `ClearHolidaySchedule` (command `0x13`).
2412#[derive(Debug, Clone, Copy, PartialEq)]
2413pub struct ClearHolidayScheduleFields {
2414    /// `HolidayIndex`, field 0.
2415    pub holiday_index: u8,
2416}
2417
2418impl ToTlv for ClearHolidayScheduleFields {
2419    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2420        w.start_structure(tag)?;
2421        self.holiday_index.to_tlv(w, Tag::Context(0))?;
2422        w.end_container()
2423    }
2424}
2425
2426impl<'a> FromTlv<'a> for ClearHolidayScheduleFields {
2427    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2428        if element.value.container() != Some(ContainerKind::Structure) {
2429            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2430        }
2431        let mut holiday_index = None;
2432        loop {
2433            let Some(field) = reader.next_element()? else {
2434                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2435            };
2436            if field.value == Value::EndOfContainer {
2437                break;
2438            }
2439            match field.tag.context() {
2440                Some(0) => holiday_index = Some(<u8>::from_tlv(reader, &field)?),
2441                // A field this revision does not define. §7.19.2: a receiver
2442                // ignores what it does not know rather than refusing the whole
2443                // structure, which is what lets a newer peer talk to an older one.
2444                _ => reader.skip_value(&field)?,
2445            }
2446        }
2447        Ok(Self {
2448            holiday_index: holiday_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2449        })
2450    }
2451}
2452
2453/// The fields of `SetUser` (command `0x1A`).
2454#[derive(Debug, Clone, Copy, PartialEq)]
2455pub struct SetUserFields<'a> {
2456    /// `OperationType`, field 0.
2457    pub operation_type: DataOperationTypeEnum,
2458    /// `UserIndex`, field 1.
2459    pub user_index: u16,
2460    /// `UserName`, field 2.
2461    pub user_name: Nullable<&'a str>,
2462    /// `UserUniqueID`, field 3.
2463    pub user_unique_id: Nullable<u32>,
2464    /// `UserStatus`, field 4.
2465    pub user_status: Nullable<UserStatusEnum>,
2466    /// `UserType`, field 5.
2467    pub user_type: Nullable<UserTypeEnum>,
2468    /// `CredentialRule`, field 6.
2469    pub credential_rule: Nullable<CredentialRuleEnum>,
2470}
2471
2472impl<'a> ToTlv for SetUserFields<'a> {
2473    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2474        w.start_structure(tag)?;
2475        self.operation_type.to_tlv(w, Tag::Context(0))?;
2476        self.user_index.to_tlv(w, Tag::Context(1))?;
2477        self.user_name.to_tlv(w, Tag::Context(2))?;
2478        self.user_unique_id.to_tlv(w, Tag::Context(3))?;
2479        self.user_status.to_tlv(w, Tag::Context(4))?;
2480        self.user_type.to_tlv(w, Tag::Context(5))?;
2481        self.credential_rule.to_tlv(w, Tag::Context(6))?;
2482        w.end_container()
2483    }
2484}
2485
2486impl<'a> FromTlv<'a> for SetUserFields<'a> {
2487    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2488        if element.value.container() != Some(ContainerKind::Structure) {
2489            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2490        }
2491        let mut operation_type = None;
2492        let mut user_index = None;
2493        let mut user_name = None;
2494        let mut user_unique_id = None;
2495        let mut user_status = None;
2496        let mut user_type = None;
2497        let mut credential_rule = None;
2498        loop {
2499            let Some(field) = reader.next_element()? else {
2500                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2501            };
2502            if field.value == Value::EndOfContainer {
2503                break;
2504            }
2505            match field.tag.context() {
2506                Some(0) => {
2507                    operation_type = Some(<DataOperationTypeEnum>::from_tlv(reader, &field)?)
2508                }
2509                Some(1) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2510                Some(2) => user_name = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
2511                Some(3) => user_unique_id = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
2512                Some(4) => {
2513                    user_status = Some(<Nullable<UserStatusEnum>>::from_tlv(reader, &field)?)
2514                }
2515                Some(5) => user_type = Some(<Nullable<UserTypeEnum>>::from_tlv(reader, &field)?),
2516                Some(6) => {
2517                    credential_rule =
2518                        Some(<Nullable<CredentialRuleEnum>>::from_tlv(reader, &field)?)
2519                }
2520                // A field this revision does not define. §7.19.2: a receiver
2521                // ignores what it does not know rather than refusing the whole
2522                // structure, which is what lets a newer peer talk to an older one.
2523                _ => reader.skip_value(&field)?,
2524            }
2525        }
2526        Ok(Self {
2527            operation_type: operation_type
2528                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2529            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2530            user_name: user_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2531            user_unique_id: user_unique_id
2532                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2533            user_status: user_status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2534            user_type: user_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2535            credential_rule: credential_rule
2536                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2537        })
2538    }
2539}
2540
2541/// The fields of `GetUser` (command `0x1B`).
2542#[derive(Debug, Clone, Copy, PartialEq)]
2543pub struct GetUserFields {
2544    /// `UserIndex`, field 0.
2545    pub user_index: u16,
2546}
2547
2548impl ToTlv for GetUserFields {
2549    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2550        w.start_structure(tag)?;
2551        self.user_index.to_tlv(w, Tag::Context(0))?;
2552        w.end_container()
2553    }
2554}
2555
2556impl<'a> FromTlv<'a> for GetUserFields {
2557    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2558        if element.value.container() != Some(ContainerKind::Structure) {
2559            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2560        }
2561        let mut user_index = None;
2562        loop {
2563            let Some(field) = reader.next_element()? else {
2564                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2565            };
2566            if field.value == Value::EndOfContainer {
2567                break;
2568            }
2569            match field.tag.context() {
2570                Some(0) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2571                // A field this revision does not define. §7.19.2: a receiver
2572                // ignores what it does not know rather than refusing the whole
2573                // structure, which is what lets a newer peer talk to an older one.
2574                _ => reader.skip_value(&field)?,
2575            }
2576        }
2577        Ok(Self {
2578            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2579        })
2580    }
2581}
2582
2583/// The fields of `GetUserResponse` (command `0x1C`).
2584#[derive(Debug, Clone, Copy, PartialEq)]
2585pub struct GetUserResponseFields<'a> {
2586    /// `UserIndex`, field 0.
2587    pub user_index: u16,
2588    /// `UserName`, field 1.
2589    pub user_name: Nullable<&'a str>,
2590    /// `UserUniqueID`, field 2.
2591    pub user_unique_id: Nullable<u32>,
2592    /// `UserStatus`, field 3.
2593    pub user_status: Nullable<UserStatusEnum>,
2594    /// `UserType`, field 4.
2595    pub user_type: Nullable<UserTypeEnum>,
2596    /// `CredentialRule`, field 5.
2597    pub credential_rule: Nullable<CredentialRuleEnum>,
2598    /// `Credentials`, field 6.
2599    pub credentials: Nullable<TlvList<'a, CredentialStruct>>,
2600    /// `CreatorFabricIndex`, field 7.
2601    pub creator_fabric_index: Nullable<crate::msg::FabricIndex>,
2602    /// `LastModifiedFabricIndex`, field 8.
2603    pub last_modified_fabric_index: Nullable<crate::msg::FabricIndex>,
2604    /// `NextUserIndex`, field 9.
2605    pub next_user_index: Nullable<u16>,
2606}
2607
2608impl<'a> ToTlv for GetUserResponseFields<'a> {
2609    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2610        w.start_structure(tag)?;
2611        self.user_index.to_tlv(w, Tag::Context(0))?;
2612        self.user_name.to_tlv(w, Tag::Context(1))?;
2613        self.user_unique_id.to_tlv(w, Tag::Context(2))?;
2614        self.user_status.to_tlv(w, Tag::Context(3))?;
2615        self.user_type.to_tlv(w, Tag::Context(4))?;
2616        self.credential_rule.to_tlv(w, Tag::Context(5))?;
2617        self.credentials.to_tlv(w, Tag::Context(6))?;
2618        self.creator_fabric_index.to_tlv(w, Tag::Context(7))?;
2619        self.last_modified_fabric_index.to_tlv(w, Tag::Context(8))?;
2620        self.next_user_index.to_tlv(w, Tag::Context(9))?;
2621        w.end_container()
2622    }
2623}
2624
2625impl<'a> FromTlv<'a> for GetUserResponseFields<'a> {
2626    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2627        if element.value.container() != Some(ContainerKind::Structure) {
2628            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2629        }
2630        let mut user_index = None;
2631        let mut user_name = None;
2632        let mut user_unique_id = None;
2633        let mut user_status = None;
2634        let mut user_type = None;
2635        let mut credential_rule = None;
2636        let mut credentials = None;
2637        let mut creator_fabric_index = None;
2638        let mut last_modified_fabric_index = None;
2639        let mut next_user_index = None;
2640        loop {
2641            let Some(field) = reader.next_element()? else {
2642                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2643            };
2644            if field.value == Value::EndOfContainer {
2645                break;
2646            }
2647            match field.tag.context() {
2648                Some(0) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2649                Some(1) => user_name = Some(<Nullable<&'a str>>::from_tlv(reader, &field)?),
2650                Some(2) => user_unique_id = Some(<Nullable<u32>>::from_tlv(reader, &field)?),
2651                Some(3) => {
2652                    user_status = Some(<Nullable<UserStatusEnum>>::from_tlv(reader, &field)?)
2653                }
2654                Some(4) => user_type = Some(<Nullable<UserTypeEnum>>::from_tlv(reader, &field)?),
2655                Some(5) => {
2656                    credential_rule =
2657                        Some(<Nullable<CredentialRuleEnum>>::from_tlv(reader, &field)?)
2658                }
2659                Some(6) => {
2660                    credentials = Some(<Nullable<TlvList<'a, CredentialStruct>>>::from_tlv(
2661                        reader, &field,
2662                    )?)
2663                }
2664                Some(7) => {
2665                    creator_fabric_index = Some(<Nullable<crate::msg::FabricIndex>>::from_tlv(
2666                        reader, &field,
2667                    )?)
2668                }
2669                Some(8) => {
2670                    last_modified_fabric_index = Some(
2671                        <Nullable<crate::msg::FabricIndex>>::from_tlv(reader, &field)?,
2672                    )
2673                }
2674                Some(9) => next_user_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2675                // A field this revision does not define. §7.19.2: a receiver
2676                // ignores what it does not know rather than refusing the whole
2677                // structure, which is what lets a newer peer talk to an older one.
2678                _ => reader.skip_value(&field)?,
2679            }
2680        }
2681        Ok(Self {
2682            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2683            user_name: user_name.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2684            user_unique_id: user_unique_id
2685                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2686            user_status: user_status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2687            user_type: user_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2688            credential_rule: credential_rule
2689                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2690            credentials: credentials.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2691            creator_fabric_index: creator_fabric_index
2692                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2693            last_modified_fabric_index: last_modified_fabric_index
2694                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2695            next_user_index: next_user_index
2696                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2697        })
2698    }
2699}
2700
2701/// The fields of `ClearUser` (command `0x1D`).
2702#[derive(Debug, Clone, Copy, PartialEq)]
2703pub struct ClearUserFields {
2704    /// `UserIndex`, field 0.
2705    pub user_index: u16,
2706}
2707
2708impl ToTlv for ClearUserFields {
2709    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2710        w.start_structure(tag)?;
2711        self.user_index.to_tlv(w, Tag::Context(0))?;
2712        w.end_container()
2713    }
2714}
2715
2716impl<'a> FromTlv<'a> for ClearUserFields {
2717    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2718        if element.value.container() != Some(ContainerKind::Structure) {
2719            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2720        }
2721        let mut user_index = None;
2722        loop {
2723            let Some(field) = reader.next_element()? else {
2724                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2725            };
2726            if field.value == Value::EndOfContainer {
2727                break;
2728            }
2729            match field.tag.context() {
2730                Some(0) => user_index = Some(<u16>::from_tlv(reader, &field)?),
2731                // A field this revision does not define. §7.19.2: a receiver
2732                // ignores what it does not know rather than refusing the whole
2733                // structure, which is what lets a newer peer talk to an older one.
2734                _ => reader.skip_value(&field)?,
2735            }
2736        }
2737        Ok(Self {
2738            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2739        })
2740    }
2741}
2742
2743/// The fields of `SetCredential` (command `0x22`).
2744#[derive(Debug, Clone, Copy, PartialEq)]
2745pub struct SetCredentialFields<'a> {
2746    /// `OperationType`, field 0.
2747    pub operation_type: DataOperationTypeEnum,
2748    /// `Credential`, field 1.
2749    pub credential: CredentialStruct,
2750    /// `CredentialData`, field 2.
2751    pub credential_data: &'a [u8],
2752    /// `UserIndex`, field 3.
2753    pub user_index: Nullable<u16>,
2754    /// `UserStatus`, field 4.
2755    pub user_status: Nullable<UserStatusEnum>,
2756    /// `UserType`, field 5.
2757    pub user_type: Nullable<UserTypeEnum>,
2758}
2759
2760impl<'a> ToTlv for SetCredentialFields<'a> {
2761    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2762        w.start_structure(tag)?;
2763        self.operation_type.to_tlv(w, Tag::Context(0))?;
2764        self.credential.to_tlv(w, Tag::Context(1))?;
2765        self.credential_data.to_tlv(w, Tag::Context(2))?;
2766        self.user_index.to_tlv(w, Tag::Context(3))?;
2767        self.user_status.to_tlv(w, Tag::Context(4))?;
2768        self.user_type.to_tlv(w, Tag::Context(5))?;
2769        w.end_container()
2770    }
2771}
2772
2773impl<'a> FromTlv<'a> for SetCredentialFields<'a> {
2774    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2775        if element.value.container() != Some(ContainerKind::Structure) {
2776            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2777        }
2778        let mut operation_type = None;
2779        let mut credential = None;
2780        let mut credential_data = None;
2781        let mut user_index = None;
2782        let mut user_status = None;
2783        let mut user_type = None;
2784        loop {
2785            let Some(field) = reader.next_element()? else {
2786                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2787            };
2788            if field.value == Value::EndOfContainer {
2789                break;
2790            }
2791            match field.tag.context() {
2792                Some(0) => {
2793                    operation_type = Some(<DataOperationTypeEnum>::from_tlv(reader, &field)?)
2794                }
2795                Some(1) => credential = Some(<CredentialStruct>::from_tlv(reader, &field)?),
2796                Some(2) => credential_data = Some(<&'a [u8]>::from_tlv(reader, &field)?),
2797                Some(3) => user_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2798                Some(4) => {
2799                    user_status = Some(<Nullable<UserStatusEnum>>::from_tlv(reader, &field)?)
2800                }
2801                Some(5) => user_type = Some(<Nullable<UserTypeEnum>>::from_tlv(reader, &field)?),
2802                // A field this revision does not define. §7.19.2: a receiver
2803                // ignores what it does not know rather than refusing the whole
2804                // structure, which is what lets a newer peer talk to an older one.
2805                _ => reader.skip_value(&field)?,
2806            }
2807        }
2808        Ok(Self {
2809            operation_type: operation_type
2810                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2811            credential: credential.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2812            credential_data: credential_data
2813                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2814            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2815            user_status: user_status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2816            user_type: user_type.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2817        })
2818    }
2819}
2820
2821/// The fields of `SetCredentialResponse` (command `0x23`).
2822#[derive(Debug, Clone, Copy, PartialEq)]
2823pub struct SetCredentialResponseFields {
2824    /// `Status`, field 0.
2825    pub status: u8,
2826    /// `UserIndex`, field 1.
2827    pub user_index: Nullable<u16>,
2828    /// `NextCredentialIndex`, field 2.
2829    pub next_credential_index: Option<Nullable<u16>>,
2830}
2831
2832impl ToTlv for SetCredentialResponseFields {
2833    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2834        w.start_structure(tag)?;
2835        self.status.to_tlv(w, Tag::Context(0))?;
2836        self.user_index.to_tlv(w, Tag::Context(1))?;
2837        if let Some(value) = &self.next_credential_index {
2838            value.to_tlv(w, Tag::Context(2))?;
2839        }
2840        w.end_container()
2841    }
2842}
2843
2844impl<'a> FromTlv<'a> for SetCredentialResponseFields {
2845    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2846        if element.value.container() != Some(ContainerKind::Structure) {
2847            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2848        }
2849        let mut status = None;
2850        let mut user_index = None;
2851        let mut next_credential_index = None;
2852        loop {
2853            let Some(field) = reader.next_element()? else {
2854                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2855            };
2856            if field.value == Value::EndOfContainer {
2857                break;
2858            }
2859            match field.tag.context() {
2860                Some(0) => status = Some(<u8>::from_tlv(reader, &field)?),
2861                Some(1) => user_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2862                Some(2) => next_credential_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2863                // A field this revision does not define. §7.19.2: a receiver
2864                // ignores what it does not know rather than refusing the whole
2865                // structure, which is what lets a newer peer talk to an older one.
2866                _ => reader.skip_value(&field)?,
2867            }
2868        }
2869        Ok(Self {
2870            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2871            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2872            next_credential_index,
2873        })
2874    }
2875}
2876
2877/// The fields of `GetCredentialStatus` (command `0x24`).
2878#[derive(Debug, Clone, Copy, PartialEq)]
2879pub struct GetCredentialStatusFields {
2880    /// `Credential`, field 0.
2881    pub credential: CredentialStruct,
2882}
2883
2884impl ToTlv for GetCredentialStatusFields {
2885    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2886        w.start_structure(tag)?;
2887        self.credential.to_tlv(w, Tag::Context(0))?;
2888        w.end_container()
2889    }
2890}
2891
2892impl<'a> FromTlv<'a> for GetCredentialStatusFields {
2893    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2894        if element.value.container() != Some(ContainerKind::Structure) {
2895            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2896        }
2897        let mut credential = None;
2898        loop {
2899            let Some(field) = reader.next_element()? else {
2900                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2901            };
2902            if field.value == Value::EndOfContainer {
2903                break;
2904            }
2905            match field.tag.context() {
2906                Some(0) => credential = Some(<CredentialStruct>::from_tlv(reader, &field)?),
2907                // A field this revision does not define. §7.19.2: a receiver
2908                // ignores what it does not know rather than refusing the whole
2909                // structure, which is what lets a newer peer talk to an older one.
2910                _ => reader.skip_value(&field)?,
2911            }
2912        }
2913        Ok(Self {
2914            credential: credential.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2915        })
2916    }
2917}
2918
2919/// The fields of `GetCredentialStatusResponse` (command `0x25`).
2920#[derive(Debug, Clone, Copy, PartialEq)]
2921pub struct GetCredentialStatusResponseFields<'a> {
2922    /// `CredentialExists`, field 0.
2923    pub credential_exists: bool,
2924    /// `UserIndex`, field 1.
2925    pub user_index: Nullable<u16>,
2926    /// `CreatorFabricIndex`, field 2.
2927    pub creator_fabric_index: Nullable<crate::msg::FabricIndex>,
2928    /// `LastModifiedFabricIndex`, field 3.
2929    pub last_modified_fabric_index: Nullable<crate::msg::FabricIndex>,
2930    /// `NextCredentialIndex`, field 4.
2931    pub next_credential_index: Option<Nullable<u16>>,
2932    /// `CredentialData`, field 5.
2933    pub credential_data: Option<Nullable<&'a [u8]>>,
2934}
2935
2936impl<'a> ToTlv for GetCredentialStatusResponseFields<'a> {
2937    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
2938        w.start_structure(tag)?;
2939        self.credential_exists.to_tlv(w, Tag::Context(0))?;
2940        self.user_index.to_tlv(w, Tag::Context(1))?;
2941        self.creator_fabric_index.to_tlv(w, Tag::Context(2))?;
2942        self.last_modified_fabric_index.to_tlv(w, Tag::Context(3))?;
2943        if let Some(value) = &self.next_credential_index {
2944            value.to_tlv(w, Tag::Context(4))?;
2945        }
2946        if let Some(value) = &self.credential_data {
2947            value.to_tlv(w, Tag::Context(5))?;
2948        }
2949        w.end_container()
2950    }
2951}
2952
2953impl<'a> FromTlv<'a> for GetCredentialStatusResponseFields<'a> {
2954    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
2955        if element.value.container() != Some(ContainerKind::Structure) {
2956            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
2957        }
2958        let mut credential_exists = None;
2959        let mut user_index = None;
2960        let mut creator_fabric_index = None;
2961        let mut last_modified_fabric_index = None;
2962        let mut next_credential_index = None;
2963        let mut credential_data = None;
2964        loop {
2965            let Some(field) = reader.next_element()? else {
2966                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
2967            };
2968            if field.value == Value::EndOfContainer {
2969                break;
2970            }
2971            match field.tag.context() {
2972                Some(0) => credential_exists = Some(<bool>::from_tlv(reader, &field)?),
2973                Some(1) => user_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2974                Some(2) => {
2975                    creator_fabric_index = Some(<Nullable<crate::msg::FabricIndex>>::from_tlv(
2976                        reader, &field,
2977                    )?)
2978                }
2979                Some(3) => {
2980                    last_modified_fabric_index = Some(
2981                        <Nullable<crate::msg::FabricIndex>>::from_tlv(reader, &field)?,
2982                    )
2983                }
2984                Some(4) => next_credential_index = Some(<Nullable<u16>>::from_tlv(reader, &field)?),
2985                Some(5) => credential_data = Some(<Nullable<&'a [u8]>>::from_tlv(reader, &field)?),
2986                // A field this revision does not define. §7.19.2: a receiver
2987                // ignores what it does not know rather than refusing the whole
2988                // structure, which is what lets a newer peer talk to an older one.
2989                _ => reader.skip_value(&field)?,
2990            }
2991        }
2992        Ok(Self {
2993            credential_exists: credential_exists
2994                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2995            user_index: user_index.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2996            creator_fabric_index: creator_fabric_index
2997                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
2998            last_modified_fabric_index: last_modified_fabric_index
2999                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
3000            next_credential_index,
3001            credential_data,
3002        })
3003    }
3004}
3005
3006/// The fields of `ClearCredential` (command `0x26`).
3007#[derive(Debug, Clone, Copy, PartialEq)]
3008pub struct ClearCredentialFields {
3009    /// `Credential`, field 0.
3010    pub credential: Nullable<CredentialStruct>,
3011}
3012
3013impl ToTlv for ClearCredentialFields {
3014    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
3015        w.start_structure(tag)?;
3016        self.credential.to_tlv(w, Tag::Context(0))?;
3017        w.end_container()
3018    }
3019}
3020
3021impl<'a> FromTlv<'a> for ClearCredentialFields {
3022    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
3023        if element.value.container() != Some(ContainerKind::Structure) {
3024            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
3025        }
3026        let mut credential = None;
3027        loop {
3028            let Some(field) = reader.next_element()? else {
3029                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
3030            };
3031            if field.value == Value::EndOfContainer {
3032                break;
3033            }
3034            match field.tag.context() {
3035                Some(0) => {
3036                    credential = Some(<Nullable<CredentialStruct>>::from_tlv(reader, &field)?)
3037                }
3038                // A field this revision does not define. §7.19.2: a receiver
3039                // ignores what it does not know rather than refusing the whole
3040                // structure, which is what lets a newer peer talk to an older one.
3041                _ => reader.skip_value(&field)?,
3042            }
3043        }
3044        Ok(Self {
3045            credential: credential.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
3046        })
3047    }
3048}
3049
3050/// The fields of `UnboltDoor` (command `0x27`).
3051#[derive(Debug, Clone, Copy, PartialEq)]
3052pub struct UnboltDoorFields<'a> {
3053    /// `PINCode`, field 0.
3054    pub pin_code: Option<&'a [u8]>,
3055}
3056
3057impl<'a> ToTlv for UnboltDoorFields<'a> {
3058    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
3059        w.start_structure(tag)?;
3060        if let Some(value) = &self.pin_code {
3061            value.to_tlv(w, Tag::Context(0))?;
3062        }
3063        w.end_container()
3064    }
3065}
3066
3067impl<'a> FromTlv<'a> for UnboltDoorFields<'a> {
3068    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
3069        if element.value.container() != Some(ContainerKind::Structure) {
3070            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
3071        }
3072        let mut pin_code = None;
3073        loop {
3074            let Some(field) = reader.next_element()? else {
3075                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
3076            };
3077            if field.value == Value::EndOfContainer {
3078                break;
3079            }
3080            match field.tag.context() {
3081                Some(0) => pin_code = Some(<&'a [u8]>::from_tlv(reader, &field)?),
3082                // A field this revision does not define. §7.19.2: a receiver
3083                // ignores what it does not know rather than refusing the whole
3084                // structure, which is what lets a newer peer talk to an older one.
3085                _ => reader.skip_value(&field)?,
3086            }
3087        }
3088        Ok(Self { pin_code })
3089    }
3090}
3091
3092/// The fields of `SetAliroReaderConfig` (command `0x28`).
3093#[derive(Debug, Clone, Copy, PartialEq)]
3094pub struct SetAliroReaderConfigFields<'a> {
3095    /// `SigningKey`, field 0.
3096    pub signing_key: &'a [u8],
3097    /// `VerificationKey`, field 1.
3098    pub verification_key: &'a [u8],
3099    /// `GroupIdentifier`, field 2.
3100    pub group_identifier: &'a [u8],
3101    /// `GroupResolvingKey`, field 3.
3102    pub group_resolving_key: Option<&'a [u8]>,
3103}
3104
3105impl<'a> ToTlv for SetAliroReaderConfigFields<'a> {
3106    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
3107        w.start_structure(tag)?;
3108        self.signing_key.to_tlv(w, Tag::Context(0))?;
3109        self.verification_key.to_tlv(w, Tag::Context(1))?;
3110        self.group_identifier.to_tlv(w, Tag::Context(2))?;
3111        if let Some(value) = &self.group_resolving_key {
3112            value.to_tlv(w, Tag::Context(3))?;
3113        }
3114        w.end_container()
3115    }
3116}
3117
3118impl<'a> FromTlv<'a> for SetAliroReaderConfigFields<'a> {
3119    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
3120        if element.value.container() != Some(ContainerKind::Structure) {
3121            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
3122        }
3123        let mut signing_key = None;
3124        let mut verification_key = None;
3125        let mut group_identifier = None;
3126        let mut group_resolving_key = None;
3127        loop {
3128            let Some(field) = reader.next_element()? else {
3129                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
3130            };
3131            if field.value == Value::EndOfContainer {
3132                break;
3133            }
3134            match field.tag.context() {
3135                Some(0) => signing_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
3136                Some(1) => verification_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
3137                Some(2) => group_identifier = Some(<&'a [u8]>::from_tlv(reader, &field)?),
3138                Some(3) => group_resolving_key = Some(<&'a [u8]>::from_tlv(reader, &field)?),
3139                // A field this revision does not define. §7.19.2: a receiver
3140                // ignores what it does not know rather than refusing the whole
3141                // structure, which is what lets a newer peer talk to an older one.
3142                _ => reader.skip_value(&field)?,
3143            }
3144        }
3145        Ok(Self {
3146            signing_key: signing_key.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
3147            verification_key: verification_key
3148                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
3149            group_identifier: group_identifier
3150                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
3151            group_resolving_key,
3152        })
3153    }
3154}
3155
3156/// Every attribute the specification defines, with its conformance.
3157pub const ATTRIBUTES: &[Attribute] = &[
3158    Attribute {
3159        id: 0x0000,
3160        name: "LockState",
3161        kind: "LockStateEnum",
3162        access: Access::read_only(Privilege::View),
3163        qualities: AttributeQualities::NULLABLE,
3164        reporting: Reporting::OnChange,
3165        conform: Conform::MANDATORY,
3166    },
3167    Attribute {
3168        id: 0x0001,
3169        name: "LockType",
3170        kind: "LockTypeEnum",
3171        access: Access::read_only(Privilege::View),
3172        qualities: AttributeQualities::empty(),
3173        reporting: Reporting::OnChange,
3174        conform: Conform::MANDATORY,
3175    },
3176    Attribute {
3177        id: 0x0002,
3178        name: "ActuatorEnabled",
3179        kind: "bool",
3180        access: Access::read_only(Privilege::View),
3181        qualities: AttributeQualities::empty(),
3182        reporting: Reporting::OnChange,
3183        conform: Conform::MANDATORY,
3184    },
3185    Attribute {
3186        id: 0x0003,
3187        name: "DoorState",
3188        kind: "DoorStateEnum",
3189        access: Access::read_only(Privilege::View),
3190        qualities: AttributeQualities::NULLABLE,
3191        reporting: Reporting::OnChange,
3192        conform: Conform {
3193            clauses: &[Clause {
3194                verdict: Conformance::Mandatory,
3195                when: Condition::Feature(5),
3196            }],
3197        },
3198    },
3199    Attribute {
3200        id: 0x0004,
3201        name: "DoorOpenEvents",
3202        kind: "uint32",
3203        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3204        qualities: AttributeQualities::empty(),
3205        reporting: Reporting::OnChange,
3206        conform: Conform {
3207            clauses: &[Clause {
3208                verdict: Conformance::Optional,
3209                when: Condition::Feature(5),
3210            }],
3211        },
3212    },
3213    Attribute {
3214        id: 0x0005,
3215        name: "DoorClosedEvents",
3216        kind: "uint32",
3217        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3218        qualities: AttributeQualities::empty(),
3219        reporting: Reporting::OnChange,
3220        conform: Conform {
3221            clauses: &[Clause {
3222                verdict: Conformance::Optional,
3223                when: Condition::Feature(5),
3224            }],
3225        },
3226    },
3227    Attribute {
3228        id: 0x0006,
3229        name: "OpenPeriod",
3230        kind: "uint16",
3231        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3232        qualities: AttributeQualities::empty(),
3233        reporting: Reporting::OnChange,
3234        conform: Conform {
3235            clauses: &[Clause {
3236                verdict: Conformance::Optional,
3237                when: Condition::Feature(5),
3238            }],
3239        },
3240    },
3241    Attribute {
3242        id: 0x0011,
3243        name: "NumberOfTotalUsersSupported",
3244        kind: "uint16",
3245        access: Access::read_only(Privilege::View),
3246        qualities: AttributeQualities::FIXED,
3247        reporting: Reporting::OnChange,
3248        conform: Conform {
3249            clauses: &[Clause {
3250                verdict: Conformance::Mandatory,
3251                when: Condition::Feature(8),
3252            }],
3253        },
3254    },
3255    Attribute {
3256        id: 0x0012,
3257        name: "NumberOfPINUsersSupported",
3258        kind: "uint16",
3259        access: Access::read_only(Privilege::View),
3260        qualities: AttributeQualities::FIXED,
3261        reporting: Reporting::OnChange,
3262        conform: Conform {
3263            clauses: &[Clause {
3264                verdict: Conformance::Mandatory,
3265                when: Condition::Feature(0),
3266            }],
3267        },
3268    },
3269    Attribute {
3270        id: 0x0013,
3271        name: "NumberOfRFIDUsersSupported",
3272        kind: "uint16",
3273        access: Access::read_only(Privilege::View),
3274        qualities: AttributeQualities::FIXED,
3275        reporting: Reporting::OnChange,
3276        conform: Conform {
3277            clauses: &[Clause {
3278                verdict: Conformance::Mandatory,
3279                when: Condition::Feature(1),
3280            }],
3281        },
3282    },
3283    Attribute {
3284        id: 0x0014,
3285        name: "NumberOfWeekDaySchedulesSupportedPerUser",
3286        kind: "uint8",
3287        access: Access::read_only(Privilege::View),
3288        qualities: AttributeQualities::FIXED,
3289        reporting: Reporting::OnChange,
3290        conform: Conform {
3291            clauses: &[Clause {
3292                verdict: Conformance::Mandatory,
3293                when: Condition::Feature(4),
3294            }],
3295        },
3296    },
3297    Attribute {
3298        id: 0x0015,
3299        name: "NumberOfYearDaySchedulesSupportedPerUser",
3300        kind: "uint8",
3301        access: Access::read_only(Privilege::View),
3302        qualities: AttributeQualities::FIXED,
3303        reporting: Reporting::OnChange,
3304        conform: Conform {
3305            clauses: &[Clause {
3306                verdict: Conformance::Mandatory,
3307                when: Condition::Feature(10),
3308            }],
3309        },
3310    },
3311    Attribute {
3312        id: 0x0016,
3313        name: "NumberOfHolidaySchedulesSupported",
3314        kind: "uint8",
3315        access: Access::read_only(Privilege::View),
3316        qualities: AttributeQualities::FIXED,
3317        reporting: Reporting::OnChange,
3318        conform: Conform {
3319            clauses: &[Clause {
3320                verdict: Conformance::Mandatory,
3321                when: Condition::Feature(11),
3322            }],
3323        },
3324    },
3325    Attribute {
3326        id: 0x0017,
3327        name: "MaxPINCodeLength",
3328        kind: "uint8",
3329        access: Access::read_only(Privilege::View),
3330        qualities: AttributeQualities::FIXED,
3331        reporting: Reporting::OnChange,
3332        conform: Conform {
3333            clauses: &[Clause {
3334                verdict: Conformance::Mandatory,
3335                when: Condition::Feature(0),
3336            }],
3337        },
3338    },
3339    Attribute {
3340        id: 0x0018,
3341        name: "MinPINCodeLength",
3342        kind: "uint8",
3343        access: Access::read_only(Privilege::View),
3344        qualities: AttributeQualities::FIXED,
3345        reporting: Reporting::OnChange,
3346        conform: Conform {
3347            clauses: &[Clause {
3348                verdict: Conformance::Mandatory,
3349                when: Condition::Feature(0),
3350            }],
3351        },
3352    },
3353    Attribute {
3354        id: 0x0019,
3355        name: "MaxRFIDCodeLength",
3356        kind: "uint8",
3357        access: Access::read_only(Privilege::View),
3358        qualities: AttributeQualities::FIXED,
3359        reporting: Reporting::OnChange,
3360        conform: Conform {
3361            clauses: &[Clause {
3362                verdict: Conformance::Mandatory,
3363                when: Condition::Feature(1),
3364            }],
3365        },
3366    },
3367    Attribute {
3368        id: 0x001A,
3369        name: "MinRFIDCodeLength",
3370        kind: "uint8",
3371        access: Access::read_only(Privilege::View),
3372        qualities: AttributeQualities::FIXED,
3373        reporting: Reporting::OnChange,
3374        conform: Conform {
3375            clauses: &[Clause {
3376                verdict: Conformance::Mandatory,
3377                when: Condition::Feature(1),
3378            }],
3379        },
3380    },
3381    Attribute {
3382        id: 0x001B,
3383        name: "CredentialRulesSupport",
3384        kind: "CredentialRulesBitmap",
3385        access: Access::read_only(Privilege::View),
3386        qualities: AttributeQualities::FIXED,
3387        reporting: Reporting::OnChange,
3388        conform: Conform {
3389            clauses: &[Clause {
3390                verdict: Conformance::Mandatory,
3391                when: Condition::Feature(8),
3392            }],
3393        },
3394    },
3395    Attribute {
3396        id: 0x001C,
3397        name: "NumberOfCredentialsSupportedPerUser",
3398        kind: "uint8",
3399        access: Access::read_only(Privilege::View),
3400        qualities: AttributeQualities::FIXED,
3401        reporting: Reporting::OnChange,
3402        conform: Conform {
3403            clauses: &[Clause {
3404                verdict: Conformance::Mandatory,
3405                when: Condition::Feature(8),
3406            }],
3407        },
3408    },
3409    Attribute {
3410        id: 0x0021,
3411        name: "Language",
3412        kind: "string",
3413        access: Access::read_only(Privilege::View),
3414        qualities: AttributeQualities::empty(),
3415        reporting: Reporting::OnChange,
3416        conform: Conform::OPTIONAL,
3417    },
3418    Attribute {
3419        id: 0x0022,
3420        name: "LEDSettings",
3421        kind: "LEDSettingEnum",
3422        access: Access::read_only(Privilege::View),
3423        qualities: AttributeQualities::empty(),
3424        reporting: Reporting::OnChange,
3425        conform: Conform::OPTIONAL,
3426    },
3427    Attribute {
3428        id: 0x0023,
3429        name: "AutoRelockTime",
3430        kind: "uint32",
3431        access: Access::read_only(Privilege::View),
3432        qualities: AttributeQualities::empty(),
3433        reporting: Reporting::OnChange,
3434        conform: Conform::OPTIONAL,
3435    },
3436    Attribute {
3437        id: 0x0024,
3438        name: "SoundVolume",
3439        kind: "SoundVolumeEnum",
3440        access: Access::read_only(Privilege::View),
3441        qualities: AttributeQualities::empty(),
3442        reporting: Reporting::OnChange,
3443        conform: Conform::OPTIONAL,
3444    },
3445    Attribute {
3446        id: 0x0025,
3447        name: "OperatingMode",
3448        kind: "OperatingModeEnum",
3449        access: Access::read_only(Privilege::View),
3450        qualities: AttributeQualities::empty(),
3451        reporting: Reporting::OnChange,
3452        conform: Conform::MANDATORY,
3453    },
3454    Attribute {
3455        id: 0x0026,
3456        name: "SupportedOperatingModes",
3457        kind: "OperatingModesBitmap",
3458        access: Access::read_only(Privilege::View),
3459        qualities: AttributeQualities::FIXED,
3460        reporting: Reporting::OnChange,
3461        conform: Conform::MANDATORY,
3462    },
3463    Attribute {
3464        id: 0x0027,
3465        name: "DefaultConfigurationRegister",
3466        kind: "ConfigurationRegisterBitmap",
3467        access: Access::read_only(Privilege::View),
3468        qualities: AttributeQualities::empty(),
3469        reporting: Reporting::OnChange,
3470        conform: Conform::OPTIONAL,
3471    },
3472    Attribute {
3473        id: 0x0028,
3474        name: "EnableLocalProgramming",
3475        kind: "bool",
3476        access: Access::read_only(Privilege::View),
3477        qualities: AttributeQualities::empty(),
3478        reporting: Reporting::OnChange,
3479        conform: Conform::OPTIONAL,
3480    },
3481    Attribute {
3482        id: 0x0029,
3483        name: "EnableOneTouchLocking",
3484        kind: "bool",
3485        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3486        qualities: AttributeQualities::empty(),
3487        reporting: Reporting::OnChange,
3488        conform: Conform::OPTIONAL,
3489    },
3490    Attribute {
3491        id: 0x002A,
3492        name: "EnableInsideStatusLED",
3493        kind: "bool",
3494        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3495        qualities: AttributeQualities::empty(),
3496        reporting: Reporting::OnChange,
3497        conform: Conform::OPTIONAL,
3498    },
3499    Attribute {
3500        id: 0x002B,
3501        name: "EnablePrivacyModeButton",
3502        kind: "bool",
3503        access: Access::read_write_with(Privilege::View, Privilege::Manage),
3504        qualities: AttributeQualities::empty(),
3505        reporting: Reporting::OnChange,
3506        conform: Conform::OPTIONAL,
3507    },
3508    Attribute {
3509        id: 0x002C,
3510        name: "LocalProgrammingFeatures",
3511        kind: "LocalProgrammingFeaturesBitmap",
3512        access: Access::read_only(Privilege::View),
3513        qualities: AttributeQualities::empty(),
3514        reporting: Reporting::OnChange,
3515        conform: Conform::OPTIONAL,
3516    },
3517    Attribute {
3518        id: 0x0030,
3519        name: "WrongCodeEntryLimit",
3520        kind: "uint8",
3521        access: Access::read_only(Privilege::View),
3522        qualities: AttributeQualities::empty(),
3523        reporting: Reporting::OnChange,
3524        conform: Conform {
3525            clauses: &[Clause {
3526                verdict: Conformance::Mandatory,
3527                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
3528            }],
3529        },
3530    },
3531    Attribute {
3532        id: 0x0031,
3533        name: "UserCodeTemporaryDisableTime",
3534        kind: "uint8",
3535        access: Access::read_only(Privilege::View),
3536        qualities: AttributeQualities::empty(),
3537        reporting: Reporting::OnChange,
3538        conform: Conform {
3539            clauses: &[Clause {
3540                verdict: Conformance::Mandatory,
3541                when: Condition::Any(&[Condition::Feature(0), Condition::Feature(1)]),
3542            }],
3543        },
3544    },
3545    Attribute {
3546        id: 0x0032,
3547        name: "SendPINOverTheAir",
3548        kind: "bool",
3549        access: Access::read_only(Privilege::View),
3550        qualities: AttributeQualities::empty(),
3551        reporting: Reporting::OnChange,
3552        conform: Conform {
3553            clauses: &[Clause {
3554                verdict: Conformance::Optional,
3555                when: Condition::All(&[
3556                    Condition::Not(&Condition::Feature(8)),
3557                    Condition::Feature(0),
3558                ]),
3559            }],
3560        },
3561    },
3562    Attribute {
3563        id: 0x0033,
3564        name: "RequirePINforRemoteOperation",
3565        kind: "bool",
3566        access: Access::read_only(Privilege::View),
3567        qualities: AttributeQualities::empty(),
3568        reporting: Reporting::OnChange,
3569        conform: Conform {
3570            clauses: &[Clause {
3571                verdict: Conformance::Mandatory,
3572                when: Condition::All(&[Condition::Feature(7), Condition::Feature(0)]),
3573            }],
3574        },
3575    },
3576    Attribute {
3577        id: 0x0034,
3578        name: "SecurityLevel",
3579        kind: "",
3580        access: Access::read_only(Privilege::View),
3581        qualities: AttributeQualities::empty(),
3582        reporting: Reporting::OnChange,
3583        conform: Conform {
3584            clauses: &[Clause::always(Conformance::Deprecated)],
3585        },
3586    },
3587    Attribute {
3588        id: 0x0035,
3589        name: "ExpiringUserTimeout",
3590        kind: "uint16",
3591        access: Access::read_only(Privilege::View),
3592        qualities: AttributeQualities::empty(),
3593        reporting: Reporting::OnChange,
3594        conform: Conform {
3595            clauses: &[Clause {
3596                verdict: Conformance::Optional,
3597                when: Condition::Feature(8),
3598            }],
3599        },
3600    },
3601    Attribute {
3602        id: 0x0080,
3603        name: "AliroReaderVerificationKey",
3604        kind: "octstr",
3605        access: Access::read_only(Privilege::Administer),
3606        qualities: AttributeQualities::NULLABLE,
3607        reporting: Reporting::OnChange,
3608        conform: Conform {
3609            clauses: &[Clause {
3610                verdict: Conformance::Mandatory,
3611                when: Condition::Feature(13),
3612            }],
3613        },
3614    },
3615    Attribute {
3616        id: 0x0081,
3617        name: "AliroReaderGroupIdentifier",
3618        kind: "octstr",
3619        access: Access::read_only(Privilege::Administer),
3620        qualities: AttributeQualities::NULLABLE,
3621        reporting: Reporting::OnChange,
3622        conform: Conform {
3623            clauses: &[Clause {
3624                verdict: Conformance::Mandatory,
3625                when: Condition::Feature(13),
3626            }],
3627        },
3628    },
3629    Attribute {
3630        id: 0x0082,
3631        name: "AliroReaderGroupSubIdentifier",
3632        kind: "octstr",
3633        access: Access::read_only(Privilege::Administer),
3634        qualities: AttributeQualities::FIXED,
3635        reporting: Reporting::OnChange,
3636        conform: Conform {
3637            clauses: &[Clause {
3638                verdict: Conformance::Mandatory,
3639                when: Condition::Feature(13),
3640            }],
3641        },
3642    },
3643    Attribute {
3644        id: 0x0083,
3645        name: "AliroExpeditedTransactionSupportedProtocolVersions",
3646        kind: "list[octstr]",
3647        access: Access::read_only(Privilege::Administer),
3648        qualities: AttributeQualities::FIXED,
3649        reporting: Reporting::OnChange,
3650        conform: Conform {
3651            clauses: &[Clause {
3652                verdict: Conformance::Mandatory,
3653                when: Condition::Feature(13),
3654            }],
3655        },
3656    },
3657    Attribute {
3658        id: 0x0084,
3659        name: "AliroGroupResolvingKey",
3660        kind: "octstr",
3661        access: Access::read_only(Privilege::Administer),
3662        qualities: AttributeQualities::NULLABLE,
3663        reporting: Reporting::OnChange,
3664        conform: Conform {
3665            clauses: &[Clause {
3666                verdict: Conformance::Mandatory,
3667                when: Condition::Feature(14),
3668            }],
3669        },
3670    },
3671    Attribute {
3672        id: 0x0085,
3673        name: "AliroSupportedBLEUWBProtocolVersions",
3674        kind: "list[octstr]",
3675        access: Access::read_only(Privilege::Administer),
3676        qualities: AttributeQualities::FIXED,
3677        reporting: Reporting::OnChange,
3678        conform: Conform {
3679            clauses: &[Clause {
3680                verdict: Conformance::Mandatory,
3681                when: Condition::Feature(14),
3682            }],
3683        },
3684    },
3685    Attribute {
3686        id: 0x0086,
3687        name: "AliroBLEAdvertisingVersion",
3688        kind: "uint8",
3689        access: Access::read_only(Privilege::Administer),
3690        qualities: AttributeQualities::FIXED,
3691        reporting: Reporting::OnChange,
3692        conform: Conform {
3693            clauses: &[Clause {
3694                verdict: Conformance::Mandatory,
3695                when: Condition::Feature(14),
3696            }],
3697        },
3698    },
3699    Attribute {
3700        id: 0x0087,
3701        name: "NumberOfAliroCredentialIssuerKeysSupported",
3702        kind: "uint16",
3703        access: Access::read_only(Privilege::View),
3704        qualities: AttributeQualities::FIXED,
3705        reporting: Reporting::OnChange,
3706        conform: Conform {
3707            clauses: &[Clause {
3708                verdict: Conformance::Mandatory,
3709                when: Condition::Feature(13),
3710            }],
3711        },
3712    },
3713    Attribute {
3714        id: 0x0088,
3715        name: "NumberOfAliroEndpointKeysSupported",
3716        kind: "uint16",
3717        access: Access::read_only(Privilege::View),
3718        qualities: AttributeQualities::FIXED,
3719        reporting: Reporting::OnChange,
3720        conform: Conform {
3721            clauses: &[Clause {
3722                verdict: Conformance::Mandatory,
3723                when: Condition::Feature(13),
3724            }],
3725        },
3726    },
3727];
3728
3729/// Every command, with its conformance.
3730pub const COMMANDS: &[Command] = &[
3731    Command {
3732        id: 0x00,
3733        name: "LockDoor",
3734        to_server: true,
3735        response: None,
3736        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
3737        conform: Conform::MANDATORY,
3738    },
3739    Command {
3740        id: 0x01,
3741        name: "UnlockDoor",
3742        to_server: true,
3743        response: None,
3744        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
3745        conform: Conform::MANDATORY,
3746    },
3747    Command {
3748        id: 0x02,
3749        name: "Toggle",
3750        to_server: true,
3751        response: None,
3752        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
3753        conform: Conform::DISALLOWED,
3754    },
3755    Command {
3756        id: 0x03,
3757        name: "UnlockWithTimeout",
3758        to_server: true,
3759        response: None,
3760        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
3761        conform: Conform::OPTIONAL,
3762    },
3763    Command {
3764        id: 0x0B,
3765        name: "SetWeekDaySchedule",
3766        to_server: true,
3767        response: None,
3768        access: Access::invoke(Privilege::Administer),
3769        conform: Conform {
3770            clauses: &[Clause {
3771                verdict: Conformance::Mandatory,
3772                when: Condition::Feature(4),
3773            }],
3774        },
3775    },
3776    Command {
3777        id: 0x0C,
3778        name: "GetWeekDaySchedule",
3779        to_server: true,
3780        response: Some(0x0C),
3781        access: Access::invoke(Privilege::Administer),
3782        conform: Conform {
3783            clauses: &[Clause {
3784                verdict: Conformance::Mandatory,
3785                when: Condition::Feature(4),
3786            }],
3787        },
3788    },
3789    Command {
3790        id: 0x0C,
3791        name: "GetWeekDayScheduleResponse",
3792        to_server: false,
3793        response: None,
3794        access: Access::invoke(Privilege::Operate),
3795        conform: Conform {
3796            clauses: &[Clause {
3797                verdict: Conformance::Mandatory,
3798                when: Condition::Feature(4),
3799            }],
3800        },
3801    },
3802    Command {
3803        id: 0x0D,
3804        name: "ClearWeekDaySchedule",
3805        to_server: true,
3806        response: None,
3807        access: Access::invoke(Privilege::Administer),
3808        conform: Conform {
3809            clauses: &[Clause {
3810                verdict: Conformance::Mandatory,
3811                when: Condition::Feature(4),
3812            }],
3813        },
3814    },
3815    Command {
3816        id: 0x0E,
3817        name: "SetYearDaySchedule",
3818        to_server: true,
3819        response: None,
3820        access: Access::invoke(Privilege::Administer),
3821        conform: Conform {
3822            clauses: &[Clause {
3823                verdict: Conformance::Mandatory,
3824                when: Condition::Feature(10),
3825            }],
3826        },
3827    },
3828    Command {
3829        id: 0x0F,
3830        name: "GetYearDaySchedule",
3831        to_server: true,
3832        response: Some(0x0F),
3833        access: Access::invoke(Privilege::Administer),
3834        conform: Conform {
3835            clauses: &[Clause {
3836                verdict: Conformance::Mandatory,
3837                when: Condition::Feature(10),
3838            }],
3839        },
3840    },
3841    Command {
3842        id: 0x0F,
3843        name: "GetYearDayScheduleResponse",
3844        to_server: false,
3845        response: None,
3846        access: Access::invoke(Privilege::Operate),
3847        conform: Conform {
3848            clauses: &[Clause {
3849                verdict: Conformance::Mandatory,
3850                when: Condition::Feature(10),
3851            }],
3852        },
3853    },
3854    Command {
3855        id: 0x10,
3856        name: "ClearYearDaySchedule",
3857        to_server: true,
3858        response: None,
3859        access: Access::invoke(Privilege::Administer),
3860        conform: Conform {
3861            clauses: &[Clause {
3862                verdict: Conformance::Mandatory,
3863                when: Condition::Feature(10),
3864            }],
3865        },
3866    },
3867    Command {
3868        id: 0x11,
3869        name: "SetHolidaySchedule",
3870        to_server: true,
3871        response: None,
3872        access: Access::invoke(Privilege::Administer),
3873        conform: Conform {
3874            clauses: &[Clause {
3875                verdict: Conformance::Mandatory,
3876                when: Condition::Feature(11),
3877            }],
3878        },
3879    },
3880    Command {
3881        id: 0x12,
3882        name: "GetHolidaySchedule",
3883        to_server: true,
3884        response: Some(0x12),
3885        access: Access::invoke(Privilege::Administer),
3886        conform: Conform {
3887            clauses: &[Clause {
3888                verdict: Conformance::Mandatory,
3889                when: Condition::Feature(11),
3890            }],
3891        },
3892    },
3893    Command {
3894        id: 0x12,
3895        name: "GetHolidayScheduleResponse",
3896        to_server: false,
3897        response: None,
3898        access: Access::invoke(Privilege::Operate),
3899        conform: Conform {
3900            clauses: &[Clause {
3901                verdict: Conformance::Mandatory,
3902                when: Condition::Feature(11),
3903            }],
3904        },
3905    },
3906    Command {
3907        id: 0x13,
3908        name: "ClearHolidaySchedule",
3909        to_server: true,
3910        response: None,
3911        access: Access::invoke(Privilege::Administer),
3912        conform: Conform {
3913            clauses: &[Clause {
3914                verdict: Conformance::Mandatory,
3915                when: Condition::Feature(11),
3916            }],
3917        },
3918    },
3919    Command {
3920        id: 0x1A,
3921        name: "SetUser",
3922        to_server: true,
3923        response: None,
3924        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
3925        conform: Conform {
3926            clauses: &[Clause {
3927                verdict: Conformance::Mandatory,
3928                when: Condition::Feature(8),
3929            }],
3930        },
3931    },
3932    Command {
3933        id: 0x1B,
3934        name: "GetUser",
3935        to_server: true,
3936        response: Some(0x1C),
3937        access: Access::invoke(Privilege::Administer),
3938        conform: Conform {
3939            clauses: &[Clause {
3940                verdict: Conformance::Mandatory,
3941                when: Condition::Feature(8),
3942            }],
3943        },
3944    },
3945    Command {
3946        id: 0x1C,
3947        name: "GetUserResponse",
3948        to_server: false,
3949        response: None,
3950        access: Access::invoke(Privilege::Operate),
3951        conform: Conform {
3952            clauses: &[Clause {
3953                verdict: Conformance::Mandatory,
3954                when: Condition::Feature(8),
3955            }],
3956        },
3957    },
3958    Command {
3959        id: 0x1D,
3960        name: "ClearUser",
3961        to_server: true,
3962        response: None,
3963        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
3964        conform: Conform {
3965            clauses: &[Clause {
3966                verdict: Conformance::Mandatory,
3967                when: Condition::Feature(8),
3968            }],
3969        },
3970    },
3971    Command {
3972        id: 0x22,
3973        name: "SetCredential",
3974        to_server: true,
3975        response: Some(0x23),
3976        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
3977        conform: Conform {
3978            clauses: &[Clause {
3979                verdict: Conformance::Mandatory,
3980                when: Condition::Feature(8),
3981            }],
3982        },
3983    },
3984    Command {
3985        id: 0x23,
3986        name: "SetCredentialResponse",
3987        to_server: false,
3988        response: None,
3989        access: Access::invoke(Privilege::Operate),
3990        conform: Conform {
3991            clauses: &[Clause {
3992                verdict: Conformance::Mandatory,
3993                when: Condition::Feature(8),
3994            }],
3995        },
3996    },
3997    Command {
3998        id: 0x24,
3999        name: "GetCredentialStatus",
4000        to_server: true,
4001        response: Some(0x25),
4002        access: Access::invoke(Privilege::Administer),
4003        conform: Conform {
4004            clauses: &[Clause {
4005                verdict: Conformance::Mandatory,
4006                when: Condition::Feature(8),
4007            }],
4008        },
4009    },
4010    Command {
4011        id: 0x25,
4012        name: "GetCredentialStatusResponse",
4013        to_server: false,
4014        response: None,
4015        access: Access::invoke(Privilege::Operate),
4016        conform: Conform {
4017            clauses: &[Clause {
4018                verdict: Conformance::Mandatory,
4019                when: Condition::Feature(8),
4020            }],
4021        },
4022    },
4023    Command {
4024        id: 0x26,
4025        name: "ClearCredential",
4026        to_server: true,
4027        response: None,
4028        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
4029        conform: Conform {
4030            clauses: &[Clause {
4031                verdict: Conformance::Mandatory,
4032                when: Condition::Feature(8),
4033            }],
4034        },
4035    },
4036    Command {
4037        id: 0x27,
4038        name: "UnboltDoor",
4039        to_server: true,
4040        response: None,
4041        access: Access::invoke(Privilege::Operate).with_qualities(AccessQualities::TIMED),
4042        conform: Conform {
4043            clauses: &[Clause {
4044                verdict: Conformance::Mandatory,
4045                when: Condition::Feature(12),
4046            }],
4047        },
4048    },
4049    Command {
4050        id: 0x28,
4051        name: "SetAliroReaderConfig",
4052        to_server: true,
4053        response: None,
4054        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
4055        conform: Conform {
4056            clauses: &[Clause {
4057                verdict: Conformance::Mandatory,
4058                when: Condition::Feature(13),
4059            }],
4060        },
4061    },
4062    Command {
4063        id: 0x29,
4064        name: "ClearAliroReaderConfig",
4065        to_server: true,
4066        response: None,
4067        access: Access::invoke(Privilege::Administer).with_qualities(AccessQualities::TIMED),
4068        conform: Conform {
4069            clauses: &[Clause {
4070                verdict: Conformance::Mandatory,
4071                when: Condition::Feature(13),
4072            }],
4073        },
4074    },
4075];
4076
4077/// Every event, with its conformance.
4078pub const EVENTS: &[Event] = &[
4079    Event {
4080        id: 0x00,
4081        name: "DoorLockAlarm",
4082        priority: EventPriority::Critical,
4083        access: Access::read_only(Privilege::View),
4084        conform: Conform::MANDATORY,
4085    },
4086    Event {
4087        id: 0x01,
4088        name: "DoorStateChange",
4089        priority: EventPriority::Info,
4090        access: Access::read_only(Privilege::View),
4091        conform: Conform {
4092            clauses: &[Clause {
4093                verdict: Conformance::Mandatory,
4094                when: Condition::Feature(5),
4095            }],
4096        },
4097    },
4098    Event {
4099        id: 0x02,
4100        name: "LockOperation",
4101        priority: EventPriority::Info,
4102        access: Access::read_only(Privilege::View),
4103        conform: Conform::MANDATORY,
4104    },
4105    Event {
4106        id: 0x03,
4107        name: "LockOperationError",
4108        priority: EventPriority::Info,
4109        access: Access::read_only(Privilege::View),
4110        conform: Conform::MANDATORY,
4111    },
4112    Event {
4113        id: 0x04,
4114        name: "LockUserChange",
4115        priority: EventPriority::Info,
4116        access: Access::read_only(Privilege::View),
4117        conform: Conform {
4118            clauses: &[Clause {
4119                verdict: Conformance::Mandatory,
4120                when: Condition::Feature(8),
4121            }],
4122        },
4123    },
4124];
4125
4126/// The whole cluster, as the specification defines it.
4127pub const CLUSTER: Cluster = Cluster {
4128    id: ID,
4129    name: "Door Lock",
4130    revision: REVISION,
4131    pics: "DRLK",
4132    derived_from: None,
4133    features: FEATURES,
4134    attributes: ATTRIBUTES,
4135    commands: COMMANDS,
4136    events: EVENTS,
4137};