diff --git a/src/include/platform/CHIPDeviceLayer.h b/src/include/platform/CHIPDeviceLayer.h index cce60cc6061ef6..73453f0bf77640 100644 --- a/src/include/platform/CHIPDeviceLayer.h +++ b/src/include/platform/CHIPDeviceLayer.h @@ -32,9 +32,6 @@ #include #include #include -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#include -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD diff --git a/src/include/platform/SoftwareUpdateManager.h b/src/include/platform/SoftwareUpdateManager.h deleted file mode 100644 index 2778fa7b765d1f..00000000000000 --- a/src/include/platform/SoftwareUpdateManager.h +++ /dev/null @@ -1,511 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Defines the public interface for the Device Layer SoftwareUpdateManager object. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -namespace chip { -namespace DeviceLayer { - -using namespace chip::TLV; - -class SoftwareUpdateManagerImpl; - -class SoftwareUpdateManager -{ - using ImplClass = SoftwareUpdateManagerImpl; - -public: - // ===== Members that define the public interface of the SoftwareUpdateManager - - enum State - { - kState_Idle = 1, - kState_ScheduledHoldoff = 2, - kState_PrepareQuery = 3, - kState_Query = 4, - kState_PrepareImageStorage = 5, - kState_Download = 6, - kState_Install = 7, - - kState_ApplicationManaged = 8, - - kState_MaxState - }; - - /** - * API events generated by the \c SoftwareUpdateManager object. - */ - enum EventType - { - /** - * Prepare ImageQuery message - * - * Generated when a software update check has been triggered. Provides an opportunity - * for the application to supply product related information to the - * SofwareUpdate:ImageQuery message. - */ - kEvent_PrepareQuery, - - /** - * Prepare meta-data for ImageQuery request - * - * Provides an opportunity for the application to append additional meta-data - * to the SofwareUpdate:ImageQuery message if needed. Generated when implementation - * is ready to get meta-data from the application. - */ - kEvent_PrepareQuery_Metadata, - - /** - * Error preparing an ImageQuery request - * - * Generated when the implementation encounters an error while preparing to send out - * a software update query. - */ - kEvent_QueryPrepareFailed, - - /** - * ImageQuery request has been sent - * - * Informational event to signal that a SofwareUpdate:ImageQuery message has been sent. - */ - kEvent_QuerySent, - - /** - * Software update is available - * - * Generated when a SofwareUpdate:ImageQueryResponse is received in response to - * a query containing information of the available update. - */ - kEvent_SoftwareUpdateAvailable, - - /** - * Fetch persisted state information for a partially downloaded image - * - * Provides an opportunity for the application to disclose information - * of a partial image previously downloaded so that the download - * may be continued from the point where it last stopped. URI of the available - * software update is provided as an input parameter that the application can use - * to compare if the image being downloaded is the same as the partial image. - * - * The application is expected to return the length of the partial image in the - * PartialImageLenInBytes output parameter. The application can set the value - * of PartialImageLenInBytes to 0 to indicate that no partial image exists or - * that the URI of the partial image does not match. - * - * The application may choose to ignore this event by passing it to the default - * event handler. If this is done, the system will always download the entirety - * of the available firmware image. - */ - kEvent_FetchPartialImageInfo, - - /** - * Prepare for storage of a new image - * - * Requests the application to perform any steps necessary to prepare local storage - * for the download of a new firmware image. The application can use this, for example, - * to erase flash pages. - * - * The PrepareImageStorage event is generated only in the case where a new firmware - * image is being downloaded. When a previously interrupted download is resumed, - * PrepareImageStorage is not generated. - * - * The application must signal completion of the prepare operation by calling the - * \c PrepareImageStorageComplete() method. It may do this within the event callback - * itself, or at a later time. If called from a task other than the chip task, - * the caller must hold the chip stack lock. - * - * The application can choose to ignore the PrepareImageStorage event by passing it - * to the default event handler. If this is done, the system automatically proceeds - * to the image download state. - * - * To support resuming an interrupted download, the application should persist the - * image URI (supplied as an event parameter), and use this when handling subsequent - * FetchPartialImageInfo events. - */ - kEvent_PrepareImageStorage, - - /** - * Image download has begun - * - * Informational event to signal the start of an image download transaction. - */ - kEvent_StartImageDownload, - - /** - * Store a block of image data - * - * Generated whenever a data block is received from the file download server. - * Parameters included with this event provide the data and the length of the data. - * - * To support resuming an interrupted download, the application should maintain a - * persistent count of the total number of image bytes stored, and use this value - * when handling subsequent FetchPartialImageInfo events. - */ - kEvent_StoreImageBlock, - - /** - * Compute an image integrity check value - * - * Requests the application to compute an integrity check value over the downloaded - * image. Generated once downloading is complete. - */ - kEvent_ComputeImageIntegrity, - - /** - * Reset state of partially downloaded image - * - * Requests the application to forget the persisted state associated with a downloaded - * image. A ResetPartialImageInfo event is generated whenever a downloaded image fails - * its integrity check. After a ResetPartialImageInfo event has been processed, - * subsequent FetchPartialImageInfo events should indicate that no partial image is - * available. - * - * Note that, when handling the ResetPartialImageInfo event, the application is NOT - * required to clear image data itself, only the state information associated with the - * image (i.e. the URI and partial image length). - * - * If the application does not support image download resumption, it may ignore this - * event by passing it to the default event handler. - */ - kEvent_ResetPartialImageInfo, - - /** - * Image is ready to be installed - * - * Informational event to signal that image is ready to be installed. - * Generated once an image passes the integrity check. - */ - kEvent_ReadyToInstall, - - /** - * Begin image installation - * - * Requests the application to being the process of installing a downloaded firmware - * image. - */ - kEvent_StartInstallImage, - - /** - * Software update process finished - * - * Generated when a software update check has finished with or without - * errors. Parameters included with this event provide the reason for failure - * if the attempt finished due to a failure. - */ - kEvent_Finished, - - /** - * Check default event handling behavior. - * - * Used to verify correct default event handling in the application. - * - * Applications must NOT handle this event. - */ - kEvent_DefaultCheck = 100, - - }; - - /** - * When a software update is available, the application can chose one of - * the following actions as part of the SoftwareUpdateAvailable API event - * callback. The default action will be set to kAction_Now. - */ - enum ActionType - { - /** - * Ignore the download completely. A kEvent_Finished API event callback will - * be generated with error CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_CANCELLED if - * this option is selected and the retry logic will not be invoked. - */ - kAction_Ignore, - - /** - * Start the download right away. A kEvent_FetchPartialImageInfo API event - * callback will be generated right after. - */ - kAction_DownloadNow, - - /** - * Pause download on start. Scheduled software update checks (if enabled) will be suspended. - * State machine will remain in Download state. When ready, application can - * call the resume download API to proceed with download or call Abort to cancel. - */ - kAction_DownloadLater, - - /** - * Allows application to manage the rest of the phases of software update such as - * download, image integrity validation and install. Software update manager - * state machine will move to the ApplicationManaged state. Scheduled software update checks (if enabled) - * will be suspended till application calls Abort or ImageInstallComplete API. - */ - kAction_ApplicationManaged, - }; - - /** - * Incoming parameters sent with events generated directly from this component - * - */ - union InEventParam; - - /** - * Outgoing parameters sent with events generated directly from this component - * - */ - union OutEventParam; - - struct RetryParam - { - /** - * Specifies the retry attempt number. - * It is reset on a successful software update attempt. - */ - uint32_t NumRetries; - }; - - typedef void (*EventCallback)(void * apAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam); - typedef void (*RetryPolicyCallback)(void * aAppState, RetryParam & aRetryParam, uint32_t & aOutIntervalMsec); - - CHIP_ERROR Abort(); - CHIP_ERROR CheckNow(); - CHIP_ERROR ImageInstallComplete(CHIP_ERROR aError); - CHIP_ERROR PrepareImageStorageComplete(CHIP_ERROR aError); - CHIP_ERROR SetEventCallback(void * aAppState, EventCallback aEventCallback); - CHIP_ERROR SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs); - - bool IsInProgress(); - - void SetRetryPolicyCallback(RetryPolicyCallback aRetryPolicyCallback); - - State GetState(); - - static void DefaultEventHandler(void * apAppState, EventType aEvent, const InEventParam & aInParam, OutEventParam & aOutParam); - -private: - // ===== Members for internal use by the following friends. - - // friend class SoftwareUpdateManagerImpl; - template - friend class Internal::GenericPlatformManagerImpl; - - CHIP_ERROR Init(); - -protected: - // Construction/destruction limited to subclasses. - SoftwareUpdateManager() = default; - ~SoftwareUpdateManager() = default; - - // No copy, move or assignment. - SoftwareUpdateManager(const SoftwareUpdateManager &) = delete; - SoftwareUpdateManager(const SoftwareUpdateManager &&) = delete; - SoftwareUpdateManager & operator=(const SoftwareUpdateManager &) = delete; -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * chip application should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -extern SoftwareUpdateManager & SoftwareUpdateMgr(); - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * chip applications can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the selected platform. - */ -extern SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(); - -} // namespace DeviceLayer -} // namespace chip - -/* Include a header file containing the implementation of the SoftwareUpdateManager - * object for the selected platform. - */ -#ifdef EXTERNAL_SOFTWAREUPDATEMANAGERIMPL_HEADER -#include EXTERNAL_SOFTWAREUPDATEMANAGERIMPL_HEADER -#else -#define SOFTWAREUPDATEMANAGERIMPL_HEADER -#include SOFTWAREUPDATEMANAGERIMPL_HEADER -#endif - -namespace chip { -namespace DeviceLayer { - -using namespace chip::TLV; - -union SoftwareUpdateManager::InEventParam -{ - void Clear() { memset(this, 0, sizeof(*this)); } - - SoftwareUpdateManager * Source; - struct - { - TLVWriter * MetaDataWriter; - } PrepareQuery_Metadata; - - struct - { - CHIP_ERROR Error; - } QueryPrepareFailed; - - struct - { - uint8_t IntegrityType; - const char * URI; - const char * Version; - } SoftwareUpdateAvailable; - - struct - { - const char * URI; - } FetchPartialImageInfo; - - struct - { - const char * URI; - uint8_t IntegrityType; - } PrepareImageStorage; - - struct - { - uint8_t * DataBlock; - uint32_t DataBlockLen; - } StoreImageBlock; - - struct - { - uint8_t IntegrityType; - uint8_t * IntegrityValueBuf; // Pointer to the buffer for the app to copy Integrity Value into. - uint8_t IntegrityValueBufLen; // Length of the provided buffer. - } ComputeImageIntegrity; - - struct - { - CHIP_ERROR Error; - } Finished; -}; - -union SoftwareUpdateManager::OutEventParam -{ - void Clear() { memset(this, 0, sizeof(*this)); } - - bool DefaultHandlerCalled; - struct - { - const char * PackageSpecification; - const char * DesiredLocale; - CHIP_ERROR Error; - } PrepareQuery; - - struct - { - CHIP_ERROR Error; - } PrepareQuery_Metadata; - - struct - { - ActionType Action; - } SoftwareUpdateAvailable; - - struct - { - uint64_t PartialImageLen; - } FetchPartialImageInfo; - - struct - { - CHIP_ERROR Error; - } StoreImageBlock; - - struct - { - CHIP_ERROR Error; - } ComputeImageIntegrity; -}; - -inline CHIP_ERROR SoftwareUpdateManager::Init() -{ - return static_cast(this)->_Init(); -} - -inline CHIP_ERROR SoftwareUpdateManager::CheckNow() -{ - return static_cast(this)->_CheckNow(); -} - -inline CHIP_ERROR SoftwareUpdateManager::ImageInstallComplete(CHIP_ERROR aError) -{ - return static_cast(this)->_ImageInstallComplete(aError); -} - -inline CHIP_ERROR SoftwareUpdateManager::PrepareImageStorageComplete(CHIP_ERROR aError) -{ - return static_cast(this)->_PrepareImageStorageComplete(aError); -} - -inline SoftwareUpdateManager::State SoftwareUpdateManager::GetState() -{ - return static_cast(this)->_GetState(); -} - -inline CHIP_ERROR SoftwareUpdateManager::Abort() -{ - return static_cast(this)->_Abort(); -} - -inline bool SoftwareUpdateManager::IsInProgress() -{ - return static_cast(this)->_IsInProgress(); -} - -inline CHIP_ERROR SoftwareUpdateManager::SetQueryIntervalWindow(uint32_t aMinRangeSecs, uint32_t aMaxRangeSecs) -{ - return static_cast(this)->_SetQueryIntervalWindow(aMinRangeSecs, aMaxRangeSecs); -} - -inline void SoftwareUpdateManager::SetRetryPolicyCallback(const RetryPolicyCallback aRetryPolicyCallback) -{ - static_cast(this)->_SetRetryPolicyCallback(aRetryPolicyCallback); -} - -inline CHIP_ERROR SoftwareUpdateManager::SetEventCallback(void * const aAppState, const EventCallback aEventCallback) -{ - return static_cast(this)->_SetEventCallback(aAppState, aEventCallback); -} - -inline void SoftwareUpdateManager::DefaultEventHandler(void * apAppState, EventType aEvent, const InEventParam & aInParam, - OutEventParam & aOutParam) -{ - ImplClass::_DefaultEventHandler(apAppState, aEvent, aInParam, aOutParam); -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/include/platform/SoftwareUpdateManagerImpl.h b/src/include/platform/SoftwareUpdateManagerImpl.h deleted file mode 100644 index 3b07219674a1a1..00000000000000 --- a/src/include/platform/SoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include - -namespace chip { -namespace DeviceLayer { - -/** - * Concrete implementation of the SoftwareUpdateManager singleton object for the - * nRF52 platforms. - */ -class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl -{ - // Allow the SoftwareUpdateManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class SoftwareUpdateManager; - - // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl; - -public: - // ===== Members for internal use by the following friends. - - friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(); - - static SoftwareUpdateManagerImpl sInstance; - -private: - // ===== Members that implement the SoftwareUpdateManager abstract interface. - - CHIP_ERROR _Init(); -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * Internal components should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -inline SoftwareUpdateManager & SoftwareUpdateMgr() -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * Internal components can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the nRF5 platform. - */ -inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl() -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp deleted file mode 100644 index b9aab7f843d718..00000000000000 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,1112 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Contains non-inline method definitions for the - * GenericSoftwareUpdateManagerImpl<> template. - */ - -#ifndef GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_CPP -#define GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_CPP - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -using namespace ::chip; -using namespace ::chip::TLV; - -#define LogEvent(...) -#define NullifyAllEventFields(...) - -// Fully instantiate the generic implementation class in whatever compilation unit includes this file. -template class GenericSoftwareUpdateManagerImpl; - -template -void GenericSoftwareUpdateManagerImpl::DoInit() -{ - mShouldRetry = false; - mScheduledCheckEnabled = false; - mIgnorePartialImage = false; - - mEventHandlerCallback = NULL; - mRetryPolicyCallback = DefaultRetryPolicyCallback; - - mRetryCounter = 0; - mMinWaitTimeMs = 0; - mMaxWaitTimeMs = 0; - - mState = SoftwareUpdateManager::kState_Idle; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_SetEventCallback(void * const aAppState, - const SoftwareUpdateManager::EventCallback aEventCallback) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - mAppState = aAppState; - mEventHandlerCallback = aEventCallback; - -#if DEBUG - /* Verify that the application's event callback function correctly calls the default handler. - * - * NOTE: If your code receives CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED it means that the event handler - * function you supplied for the software update manager does not properly call SoftwareUpdateManager::DefaultEventHandler - * for unrecognized/unhandled events. - */ - { - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - inParam.Clear(); - inParam.Source = &SoftwareUpdateMgrImpl(); - outParam.Clear(); - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_DefaultCheck, inParam, outParam); - VerifyOrExit(outParam.DefaultHandlerCalled, err = CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED); - } - -exit: -#endif - - return err; -} - -template -void GenericSoftwareUpdateManagerImpl::_SetRetryPolicyCallback( - const SoftwareUpdateManager::RetryPolicyCallback aRetryPolicyCallback) -{ - mRetryPolicyCallback = (aRetryPolicyCallback != NULL) ? aRetryPolicyCallback : DefaultRetryPolicyCallback; -} - -template -void GenericSoftwareUpdateManagerImpl::PrepareBinding(intptr_t arg) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - self->Cleanup(); -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::PrepareQuery(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - ImageQuery imageQuery; - TLVWriter writer; - TLVType containerType; - - QueryBeginEvent ev; - EventOptions evOptions(true); - - char firmwareRev[ConfigurationManager::kMaxFirmwareRevisionLength + 1]; - - size_t firmwareRevLen; - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - err = ConfigurationMgr().GetProductId(imageQuery.productSpec.productId); - SuccessOrExit(err); - - err = ConfigurationMgr().GetVendorId(imageQuery.productSpec.vendorId); - SuccessOrExit(err); - - err = ConfigurationMgr().GetProductRevision(imageQuery.productSpec.productRev); - SuccessOrExit(err); - - err = ConfigurationMgr().GetFirmwareRevision(firmwareRev, sizeof(firmwareRev), firmwareRevLen); - SuccessOrExit(err); - - NullifyAllEventFields(&ev); - evOptions.relatedEventID = mEventId; - ev.currentSwVersion = firmwareRev; - ev.vendorId = imageQuery.productSpec.vendorId; - ev.vendorProductId = imageQuery.productSpec.productId; - ev.productRevision = imageQuery.productSpec.productRev; - ev.SetCurrentSwVersionPresent(); - ev.SetVendorIdPresent(); - ev.SetVendorProductIdPresent(); - ev.SetProductRevisionPresent(); - - err = Impl()->GetUpdateSchemeList(&imageQuery.updateSchemes); - SuccessOrExit(err); - - err = Impl()->GetIntegrityTypeList(&imageQuery.integrityTypes); - SuccessOrExit(err); - - outParam.PrepareQuery.PackageSpecification = NULL; - outParam.PrepareQuery.DesiredLocale = NULL; - outParam.PrepareQuery.Error = CHIP_NO_ERROR; - - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_PrepareQuery, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_PrepareQuery, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - // Check for a preparation error returned by the application - err = outParam.PrepareQuery.Error; - SuccessOrExit(err); - - err = imageQuery.version.init((uint8_t) firmwareRevLen, firmwareRev); - SuccessOrExit(err); - - // Locale is an optional field in the CHIP software update protocol. If one is not provided by the application, - // then skip over and move to the next field. - if (outParam.PrepareQuery.DesiredLocale != NULL) - { - err = imageQuery.localeSpec.init((uint8_t) strlen(outParam.PrepareQuery.DesiredLocale), - (char *) outParam.PrepareQuery.DesiredLocale); - SuccessOrExit(err); - - ev.locale = outParam.PrepareQuery.DesiredLocale; - ev.SetLocalePresent(); - } - - // Package specification is an option field in the CHIP software update protocol. If one is not - // provided by the application, skip and move to the next field. - if (outParam.PrepareQuery.PackageSpecification != NULL) - { - err = imageQuery.packageSpec.init((uint8_t) strlen(outParam.PrepareQuery.PackageSpecification), - (char *) outParam.PrepareQuery.PackageSpecification); - SuccessOrExit(err); - } - - // Allocate a buffer to hold the image query. - mImageQueryPacketBuffer = PacketBufferHandle::New(PacketBuffer::kMaxSize); - VerifyOrExit(mImageQueryPacketBuffer != NULL, err = CHIP_ERROR_NO_MEMORY); - - err = imageQuery.pack(mImageQueryPacketBuffer); - SuccessOrExit(err); - - writer.Init(mImageQueryPacketBuffer); - - err = writer.StartContainer(AnonymousTag, kTLVType_Structure, containerType); - SuccessOrExit(err); - - inParam.Clear(); - outParam.Clear(); - - inParam.PrepareQuery_Metadata.MetaDataWriter = &writer; - outParam.PrepareQuery_Metadata.Error = CHIP_NO_ERROR; - - // Call EventHandler Callback to allow application to write meta-data. - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_PrepareQuery_Metadata, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_PrepareQuery, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - // Check for a preparation error returned by the application - err = outParam.PrepareQuery_Metadata.Error; - SuccessOrExit(err); - - err = writer.EndContainer(containerType); - SuccessOrExit(err); - - writer.Finalize(); - - LogEvent(&ev, evOptions); - -exit: - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_CheckNow(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrExit(mEventHandlerCallback != NULL, err = CHIP_ERROR_INCORRECT_STATE); - - if (!Impl()->IsInProgress()) - { - if (mState == SoftwareUpdateManager::kState_ScheduledHoldoff) - { - // Cancel scheduled hold off and trigger software update prepare. - DeviceLayer::SystemLayer().CancelTimer(HandleHoldOffTimerExpired, NULL); - } - - { - SoftwareUpdateStartEvent ev; - EventOptions evOptions(true); - ev.trigger = START_TRIGGER_USER_INITIATED; - mEventId = LogEvent(&ev, evOptions); - } - - DriveState(SoftwareUpdateManager::kState_PrepareQuery); - } - -exit: - return err; -} - -template -void GenericSoftwareUpdateManagerImpl::GetEventState(int32_t & aEventState) -{ - int32_t event_state = 0; - - switch (mState) - { - case SoftwareUpdateManager::kState_Idle: - case SoftwareUpdateManager::kState_ScheduledHoldoff: - event_state = STATE_IDLE; - break; - case SoftwareUpdateManager::kState_PrepareQuery: - case SoftwareUpdateManager::kState_Query: - event_state = STATE_QUERYING; - break; - case SoftwareUpdateManager::kState_Download: - event_state = STATE_DOWNLOADING; - break; - case SoftwareUpdateManager::kState_Install: - event_state = STATE_INSTALLING; - break; - default: - event_state = 0; - break; - } - - aEventState = event_state; -} - -template -void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFailed(CHIP_ERROR aError) -{ - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - if (aError == CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED) - { - /* - * No need to do anything since an abort by the application would have already - * called SoftwareUpdateFinished with CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED error - * and moved to Idle state. - */ - ExitNow(); - } - - mShouldRetry = true; - mRetryCounter++; - - { - FailureEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - GetEventState(ev.state); - evOptions.relatedEventID = mEventId; - - ev.platformReturnCode = aError; - ev.SetPrimaryStatusCodeNull(); - - ev.SetRemoteStatusCodeNull(); - - LogEvent(&ev, evOptions); - } - - if (mState == SoftwareUpdateManager::kState_PrepareQuery) - { - inParam.QueryPrepareFailed.Error = aError; - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_QueryPrepareFailed, inParam, outParam); - } - else - { - inParam.Finished.Error = aError; - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_Finished, inParam, outParam); - } - - DriveState(SoftwareUpdateManager::kState_Idle); - -exit: - return; -} - -template -void GenericSoftwareUpdateManagerImpl::SoftwareUpdateFinished(CHIP_ERROR aError) -{ - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - mShouldRetry = false; - mRetryCounter = 0; - - if (aError == CHIP_ERROR_NO_SW_UPDATE_AVAILABLE) - { - /* Log a Query Finish event with null fields - * as per the software update trait schema to indicate no update available. - */ - QueryFinishEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - evOptions.relatedEventID = mEventId; - LogEvent(&ev, evOptions); - } - else if (aError != CHIP_NO_ERROR) - { - /* Log a Failure event to indicate that software update finished - * because of an error. - */ - FailureEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - GetEventState(ev.state); - evOptions.relatedEventID = mEventId; - ev.platformReturnCode = aError; - LogEvent(&ev, evOptions); - } - - inParam.Finished.Error = aError; - inParam.Finished.StatusReport = NULL; - - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_Finished, inParam, outParam); - - DriveState(SoftwareUpdateManager::kState_Idle); -} - -template -bool GenericSoftwareUpdateManagerImpl::_IsInProgress(void) -{ - return ((mState == SoftwareUpdateManager::kState_Idle || mState == SoftwareUpdateManager::kState_ScheduledHoldoff) ? false - : true); -} - -template -void GenericSoftwareUpdateManagerImpl::SendQuery(void) -{ - CHIP_ERROR err; - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_QuerySent, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Query, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - -exit: - if (err != CHIP_NO_ERROR) - { - Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl::HandleStatusReport(PacketBuffer * payload) -{ - CHIP_ERROR err; - StatusReport statusReport; - - // Parse the status report to uncover the underlying errors. - err = StatusReport::parse(payload, statusReport); - - if (err != CHIP_NO_ERROR) - { - PacketBuffer::Free(payload); - Impl()->SoftwareUpdateFailed(err, NULL); - } - else if ((statusReport.mProfileId == kChipProfile_SWU) && (statusReport.mStatusCode == kStatus_NoUpdateAvailable)) - { - PacketBuffer::Free(payload); - Impl()->SoftwareUpdateFinished(CHIP_ERROR_NO_SW_UPDATE_AVAILABLE); - } - else - { - Impl()->SoftwareUpdateFailed(err, &statusReport); - PacketBuffer::Free(payload); // Release the buffer *after* the call since the statusReport - // object may contain a pointer to data in the buffer. - } -} - -template -void GenericSoftwareUpdateManagerImpl::HandleImageQueryResponse(PacketBuffer * payload) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - char versionString[ConfigurationManager::kMaxFirmwareRevisionLength + 1]; - - { - ImageQueryResponse imageQueryResponse; - - // Parse out the query response - err = ImageQueryResponse::parse(payload, imageQueryResponse); - SuccessOrExit(err); - - // Copy URI and version string since the original payload will be freed after this. - VerifyOrExit(imageQueryResponse.uri.theLength < CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN, - err = CHIP_ERROR_BUFFER_TOO_SMALL); - strncpy(mURI, imageQueryResponse.uri.theString, imageQueryResponse.uri.theLength); - mURI[imageQueryResponse.uri.theLength] = 0; - VerifyOrExit(imageQueryResponse.versionSpec.theLength < ArraySize(versionString), err = CHIP_ERROR_BUFFER_TOO_SMALL); - strncpy(versionString, imageQueryResponse.versionSpec.theString, imageQueryResponse.versionSpec.theLength); - versionString[imageQueryResponse.versionSpec.theLength] = 0; - - // Save the integrity spec - mIntegritySpec = imageQueryResponse.integritySpec; - - // Arrange to pass query response information to the application. - inParam.SoftwareUpdateAvailable.Priority = imageQueryResponse.updatePriority; - inParam.SoftwareUpdateAvailable.Condition = imageQueryResponse.updateCondition; - inParam.SoftwareUpdateAvailable.IntegrityType = imageQueryResponse.integritySpec.type; - inParam.SoftwareUpdateAvailable.Version = versionString; - inParam.SoftwareUpdateAvailable.URI = mURI; - } - - // Release the packet buffer. - PacketBuffer::Free(payload); - payload = NULL; - - // Log a QueryFinish event. - { - QueryFinishEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - evOptions.relatedEventID = mEventId; - ev.imageUrl = mURI; - ev.imageVersion = versionString; - ev.SetImageUrlPresent(); - ev.SetImageVersionPresent(); - LogEvent(&ev, evOptions); - } - - // Set DownloadNow as the default option. Application can override during event callback - outParam.SoftwareUpdateAvailable.Action = SoftwareUpdateManager::kAction_DownloadNow; - - // Tell the application that a software update is available. - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_SoftwareUpdateAvailable, inParam, outParam); - - // Check to see which action was selected by the application. - switch (outParam.SoftwareUpdateAvailable.Action) - { - case SoftwareUpdateManager::kAction_Ignore: - Impl()->SoftwareUpdateFinished(CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED); - break; - - case SoftwareUpdateManager::kAction_DownloadLater: - // TODO: Support DownloadLater SoftwareUpdateAvailable action - ExitNow(err = CHIP_ERROR_NOT_IMPLEMENTED); - break; - - case SoftwareUpdateManager::kAction_ApplicationManaged: - DriveState(SoftwareUpdateManager::kState_ApplicationManaged); - break; - - case SoftwareUpdateManager::kAction_DownloadNow: - - // If not ignoring partial images... - if (!mIgnorePartialImage) - { - inParam.Clear(); - outParam.Clear(); - - // Call the application to determine if a partially downloaded copy of the desired firmware image - // already exists in local storage. Pass the URI of the desired image, which must match the metadata - // stored with the image. - inParam.FetchPartialImageInfo.URI = mURI; - outParam.FetchPartialImageInfo.PartialImageLen = 0; - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_FetchPartialImageInfo, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Query, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - // If some part of the desired image has already been downloaded... - if (outParam.FetchPartialImageInfo.PartialImageLen != 0) - { - // Use the length of the partial image as the starting offset for the download. - mStartOffset = outParam.FetchPartialImageInfo.PartialImageLen; - - // Resume downloading the image. - DriveState(SoftwareUpdateManager::kState_Download); - - break; - } - } - - // Start downloading from the image from the beginning. - mStartOffset = 0; - - // Initiate the process of preparing local storage for new the image. - DriveState(SoftwareUpdateManager::kState_PrepareImageStorage); - - break; - - default: - ExitNow(err = CHIP_ERROR_INVALID_ARGUMENT); - break; - } - -exit: - PacketBuffer::Free(payload); - if (err != CHIP_NO_ERROR) - { - Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl::HandleHoldOffTimerExpired(::chip::System::Layer * aLayer, void * aAppState, - ::CHIP_ERROR aError) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - { - SoftwareUpdateStartEvent ev; - EventOptions evOptions(true); - ev.trigger = START_TRIGGER_SCHEDULED; - self->mEventId = LogEvent(&ev, evOptions); - } - - self->DriveState(SoftwareUpdateManager::kState_PrepareQuery); -} - -template -void GenericSoftwareUpdateManagerImpl::DriveState(SoftwareUpdateManager::State aNextState) -{ - if (mState != SoftwareUpdateManager::kState_Idle && - (aNextState == mState || aNextState >= SoftwareUpdateManager::kState_MaxState)) - { - ExitNow(); - } - - mState = aNextState; - - switch (mState) - { - case SoftwareUpdateManager::kState_Idle: { - /* Compute the next wait time interval only if scheduled software update checks are - * enabled or when the previous attempt failed provided service connectivity is - * present. Start the timer once we have a valid interval. A Software Update Check - * will trigger on expiration of the timer unless service connectivity was lost or - * the application requested a manual software update check. - */ - if (mScheduledCheckEnabled || mShouldRetry) - { - uint32_t timeToNextQueryMS = GetNextWaitTimeInterval(); - - // If timeToNextQueryMs is 0, then do nothing. - if (timeToNextQueryMS) - { - mState = SoftwareUpdateManager::kState_ScheduledHoldoff; - DeviceLayer::SystemLayer().StartTimer(timeToNextQueryMS, HandleHoldOffTimerExpired, NULL); - } - } - } - break; - - case SoftwareUpdateManager::kState_PrepareQuery: { - PlatformMgr().ScheduleWork(PrepareBinding); - } - break; - - case SoftwareUpdateManager::kState_Query: { - SendQuery(); - } - break; - - case SoftwareUpdateManager::kState_PrepareImageStorage: { - PrepareImageStorage(); - } - break; - - case SoftwareUpdateManager::kState_Download: { - PlatformMgr().ScheduleWork(StartDownload); - } - break; - - case SoftwareUpdateManager::kState_Install: { - StartImageInstall(); - } - break; - - default: - break; - } - -exit: - return; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - VerifyOrExit(mEventHandlerCallback != NULL, err = CHIP_ERROR_INCORRECT_STATE); - - if (aMaxWaitTimeMs == 0) - { - ChipLogProgress(DeviceLayer, "Scheduled Software Update Check Disabled"); - mScheduledCheckEnabled = false; - } - else - { - mMinWaitTimeMs = aMinWaitTimeMs; - mMaxWaitTimeMs = aMaxWaitTimeMs; - - mScheduledCheckEnabled = true; - } - - DriveState(SoftwareUpdateManager::kState_Idle); - -exit: - return err; -} - -template -uint32_t GenericSoftwareUpdateManagerImpl::GetNextWaitTimeInterval() -{ - uint32_t timeOutMsecs; - - if (mShouldRetry) - { - SoftwareUpdateManager::RetryParam param; - param.NumRetries = mRetryCounter; - - mRetryPolicyCallback(mAppState, param, timeOutMsecs); - - if (timeOutMsecs == 0) - { - if (mScheduledCheckEnabled && timeOutMsecs == 0) - { - /** If we have exceeded the max. no. retries, and scheduled queries - * are enabled, revert to using scheduled query intervals for computing - * wait time. - */ - timeOutMsecs = ComputeNextScheduledWaitTimeInterval(); - } - } - else - { - ChipLogProgress(DeviceLayer, "Retrying Software Update Check in %ums RetryCounter: %u", timeOutMsecs, mRetryCounter); - } - } - else - { - timeOutMsecs = ComputeNextScheduledWaitTimeInterval(); - } - - return timeOutMsecs; -} - -template -uint32_t GenericSoftwareUpdateManagerImpl::ComputeNextScheduledWaitTimeInterval(void) -{ - uint32_t timeOutMsecs = (mMinWaitTimeMs + (chip::Crypto::GetRandU32() % (mMaxWaitTimeMs - mMinWaitTimeMs))); - - ChipLogProgress(DeviceLayer, "Next Scheduled Software Update Check in %ums", timeOutMsecs); - - return timeOutMsecs; -} - -template -void GenericSoftwareUpdateManagerImpl::_DefaultEventHandler(void * apAppState, SoftwareUpdateManager::EventType aEvent, - const SoftwareUpdateManager::InEventParam & aInParam, - SoftwareUpdateManager::OutEventParam & aOutParam) -{ - // No actions required for current implementation - aOutParam.DefaultHandlerCalled = true; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::StoreImageBlock(uint32_t aLength, uint8_t * aData) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - inParam.StoreImageBlock.DataBlockLen = aLength; - inParam.StoreImageBlock.DataBlock = aData; - outParam.StoreImageBlock.Error = CHIP_NO_ERROR; - - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_StoreImageBlock, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Download, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - // Fail if the application didn't handle the StoreImageBlock event. - VerifyOrExit(!outParam.DefaultHandlerCalled, err = CHIP_ERROR_NOT_IMPLEMENTED); - - // Check if the application returned an error while storing an image block. - err = outParam.StoreImageBlock.Error; - SuccessOrExit(err); - -exit: - return err; -} - -template -void GenericSoftwareUpdateManagerImpl::PrepareImageStorage(void) -{ - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - // Call the application to begin the process of preparing local storage for the - // image to be downloaded. - inParam.Clear(); - outParam.Clear(); - inParam.PrepareImageStorage.URI = mURI; - inParam.PrepareImageStorage.IntegrityType = mIntegritySpec.type; - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_PrepareImageStorage, inParam, outParam); - - // If the application didn't handle the PrepareImageStorage event, immediately proceed to the - // download state. - if (outParam.DefaultHandlerCalled) - { - Impl()->PrepareImageStorageComplete(CHIP_NO_ERROR); - } -} - -template -void GenericSoftwareUpdateManagerImpl::StartDownload(intptr_t arg) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - self->mEventHandlerCallback(self->mAppState, SoftwareUpdateManager::kEvent_StartImageDownload, inParam, outParam); - VerifyOrExit(self->mState == SoftwareUpdateManager::kState_Download, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - err = self->Impl()->StartImageDownload(self->mURI, self->mStartOffset); - SuccessOrExit(err); - - { - DownloadStartEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - evOptions.relatedEventID = self->mEventId; - ev.imageUrl = self->mURI; - ev.offset = self->mStartOffset; - ev.SetImageUrlPresent(); - ev.SetOffsetPresent(); - LogEvent(&ev, evOptions); - } - -exit: - if (err != CHIP_NO_ERROR) - { - self->Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl::DownloadComplete() -{ - DownloadFinishEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - evOptions.relatedEventID = mEventId; - LogEvent(&ev, evOptions); - - // Download is complete. Check Image Integrity. - CheckImageIntegrity(); -} - -template -void GenericSoftwareUpdateManagerImpl::CheckImageIntegrity(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - int result = 0; - uint8_t typeLength = 0; - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - switch (mIntegritySpec.type) - { - case kIntegrityType_SHA160: - typeLength = kLength_SHA160; - break; - case kIntegrityType_SHA256: - typeLength = kLength_SHA256; - break; - case kIntegrityType_SHA512: - typeLength = kLength_SHA512; - break; - default: - typeLength = 0; - break; - } - - uint8_t computedIntegrityValue[typeLength]; - - inParam.ComputeImageIntegrity.IntegrityType = mIntegritySpec.type; - inParam.ComputeImageIntegrity.IntegrityValueBuf = computedIntegrityValue; - inParam.ComputeImageIntegrity.IntegrityValueBufLen = typeLength; - outParam.ComputeImageIntegrity.Error = CHIP_NO_ERROR; - - // Request the application to compute an integrity check value for the stored image. - // Fail if the application returns an error. - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_ComputeImageIntegrity, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Download, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - err = outParam.ComputeImageIntegrity.Error; - SuccessOrExit(err); - - // Verify the computed integrity value matches the expected value given - // in the SoftwareUpdate:ImageQueryResponse. - result = memcmp(computedIntegrityValue, mIntegritySpec.value, typeLength); - VerifyOrExit(result == 0, err = CHIP_ERROR_INTEGRITY_CHECK_FAILED); - - // Given that the integrity check succeeded, allow future software update attempts - // to restart an interrupted download. This turns off the defensive mechanism enabled - // below when an image fails its integrity check. - mIgnorePartialImage = false; - - // Tell the application that the image is ready to be installed. - inParam.Clear(); - outParam.Clear(); - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_ReadyToInstall, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Download, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - // Advance to the install state. - DriveState(SoftwareUpdateManager::kState_Install); - -exit: - if (err != CHIP_NO_ERROR && err != CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED) - { - /* Since image integrity validation failed, request the application to reset - * the persisted image state. This will make sure the image is downloaded from - * scratch on the next attempt. - */ - inParam.Clear(); - outParam.Clear(); - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_ResetPartialImageInfo, inParam, outParam); - err = (mState == SoftwareUpdateManager::kState_Download) ? CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED : err; - - // Arrange to ignore any partial image on the next software update attempt. - // This is a defensive measure against an infinite software update loop in the - // case where the application does not properly handle the ResetPartialImageInfo - // event. - mIgnorePartialImage = true; - - Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl::StartImageInstall(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - SoftwareUpdateManager::InEventParam inParam; - SoftwareUpdateManager::OutEventParam outParam; - - inParam.Clear(); - outParam.Clear(); - - mEventHandlerCallback(mAppState, SoftwareUpdateManager::kEvent_StartInstallImage, inParam, outParam); - VerifyOrExit(mState == SoftwareUpdateManager::kState_Install, err = CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - - { - /* Log an Install Start Event to indicate that software update - * install phase has started. The subsequent Install Finish Event - * should be logged by the application once image installation is complete - * and the device boots to the new image. If image installation fails and a - * rollback was performed, application must emit Image Rollback Event. It rollback - * is not a supported feature, application must emit a Failure Event. - */ - InstallStartEvent ev; - EventOptions evOptions(true); - NullifyAllEventFields(&ev); - evOptions.relatedEventID = mEventId; - LogEvent(&ev, evOptions); - } - - err = Impl()->InstallImage(); - if (err == CHIP_ERROR_NOT_IMPLEMENTED) - { - /* - * Since the platform does not provide a way to install the image, it is uptp - * the application to do the install and call ImageInstallComplete API - * to mark completion of image installation. - */ - err = CHIP_NO_ERROR; - } - SuccessOrExit(err); - -exit: - if (err != CHIP_NO_ERROR) - { - Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl::Cleanup(void) -{} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_Abort(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - if (mState == SoftwareUpdateManager::kState_Idle || mState == SoftwareUpdateManager::kState_ScheduledHoldoff) - { - err = CHIP_ERROR_INCORRECT_STATE; - } - else - { - if (mState == SoftwareUpdateManager::kState_Download) - { - Impl()->AbortDownload(); - } - - Cleanup(); - - Impl()->SoftwareUpdateFinished(CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED); - } - - return err; -} - -/** - * Default Policy: - */ -template -void GenericSoftwareUpdateManagerImpl::DefaultRetryPolicyCallback(void * const aAppState, - SoftwareUpdateManager::RetryParam & aRetryParam, - uint32_t & aOutIntervalMsec) -{ - GenericSoftwareUpdateManagerImpl * self = &SoftwareUpdateMgrImpl(); - - IgnoreUnusedVariable(aAppState); - - uint32_t fibonacciNum = 0; - uint32_t maxWaitTimeInMsec = 0; - uint32_t waitTimeInMsec = 0; - uint32_t minWaitTimeInMsec = 0; - - if (aRetryParam.NumRetries <= CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_RETRIES) - { - fibonacciNum = GetFibonacciForIndex(aRetryParam.NumRetries); - maxWaitTimeInMsec = fibonacciNum * CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS; - - if (self->mScheduledCheckEnabled && CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS > self->mMinWaitTimeMs) - { - waitTimeInMsec = 0; - maxWaitTimeInMsec = 0; - } - else - { - if (maxWaitTimeInMsec > CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS) - { - maxWaitTimeInMsec = CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS; - } - } - } - else - { - maxWaitTimeInMsec = 0; - } - - if (maxWaitTimeInMsec != 0) - { - minWaitTimeInMsec = (CHIP_DEVICE_CONFIG_SWU_MIN_WAIT_TIME_INTERVAL_PERCENT_PER_STEP * maxWaitTimeInMsec) / 100; - waitTimeInMsec = minWaitTimeInMsec + (chip::Crypto::GetRandU32() % (maxWaitTimeInMsec - minWaitTimeInMsec)); - - ChipLogDetail(DeviceLayer, - "Computing swu retry policy: attempts %" PRIu32 ", max wait time %" PRIu32 " ms, selected wait time %" PRIu32 - " ms", - aRetryParam.NumRetries, maxWaitTimeInMsec, waitTimeInMsec); - } - - aOutIntervalMsec = waitTimeInMsec; - - return; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_PrepareImageStorageComplete(CHIP_ERROR aError) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - // Fail if called in the wrong state. - VerifyOrExit(mState == SoftwareUpdateManager::kState_PrepareImageStorage, err = CHIP_ERROR_INCORRECT_STATE); - - // If the application completed the prepare process successfully, advance to the Download state. - // Otherwise, fail the software update attempt. - if (aError == CHIP_NO_ERROR) - { - DriveState(SoftwareUpdateManager::kState_Download); - } - else - { - Impl()->SoftwareUpdateFailed(aError, NULL); - } - -exit: - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::_ImageInstallComplete(CHIP_ERROR aError) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - - if (mState == SoftwareUpdateManager::kState_ApplicationManaged || mState == SoftwareUpdateManager::kState_Install) - { - Impl()->SoftwareUpdateFinished(aError); - } - else - { - err = CHIP_ERROR_INCORRECT_STATE; - } - - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl::InstallImage(void) -{ - return CHIP_ERROR_NOT_IMPLEMENTED; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#endif // GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_CPP diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h deleted file mode 100644 index 08a4a561973162..00000000000000 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,137 +0,0 @@ -/* - * - * Copyright (c) 2020-2021 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Provides an generic implementation of SoftwareUpdateManager features - * for use on various platforms. - */ - -#pragma once - -// #if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include - -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -using namespace chip::Inet; - -/** - * Provides a generic implementation of Software Update Manager features that works on multiple platforms. - * - * This template contains implementations of select features from the SoftwareUpdateManager abstract - * interface that are suitable for use on all platforms. It is intended to be inherited (directly - * or indirectly) by the SoftwareUpdateManagerImpl class, which also appears as the template's ImplClass - * parameter. - */ -template -class GenericSoftwareUpdateManagerImpl -{ - -protected: - // ===== Methods that implement the SoftwareUpdateManager abstract interface. - - bool _IsInProgress(); - SoftwareUpdateManager::State _GetState(); - - void _SetRetryPolicyCallback(SoftwareUpdateManager::RetryPolicyCallback aRetryPolicyCallback); - - static void _DefaultEventHandler(void * apAppState, SoftwareUpdateManager::EventType aEvent, - const SoftwareUpdateManager::InEventParam & aInParam, - SoftwareUpdateManager::OutEventParam & aOutParam); - - CHIP_ERROR _Abort(); - CHIP_ERROR _CheckNow(); - CHIP_ERROR _PrepareImageStorageComplete(CHIP_ERROR aError); - CHIP_ERROR _ImageInstallComplete(CHIP_ERROR aError); - CHIP_ERROR _SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs); - CHIP_ERROR _SetEventCallback(void * aAppState, SoftwareUpdateManager::EventCallback aEventCallback); - - // ===== Members for use by the implementation subclass. - - void DoInit(); - void DownloadComplete(); - void SoftwareUpdateFinished(CHIP_ERROR aError); - - CHIP_ERROR InstallImage(); - CHIP_ERROR StoreImageBlock(uint32_t aLength, uint8_t * aData); - -private: - // ===== Private members reserved for use by this class only. - - void Cleanup(); - void CheckImageState(); - void CheckImageIntegrity(); - void DriveState(SoftwareUpdateManager::State aNextState); - void GetEventState(int32_t & aEventState); - void HandleImageQueryResponse(chip::System::PacketBuffer * aPayload); - void SendQuery(); - void StartImageInstall(); - void PrepareImageStorage(); - - CHIP_ERROR PrepareQuery(); - - uint32_t GetNextWaitTimeInterval(); - uint32_t ComputeNextScheduledWaitTimeInterval(); - - static void PrepareBinding(intptr_t arg); - static void StartDownload(intptr_t arg); - static void HandleHoldOffTimerExpired(::chip::System::Layer * aLayer, void * aAppState, ::CHIP_ERROR aError); - static void DefaultRetryPolicyCallback(void * aAppState, SoftwareUpdateManager::RetryParam & aRetryParam, - uint32_t & aOutIntervalMsec); - - SoftwareUpdateManager::State mState; - - void * mAppState; - - char mURI[CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN]; - - SoftwareUpdateManager::EventCallback mEventHandlerCallback; - SoftwareUpdateManager::RetryPolicyCallback mRetryPolicyCallback; - - chip::System::PacketBuffer * mImageQueryPacketBuffer; - - bool mScheduledCheckEnabled; - bool mShouldRetry; - bool mIgnorePartialImage; - - uint64_t mNumBytesToDownload; - uint64_t mStartOffset; - - uint32_t mMinWaitTimeMs; - uint32_t mMaxWaitTimeMs; - uint32_t mEventId; - - uint16_t mRetryCounter; - - ImplClass * Impl() { return static_cast(this); } -}; - -// Instruct the compiler to instantiate the template only when explicitly told to do so. -extern template class Internal::GenericSoftwareUpdateManagerImpl; - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -// #endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.cpp b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.cpp deleted file mode 100644 index 5f5df418553dac..00000000000000 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Contains non-inline method definitions for the - * GenericSoftwareUpdateManagerImpl<> template. - */ - -#ifndef GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_BDX_CPP -#define GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_BDX_CPP - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include -#include -#include -#include - -namespace chip { -namespace DeviceLayer { -namespace Internal { - -using namespace ::chip::TLV; -using namespace ::chip::Profiles; -using namespace ::chip::Profiles::Common; -using namespace ::chip::Profiles::BulkDataTransfer; - -// Fully instantiate the generic implementation class in whatever compilation unit includes this file. -template class GenericSoftwareUpdateManagerImpl_BDX; - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl_BDX::DoInit(void) -{ - CHIP_ERROR err; - - mBinding = NULL; - mURI = NULL; - mBDXTransfer = NULL; - mStartOffset = 0; - - err = mBDXClient.Init(&ExchangeMgr); - - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl_BDX::StartImageDownload(char * aURI, uint64_t aStartOffset) -{ - CHIP_ERROR err; - - VerifyOrExit(aURI != NULL, err = CHIP_ERROR_INVALID_ARGUMENT); - - mURI = aURI; - mStartOffset = aStartOffset; - - mBinding = ExchangeMgr.NewBinding(HandleBindingEvent, NULL); - VerifyOrExit(mBinding != NULL, err = CHIP_ERROR_NO_MEMORY); - - err = mBinding->BeginConfiguration() - .Target_ServiceEndpoint(CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_ENDPOINT_ID) - .Transport_UDP_WRM() - .Exchange_ResponseTimeoutMsec(CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_RESPOSNE_TIMEOUT) - .Security_SharedCASESession() - .PrepareBinding(); - -exit: - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl_BDX::StartDownload(void) -{ - CHIP_ERROR err; - - ReferencedString uri; - uri.init((uint16_t) strlen(mURI), mURI); - - BDXHandlers handlers = { - NULL, // SendAcceptHandler - ReceiveAcceptHandler, - ReceiveRejectHandler, - NULL, // GetBlockHandler - BlockReceiveHandler, - XferErrorHandler, - XferDoneHandler, - ErrorHandler, - }; - - VerifyOrExit(mBDXTransfer == NULL, err = CHIP_ERROR_INCORRECT_STATE); - - err = mBDXClient.NewTransfer(mBinding, handlers, uri, this, mBDXTransfer); - SuccessOrExit(err); - - // Release our reference to the binding, as it's no longer needed. - mBinding->Release(); - mBinding = NULL; - - /* - * This implementation only supports downloading a software image from an offset - * provided by the application till the end of file. The 0 value in mLength field - * below indicates that expected length of the transfer is unknown by the initiator - * at this point and hence the remainder of the file starting from the offset - * mentioned above is expected to be downloaded in the transfer. - */ - mBDXTransfer->mMaxBlockSize = CHIP_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE; - mBDXTransfer->mStartOffset = mStartOffset; - mBDXTransfer->mLength = 0; - - err = mBDXClient.InitBdxReceive(*mBDXTransfer, true, false, false, NULL); - SuccessOrExit(err); - -exit: - if (err != CHIP_NO_ERROR) - { - ResetState(); - } - return err; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl_BDX::ReceiveAcceptHandler(BDXTransfer * aXfer, - ReceiveAccept * aReceiveAcceptMsg) -{ - return CHIP_NO_ERROR; -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::ReceiveRejectHandler(BDXTransfer * aXfer, StatusReport * aReport) -{ - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - // Release all resources. - self->ResetState(); - - // If the BDX transfer was rejected by the server with a status report containing status code - // kStatus_LengthMismatch, it specifically means that the start offset requested by the application - // in the BDX request is greater than or equal to the length of the file being downloaded. In the context - // of this implementation, it means that file download is complete since the end of file has already been - // reached. - // - if (aReport->mProfileId == kChipProfile_BDX && aReport->mStatusCode == kStatus_LengthMismatch) - { - self->Impl()->DownloadComplete(); - } - else - { - self->Impl()->SoftwareUpdateFailed(CHIP_ERROR_STATUS_REPORT_RECEIVED, aReport); - } -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::BlockReceiveHandler(BDXTransfer * xfr, uint64_t aLength, uint8_t * aDataBlock, - bool aIsLastBlock) -{ - CHIP_ERROR err; - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - err = self->Impl()->StoreImageBlock(aLength, aDataBlock); - if (err == CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED) - { - return; - } - else if (err != CHIP_NO_ERROR) - { - self->ResetState(); - self->Impl()->SoftwareUpdateFailed(err, NULL); - } -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::XferErrorHandler(BDXTransfer * aXfer, StatusReport * aReport) -{ - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - self->ResetState(); - self->Impl()->SoftwareUpdateFailed(CHIP_ERROR_STATUS_REPORT_RECEIVED, aReport); -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::XferDoneHandler(BDXTransfer * aXfer) -{ - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - self->ResetState(); - self->Impl()->DownloadComplete(); -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::ErrorHandler(BDXTransfer * aXfer, CHIP_ERROR aErrorCode) -{ - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - self->ResetState(); - self->Impl()->SoftwareUpdateFailed(aErrorCode, NULL); -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::HandleBindingEvent(void * appState, ::chip::Binding::EventType aEvent, - const ::chip::Binding::InEventParam & aInParam, - ::chip::Binding::OutEventParam & aOutParam) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - StatusReport * statusReport = NULL; - GenericSoftwareUpdateManagerImpl_BDX * self = &SoftwareUpdateMgrImpl(); - - switch (aEvent) - { - case chip::Binding::kEvent_PrepareFailed: - ChipLogProgress( - DeviceLayer, "Failed to prepare Software Update BDX binding: %s", - (aInParam.PrepareFailed.Reason == CHIP_ERROR_STATUS_REPORT_RECEIVED) - ? StatusReportStr(aInParam.PrepareFailed.StatusReport->mProfileId, aInParam.PrepareFailed.StatusReport->mStatusCode) - : ErrorStr(aInParam.PrepareFailed.Reason)); - statusReport = aInParam.PrepareFailed.StatusReport; - err = aInParam.PrepareFailed.Reason; - break; - - case chip::Binding::kEvent_BindingFailed: - ChipLogProgress(DeviceLayer, "Software Update BDX binding failed: %s", ErrorStr(aInParam.BindingFailed.Reason)); - err = aInParam.PrepareFailed.Reason; - break; - - case chip::Binding::kEvent_BindingReady: - ChipLogProgress(DeviceLayer, "Software Update BDX binding ready"); - err = self->StartDownload(); - break; - - default: - chip::Binding::DefaultEventHandler(appState, aEvent, aInParam, aOutParam); - } - - if (err != CHIP_NO_ERROR) - { - self->ResetState(); - self->Impl()->SoftwareUpdateFailed(err, statusReport); - } -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::AbortDownload(void) -{ - ResetState(); -} - -template -void GenericSoftwareUpdateManagerImpl_BDX::ResetState(void) -{ - if (mBinding != NULL) - { - mBinding->Release(); - mBinding = NULL; - } - mURI = NULL; - if (mBDXTransfer) - { - mBDXTransfer->Shutdown(); - mBDXTransfer = NULL; - } - mStartOffset = 0; -} - -template -CHIP_ERROR GenericSoftwareUpdateManagerImpl_BDX::GetUpdateSchemeList( - ::chip::Profiles::SoftwareUpdate::UpdateSchemeList * aUpdateSchemeList) -{ - uint8_t supportedSchemes[] = { Profiles::SoftwareUpdate::kUpdateScheme_BDX }; - aUpdateSchemeList->init(ArraySize(supportedSchemes), supportedSchemes); - - return CHIP_NO_ERROR; -} - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER -#endif // GENERIC_SOFTWARE_UPDATE_MANAGER_IMPL_BDX_CPP diff --git a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h b/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h deleted file mode 100644 index 0acb728c5ab19b..00000000000000 --- a/src/include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file - * Provides an generic implementation of SoftwareUpdateManager features - * for use on platforms that support BDX. - */ - -#pragma once - -#include -#include - -namespace chip { -namespace DeviceLayer { - -class SoftwareUpdateManagerImpl; - -namespace Internal { - -/** - * Provides a generic implementation of SoftwareUpdateManager features for - * use on platforms that support BDX. - * - * This class is intended to be inherited (directly or indirectly) by the SoftwareUpdateManagerImpl - * class, which also appears as the template's ImplClass parameter. - * - */ - -template -class GenericSoftwareUpdateManagerImpl_BDX -{ - using BDXTransfer = ::chip::Profiles::BulkDataTransfer::BDXTransfer; - using BDXNode = ::chip::Profiles::BulkDataTransfer::BdxNode; - using ReceiveAccept = ::chip::Profiles::BulkDataTransfer::ReceiveAccept; - -protected: - // ===== Members for use by the implementation subclass. - - CHIP_ERROR DoInit(void); - CHIP_ERROR StartImageDownload(char * aURI, uint64_t aStartOffset); - CHIP_ERROR GetUpdateSchemeList(::chip::Profiles::SoftwareUpdate::UpdateSchemeList * aUpdateSchemeList); - void AbortDownload(void); - -private: - // ===== Private members reserved for use by this class only. - - CHIP_ERROR PrepareBinding(void); - CHIP_ERROR StartDownload(void); - void ResetState(void); - - static void BlockReceiveHandler(BDXTransfer * aXfer, uint64_t alength, uint8_t * aDataBlock, bool aIsLastBlock); - static void ErrorHandler(BDXTransfer * aXfer, CHIP_ERROR anErrorCode); - static CHIP_ERROR ReceiveAcceptHandler(BDXTransfer * aXfer, ReceiveAccept * aEeceiveAcceptMsg); - static void ReceiveRejectHandler(BDXTransfer * aXfer, chip::StatusReport * aReport); - static void XferErrorHandler(BDXTransfer * aXfer, ::chip::StatusReport * aXferError); - static void XferDoneHandler(BDXTransfer * aXfer); - - static void HandleBindingEvent(void * apAppState, ::chip::Binding::EventType aEvent, - const ::chip::Binding::InEventParam & aInParam, ::chip::Binding::OutEventParam & aOutParam); - - ImplClass * Impl() { return static_cast(this); } - - ::chip::Binding * mBinding; - char * mURI; - - BDXNode mBDXClient; - BDXTransfer * mBDXTransfer; - - uint64_t mStartOffset; -}; - -// Instruct the compiler to instantiate the template only when explicitly told to do so. -extern template class GenericSoftwareUpdateManagerImpl_BDX; - -} // namespace Internal -} // namespace DeviceLayer -} // namespace chip diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index c95ecac1742e5e..ef518e59833ffe 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -256,7 +256,6 @@ if (chip_device_platform != "none") { "../include/platform/KeyValueStoreManager.h", "../include/platform/PersistedStorage.h", "../include/platform/PlatformManager.h", - "../include/platform/SoftwareUpdateManagerImpl.h", "../include/platform/ThreadStackManager.h", "../include/platform/internal/BLEManager.h", "../include/platform/internal/CHIPDeviceLayerInternal.h", @@ -275,8 +274,6 @@ if (chip_device_platform != "none") { "../include/platform/internal/GenericPlatformManagerImpl.h", "../include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h", "../include/platform/internal/GenericPlatformManagerImpl_POSIX.h", - "../include/platform/internal/GenericSoftwareUpdateManagerImpl.h", - "../include/platform/internal/GenericSoftwareUpdateManagerImpl_BDX.h", "../include/platform/internal/testing/ConfigUnitTest.h", "DeviceControlServer.cpp", "Entropy.cpp", diff --git a/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp b/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp deleted file mode 100644 index 993a009ea7b890..00000000000000 --- a/src/platform/EFR32/SoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* this file behaves like a config.h, comes first */ -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { - -SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; - -CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) -{ - Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); - Internal::GenericSoftwareUpdateManagerImpl::DoInit(); - - return CHIP_NO_ERROR; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/EFR32/SoftwareUpdateManagerImpl.h b/src/platform/EFR32/SoftwareUpdateManagerImpl.h deleted file mode 100644 index e3e55c34fa4c7c..00000000000000 --- a/src/platform/EFR32/SoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -namespace chip { -namespace DeviceLayer { - -/** - * Concrete implementation of the SoftwareUpdateManager singleton object for the - * Silicon Labs EFR32 platforms. - */ -class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl, - public Internal::GenericSoftwareUpdateManagerImpl_BDX -{ - // Allow the SoftwareUpdateManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class SoftwareUpdateManager; - - // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl; - - // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl_BDX; - -public: - // ===== Members for internal use by the following friends. - - friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); - - static SoftwareUpdateManagerImpl sInstance; - -private: - // ===== Members that implement the SoftwareUpdateManager abstract interface. - - CHIP_ERROR _Init(void); -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * Internal components should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -inline SoftwareUpdateManager & SoftwareUpdateMgr(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * Internal components can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the EFR32 platform. - */ -inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/ESP32/BUILD.gn b/src/platform/ESP32/BUILD.gn index d43cdb84d6cc20..175b83e29267ed 100644 --- a/src/platform/ESP32/BUILD.gn +++ b/src/platform/ESP32/BUILD.gn @@ -40,7 +40,6 @@ static_library("ESP32") { "LwIPCoreLock.cpp", "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", - "SoftwareUpdateManagerImpl.h", "SystemTimeSupport.cpp", "bluedroid/BLEManagerImpl.cpp", "nimble/BLEManagerImpl.cpp", diff --git a/src/platform/ESP32/SoftwareUpdateManagerImpl.cpp b/src/platform/ESP32/SoftwareUpdateManagerImpl.cpp deleted file mode 100644 index f5b0b02b4053ab..00000000000000 --- a/src/platform/ESP32/SoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* this file behaves like a config.h, comes first */ -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { - -SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; - -CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) -{ - Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); - Internal::GenericSoftwareUpdateManagerImpl::DoInit(); - - return CHIP_NO_ERROR; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/ESP32/SoftwareUpdateManagerImpl.h b/src/platform/ESP32/SoftwareUpdateManagerImpl.h deleted file mode 100644 index 4d941cba97dfe1..00000000000000 --- a/src/platform/ESP32/SoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -namespace chip { -namespace DeviceLayer { - -/** - * Concrete implementation of the SoftwareUpdateManager singleton object for the - * ESP32 platforms. - */ -class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl, - public Internal::GenericSoftwareUpdateManagerImpl_BDX -{ - // Allow the SoftwareUpdateManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class SoftwareUpdateManager; - - // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl; - - // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl_BDX; - -public: - // ===== Members for internal use by the following friends. - - friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); - - static SoftwareUpdateManagerImpl sInstance; - -private: - // ===== Members that implement the SoftwareUpdateManager abstract interface. - - CHIP_ERROR _Init(void); -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * Internal components should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -inline SoftwareUpdateManager & SoftwareUpdateMgr(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * Internal components can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the ESP32 platform. - */ -inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp index 98a8f28bed50a2..d0492d7f74ff3c 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.cpp @@ -73,6 +73,8 @@ using namespace chip::app; using namespace chip::app::Clusters; using namespace chip::app::DataModel; +using chip::Inet::IPPrefix; + namespace chip { namespace DeviceLayer { namespace Internal { @@ -114,7 +116,7 @@ void GenericThreadStackManagerImpl_OpenThread::_ProcessThreadActivity } template -bool GenericThreadStackManagerImpl_OpenThread::_HaveRouteToAddress(const IPAddress & destAddr) +bool GenericThreadStackManagerImpl_OpenThread::_HaveRouteToAddress(const Inet::IPAddress & destAddr) { bool res = false; diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp index 63e760a05e5677..974808351f4759 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread_LwIP.cpp @@ -176,7 +176,7 @@ void GenericThreadStackManagerImpl_OpenThread_LwIP::UpdateThreadInter const otNetifAddress * otAddrs = otIp6GetUnicastAddresses(Impl()->OTInstance()); for (const otNetifAddress * otAddr = otAddrs; otAddr != NULL; otAddr = otAddr->mNext) { - IPAddress addr = ToIPAddress(otAddr->mAddress); + Inet::IPAddress addr = ToIPAddress(otAddr->mAddress); // Assign the following OpenThread addresses to LwIP's address table: // - link-local addresses. @@ -247,7 +247,7 @@ void GenericThreadStackManagerImpl_OpenThread_LwIP::UpdateThreadInter uint8_t state = netif_ip6_addr_state(mNetIf, addrIdx); if (state != IP6_ADDR_INVALID) { - IPAddress addr = IPAddress::FromIPv6(*netif_ip6_addr(mNetIf, addrIdx)); + Inet::IPAddress addr = Inet::IPAddress::FromIPv6(*netif_ip6_addr(mNetIf, addrIdx)); char addrStr[50]; addr.ToString(addrStr, sizeof(addrStr)); const char * typeStr; diff --git a/src/platform/OpenThread/OpenThreadUtils.cpp b/src/platform/OpenThread/OpenThreadUtils.cpp index 3396469001a31c..659107946bc4f9 100644 --- a/src/platform/OpenThread/OpenThreadUtils.cpp +++ b/src/platform/OpenThread/OpenThreadUtils.cpp @@ -24,6 +24,7 @@ #include "OpenThreadUtils.h" +#include #include #include #include @@ -171,7 +172,7 @@ void LogOpenThreadPacket(const char * titleStr, otMessage * pkt) char srcStr[50], destStr[50], typeBuf[20]; const char * type = typeBuf; - IPAddress addr; + Inet::IPAddress addr; uint8_t headerData[44]; uint16_t pktLen; @@ -248,7 +249,7 @@ void LogOpenThreadPacket(const char * titleStr, otMessage * pkt) #endif // CHIP_DETAIL_LOGGING } -bool IsOpenThreadMeshLocalAddress(otInstance * otInst, const IPAddress & addr) +bool IsOpenThreadMeshLocalAddress(otInstance * otInst, const Inet::IPAddress & addr) { const otMeshLocalPrefix * otMeshPrefix = otThreadGetMeshLocalPrefix(otInst); diff --git a/src/platform/P6/BUILD.gn b/src/platform/P6/BUILD.gn index 45fbf8ee460a49..7269cd9a817f7b 100644 --- a/src/platform/P6/BUILD.gn +++ b/src/platform/P6/BUILD.gn @@ -51,8 +51,6 @@ static_library("P6") { "P6Utils.h", "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", - "SoftwareUpdateManagerImpl.cpp", - "SoftwareUpdateManagerImpl.h", "SystemPlatformConfig.h", "WarmPlatformConfig.h", "app_platform_cfg.c", diff --git a/src/platform/P6/SoftwareUpdateManagerImpl.cpp b/src/platform/P6/SoftwareUpdateManagerImpl.cpp deleted file mode 100644 index eabccdae3f4a71..00000000000000 --- a/src/platform/P6/SoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* this file behaves like a config.h, comes first */ -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -namespace chip { -namespace DeviceLayer { - -SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; - -CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) -{ - CHIP_ERROR err = CHIP_NO_ERROR; - return err; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/P6/SoftwareUpdateManagerImpl.h b/src/platform/P6/SoftwareUpdateManagerImpl.h deleted file mode 100644 index fe42c52df70edd..00000000000000 --- a/src/platform/P6/SoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * Copyright (c) 2021 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -namespace chip { -namespace DeviceLayer { - -/** - * Concrete implementation of the SoftwareUpdateManager singleton object for the - * PSoC6 platforms. - */ -class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl, - public Internal::GenericSoftwareUpdateManagerImpl_BDX -{ - // Allow the SoftwareUpdateManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class SoftwareUpdateManager; - - // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl; - - // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl_BDX; - -public: - // ===== Members for internal use by the following friends. - - friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); - - static SoftwareUpdateManagerImpl sInstance; - -private: - // ===== Members that implement the SoftwareUpdateManager abstract interface. - - CHIP_ERROR _Init(void); -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * Internal components should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -inline SoftwareUpdateManager & SoftwareUpdateMgr(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * Internal components can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the PSoC6 platform. - */ -inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/nxp/k32w/k32w0/BUILD.gn b/src/platform/nxp/k32w/k32w0/BUILD.gn index aba72e6da7c2a8..10628fd4466e5c 100644 --- a/src/platform/nxp/k32w/k32w0/BUILD.gn +++ b/src/platform/nxp/k32w/k32w0/BUILD.gn @@ -44,7 +44,6 @@ static_library("k32w0") { "NFCManagerImpl.h", "PlatformManagerImpl.cpp", "PlatformManagerImpl.h", - "SoftwareUpdateManagerImpl.h", "ble_function_mux.c", ] diff --git a/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.cpp b/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.cpp deleted file mode 100644 index c464bb327c24a6..00000000000000 --- a/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2020 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/* this file behaves like a config.h, comes first */ -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -#include -#include - -namespace chip { -namespace DeviceLayer { - -SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; - -CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) -{ - Internal::GenericSoftwareUpdateManagerImpl_BDX::DoInit(); - Internal::GenericSoftwareUpdateManagerImpl::DoInit(); - - return CHIP_NO_ERROR; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.h b/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.h deleted file mode 100644 index f04025435928d5..00000000000000 --- a/src/platform/nxp/k32w/k32w0/SoftwareUpdateManagerImpl.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2020 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include -#include - -namespace chip { -namespace DeviceLayer { - -/** - * Concrete implementation of the SoftwareUpdateManager singleton object for the - * NXP K32W platforms. - */ -class SoftwareUpdateManagerImpl final : public SoftwareUpdateManager, - public Internal::GenericSoftwareUpdateManagerImpl, - public Internal::GenericSoftwareUpdateManagerImpl_BDX -{ - // Allow the SoftwareUpdateManager interface class to delegate method calls to - // the implementation methods provided by this class. - friend class SoftwareUpdateManager; - - // Allow the GenericSoftwareUpdateManagerImpl base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl; - - // Allow the GenericSoftwareUpdateManagerImpl_BDX base class to access helper methods - // and types defined on this class. - friend class Internal::GenericSoftwareUpdateManagerImpl_BDX; - -public: - // ===== Members for internal use by the following friends. - - friend ::chip::DeviceLayer::SoftwareUpdateManager & SoftwareUpdateMgr(void); - friend SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); - - static SoftwareUpdateManagerImpl sInstance; - -private: - // ===== Members that implement the SoftwareUpdateManager abstract interface. - - CHIP_ERROR _Init(void); -}; - -/** - * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. - * - * Internal components should use this to access features of the SoftwareUpdateManager object - * that are common to all platforms. - */ -inline SoftwareUpdateManager & SoftwareUpdateMgr(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -/** - * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. - * - * Internal components can use this to gain access to features of the SoftwareUpdateManager - * that are specific to the K32W platform. - */ -inline SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void) -{ - return SoftwareUpdateManagerImpl::sInstance; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER diff --git a/src/platform/qpg/SoftwareUpdateManagerImpl.cpp b/src/platform/qpg/SoftwareUpdateManagerImpl.cpp deleted file mode 100644 index ce64b8139c7c29..00000000000000 --- a/src/platform/qpg/SoftwareUpdateManagerImpl.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER - -#include - -namespace chip { -namespace DeviceLayer { - -SoftwareUpdateManagerImpl SoftwareUpdateManagerImpl::sInstance; - -CHIP_ERROR SoftwareUpdateManagerImpl::_Init(void) -{ - Internal::GenericSoftwareUpdateManagerImpl::DoInit(); - - return CHIP_NO_ERROR; -} - -} // namespace DeviceLayer -} // namespace chip - -#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER