Skip to content

Commit

Permalink
Merge branch 'update/thread_br' into 'main'
Browse files Browse the repository at this point in the history
Remove esp_matter_thread_br component and add thread_border_router_management cluster and thread br example

See merge request app-frameworks/esp-matter!863
  • Loading branch information
chshu committed Sep 20, 2024
2 parents 3ca361d + 4b8d838 commit 3578a0e
Show file tree
Hide file tree
Showing 44 changed files with 772 additions and 956 deletions.
3 changes: 3 additions & 0 deletions SUPPORTED_DEVICE_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,6 @@ i. Appliances

j. Energy
1. EVSE (Electric Vehicle Supply Equipment)

k. Network Infrastructure
1. Thread Border Router
42 changes: 42 additions & 0 deletions components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4705,5 +4705,47 @@ attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint
} /* attribute */
} /* application_basic */

namespace thread_border_router_management {
namespace attribute {

attribute_t *create_border_router_name(cluster_t *cluster, char *value, uint16_t length)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::BorderRouterName::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_char_str(value, length));
}

attribute_t *create_border_agent_id(cluster_t *cluster, uint8_t *value, uint16_t length)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::BorderAgentID::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_octet_str(value, length));
}

attribute_t *create_thread_version(cluster_t *cluster, uint16_t value)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::ThreadVersion::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
}

attribute_t *create_interface_enabled(cluster_t *cluster, bool value)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::InterfaceEnabled::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_bool(value));
}

attribute_t *create_active_dataset_timestamp(cluster_t *cluster, nullable<uint64_t> value)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::ActiveDatasetTimestamp::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_nullable_uint64(value));
}

attribute_t *create_pending_dataset_timestamp(cluster_t *cluster, nullable<uint64_t> value)
{
return esp_matter::attribute::create(cluster, ThreadBorderRouterManagement::Attributes::PendingDatasetTimestamp::Id,
ATTRIBUTE_FLAG_NONE, esp_matter_nullable_uint64(value));
}

} /* attribute */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
11 changes: 11 additions & 0 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -1121,5 +1121,16 @@ attribute_t *create_allowed_vendor_list(cluster_t *cluster, uint8_t *value, uint
} /* attribute */
} /* application_basic */

namespace thread_border_router_management {
namespace attribute {
attribute_t *create_border_router_name(cluster_t *cluster, char *value, uint16_t length);
attribute_t *create_border_agent_id(cluster_t *cluster, uint8_t *value, uint16_t length);
attribute_t *create_thread_version(cluster_t *cluster, uint16_t value);
attribute_t *create_interface_enabled(cluster_t *cluster, bool value);
attribute_t *create_active_dataset_timestamp(cluster_t *cluster, nullable<uint64_t> value);
attribute_t *create_pending_dataset_timestamp(cluster_t *cluster, nullable<uint64_t> value);
} /* attribute */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
48 changes: 48 additions & 0 deletions components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
attribute::create_hardware_version_string(cluster, NULL, 0);
attribute::create_software_version(cluster, 0);
attribute::create_software_version_string(cluster, NULL, 0);
attribute::create_unique_id(cluster, NULL, 0);
attribute::create_capability_minima(cluster, NULL, 0, 0);
attribute::create_specification_version(cluster, 0);
attribute::create_max_paths_per_invoke(cluster, 0);
Expand Down Expand Up @@ -3545,6 +3546,53 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
}
} /* application_basic */

