Skip to content

Commit

Permalink
Merge branch 'ota-impl-cfg' into 'main'
Browse files Browse the repository at this point in the history
components/esp-matter: support to configure the ota implementation

See merge request app-frameworks/esp-matter!999
  • Loading branch information
dhrishi committed Jan 7, 2025
2 parents ea6d52c + 72a8608 commit 4c71deb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
50 changes: 42 additions & 8 deletions components/esp_matter/esp_matter_ota.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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
}

Expand All @@ -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
Expand Down
30 changes: 25 additions & 5 deletions components/esp_matter/esp_matter_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,24 +42,31 @@ 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);

/**
* @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.
*
Expand Down

0 comments on commit 4c71deb

Please sign in to comment.