/* * * Copyright (c) 2022 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. */ /** * @file * Provides an implementation of Device Firmware Upgrade using Matter OTA. */ #pragma once #include #include #include #ifdef CHIP_OTA_REQUESTOR #include #include #include #include #include #endif // CHIP_OTA_REQUESTOR typedef bool (*OnUpdateAvailable)(void * context, uint32_t softwareVersion, chip::CharSpan softwareVersionString); typedef bool (*OnUpdateApply)(void * context); class DFUManager { public: CHIP_ERROR Init(chip::Callback::Callback * onUpdateAvailable = nullptr, chip::Callback::Callback * onUpdateApply = nullptr); private: #ifdef CHIP_OTA_REQUESTOR DFUManager() : mOnOtaUpdateAvailableCallback(OnOtaUpdateAvailableHandler, this), mOnOtaUpdateApplyCallback(OnOtaUpdateApplyHandler, this) {} #endif friend DFUManager & GetDFUManager(void); static DFUManager sDFUMgr; #ifdef CHIP_OTA_REQUESTOR chip::DefaultOTARequestor mRequestorCore; chip::DefaultOTARequestorStorage mRequestorStorage; chip::DeviceLayer::OTARequestorDriverImpl mRequestorDriver; chip::BDXDownloader mDownloader; chip::OTAImageProcessorImpl mImageProcessor; static bool OnOtaUpdateAvailableHandler(void * context, const chip::UpdateDescription & desc); static bool OnOtaUpdateApplyHandler(void * context); chip::Callback::Callback mOnOtaUpdateAvailableCallback; chip::Callback::Callback mOnOtaUpdateApplyCallback; #endif // CHIP_OTA_REQUESTOR chip::Callback::Callback * mOnUpdateAvailableCallback; chip::Callback::Callback * mOnUpdateApplyCallback; }; inline DFUManager & GetDFUManager(void) { return DFUManager::sDFUMgr; }