matter_kit/clusters/ota_requestor.rs
1//! OTA Software Update Requestor, cluster `0x002A` (Core §11.20.7).
2//!
3//! The other half of [`ota_provider`](super::ota_provider): this is the cluster on the device
4//! *being* updated. It holds where to ask ([`DEFAULT_OTA_PROVIDERS`]), says how far along an
5//! update is ([`UPDATE_STATE`], [`UPDATE_STATE_PROGRESS`]), and reports what happened through
6//! §11.20.7.7's three events.
7//!
8//! The download itself is [`bdx`](crate::bdx). A requestor asks a provider for an image, gets a
9//! `bdx:` URI back ([`ImageUri`](super::ota_provider::ImageUri)), and opens a BDX transfer as
10//! the Initiator and Receiver. What lives here is the *state* of that, because a controller
11//! subscribing to `UpdateState` is how a user watches an update they cannot see.
12//!
13//! # One provider per fabric, and an announcement is not a provider
14//!
15//! §11.20.7.5: "There SHALL NOT be more than one entry per Fabric. On a list update that would
16//! introduce more than one entry per fabric, the write SHALL fail with CONSTRAINT_ERROR status
17//! code." Each fabric's administrator names its own provider, and the device asks each of them.
18//!
19//! The rule that is easy to get wrong is the one next to it:
20//!
21//! > Provider Locations obtained using the AnnounceOTAProvider command SHALL NOT overwrite
22//! > values set in the DefaultOTAProviders attribute.
23//!
24//! An announcement is a hint to query *sooner*, from a provider that announced itself. It is
25//! not a configuration change, and a device that let one rewrite the list would let any
26//! administrator on the fabric redirect every later update — including after its own access was
27//! removed. [`Announcement`] is handed to the application and the list is left alone.
28//!
29//! # The state machine is the product's, and the event is this cluster's
30//!
31//! §11.20.7.4.2's nine states are the shape of an OTA: `Idle`, `Querying`, `DelayedOnQuery`,
32//! `Downloading`, `Applying`, and the rest. Which one the device is in is the application's to
33//! say — [`OtaRequestor::transition`] is how it says so, and the `StateTransition` event, the
34//! `TargetSoftwareVersion` rule and the progress reset all follow from it rather than having to
35//! be remembered at nine call sites.
36
37use core::cell::{Cell, RefCell};
38
39use crate::clusters::generated::ota_software_update_requestor as spec_requestor;
40use crate::dm::spec::{Conforming, Optional};
41use crate::dm::{Resolved, ResolvedCommand};
42use crate::error::Result;
43use crate::im::{
44 ClusterHandler, ClusterId, CommandId, EndpointId, InteractionContext, Status, StatusIb, WriteOp,
45};
46use crate::msg::{FabricIndex, NodeId, VendorId};
47use crate::tlv::{ContainerKind, FromTlv, Tag, TlvReader, TlvWriter, ToTlv, Value};
48
49use super::Cluster;
50
51pub use spec_requestor::attribute::{
52 DEFAULT_OTA_PROVIDERS, UPDATE_POSSIBLE, UPDATE_STATE, UPDATE_STATE_PROGRESS,
53};
54pub use spec_requestor::command::ANNOUNCE_OTA_PROVIDER;
55pub use spec_requestor::event::{DOWNLOAD_ERROR, STATE_TRANSITION, VERSION_APPLIED};
56pub use spec_requestor::{
57 AnnouncementReasonEnum, ChangeReasonEnum, ID, PICS, ProviderLocation, REVISION, UpdateStateEnum,
58};
59
60/// §11.20.7.6.1's constraint on `MetadataForNode`: "max 512".
61pub const METADATA_MAX: usize = 512;
62
63/// §11.20.7.5's constraint on `UpdateStateProgress`: "0 to 100".
64pub const PROGRESS_MAX: u8 = 100;
65
66/// How many events are held before the oldest is dropped.
67pub const EVENT_QUEUE: usize = 8;
68
69/// An `AnnounceOTAProvider` that arrived (§11.20.7.6.1).
70///
71/// Everything the command carried, including the metadata — which borrows the invoke's own
72/// payload, and so is readable exactly while the application is being told about it.
73#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub struct Announcement<'a> {
75 /// The fabric the announcement came in on, which is the only one it applies to.
76 pub fabric_index: FabricIndex,
77 /// The node to query, "on the accessing fabric".
78 pub provider_node_id: NodeId,
79 /// "the endpoint number which has the OTA Provider device type and OTA Software Update
80 /// Provider cluster server on the ProviderNodeID".
81 pub endpoint: EndpointId,
82 /// "the assigned Vendor ID of the Node invoking this command".
83 pub vendor_id: VendorId,
84 /// Why the provider is speaking up, and so how soon to act.
85 pub reason: AnnouncementReasonEnum,
86 /// "a manufacturer-specific payload, which the Node invoking this command wants to expose
87 /// to the receiving Node".
88 pub metadata: Option<&'a [u8]>,
89}
90
91impl Announcement<'_> {
92 /// Where this announcement says to look, as a [`ProviderLocation`].
93 ///
94 /// Note what this is *not* for: §11.20.7.5 says an announcement "SHALL NOT overwrite values
95 /// set in the DefaultOTAProviders attribute", so this is somewhere to query now, not
96 /// somewhere to store.
97 #[must_use]
98 pub const fn location(&self) -> ProviderLocation {
99 ProviderLocation {
100 provider_node_id: self.provider_node_id,
101 endpoint: self.endpoint,
102 fabric_index: self.fabric_index,
103 }
104 }
105
106 /// Whether §11.20.7.4.1 says to query now rather than at the next scheduled time.
107 ///
108 /// `UrgentUpdateAvailable` is "an important security update, or just after initial
109 /// commissioning of a device"; the requestor "SHOULD query … after a random jitter delay
110 /// between 1 and 600 seconds", which is the application's to schedule.
111 #[must_use]
112 pub const fn is_urgent(&self) -> bool {
113 matches!(self.reason, AnnouncementReasonEnum::UrgentUpdateAvailable)
114 }
115}
116
117/// What the product does with an announcement.
118pub trait OtaRequestorHooks {
119 /// An `AnnounceOTAProvider` arrived (§11.20.7.6.1).
120 ///
121 /// > The receiving Node MAY ignore the content of the announcement if it is unable or
122 /// > unwilling to further query OTA Providers temporarily, or if its provider list is full.
123 /// > If the announcement is ignored, the response SHOULD be SUCCESS.
124 ///
125 /// So this returns nothing: there is no way to refuse, only to do nothing.
126 fn announced(&self, announcement: &Announcement<'_>) {
127 let _ = announcement;
128 }
129}
130
131/// A requestor that ignores announcements, which §11.20.7.6.1 explicitly permits.
132impl OtaRequestorHooks for () {}
133
134/// One of §11.20.7.7's three events, waiting to be recorded.
135#[derive(Debug, Clone, Copy, PartialEq, Eq)]
136pub enum Event {
137 /// `StateTransition` (§11.20.7.7.1), INFO — the `UpdateState` attribute changed.
138 StateTransition {
139 /// The state that preceded the transition, or `Unknown` if there was none.
140 previous: UpdateStateEnum,
141 /// The state now in effect.
142 new_state: UpdateStateEnum,
143 /// Why it changed.
144 reason: ChangeReasonEnum,
145 /// The version being worked on — non-null only while `Downloading`, `Applying` or
146 /// `RollingBack`.
147 target_software_version: Option<u32>,
148 },
149 /// `VersionApplied` (§11.20.7.7.2), CRITICAL — a new version is running.
150 VersionApplied {
151 /// "the same value as the one available in the SoftwareVersion attribute of the Basic
152 /// Information Cluster for the newly executing version".
153 software_version: u32,
154 /// "the ProductID applying to the executing version".
155 product_id: u16,
156 },
157 /// `DownloadError` (§11.20.7.7.3), INFO — a download failed.
158 DownloadError {
159 /// The version that was being downloaded.
160 software_version: u32,
161 /// How far the failed transfer got.
162 bytes_downloaded: u64,
163 /// "the nearest integer percent value" — null when the total length is unknown.
164 progress_percent: Option<u8>,
165 /// "some internal product-specific error code", or null.
166 platform_code: Option<i64>,
167 },
168}
169
170impl Event {
171 /// The event id this record carries (§11.20.7.7).
172 #[must_use]
173 pub const fn id(&self) -> crate::im::EventId {
174 match self {
175 Self::StateTransition { .. } => STATE_TRANSITION,
176 Self::VersionApplied { .. } => VERSION_APPLIED,
177 Self::DownloadError { .. } => DOWNLOAD_ERROR,
178 }
179 }
180}
181
182impl ToTlv for Event {
183 fn to_tlv(&self, w: &mut TlvWriter<'_>, tag: Tag) -> Result<()> {
184 w.start_structure(tag)?;
185 match *self {
186 Self::StateTransition {
187 previous,
188 new_state,
189 reason,
190 target_software_version,
191 } => {
192 w.unsigned(Tag::Context(0), u64::from(previous.value()))?;
193 w.unsigned(Tag::Context(1), u64::from(new_state.value()))?;
194 w.unsigned(Tag::Context(2), u64::from(reason.value()))?;
195 match target_software_version {
196 Some(version) => w.unsigned(Tag::Context(3), u64::from(version))?,
197 None => w.null(Tag::Context(3))?,
198 }
199 }
200 Self::VersionApplied {
201 software_version,
202 product_id,
203 } => {
204 w.unsigned(Tag::Context(0), u64::from(software_version))?;
205 w.unsigned(Tag::Context(1), u64::from(product_id))?;
206 }
207 Self::DownloadError {
208 software_version,
209 bytes_downloaded,
210 progress_percent,
211 platform_code,
212 } => {
213 w.unsigned(Tag::Context(0), u64::from(software_version))?;
214 w.unsigned(Tag::Context(1), bytes_downloaded)?;
215 match progress_percent {
216 Some(percent) => w.unsigned(Tag::Context(2), u64::from(percent))?,
217 None => w.null(Tag::Context(2))?,
218 }
219 match platform_code {
220 Some(code) => w.signed(Tag::Context(3), code)?,
221 None => w.null(Tag::Context(3))?,
222 }
223 }
224 }
225 w.end_container()
226 }
227}
228
229/// The OTA Software Update Requestor cluster (§11.20.7).
230///
231/// `N` is how many provider locations the node can hold at once, which §11.20.7.5 makes one per
232/// fabric — so a node that wants a provider for every fabric it supports sizes this at
233/// [`Config::FABRICS`](crate::Config::FABRICS).
234#[derive(Debug)]
235pub struct OtaRequestor<'a, H: OtaRequestorHooks, const N: usize> {
236 hooks: &'a H,
237 providers: RefCell<heapless::Vec<ProviderLocation, N>>,
238 possible: Cell<bool>,
239 state: Cell<UpdateStateEnum>,
240 progress: Cell<Option<u8>>,
241 events: RefCell<heapless::Vec<Event, EVENT_QUEUE>>,
242}
243
244impl<'a, H: OtaRequestorHooks, const N: usize> OtaRequestor<'a, H, N> {
245 /// A requestor with no providers configured, in §11.20.7.5's fallback state: an empty list
246 /// and `UpdatePossible` true.
247 ///
248 /// The initial `UpdateState` is `Unknown`, which §11.20.7.4.2 defines as "the current state
249 /// is not yet determined" — true of a device that has just booted and not yet decided
250 /// whether it is idle or rolling back.
251 #[must_use]
252 pub const fn new(hooks: &'a H) -> Self {
253 Self {
254 hooks,
255 providers: RefCell::new(heapless::Vec::new()),
256 possible: Cell::new(true),
257 state: Cell::new(UpdateStateEnum::Unknown),
258 progress: Cell::new(None),
259 events: RefCell::new(heapless::Vec::new()),
260 }
261 }
262
263 /// The descriptor for an instance, derived from the specification's tables.
264 pub fn conforming(feature_map: u32, optional: &Optional<'_>) -> Result<Conforming<4, 1, 0, 3>> {
265 Conforming::new(&spec_requestor::CLUSTER, feature_map, optional)
266 }
267
268 /// Every configured provider, for a device about to persist them (`N` is non-volatile).
269 #[must_use]
270 pub fn providers(&self) -> core::cell::Ref<'_, heapless::Vec<ProviderLocation, N>> {
271 self.providers.borrow()
272 }
273
274 /// The provider configured for one fabric, if any.
275 #[must_use]
276 pub fn provider_for(&self, fabric: FabricIndex) -> Option<ProviderLocation> {
277 self.providers
278 .borrow()
279 .iter()
280 .find(|p| p.fabric_index == fabric)
281 .copied()
282 }
283
284 /// Sets one fabric's provider, replacing whatever it had.
285 ///
286 /// §11.20.7.5 allows exactly one entry per fabric, so this replaces rather than appends —
287 /// there is no list to append to.
288 pub fn set_provider(&self, provider: ProviderLocation) -> core::result::Result<(), Status> {
289 if provider.fabric_index.0 == 0 {
290 return Err(Status::UnsupportedAccess);
291 }
292 let mut providers = self.providers.borrow_mut();
293 if let Some(slot) = providers
294 .iter_mut()
295 .find(|p| p.fabric_index == provider.fabric_index)
296 {
297 *slot = provider;
298 return Ok(());
299 }
300 providers
301 .push(provider)
302 .map_err(|_| Status::ResourceExhausted)
303 }
304
305 /// Forgets a fabric's provider — what `RemoveFabric` must do.
306 pub fn remove_fabric(&self, fabric: FabricIndex) {
307 self.providers
308 .borrow_mut()
309 .retain(|p| p.fabric_index != fabric);
310 }
311
312 /// `UpdatePossible` (§11.20.7.5).
313 #[must_use]
314 pub fn update_possible(&self) -> bool {
315 self.possible.get()
316 }
317
318 /// Says whether the device could take an update right now.
319 ///
320 /// > This field is merely informational for diagnostics purposes and SHALL NOT affect the
321 /// > responses provided by an OTA Provider to an OTA Requestor.
322 ///
323 /// So a device with a flat battery still asks, and still gets an answer; this is how a
324 /// controller finds out why nothing happened.
325 pub fn set_update_possible(&self, possible: bool) {
326 self.possible.set(possible);
327 }
328
329 /// `UpdateState` (§11.20.7.5).
330 #[must_use]
331 pub fn state(&self) -> UpdateStateEnum {
332 self.state.get()
333 }
334
335 /// `UpdateStateProgress` (§11.20.7.5), null when progress does not apply.
336 #[must_use]
337 pub fn progress(&self) -> Option<u8> {
338 self.progress.get()
339 }
340
341 /// Moves to a new state, recording §11.20.7.7.1's `StateTransition` event.
342 ///
343 /// Three rules land here rather than at every call site:
344 ///
345 /// * The event is generated "when a change of the UpdateState attribute occurs" — so a
346 /// transition to the state already in effect records nothing.
347 /// * `TargetSoftwareVersion` is set "whenever the NewState is Downloading, Applying or
348 /// RollingBack. Otherwise TargetSoftwareVersion SHALL be null" — a version passed for any
349 /// other state is dropped, not reported.
350 /// * `UpdateStateProgress` "SHALL be null if a progress indication does not apply to the
351 /// current state", and after a transition nothing has been reported about the new one.
352 pub fn transition(
353 &self,
354 new_state: UpdateStateEnum,
355 reason: ChangeReasonEnum,
356 target_software_version: Option<u32>,
357 ) {
358 let previous = self.state.get();
359 if previous == new_state {
360 return;
361 }
362 self.state.set(new_state);
363 self.progress.set(None);
364 self.push(Event::StateTransition {
365 previous,
366 new_state,
367 reason,
368 target_software_version: target_software_version
369 .filter(|_| Self::has_target(new_state)),
370 });
371 }
372
373 /// Reports progress within the current state (§11.20.7.5).
374 ///
375 /// "A value of 0 SHALL indicate that the beginning has occurred. A value of 100 SHALL
376 /// indicate completion." Anything past 100 is outside the attribute's constraint, and
377 /// [`Status::ConstraintError`] is what a write of it would earn.
378 pub fn set_progress(&self, percent: Option<u8>) -> core::result::Result<(), Status> {
379 if percent.is_some_and(|p| p > PROGRESS_MAX) {
380 return Err(Status::ConstraintError);
381 }
382 self.progress.set(percent);
383 Ok(())
384 }
385
386 /// Records §11.20.7.7.2's `VersionApplied`.
387 ///
388 /// > This event SHOULD be generated even if a software update was done using means outside
389 /// > of this cluster.
390 pub fn version_applied(&self, software_version: u32, product_id: u16) {
391 self.push(Event::VersionApplied {
392 software_version,
393 product_id,
394 });
395 }
396
397 /// Records §11.20.7.7.3's `DownloadError`, working out `ProgressPercent` from the transfer.
398 ///
399 /// `total` is the size of the transfer, when it was known — a BDX transfer with a definite
400 /// length ([`Parameters::length`](crate::bdx::Parameters::length)) has one, and an
401 /// indefinite one does not. "unless the total length of the transfer is unknown, in which
402 /// case it SHALL be null."
403 pub fn download_error(
404 &self,
405 software_version: u32,
406 bytes_downloaded: u64,
407 total: Option<u64>,
408 platform_code: Option<i64>,
409 ) {
410 self.push(Event::DownloadError {
411 software_version,
412 bytes_downloaded,
413 progress_percent: Self::percent(bytes_downloaded, total),
414 platform_code,
415 });
416 }
417
418 /// Takes the recorded events, for a device that turns them into §7.14 event records.
419 pub fn take_events(&self) -> heapless::Vec<Event, EVENT_QUEUE> {
420 core::mem::take(&mut self.events.borrow_mut())
421 }
422
423 /// "the nearest integer percent value reflecting how far within the transfer the failure
424 /// occurred", or null when there is nothing to be a percentage of.
425 fn percent(done: u64, total: Option<u64>) -> Option<u8> {
426 let total = total.filter(|t| *t != 0)?;
427 let scaled = done
428 .checked_mul(200)?
429 .checked_add(total)?
430 .checked_div(total.checked_mul(2)?)?;
431 u8::try_from(scaled.min(u64::from(PROGRESS_MAX))).ok()
432 }
433
434 /// §11.20.7.7.1: the three states a target version belongs to.
435 const fn has_target(state: UpdateStateEnum) -> bool {
436 matches!(
437 state,
438 UpdateStateEnum::Downloading | UpdateStateEnum::Applying | UpdateStateEnum::RollingBack
439 )
440 }
441
442 fn push(&self, event: Event) {
443 let mut events = self.events.borrow_mut();
444 if events.is_full() {
445 events.remove(0);
446 }
447 let _ = events.push(event);
448 }
449
450 /// Whether a fabric's entry belongs in this read (§7.19.1.8.2).
451 fn visible(ctx: &InteractionContext<'_>, index: FabricIndex) -> bool {
452 !ctx.fabric_filtered || ctx.fabric_index == Some(index)
453 }
454}
455
456impl<H: OtaRequestorHooks, const N: usize> ClusterHandler for OtaRequestor<'_, H, N> {
457 /// §11.20.7.5: `DefaultOTAProviders` is fabric-scoped, so a removed fabric's provider
458 /// goes with it — otherwise this node would still ask it for firmware.
459 fn on_lifecycle(&self, event: crate::im::Lifecycle) {
460 if let crate::im::Lifecycle::FabricRemoved(fabric) = event {
461 self.remove_fabric(fabric);
462 }
463 }
464 fn read(
465 &self,
466 resolved: &Resolved<'_>,
467 ctx: &InteractionContext<'_>,
468 w: &mut TlvWriter<'_>,
469 tag: Tag,
470 ) -> core::result::Result<(), Status> {
471 let full = |r: Result<()>| r.map_err(|_| Status::ResourceExhausted);
472 match resolved.attribute {
473 DEFAULT_OTA_PROVIDERS => {
474 let providers = self.providers.borrow();
475 full(w.start_array(tag))?;
476 for provider in providers
477 .iter()
478 .filter(|p| Self::visible(ctx, p.fabric_index))
479 {
480 full(provider.to_tlv(w, Tag::Anonymous))?;
481 }
482 full(w.end_container())
483 }
484 UPDATE_POSSIBLE => full(w.bool(tag, self.possible.get())),
485 UPDATE_STATE => full(w.unsigned(tag, u64::from(self.state.get().value()))),
486 UPDATE_STATE_PROGRESS => match self.progress.get() {
487 Some(percent) => full(w.unsigned(tag, u64::from(percent))),
488 None => full(w.null(tag)),
489 },
490 _ => Err(Status::UnsupportedAttribute),
491 }
492 }
493
494 fn write(
495 &self,
496 resolved: &Resolved<'_>,
497 data: &[u8],
498 op: WriteOp,
499 ctx: &InteractionContext<'_>,
500 ) -> core::result::Result<(), Status> {
501 if resolved.attribute != DEFAULT_OTA_PROVIDERS {
502 return Err(Status::UnsupportedWrite);
503 }
504 // §7.19.1.8.1: a fabric-scoped list needs an accessing fabric to scope the write to.
505 let Some(fabric_index) = ctx.fabric_index else {
506 return Err(Status::UnsupportedAccess);
507 };
508
509 let mut reader = TlvReader::new_in(data, ContainerKind::Structure);
510 let element = reader
511 .next_element()
512 .map_err(|_| Status::InvalidAction)?
513 .ok_or(Status::InvalidAction)?;
514
515 match op {
516 WriteOp::Replace => {
517 if element.value.container() != Some(ContainerKind::Array) {
518 return Err(Status::InvalidAction);
519 }
520 let mut replacement: Option<ProviderLocation> = None;
521 loop {
522 let Some(item) = reader.next_element().map_err(|_| Status::InvalidAction)?
523 else {
524 return Err(Status::InvalidAction);
525 };
526 if item.value == Value::EndOfContainer {
527 break;
528 }
529 let provider = decode_provider(&mut reader, &item, fabric_index)?;
530 // §11.20.7.5: "On a list update that would introduce more than one entry
531 // per fabric, the write SHALL fail with CONSTRAINT_ERROR status code."
532 if replacement.replace(provider).is_some() {
533 return Err(Status::ConstraintError);
534 }
535 }
536 let mut providers = self.providers.borrow_mut();
537 providers.retain(|p| p.fabric_index != fabric_index);
538 if let Some(provider) = replacement {
539 providers
540 .push(provider)
541 .map_err(|_| Status::ResourceExhausted)?;
542 }
543 Ok(())
544 }
545 WriteOp::Append => {
546 let provider = decode_provider(&mut reader, &element, fabric_index)?;
547 // One entry per fabric, so appending to a fabric that already has one is the
548 // same violation as sending two in a replace.
549 if self.provider_for(fabric_index).is_some() {
550 return Err(Status::ConstraintError);
551 }
552 self.set_provider(provider)
553 }
554 }
555 }
556
557 fn invoke(
558 &self,
559 resolved: &ResolvedCommand<'_>,
560 fields: Option<&[u8]>,
561 ctx: &InteractionContext<'_>,
562 _w: &mut TlvWriter<'_>,
563 _tag: Tag,
564 ) -> core::result::Result<Option<CommandId>, StatusIb> {
565 if resolved.command.id != ANNOUNCE_OTA_PROVIDER {
566 return Err(Status::UnsupportedCommand.into());
567 }
568 // §11.20.7.6.1: "If the accessing fabric index is 0, this command SHALL fail with an
569 // UNSUPPORTED_ACCESS status code." A provider that is on no fabric is announcing
570 // itself to a node that could never reach it.
571 let Some(fabric_index) = ctx.fabric_index.filter(|f| f.0 != 0) else {
572 return Err(Status::UnsupportedAccess.into());
573 };
574 let payload = fields.ok_or(StatusIb::from(Status::InvalidCommand))?;
575 let decoded: spec_requestor::AnnounceOTAProviderFields<'_> = super::decode_fields(payload)?;
576 if decoded
577 .metadata_for_node
578 .is_some_and(|m| m.len() > METADATA_MAX)
579 {
580 return Err(Status::ConstraintError.into());
581 }
582 self.hooks.announced(&Announcement {
583 fabric_index,
584 provider_node_id: decoded.provider_node_id,
585 endpoint: decoded.endpoint,
586 vendor_id: decoded.vendor_id,
587 reason: decoded.announcement_reason,
588 metadata: decoded.metadata_for_node,
589 });
590 // §11.20.7.5: an announcement "SHALL NOT overwrite values set in the
591 // DefaultOTAProviders attribute" — so nothing here touches the list. §11.20.7.6.1:
592 // "If the announcement is ignored, the response SHOULD be SUCCESS."
593 Ok(None)
594 }
595}
596
597/// Reads one `ProviderLocation`, stamped with the accessing fabric.
598///
599/// §7.19.1.8.1: "the FabricIndex field … SHALL be ignored" on a write, and the entry belongs to
600/// whoever wrote it. A client that names another fabric's index is not permitted to place an
601/// entry there.
602fn decode_provider<'a>(
603 reader: &mut TlvReader<'a>,
604 element: &crate::tlv::Element<'a>,
605 fabric_index: FabricIndex,
606) -> core::result::Result<ProviderLocation, Status> {
607 if element.value.container() != Some(ContainerKind::Structure) {
608 return Err(Status::InvalidAction);
609 }
610 let mut provider =
611 ProviderLocation::from_tlv(reader, element).map_err(|_| Status::InvalidAction)?;
612 provider.fabric_index = fabric_index;
613 Ok(provider)
614}
615
616/// So a tuple of clusters can dispatch to it by id.
617impl<H: OtaRequestorHooks, const N: usize> Cluster for OtaRequestor<'_, H, N> {
618 const ID: ClusterId = ID;
619}