namespace thread_border_router_management {
const function_generic_t *function_list = NULL;
const int function_flags = CLUSTER_FLAG_NONE;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
{
cluster_t *cluster = cluster::create(endpoint, ThreadBorderRouterManagement::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}
if (flags & CLUSTER_FLAG_SERVER) {
if (config -> delegate != nullptr) {
static const auto delegate_init_cb = ThreadBorderRouterManagementDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
static const auto plugin_server_init_cb = CALL_ONCE(MatterThreadBorderRouterManagementPluginServerInitCallback);
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
add_function_list(cluster, function_list, function_flags);

/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
attribute::create_border_router_name(cluster, nullptr, 0);
attribute::create_border_agent_id(cluster, nullptr, 0);
attribute::create_thread_version(cluster, 0);
attribute::create_interface_enabled(cluster, false);
nullable<uint64_t> timestamp;
attribute::create_active_dataset_timestamp(cluster, timestamp);

/** Attributes not managed internally **/
global::attribute::create_cluster_revision(cluster, cluster_revision);
}

command::create_get_active_dataset_request(cluster);
command::create_get_pending_dataset_request(cluster);
command::create_dataset_response(cluster);
command::create_set_active_dataset_request(cluster);

if (features & feature::pan_change::get_id()) {
feature::pan_change::add(cluster);
}

return cluster;
}

} /* thread_border_router_management */

// namespace binary_input_basic {
// // ToDo
// } /* binary_input_basic */
Expand Down
9 changes: 9 additions & 0 deletions components/esp_matter/esp_matter_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -864,5 +864,14 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* application_basic */

namespace thread_border_router_management {
typedef struct config {
void *delegate;
config() : delegate(nullptr) {}
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
36 changes: 36 additions & 0 deletions components/esp_matter/esp_matter_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2858,6 +2858,42 @@ command_t *create_cancel_request(cluster_t *cluster)
} /* command */
} /* device_energy_management */

namespace thread_border_router_management {
namespace command {

command_t *create_get_active_dataset_request(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ThreadBorderRouterManagement::Commands::GetActiveDatasetRequest::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}

command_t *create_get_pending_dataset_request(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ThreadBorderRouterManagement::Commands::GetPendingDatasetRequest::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}

command_t *create_dataset_response(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ThreadBorderRouterManagement::Commands::DatasetResponse::Id,
COMMAND_FLAG_GENERATED, NULL);
}

command_t *create_set_active_dataset_request(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ThreadBorderRouterManagement::Commands::SetActiveDatasetRequest::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}

command_t *create_set_pending_dataset_request(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ThreadBorderRouterManagement::Commands::SetPendingDatasetRequest::Id,
COMMAND_FLAG_ACCEPTED, NULL);
}

} /* command */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */

Expand Down
10 changes: 10 additions & 0 deletions components/esp_matter/esp_matter_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,5 +417,15 @@ command_t *create_cancel_request(cluster_t *cluster);
} /* command */
} /* device_energy_management */

namespace thread_border_router_management {
namespace command {
command_t *create_get_active_dataset_request(cluster_t *cluster);
command_t *create_get_pending_dataset_request(cluster_t *cluster);
command_t *create_dataset_response(cluster_t *cluster);
command_t *create_set_active_dataset_request(cluster_t *cluster);
command_t *create_set_pending_dataset_request(cluster_t *cluster);
} /* command */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
21 changes: 21 additions & 0 deletions components/esp_matter/esp_matter_delegate_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <inttypes.h>
#include <esp_matter_delegate_callbacks.h>
#include <esp_matter_core.h>
#include <esp_matter_feature.h>
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/clusters/energy-evse-server/energy-evse-server.h>
#include <app/clusters/microwave-oven-control-server/microwave-oven-control-server.h>
Expand All @@ -36,6 +37,7 @@
#include <app/clusters/dishwasher-alarm-server/dishwasher-alarm-server.h>
#include <app/clusters/keypad-input-server/keypad-input-server.h>
#include <app/clusters/mode-select-server//supported-modes-manager.h>
#include <app/clusters/thread-border-router-management-server/thread-border-router-management-server.h>

using namespace chip::app::Clusters;
namespace esp_matter {
Expand Down Expand Up @@ -354,6 +356,25 @@ void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id)
ModeSelect::setSupportedModesManager(supported_modes_manager);
}

void ThreadBorderRouterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
assert(delegate != nullptr);
esp_matter::cluster_t *cluster = esp_matter::cluster::get(endpoint_id, ThreadBorderRouterManagement::Id);
assert(cluster != nullptr);
/* Get the attribute */
attribute_t *attribute = attribute::get(cluster, Globals::Attributes::FeatureMap::Id);
assert(attribute != nullptr);
/* Update the value if the attribute already exists */
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
attribute::get_val(attribute, &val);
bool pan_change_supported = (val.val.u32 & thread_border_router_management::feature::pan_change::get_id()) ? true : false;
ThreadBorderRouterManagement::Delegate *thread_br_delegate = static_cast<ThreadBorderRouterManagement::Delegate *>(delegate);
assert(thread_br_delegate->GetPanChangeSupported() == pan_change_supported);
ThreadBorderRouterManagement::ServerInstance *server_instance =
chip::Platform::New<ThreadBorderRouterManagement::ServerInstance>(endpoint_id, thread_br_delegate, chip::Server::GetInstance().GetFailSafeContext());
server_instance->Init();
}

} // namespace delegate_cb

} // namespace cluster
Expand Down
1 change: 1 addition & 0 deletions components/esp_matter/esp_matter_delegate_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void WindowCoveringDelegateInitCB(void *delegate, uint16_t endpoint_id);
void DishwasherAlarmDelegateInitCB(void *delegate, uint16_t endpoint_id);
void KeypadInputDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ThreadBorderRouterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id);
} // namespace delegate_cb

} // namespace cluster
Expand Down
34 changes: 34 additions & 0 deletions components/esp_matter/esp_matter_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,40 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
}
} /** device_energy_management **/

