mirror of
https://github.com/espressif/esp-matter.git
synced 2026-04-27 19:13:13 +00:00
components/esp-matter: support to configure the ota implementation
Added a member variable in the ota config struct which lets user set the different ota implementation.
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <app/clusters/ota-requestor/BDXDownloader.h>
|
||||
#include <app/clusters/ota-requestor/DefaultOTARequestor.h>
|
||||
#include <app/clusters/ota-requestor/DefaultOTARequestorDriver.h>
|
||||
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
|
||||
#include <app/clusters/ota-requestor/DefaultOTARequestorStorage.h>
|
||||
#include <platform/ESP32/OTAImageProcessorImpl.h>
|
||||
|
||||
@@ -30,7 +30,7 @@ using chip::DefaultOTARequestor;
|
||||
using chip::DefaultOTARequestorStorage;
|
||||
using chip::OTAImageProcessorImpl;
|
||||
using chip::Server;
|
||||
using chip::DeviceLayer::DefaultOTARequestorDriver;
|
||||
using chip::DeviceLayer::ExtendedOTARequestorDriver;
|
||||
|
||||
using namespace esp_matter;
|
||||
using namespace esp_matter::endpoint;
|
||||
@@ -39,10 +39,15 @@ using namespace esp_matter::cluster;
|
||||
#if CONFIG_ENABLE_OTA_REQUESTOR
|
||||
DefaultOTARequestor gRequestorCore;
|
||||
DefaultOTARequestorStorage gRequestorStorage;
|
||||
DefaultOTARequestorDriver gRequestorUser;
|
||||
ExtendedOTARequestorDriver gRequestorUser;
|
||||
BDXDownloader gDownloader;
|
||||
OTAImageProcessorImpl gImageProcessor;
|
||||
#endif
|
||||
|
||||
static esp_matter_ota_requestor_impl_t s_ota_requestor_impl = {
|
||||
.driver = &gRequestorUser,
|
||||
.image_processor = &gImageProcessor,
|
||||
};
|
||||
#endif // CONFIG_ENABLE_OTA_REQUESTOR
|
||||
|
||||
esp_err_t esp_matter_ota_requestor_init(void)
|
||||
{
|
||||
@@ -61,16 +66,42 @@ esp_err_t esp_matter_ota_requestor_init(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static esp_err_t esp_matter_ota_override_impl(const esp_matter_ota_requestor_impl_t *impl)
|
||||
{
|
||||
#if CONFIG_ENABLE_OTA_REQUESTOR
|
||||
VerifyOrReturnError(impl != nullptr, ESP_ERR_INVALID_ARG);
|
||||
|
||||
if (impl->driver != nullptr) {
|
||||
s_ota_requestor_impl.driver = impl->driver;
|
||||
}
|
||||
if (impl->image_processor != nullptr) {
|
||||
s_ota_requestor_impl.image_processor = impl->image_processor;
|
||||
}
|
||||
|
||||
s_ota_requestor_impl.user_consent = impl->user_consent;
|
||||
|
||||
return ESP_OK;
|
||||
#else
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif // CONFIG_ENABLE_OTA_REQUESTOR
|
||||
}
|
||||
|
||||
void esp_matter_ota_requestor_start(void)
|
||||
{
|
||||
#if CONFIG_ENABLE_OTA_REQUESTOR
|
||||
VerifyOrReturn(chip::GetRequestorInstance() == nullptr);
|
||||
|
||||
chip::SetRequestorInstance(&gRequestorCore);
|
||||
gRequestorStorage.Init(Server::GetInstance().GetPersistentStorage());
|
||||
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, gRequestorUser, gDownloader);
|
||||
gImageProcessor.SetOTADownloader(&gDownloader);
|
||||
gDownloader.SetImageProcessorDelegate(&gImageProcessor);
|
||||
gRequestorUser.Init(&gRequestorCore, &gImageProcessor);
|
||||
|
||||
gRequestorCore.Init(Server::GetInstance(), gRequestorStorage, *s_ota_requestor_impl.driver, gDownloader);
|
||||
|
||||
s_ota_requestor_impl.image_processor->SetOTADownloader(&gDownloader);
|
||||
|
||||
gDownloader.SetImageProcessorDelegate(s_ota_requestor_impl.image_processor);
|
||||
|
||||
s_ota_requestor_impl.driver->SetUserConsentDelegate(s_ota_requestor_impl.user_consent);
|
||||
s_ota_requestor_impl.driver->Init(&gRequestorCore, s_ota_requestor_impl.image_processor);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -93,6 +124,9 @@ esp_err_t esp_matter_ota_requestor_set_config(const esp_matter_ota_config_t & co
|
||||
if (config.watchdog_timeout) {
|
||||
gRequestorUser.SetWatchdogTimeout(config.watchdog_timeout);
|
||||
}
|
||||
if (config.impl != nullptr) {
|
||||
esp_matter_ota_override_impl(config.impl);
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
#else
|
||||
|
||||
@@ -17,6 +17,19 @@
|
||||
#include "esp_err.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include <app/clusters/ota-requestor/ExtendedOTARequestorDriver.h>
|
||||
#include <app/clusters/ota-requestor/OTARequestorUserConsentDelegate.h>
|
||||
#include <platform/ESP32/OTAImageProcessorImpl.h>
|
||||
|
||||
typedef struct {
|
||||
// ota requestor driver
|
||||
chip::DeviceLayer::ExtendedOTARequestorDriver *driver = nullptr;
|
||||
// user consent
|
||||
chip::ota::OTARequestorUserConsentDelegate *user_consent = nullptr;
|
||||
// ota image processor
|
||||
chip::OTAImageProcessorImpl *image_processor = nullptr;
|
||||
} esp_matter_ota_requestor_impl_t;
|
||||
|
||||
typedef struct {
|
||||
/**
|
||||
* Timeout (in seconds) for querying default OTA Providers
|
||||
@@ -29,16 +42,23 @@ typedef struct {
|
||||
* Default timeout is 300 seconds
|
||||
*/
|
||||
uint32_t watchdog_timeout;
|
||||
/**
|
||||
* Options to override the default behavior of the OTA requestor
|
||||
* Refer to esp_matter_ota_requestor_impl_t for more details.
|
||||
* If not set, default implementation is used.
|
||||
*/
|
||||
const esp_matter_ota_requestor_impl_t *impl = nullptr;
|
||||
} esp_matter_ota_config_t;
|
||||
|
||||
|
||||
/** Initialize the Matter OTA Requestor
|
||||
/**
|
||||
* Initialize the Matter OTA Requestor
|
||||
*
|
||||
* Adds the OTA requestor server cluster and ota provider client cluster to root node endpoint.
|
||||
*/
|
||||
esp_err_t esp_matter_ota_requestor_init(void);
|
||||
|
||||
/**Start the Matter OTA Requestor
|
||||
*
|
||||
/**
|
||||
* Start the Matter OTA Requestor
|
||||
*/
|
||||
void esp_matter_ota_requestor_start(void);
|
||||
|
||||
@@ -46,7 +66,7 @@ void esp_matter_ota_requestor_start(void);
|
||||
* @brief This API initializes the handling of encrypted OTA image
|
||||
*
|
||||
* @param[in] key null terminated RSA-3072 key in PEM format.
|
||||
* The key buffer must remain allocated and should not be freed.
|
||||
* The key buffer must remain allocated and should not be freed.
|
||||
* @param[in] size Size of the key, size shall contain the null terminator as well.
|
||||
* If using `strlen` then please consider adding +1 to the size.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user