Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit a3c42b2

Browse files
committed
Software Update continuation
-- Allow application to handle install if the platform has not provided an implementation. Platform/Application must call ImageInstallComplete public API to signal completion of image installation. -- Define a default value (1024) for WEAVE_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE in WeaveDeviceConfig.
1 parent 1637e18 commit a3c42b2

File tree

6 files changed

+74
-46
lines changed

6 files changed

+74
-46
lines changed

src/adaptations/device-layer/include/Weave/DeviceLayer/SoftwareUpdateManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ class SoftwareUpdateManager
222222

223223
WEAVE_ERROR Abort(void);
224224
WEAVE_ERROR CheckNow(void);
225-
WEAVE_ERROR ImageInstallComplete(void);
225+
WEAVE_ERROR ImageInstallComplete(WEAVE_ERROR aError);
226226
WEAVE_ERROR SetEventCallback(void * const aAppState, const EventCallback aEventCallback);
227227
WEAVE_ERROR SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs);
228228

@@ -394,9 +394,9 @@ inline WEAVE_ERROR SoftwareUpdateManager::CheckNow(void)
394394
return static_cast<ImplClass*>(this)->_CheckNow();
395395
}
396396

397-
inline WEAVE_ERROR SoftwareUpdateManager::ImageInstallComplete(void)
397+
inline WEAVE_ERROR SoftwareUpdateManager::ImageInstallComplete(WEAVE_ERROR aError)
398398
{
399-
return static_cast<ImplClass*>(this)->_ImageInstallComplete();
399+
return static_cast<ImplClass*>(this)->_ImageInstallComplete(aError);
400400
}
401401

402402
inline void SoftwareUpdateManager::OnPlatformEvent(const WeaveDeviceEvent * event)

src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,4 +892,11 @@
892892
#define WEAVE_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS 1*60*1000 // 1 minute
893893
#endif
894894

895+
/**
896+
* WEAVE_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE
897+
*
898+
* Specifies the block size to be used during software download over BDX.
899+
*/
900+
#define WEAVE_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE 1024
901+
895902
#endif // WEAVE_DEVICE_CONFIG_H

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericSoftwareUpdateManagerImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GenericSoftwareUpdateManagerImpl
6262

6363
WEAVE_ERROR _Abort(void);
6464
WEAVE_ERROR _CheckNow(void);
65-
WEAVE_ERROR _ImageInstallComplete(void);
65+
WEAVE_ERROR _ImageInstallComplete(WEAVE_ERROR aError);
6666
WEAVE_ERROR _SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs);
6767
WEAVE_ERROR _SetEventCallback(void * const aAppState, const SoftwareUpdateManager::EventCallback aEventCallback);
6868

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericSoftwareUpdateManagerImpl.ipp

