@@ -129,7 +129,7 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse
129
129
130
130
if (err != CHIP_NO_ERROR)
131
131
{
132
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kQuerying , err);
132
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kQuerying , err);
133
133
return ;
134
134
}
135
135
@@ -153,7 +153,7 @@ void OTARequestor::OnQueryImageResponse(void * context, const QueryImageResponse
153
153
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
154
154
break ;
155
155
default :
156
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kQuerying , CHIP_ERROR_BAD_REQUEST);
156
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kQuerying , CHIP_ERROR_BAD_REQUEST);
157
157
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
158
158
break ;
159
159
}
@@ -165,7 +165,7 @@ void OTARequestor::OnQueryImageFailure(void * context, EmberAfStatus status)
165
165
VerifyOrDie (requestorCore != nullptr );
166
166
167
167
ChipLogDetail (SoftwareUpdate, " QueryImage failure response %" PRIu8, status);
168
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kQuerying , CHIP_ERROR_BAD_REQUEST);
168
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kQuerying , CHIP_ERROR_BAD_REQUEST);
169
169
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
170
170
}
171
171
@@ -198,7 +198,19 @@ void OTARequestor::OnApplyUpdateFailure(void * context, EmberAfStatus status)
198
198
VerifyOrDie (requestorCore != nullptr );
199
199
200
200
ChipLogDetail (SoftwareUpdate, " ApplyUpdate failure response %" PRIu8, status);
201
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum::kApplying , CHIP_ERROR_BAD_REQUEST);
201
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState::kApplying , CHIP_ERROR_BAD_REQUEST);
202
+ SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
203
+ }
204
+
205
+ void OTARequestor::OnNotifyUpdateAppliedResponse (void * context, const app::DataModel::NullObjectType & response) {}
206
+
207
+ void OTARequestor::OnNotifyUpdateAppliedFailure (void * context, EmberAfStatus status)
208
+ {
209
+ OTARequestor * requestorCore = static_cast <OTARequestor *>(context);
210
+ VerifyOrDie (requestorCore != nullptr );
211
+
212
+ ChipLogDetail (SoftwareUpdate, " NotifyUpdateApplied failure response %" PRIu8, status);
213
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState::kNotifying , CHIP_ERROR_BAD_REQUEST);
202
214
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
203
215
}
204
216
@@ -287,7 +299,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
287
299
if (err != CHIP_NO_ERROR)
288
300
{
289
301
ChipLogError (SoftwareUpdate, " Failed to send QueryImage command: %" CHIP_ERROR_FORMAT, err.Format ());
290
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kQuerying , err);
302
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kQuerying , err);
291
303
return ;
292
304
}
293
305
@@ -300,7 +312,7 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
300
312
if (err != CHIP_NO_ERROR)
301
313
{
302
314
ChipLogError (SoftwareUpdate, " Failed to start download: %" CHIP_ERROR_FORMAT, err.Format ());
303
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kDownloading , err);
315
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kDownloading , err);
304
316
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
305
317
return ;
306
318
}
@@ -314,14 +326,28 @@ void OTARequestor::OnConnected(void * context, OperationalDeviceProxy * devicePr
314
326
if (err != CHIP_NO_ERROR)
315
327
{
316
328
ChipLogError (SoftwareUpdate, " Failed to send ApplyUpdate command: %" CHIP_ERROR_FORMAT, err.Format ());
317
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kApplying , err);
329
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kApplying , err);
318
330
SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
319
331
return ;
320
332
}
321
333
322
334
SetUpdateStateAttribute (OTAUpdateStateEnum::kApplying );
323
335
break ;
324
336
}
337
+ case kNotifyUpdateApplied : {
338
+ CHIP_ERROR err = requestorCore->SendNotifyUpdateAppliedRequest (*deviceProxy);
339
+
340
+ if (err != CHIP_NO_ERROR)
341
+ {
342
+ ChipLogError (SoftwareUpdate, " Failed to send NotifyUpdateApplied command: %" CHIP_ERROR_FORMAT, err.Format ());
343
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState::kNotifying , err);
344
+ SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
345
+ return ;
346
+ }
347
+
348
+ SetUpdateStateAttribute (OTAUpdateStateEnum::kIdle );
349
+ break ;
350
+ }
325
351
default :
326
352
break ;
327
353
}
@@ -339,13 +365,13 @@ void OTARequestor::OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR
339
365
switch (requestorCore->mOnConnectedAction )
340
366
{
341
367
case kQueryImage :
342
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kQuerying , error);
368
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kQuerying , error);
343
369
break ;
344
370
case kStartBDX :
345
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kDownloading , error);
371
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kDownloading , error);
346
372
break ;
347
373
case kApplyUpdate :
348
- requestorCore->mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kApplying , error);
374
+ requestorCore->mOtaRequestorDriver ->HandleError (UpdateFailureState ::kApplying , error);
349
375
break ;
350
376
default :
351
377
break ;
@@ -376,6 +402,11 @@ void OTARequestor::ApplyUpdate()
376
402
ConnectToProvider (kApplyUpdate );
377
403
}
378
404
405
+ void OTARequestor::NotifyUpdateApplied ()
406
+ {
407
+ ConnectToProvider (kNotifyUpdateApplied );
408
+ }
409
+
379
410
void OTARequestor::OnDownloadStateChanged (OTADownloader::State state)
380
411
{
381
412
VerifyOrReturn (mOtaRequestorDriver != nullptr );
@@ -386,7 +417,7 @@ void OTARequestor::OnDownloadStateChanged(OTADownloader::State state)
386
417
mOtaRequestorDriver ->UpdateDownloaded ();
387
418
break ;
388
419
case OTADownloader::State::kIdle :
389
- mOtaRequestorDriver ->HandleError (OTAUpdateStateEnum ::kDownloading , CHIP_ERROR_CONNECTION_ABORTED);
420
+ mOtaRequestorDriver ->HandleError (UpdateFailureState ::kDownloading , CHIP_ERROR_CONNECTION_ABORTED);
390
421
break ;
391
422
default :
392
423
break ;
@@ -398,6 +429,23 @@ void OTARequestor::OnUpdateProgressChanged(uint8_t percent)
398
429
OtaRequestorServerSetUpdateStateProgress (percent);
399
430
}
400
431
432
+ CHIP_ERROR OTARequestor::GenerateUpdateToken ()
433
+ {
434
+ if (mUpdateToken .empty ())
435
+ {
436
+ VerifyOrReturnError (mServer != nullptr , CHIP_ERROR_INCORRECT_STATE);
437
+
438
+ FabricInfo * fabricInfo = mServer ->GetFabricTable ().FindFabricWithIndex (mProviderFabricIndex );
439
+ VerifyOrReturnError (fabricInfo != nullptr , CHIP_ERROR_INCORRECT_STATE);
440
+
441
+ static_assert (sizeof (NodeId) == sizeof (uint64_t ), " Unexpected NodeId size" );
442
+ Encoding::BigEndian::Put64 (mUpdateTokenBuffer , fabricInfo->GetPeerId ().GetNodeId ());
443
+ mUpdateToken = ByteSpan (mUpdateTokenBuffer , sizeof (NodeId));
444
+ }
445
+
446
+ return CHIP_NO_ERROR;
447
+ }
448
+
401
449
CHIP_ERROR OTARequestor::SendQueryImageRequest (OperationalDeviceProxy & deviceProxy)
402
450
{
403
451
constexpr OTADownloadProtocol kProtocolsSupported [] = { OTADownloadProtocol::kBDXSynchronous };
@@ -488,19 +536,7 @@ CHIP_ERROR OTARequestor::StartDownload(OperationalDeviceProxy & deviceProxy)
488
536
489
537
CHIP_ERROR OTARequestor::SendApplyUpdateRequest (OperationalDeviceProxy & deviceProxy)
490
538
{
491
- if (mUpdateToken .empty ())
492
- {
493
- // OTA Requestor shall use its node ID as the update token in case the original update
494
- // token, received in QueryImageResponse, got lost.
495
- VerifyOrReturnError (mServer != nullptr , CHIP_ERROR_INCORRECT_STATE);
496
-
497
- FabricInfo * fabricInfo = mServer ->GetFabricTable ().FindFabricWithIndex (mProviderFabricIndex );
498
- VerifyOrReturnError (fabricInfo != nullptr , CHIP_ERROR_INCORRECT_STATE);
499
-
500
- static_assert (sizeof (NodeId) == sizeof (uint64_t ), " Unexpected NodeId size" );
501
- Encoding::BigEndian::Put64 (mUpdateTokenBuffer , fabricInfo->GetPeerId ().GetNodeId ());
502
- mUpdateToken = ByteSpan (mUpdateTokenBuffer , sizeof (NodeId));
503
- }
539
+ ReturnErrorOnFailure (GenerateUpdateToken ());
504
540
505
541
ApplyUpdateRequest::Type args;
506
542
args.updateToken = mUpdateToken ;
@@ -512,4 +548,18 @@ CHIP_ERROR OTARequestor::SendApplyUpdateRequest(OperationalDeviceProxy & deviceP
512
548
return cluster.InvokeCommand (args, this , OnApplyUpdateResponse, OnApplyUpdateFailure);
513
549
}
514
550
551
+ CHIP_ERROR OTARequestor::SendNotifyUpdateAppliedRequest (OperationalDeviceProxy & deviceProxy)
552
+ {
553
+ ReturnErrorOnFailure (GenerateUpdateToken ());
554
+
555
+ NotifyUpdateApplied::Type args;
556
+ args.updateToken = mUpdateToken ;
557
+ args.softwareVersion = mUpdateVersion ;
558
+
559
+ Controller::OtaSoftwareUpdateProviderCluster cluster;
560
+ cluster.Associate (&deviceProxy, mProviderEndpointId );
561
+
562
+ return cluster.InvokeCommand (args, this , OnNotifyUpdateAppliedResponse, OnNotifyUpdateAppliedFailure);
563
+ }
564
+
515
565
} // namespace chip
0 commit comments