namespace thread_border_router {

uint32_t get_device_type_id()
{
return ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_ID;
}

uint8_t get_device_type_version()
{
return ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_VERSION;
}

endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
{
return common::create<config_t>(node, config, flags, priv_data, add);
}

esp_err_t add(endpoint_t *endpoint, config_t *config)
{
VerifyOrReturnError(endpoint != nullptr, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Endpoint cannot be NULL"));
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
return err;
}

thread_network_diagnostics::create(endpoint, &(config->thread_network_diagnostics), CLUSTER_FLAG_SERVER);
thread_border_router_management::create(endpoint, &(config->thread_border_router_management), CLUSTER_FLAG_SERVER,
thread_border_router_management::feature::pan_change::get_id());
return ESP_OK;
}

} /* thread_border_router */

} /* endpoint */

namespace node {
Expand Down
16 changes: 16 additions & 0 deletions components/esp_matter/esp_matter_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@
#define ESP_MATTER_DEVICE_ENERGY_MANAGEMENT_DEVICE_TYPE_ID 0x050D
#define ESP_MATTER_DEVICE_ENERGY_MANAGEMENT_DEVICE_TYPE_VERSION 1

#define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_ID 0x0091
#define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_VERSION 1

namespace esp_matter {

/** Specific endpoint (device type) create APIs
Expand Down Expand Up @@ -853,6 +856,19 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /* device_energy_management */

namespace thread_border_router {
typedef struct config {
cluster::descriptor::config_t descriptor;
cluster::thread_network_diagnostics::config_t thread_network_diagnostics;
cluster::thread_border_router_management::config_t thread_border_router_management;
} config_t;

uint32_t get_device_type_id();
uint8_t get_device_type_version();
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /* thread_border_router */

} /* endpoint */

namespace node {
Expand Down
31 changes: 31 additions & 0 deletions components/esp_matter/esp_matter_feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4752,5 +4752,36 @@ esp_err_t add(cluster_t *cluster)
} /* feature */
} /* device_energy_management */

namespace thread_border_router_management {
namespace feature {

namespace pan_change {

uint32_t get_id()
{
return static_cast<uint32_t>(ThreadBorderRouterManagement::Feature::kPANChange);
}

esp_err_t add(cluster_t *cluster)
{
if (!cluster) {
ESP_LOGE(TAG, "Cluster cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
update_feature_map(cluster, get_id());
/* attribute */
nullable<uint64_t> timestamp;
attribute::create_pending_dataset_timestamp(cluster, timestamp);

/* command */
command::create_set_pending_dataset_request(cluster);
return ESP_OK;
}

} /* pan_change */

} /* feature */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
13 changes: 13 additions & 0 deletions components/esp_matter/esp_matter_feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -2084,5 +2084,18 @@ esp_err_t add(cluster_t *cluster);
} /* feature */
} /* device_energy_management */

namespace thread_border_router_management {
namespace feature {

namespace pan_change {

uint32_t get_id();
esp_err_t add(cluster_t *cluster);

} /* pan_change */

} /* feature */
} /* thread_border_router_management */

} /* cluster */
} /* esp_matter */
5 changes: 5 additions & 0 deletions components/esp_matter/private/esp_matter_cluster_revisions.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ namespace application_basic {
constexpr uint16_t cluster_revision = 1;
} // namespace application_basic

namespace thread_border_router_management {
constexpr uint16_t cluster_revision = 1;
} // namespace thread_border_router_management


} // namespace cluster
} // namespace esp_matter

Loading

0 comments on commit 3578a0e

Please sign in to comment.