Lines changed: 56 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_SetEventCallback(void
7777
mEventHandlerCallback = aEventCallback;
7878

7979
#if DEBUG
80-
// Verify that the application's event callback function correctly calls the default handler.
81-
//
82-
// NOTE: If your code receives WEAVE_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED it means that the event handler
83-
// function you supplied for the software update manager does not properly call SoftwareUpdateManager::DefaultEventHandler
84-
// for unrecognized/unhandled events.
85-
//
80+
/* Verify that the application's event callback function correctly calls the default handler.
81+
*
82+
* NOTE: If your code receives WEAVE_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED it means that the event handler
83+
* function you supplied for the software update manager does not properly call SoftwareUpdateManager::DefaultEventHandler
84+
* for unrecognized/unhandled events.
85+
*/
8686
{
8787
SoftwareUpdateManager::InEventParam inParam;
8888
SoftwareUpdateManager::OutEventParam outParam;
@@ -268,7 +268,7 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::SoftwareUpdateFailed(WEAVE_ERR
268268

269269
if (aError == WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED)
270270
{
271-
/**
271+
/*
272272
* No need to do anything since an abort by the application would have already
273273
* called SoftwareUpdateFinished with WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED error
274274
* and moved to Idle state.
@@ -400,10 +400,11 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::HandleResponse(ExchangeContext
400400
{
401401
GenericSoftwareUpdateManagerImpl<ImplClass> * self = &SoftwareUpdateMgrImpl();
402402

403-
// We expect to receive one of two possible responses:
404-
// 1. An Image Query Response message under the weave software update profile indicating
405-
// an update might be available or
406-
// 2. A status report indicating no software update available or a problem with the query.
403+
/* We expect to receive one of two possible responses:
404+
* 1. An Image Query Response message under the weave software update profile indicating
405+
* an update might be available or
406+
* 2. A status report indicating no software update available or a problem with the query.
407+
*/
407408
if (profileId == kWeaveProfile_SWU && msgType == kMsgType_ImageQueryResponse)
408409
{
409410
self->HandleImageQueryResponse(payload);
@@ -541,10 +542,12 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::DriveState(SoftwareUpdateManag
541542
{
542543
case SoftwareUpdateManager::kState_Idle:
543544
{
544-
// If scheduled software update check is enabled and service connectivity is present,
545-
// compute the next wait time interval and start the timer. Software Update Check
546-
// will trigger on expiration of the timer unless service connectivity was lost or
547-
// the application request a manual software update check.
545+
/* Compute the next wait time interval only if scheduled software update checks are
546+
* enabled or when the previous attempt failed provided service connectivity is
547+
* present. Start the timer once we have a valid interval. A Software Update Check
548+
* will trigger on expiration of the timer unless service connectivity was lost or
549+
* the application requested a manual software update check.
550+
*/
548551
if ((mScheduledCheckEnabled || mShouldRetry) && mHaveServiceConnectivity)
549552
{
550553
uint32_t timeToNextQueryMS = GetNextWaitTimeInterval();
@@ -827,18 +830,29 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::CheckImageIntegrity(void)
827830
{
828831
WEAVE_ERROR err = WEAVE_NO_ERROR;
829832
int result = 0;
833+
uint8_t typeLength = 0;
830834

831835
SoftwareUpdateManager::InEventParam inParam;
832836
SoftwareUpdateManager::OutEventParam outParam;
833837

834838
inParam.Clear();
835839
outParam.Clear();
836840

837-
838-
const uint8_t typeLength = (mIntegritySpec.type == kIntegrityType_SHA160) ? kLength_SHA160 :
839-
(mIntegritySpec.type == kIntegrityType_SHA256) ? kLength_SHA256 :
840-
(mIntegritySpec.type == kIntegrityType_SHA512) ? kLength_SHA512 :
841-
0;
841+
switch(mIntegritySpec.type)
842+
{
843+
case kIntegrityType_SHA160:
844+
typeLength = kLength_SHA160;
845+
break;
846+
case kIntegrityType_SHA256:
847+
typeLength = kLength_SHA256;
848+
break;
849+
case kIntegrityType_SHA512:
850+
typeLength = kLength_SHA512;
851+
break;
852+
default:
853+
typeLength = 0;
854+
break;
855+
}
842856

843857
uint8_t computedIntegrityValue[typeLength];
844858

@@ -865,9 +879,10 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::CheckImageIntegrity(void)
865879
exit:
866880
if (err != WEAVE_NO_ERROR && err != WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED)
867881
{
868-
// Since Image Integrity Validation failed, notify the application using an API event
869-
// to clear/invalidate the image from storage. This will make sure the image is downloaded from
870-
// scratch on the next attempt.
882+
/* Since Image Integrity Validation failed, notify the application using an API event
883+
* to clear/invalidate the image from storage. This will make sure the image is downloaded from
884+
* scratch on the next attempt.
885+
*/
871886
inParam.Clear();
872887
outParam.Clear();
873888

@@ -897,17 +912,22 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::StartImageInstall(void)
897912
VerifyOrExit(!mWasAborted, err = WEAVE_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED);
898913

899914
err = Impl()->InstallImage();
915+
if (err == WEAVE_ERROR_NOT_IMPLEMENTED)
916+
{
917+
/*
918+
* Since the platform does not provide a way to install the image, it is uptp
919+
* the application to do the install and call ImageInstallComplete API
920+
* to mark completion of image installation.
921+
*/
922+
err = WEAVE_NO_ERROR;
923+
}
900924
SuccessOrExit(err);
901925

902926
exit:
903927
if (err != WEAVE_NO_ERROR)
904928
{
905929
Impl()->SoftwareUpdateFailed(err, NULL);
906930
}
907-
else
908-
{
909-
Impl()->SoftwareUpdateFinished(WEAVE_NO_ERROR);
910-
}
911931
}
912932

913933
template<class ImplClass>
@@ -1009,16 +1029,19 @@ void GenericSoftwareUpdateManagerImpl<ImplClass>::DefaultRetryPolicyCallback(voi
10091029
}
10101030

10111031
template<class ImplClass>
1012-
WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_ImageInstallComplete(void)
1032+
WEAVE_ERROR GenericSoftwareUpdateManagerImpl<ImplClass>::_ImageInstallComplete(WEAVE_ERROR aError)
10131033
{
10141034
WEAVE_ERROR err = WEAVE_NO_ERROR;
10151035

1016-
VerifyOrExit(mState == SoftwareUpdateManager::kState_ApplicationManaged, err = WEAVE_ERROR_INCORRECT_STATE);
1017-
1018-
Impl()->SoftwareUpdateFinished(WEAVE_NO_ERROR);
1036+
if (mState == SoftwareUpdateManager::kState_ApplicationManaged || mState == SoftwareUpdateManager::kState_Install)
1037+
{
1038+
Impl()->SoftwareUpdateFinished(aError);
1039+
}
1040+
else
1041+
{
1042+
err = WEAVE_ERROR_INCORRECT_STATE;
1043+
}
10191044

1020-
DriveState(SoftwareUpdateManager::kState_Idle);
1021-
exit:
10221045
return err;
10231046
}
10241047

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericSoftwareUpdateManagerImpl_BDX.ipp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,15 @@ WEAVE_ERROR GenericSoftwareUpdateManagerImpl_BDX<ImplClass>::StartDownload(void)
110110
mBinding->Release();
111111
mBinding = NULL;
112112

113-
mBDXTransfer->mMaxBlockSize = WEAVE_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE;
114-
mBDXTransfer->mStartOffset = mStartOffset;
115-
116-
/**
113+
/*
117114
* This implementation only supports downloading a software image from an offset
118-
* provided by the application till the end of file. The 0 value below indicates
119-
* that expected length of the transfer is unknown by the initiator at this point
120-
* and hence the remainder of the file starting from the offset mentioned
121-
* above is expected to be downloaded in the transfer.
115+
* provided by the application till the end of file. The 0 value in mLength field
116+
* below indicates that expected length of the transfer is unknown by the initiator
117+
* at this point and hence the remainder of the file starting from the offset
118+
* mentioned above is expected to be downloaded in the transfer.
122119
*/
120+
mBDXTransfer->mMaxBlockSize = WEAVE_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE;
121+
mBDXTransfer->mStartOffset = mStartOffset;
123122
mBDXTransfer->mLength = 0;
124123

125124
err = mBDXClient.InitBdxReceive(*mBDXTransfer, true, false, false, NULL);

src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/SoftwareUpdateManagerImpl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class SoftwareUpdateManagerImpl final
6262
// ===== Members that implement the SoftwareUpdateManager abstract interface.
6363

6464
WEAVE_ERROR _Init(void);
65-
6665
};
6766

6867
/**

0 commit comments

Comments
 (0)