Skip to main content

matter_kit/clusters/generated/
ota_software_update_provider.rs

1// Generated by `cargo xtask` from the CSA data model 1.6. Do not edit.
2//
3// OTA Software Update Provider — cluster 0x0029.
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//! OTA Software Update Provider (cluster `0x0029`, revision 1).
10//!
11//! 5 identifiers, 0 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 = 0x0029;
28
29/// The highest revision the specification's history defines — what `ClusterRevision`
30/// must report (Core §7.13.1).
31pub const REVISION: u16 = 1;
32
33/// The PICS code, which a certification declaration names the cluster by.
34pub const PICS: &str = "OTAP";
35
36/// This cluster defines no features, so its `FeatureMap` is always zero.
37pub const FEATURES: &[Feature] = &[];
38
39/// The command ids.
40pub mod command {
41    use crate::im::CommandId;
42
43    /// `QueryImage`.
44    pub const QUERY_IMAGE: CommandId = 0x00;
45    /// `QueryImageResponse`.
46    pub const QUERY_IMAGE_RESPONSE: CommandId = 0x01;
47    /// `ApplyUpdateRequest`.
48    pub const APPLY_UPDATE_REQUEST: CommandId = 0x02;
49    /// `ApplyUpdateResponse`.
50    pub const APPLY_UPDATE_RESPONSE: CommandId = 0x03;
51    /// `NotifyUpdateApplied`.
52    pub const NOTIFY_UPDATE_APPLIED: CommandId = 0x04;
53}
54
55/// `ApplyUpdateActionEnum`.
56#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
57#[repr(u8)]
58pub enum ApplyUpdateActionEnum {
59    /// Apply the update.
60    Proceed = 0,
61    /// Wait at least the given delay time.
62    AwaitNextAction = 1,
63    /// The OTA Provider is conveying a desire to rescind a previously provided Software Image.
64    Discontinue = 2,
65}
66
67impl ApplyUpdateActionEnum {
68    /// Reads a wire value, or `None` for one this revision does not define.
69    #[must_use]
70    pub const fn from_value(value: u8) -> Option<Self> {
71        match value {
72            0 => Some(Self::Proceed),
73            1 => Some(Self::AwaitNextAction),
74            2 => Some(Self::Discontinue),
75            _ => None,
76        }
77    }
78
79    /// Its wire value.
80    #[must_use]
81    pub const fn value(self) -> u8 {
82        self as u8
83    }
84}
85
86impl ToTlv for ApplyUpdateActionEnum {
87    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
88        self.value().to_tlv(w, tag)
89    }
90}
91
92impl<'a> FromTlv<'a> for ApplyUpdateActionEnum {
93    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
94        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
95        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
96    }
97}
98
99/// `DownloadProtocolEnum`.
100#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
101#[repr(u8)]
102pub enum DownloadProtocolEnum {
103    /// Indicates support for synchronous BDX.
104    BDXSynchronous = 0,
105    /// Indicates support for asynchronous BDX.
106    BDXAsynchronous = 1,
107    /// Indicates support for HTTPS.
108    HTTPS = 2,
109    /// Indicates support for vendor specific protocol.
110    VendorSpecific = 3,
111}
112
113impl DownloadProtocolEnum {
114    /// Reads a wire value, or `None` for one this revision does not define.
115    #[must_use]
116    pub const fn from_value(value: u8) -> Option<Self> {
117        match value {
118            0 => Some(Self::BDXSynchronous),
119            1 => Some(Self::BDXAsynchronous),
120            2 => Some(Self::HTTPS),
121            3 => Some(Self::VendorSpecific),
122            _ => None,
123        }
124    }
125
126    /// Its wire value.
127    #[must_use]
128    pub const fn value(self) -> u8 {
129        self as u8
130    }
131}
132
133impl ToTlv for DownloadProtocolEnum {
134    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
135        self.value().to_tlv(w, tag)
136    }
137}
138
139impl<'a> FromTlv<'a> for DownloadProtocolEnum {
140    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
141        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
142        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
143    }
144}
145
146/// `StatusEnum`.
147#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
148#[repr(u8)]
149pub enum StatusEnum {
150    /// Indicates that the OTA Provider has an update available.
151    UpdateAvailable = 0,
152    /// Indicates OTA Provider may have an update, but it is not ready yet.
153    Busy = 1,
154    /// Indicates that there is definitely no update currently available from the OTA Provider.
155    NotAvailable = 2,
156    /// Indicates that the requested download protocol is not supported by the OTA Provider.
157    DownloadProtocolNotSupported = 3,
158}
159
160impl StatusEnum {
161    /// Reads a wire value, or `None` for one this revision does not define.
162    #[must_use]
163    pub const fn from_value(value: u8) -> Option<Self> {
164        match value {
165            0 => Some(Self::UpdateAvailable),
166            1 => Some(Self::Busy),
167            2 => Some(Self::NotAvailable),
168            3 => Some(Self::DownloadProtocolNotSupported),
169            _ => None,
170        }
171    }
172
173    /// Its wire value.
174    #[must_use]
175    pub const fn value(self) -> u8 {
176        self as u8
177    }
178}
179
180impl ToTlv for StatusEnum {
181    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
182        self.value().to_tlv(w, tag)
183    }
184}
185
186impl<'a> FromTlv<'a> for StatusEnum {
187    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
188        let value = <u8 as FromTlv<'a>>::from_tlv(reader, element)?;
189        Self::from_value(value).ok_or(crate::Error::new(crate::ErrorCode::TlvOutOfRange))
190    }
191}
192
193/// The fields of `QueryImage` (command `0x00`).
194#[derive(Debug, Clone, Copy, PartialEq)]
195pub struct QueryImageFields<'a> {
196    /// `VendorID`, field 0.
197    pub vendor_id: crate::msg::VendorId,
198    /// `ProductID`, field 1.
199    pub product_id: u16,
200    /// `SoftwareVersion`, field 2.
201    pub software_version: u32,
202    /// `ProtocolsSupported`, field 3.
203    pub protocols_supported: TlvList<'a, DownloadProtocolEnum>,
204    /// `HardwareVersion`, field 4.
205    pub hardware_version: Option<u16>,
206    /// `Location`, field 5.
207    pub location: Option<&'a str>,
208    /// `RequestorCanConsent`, field 6.
209    pub requestor_can_consent: Option<bool>,
210    /// `MetadataForProvider`, field 7.
211    pub metadata_for_provider: Option<&'a [u8]>,
212}
213
214impl<'a> ToTlv for QueryImageFields<'a> {
215    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
216        w.start_structure(tag)?;
217        self.vendor_id.to_tlv(w, Tag::Context(0))?;
218        self.product_id.to_tlv(w, Tag::Context(1))?;
219        self.software_version.to_tlv(w, Tag::Context(2))?;
220        self.protocols_supported.to_tlv(w, Tag::Context(3))?;
221        if let Some(value) = &self.hardware_version {
222            value.to_tlv(w, Tag::Context(4))?;
223        }
224        if let Some(value) = &self.location {
225            value.to_tlv(w, Tag::Context(5))?;
226        }
227        if let Some(value) = &self.requestor_can_consent {
228            value.to_tlv(w, Tag::Context(6))?;
229        }
230        if let Some(value) = &self.metadata_for_provider {
231            value.to_tlv(w, Tag::Context(7))?;
232        }
233        w.end_container()
234    }
235}
236
237impl<'a> FromTlv<'a> for QueryImageFields<'a> {
238    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
239        if element.value.container() != Some(ContainerKind::Structure) {
240            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
241        }
242        let mut vendor_id = None;
243        let mut product_id = None;
244        let mut software_version = None;
245        let mut protocols_supported = None;
246        let mut hardware_version = None;
247        let mut location = None;
248        let mut requestor_can_consent = None;
249        let mut metadata_for_provider = None;
250        loop {
251            let Some(field) = reader.next_element()? else {
252                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
253            };
254            if field.value == Value::EndOfContainer {
255                break;
256            }
257            match field.tag.context() {
258                Some(0) => vendor_id = Some(<crate::msg::VendorId>::from_tlv(reader, &field)?),
259                Some(1) => product_id = Some(<u16>::from_tlv(reader, &field)?),
260                Some(2) => software_version = Some(<u32>::from_tlv(reader, &field)?),
261                Some(3) => {
262                    protocols_supported = Some(<TlvList<'a, DownloadProtocolEnum>>::from_tlv(
263                        reader, &field,
264                    )?)
265                }
266                Some(4) => hardware_version = Some(<u16>::from_tlv(reader, &field)?),
267                Some(5) => location = Some(<&'a str>::from_tlv(reader, &field)?),
268                Some(6) => requestor_can_consent = Some(<bool>::from_tlv(reader, &field)?),
269                Some(7) => metadata_for_provider = Some(<&'a [u8]>::from_tlv(reader, &field)?),
270                // A field this revision does not define. §7.19.2: a receiver
271                // ignores what it does not know rather than refusing the whole
272                // structure, which is what lets a newer peer talk to an older one.
273                _ => reader.skip_value(&field)?,
274            }
275        }
276        Ok(Self {
277            vendor_id: vendor_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
278            product_id: product_id.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
279            software_version: software_version
280                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
281            protocols_supported: protocols_supported
282                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
283            hardware_version,
284            location,
285            requestor_can_consent,
286            metadata_for_provider,
287        })
288    }
289}
290
291/// The fields of `QueryImageResponse` (command `0x01`).
292#[derive(Debug, Clone, Copy, PartialEq)]
293pub struct QueryImageResponseFields<'a> {
294    /// `Status`, field 0.
295    pub status: StatusEnum,
296    /// `DelayedActionTime`, field 1.
297    pub delayed_action_time: Option<u32>,
298    /// `ImageURI`, field 2.
299    pub image_uri: Option<&'a str>,
300    /// `SoftwareVersion`, field 3.
301    pub software_version: Option<u32>,
302    /// `SoftwareVersionString`, field 4.
303    pub software_version_string: Option<&'a str>,
304    /// `UpdateToken`, field 5.
305    pub update_token: Option<&'a [u8]>,
306    /// `UserConsentNeeded`, field 6.
307    pub user_consent_needed: Option<bool>,
308    /// `MetadataForRequestor`, field 7.
309    pub metadata_for_requestor: Option<&'a [u8]>,
310}
311
312impl<'a> ToTlv for QueryImageResponseFields<'a> {
313    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
314        w.start_structure(tag)?;
315        self.status.to_tlv(w, Tag::Context(0))?;
316        if let Some(value) = &self.delayed_action_time {
317            value.to_tlv(w, Tag::Context(1))?;
318        }
319        if let Some(value) = &self.image_uri {
320            value.to_tlv(w, Tag::Context(2))?;
321        }
322        if let Some(value) = &self.software_version {
323            value.to_tlv(w, Tag::Context(3))?;
324        }
325        if let Some(value) = &self.software_version_string {
326            value.to_tlv(w, Tag::Context(4))?;
327        }
328        if let Some(value) = &self.update_token {
329            value.to_tlv(w, Tag::Context(5))?;
330        }
331        if let Some(value) = &self.user_consent_needed {
332            value.to_tlv(w, Tag::Context(6))?;
333        }
334        if let Some(value) = &self.metadata_for_requestor {
335            value.to_tlv(w, Tag::Context(7))?;
336        }
337        w.end_container()
338    }
339}
340
341impl<'a> FromTlv<'a> for QueryImageResponseFields<'a> {
342    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
343        if element.value.container() != Some(ContainerKind::Structure) {
344            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
345        }
346        let mut status = None;
347        let mut delayed_action_time = None;
348        let mut image_uri = None;
349        let mut software_version = None;
350        let mut software_version_string = None;
351        let mut update_token = None;
352        let mut user_consent_needed = None;
353        let mut metadata_for_requestor = None;
354        loop {
355            let Some(field) = reader.next_element()? else {
356                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
357            };
358            if field.value == Value::EndOfContainer {
359                break;
360            }
361            match field.tag.context() {
362                Some(0) => status = Some(<StatusEnum>::from_tlv(reader, &field)?),
363                Some(1) => delayed_action_time = Some(<u32>::from_tlv(reader, &field)?),
364                Some(2) => image_uri = Some(<&'a str>::from_tlv(reader, &field)?),
365                Some(3) => software_version = Some(<u32>::from_tlv(reader, &field)?),
366                Some(4) => software_version_string = Some(<&'a str>::from_tlv(reader, &field)?),
367                Some(5) => update_token = Some(<&'a [u8]>::from_tlv(reader, &field)?),
368                Some(6) => user_consent_needed = Some(<bool>::from_tlv(reader, &field)?),
369                Some(7) => metadata_for_requestor = Some(<&'a [u8]>::from_tlv(reader, &field)?),
370                // A field this revision does not define. §7.19.2: a receiver
371                // ignores what it does not know rather than refusing the whole
372                // structure, which is what lets a newer peer talk to an older one.
373                _ => reader.skip_value(&field)?,
374            }
375        }
376        Ok(Self {
377            status: status.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
378            delayed_action_time,
379            image_uri,
380            software_version,
381            software_version_string,
382            update_token,
383            user_consent_needed,
384            metadata_for_requestor,
385        })
386    }
387}
388
389/// The fields of `ApplyUpdateRequest` (command `0x02`).
390#[derive(Debug, Clone, Copy, PartialEq)]
391pub struct ApplyUpdateRequestFields<'a> {
392    /// `UpdateToken`, field 0.
393    pub update_token: &'a [u8],
394    /// `NewVersion`, field 1.
395    pub new_version: u32,
396}
397
398impl<'a> ToTlv for ApplyUpdateRequestFields<'a> {
399    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
400        w.start_structure(tag)?;
401        self.update_token.to_tlv(w, Tag::Context(0))?;
402        self.new_version.to_tlv(w, Tag::Context(1))?;
403        w.end_container()
404    }
405}
406
407impl<'a> FromTlv<'a> for ApplyUpdateRequestFields<'a> {
408    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
409        if element.value.container() != Some(ContainerKind::Structure) {
410            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
411        }
412        let mut update_token = None;
413        let mut new_version = None;
414        loop {
415            let Some(field) = reader.next_element()? else {
416                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
417            };
418            if field.value == Value::EndOfContainer {
419                break;
420            }
421            match field.tag.context() {
422                Some(0) => update_token = Some(<&'a [u8]>::from_tlv(reader, &field)?),
423                Some(1) => new_version = Some(<u32>::from_tlv(reader, &field)?),
424                // A field this revision does not define. §7.19.2: a receiver
425                // ignores what it does not know rather than refusing the whole
426                // structure, which is what lets a newer peer talk to an older one.
427                _ => reader.skip_value(&field)?,
428            }
429        }
430        Ok(Self {
431            update_token: update_token.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
432            new_version: new_version.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
433        })
434    }
435}
436
437/// The fields of `ApplyUpdateResponse` (command `0x03`).
438#[derive(Debug, Clone, Copy, PartialEq)]
439pub struct ApplyUpdateResponseFields {
440    /// `Action`, field 0.
441    pub action: ApplyUpdateActionEnum,
442    /// `DelayedActionTime`, field 1.
443    pub delayed_action_time: u32,
444}
445
446impl ToTlv for ApplyUpdateResponseFields {
447    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
448        w.start_structure(tag)?;
449        self.action.to_tlv(w, Tag::Context(0))?;
450        self.delayed_action_time.to_tlv(w, Tag::Context(1))?;
451        w.end_container()
452    }
453}
454
455impl<'a> FromTlv<'a> for ApplyUpdateResponseFields {
456    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
457        if element.value.container() != Some(ContainerKind::Structure) {
458            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
459        }
460        let mut action = None;
461        let mut delayed_action_time = None;
462        loop {
463            let Some(field) = reader.next_element()? else {
464                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
465            };
466            if field.value == Value::EndOfContainer {
467                break;
468            }
469            match field.tag.context() {
470                Some(0) => action = Some(<ApplyUpdateActionEnum>::from_tlv(reader, &field)?),
471                Some(1) => delayed_action_time = Some(<u32>::from_tlv(reader, &field)?),
472                // A field this revision does not define. §7.19.2: a receiver
473                // ignores what it does not know rather than refusing the whole
474                // structure, which is what lets a newer peer talk to an older one.
475                _ => reader.skip_value(&field)?,
476            }
477        }
478        Ok(Self {
479            action: action.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
480            delayed_action_time: delayed_action_time
481                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
482        })
483    }
484}
485
486/// The fields of `NotifyUpdateApplied` (command `0x04`).
487#[derive(Debug, Clone, Copy, PartialEq)]
488pub struct NotifyUpdateAppliedFields<'a> {
489    /// `UpdateToken`, field 0.
490    pub update_token: &'a [u8],
491    /// `SoftwareVersion`, field 1.
492    pub software_version: u32,
493}
494
495impl<'a> ToTlv for NotifyUpdateAppliedFields<'a> {
496    fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
497        w.start_structure(tag)?;
498        self.update_token.to_tlv(w, Tag::Context(0))?;
499        self.software_version.to_tlv(w, Tag::Context(1))?;
500        w.end_container()
501    }
502}
503
504impl<'a> FromTlv<'a> for NotifyUpdateAppliedFields<'a> {
505    fn from_tlv(reader: &mut TlvReader<'a>, element: &Element<'a>) -> Result<Self> {
506        if element.value.container() != Some(ContainerKind::Structure) {
507            return Err(crate::Error::new(crate::ErrorCode::TlvWrongType));
508        }
509        let mut update_token = None;
510        let mut software_version = None;
511        loop {
512            let Some(field) = reader.next_element()? else {
513                return Err(crate::Error::new(crate::ErrorCode::TlvTruncated));
514            };
515            if field.value == Value::EndOfContainer {
516                break;
517            }
518            match field.tag.context() {
519                Some(0) => update_token = Some(<&'a [u8]>::from_tlv(reader, &field)?),
520                Some(1) => software_version = Some(<u32>::from_tlv(reader, &field)?),
521                // A field this revision does not define. §7.19.2: a receiver
522                // ignores what it does not know rather than refusing the whole
523                // structure, which is what lets a newer peer talk to an older one.
524                _ => reader.skip_value(&field)?,
525            }
526        }
527        Ok(Self {
528            update_token: update_token.ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
529            software_version: software_version
530                .ok_or(crate::Error::new(crate::ErrorCode::TlvNotFound))?,
531        })
532    }
533}
534
535/// Every attribute the specification defines, with its conformance.
536pub const ATTRIBUTES: &[Attribute] = &[];
537
538/// Every command, with its conformance.
539pub const COMMANDS: &[Command] = &[
540    Command {
541        id: 0x00,
542        name: "QueryImage",
543        to_server: true,
544        response: Some(0x01),
545        access: Access::invoke(Privilege::Operate),
546        conform: Conform::MANDATORY,
547    },
548    Command {
549        id: 0x01,
550        name: "QueryImageResponse",
551        to_server: false,
552        response: None,
553        access: Access::invoke(Privilege::Operate),
554        conform: Conform::MANDATORY,
555    },
556    Command {
557        id: 0x02,
558        name: "ApplyUpdateRequest",
559        to_server: true,
560        response: Some(0x03),
561        access: Access::invoke(Privilege::Operate),
562        conform: Conform::MANDATORY,
563    },
564    Command {
565        id: 0x03,
566        name: "ApplyUpdateResponse",
567        to_server: false,
568        response: None,
569        access: Access::invoke(Privilege::Operate),
570        conform: Conform::MANDATORY,
571    },
572    Command {
573        id: 0x04,
574        name: "NotifyUpdateApplied",
575        to_server: true,
576        response: None,
577        access: Access::invoke(Privilege::Operate),
578        conform: Conform::MANDATORY,
579    },
580];
581
582/// Every event, with its conformance.
583pub const EVENTS: &[Event] = &[];
584
585/// The whole cluster, as the specification defines it.
586pub const CLUSTER: Cluster = Cluster {
587    id: ID,
588    name: "OTA Software Update Provider",
589    revision: REVISION,
590    pics: "OTAP",
591    derived_from: None,
592    features: FEATURES,
593    attributes: ATTRIBUTES,
594    commands: COMMANDS,
595    events: EVENTS,
596};