Skip to content

Commit 6aa71da

Browse files
committed
Merge branch 'controller/fix_shutdown_subscription' into 'main'
controller: fix shutdown subscriptions See merge request app-frameworks/esp-matter!1022
2 parents 3a1aa8c + 30bb6dc commit 6aa71da

4 files changed

+28
-64
lines changed

components/esp_matter_controller/commands/esp_matter_controller_cluster_command.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,7 @@ esp_err_t cluster_command::dispatch_group_command(void *context)
206206
#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
207207
uint8_t fabric_index = get_fabric_index();
208208
#else
209-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
210-
uint8_t fabric_index = matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
211-
#else
212-
uint8_t fabric_index = matter_controller_client::get_instance().get_controller()->GetFabricIndex();
213-
#endif // CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
209+
uint8_t fabric_index = matter_controller_client::get_instance().get_fabric_index();
214210
#endif // CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
215211
chip::app::CommandPathParams command_path = {cmd->m_endpoint_id, group_id, cmd->m_cluster_id, cmd->m_command_id,
216212
chip::app::CommandPathFlags::kGroupIdValid};

components/esp_matter_controller/commands/esp_matter_controller_subscribe_command.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,14 @@ esp_err_t send_subscribe_event_command(uint64_t node_id, uint16_t endpoint_id, u
280280

281281
esp_err_t send_shutdown_subscription(uint64_t node_id, uint32_t subscription_id)
282282
{
283-
if (CHIP_NO_ERROR !=
284-
InteractionModelEngine::GetInstance()->ShutdownSubscription(
285-
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
286-
ScopedNodeId(node_id, matter_controller_client::get_instance().get_commissioner()->GetFabricIndex()),
287-
subscription_id)) {
283+
#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
284+
chip::FabricIndex fabric_index = get_fabric_index();
288285
#else
289-
ScopedNodeId(node_id, /* fabric index */ 1), subscription_id)) {
286+
chip::FabricIndex fabric_index = matter_controller_client::get_instance().get_fabric_index();
290287
#endif
288+
if (CHIP_NO_ERROR !=
289+
InteractionModelEngine::GetInstance()->ShutdownSubscription(ScopedNodeId(node_id, fabric_index),
290+
subscription_id)) {
291291
ESP_LOGE(TAG, "Shutdown Subscription Failed");
292292
return ESP_FAIL;
293293
}
@@ -296,13 +296,13 @@ esp_err_t send_shutdown_subscription(uint64_t node_id, uint32_t subscription_id)
296296

297297
void send_shutdown_subscriptions(uint64_t node_id)
298298
{
299-
InteractionModelEngine::GetInstance()->ShutdownSubscriptions(
300-
#if CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
301-
matter_controller_client::get_instance().get_commissioner()->GetFabricIndex(),
299+
#ifdef CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER
300+
chip::FabricIndex fabric_index = get_fabric_index();
302301
#else
303-
get_fabric_index(),
302+
chip::FabricIndex fabric_index = matter_controller_client::get_instance().get_fabric_index();
304303
#endif
305-
node_id);
304+
305+
InteractionModelEngine::GetInstance()->ShutdownSubscriptions(fabric_index, node_id);
306306
ESP_LOGI(TAG, "Shutdown Subscriptions for node:0x%llx", node_id);
307307
}
308308

components/esp_matter_controller/core/esp_matter_controller_client.h

+8
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ class matter_controller_client {
144144
esp_err_t setup_controller(chip::MutableByteSpan &ipk);
145145
MatterDeviceController *get_controller() { return &m_device_controller; }
146146
#endif
147+
chip::FabricIndex get_fabric_index()
148+
{
149+
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
150+
return m_device_commissioner.GetFabricIndex();
151+
#else
152+
return m_device_controller.GetFabricIndex();
153+
#endif
154+
}
147155

148156
private:
149157
matter_controller_client() {}

components/esp_matter_controller/core/esp_matter_controller_group_settings.cpp

+8-48
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,7 @@ esp_err_t show_groups()
4949
ESP_LOGI(TAG, " | Available Groups : |");
5050
ESP_LOGI(TAG, " +-------------------------------------------------------------------------------------+");
5151
ESP_LOGI(TAG, " | Group Id | KeySet Id | Group Name |");
52-
FabricIndex fabric_index =
53-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
54-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
55-
#else
56-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
57-
#endif
52+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
5853
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
5954
auto iter = group_data_provider->IterateGroupInfo(fabric_index);
6055
GroupDataProvider::GroupInfo group_info;
@@ -79,12 +74,7 @@ esp_err_t add_group(char *group_name, uint16_t group_id)
7974
return ESP_ERR_INVALID_ARG;
8075
}
8176

82-
FabricIndex fabric_index =
83-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
84-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
85-
#else
86-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
87-
#endif
77+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
8878
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
8979
GroupDataProvider::GroupInfo group_info;
9080

@@ -101,12 +91,7 @@ esp_err_t remove_group(uint16_t group_id)
10191
return ESP_ERR_INVALID_ARG;
10292
}
10393

104-
FabricIndex fabric_index =
105-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
106-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
107-
#else
108-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
109-
#endif
94+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
11095
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
11196
ESP_RETURN_ON_FALSE(CHIP_NO_ERROR == group_data_provider->RemoveGroupInfo(fabric_index, group_id), ESP_FAIL, TAG,
11297
"Failed to remove the group info");
@@ -115,12 +100,7 @@ esp_err_t remove_group(uint16_t group_id)
115100

116101
esp_err_t show_keysets()
117102
{
118-
FabricIndex fabric_index =
119-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
120-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
121-
#else
122-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
123-
#endif
103+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
124104
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
125105
GroupDataProvider::KeySet keyset;
126106

@@ -145,12 +125,7 @@ esp_err_t show_keysets()
145125
esp_err_t bind_keyset(uint16_t group_id, uint16_t keyset_id)
146126
{
147127
size_t current_count = 0;
148-
FabricIndex fabric_index =
149-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
150-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
151-
#else
152-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
153-
#endif
128+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
154129
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
155130

156131
auto iter = group_data_provider->IterateGroupKeys(fabric_index);
@@ -169,12 +144,7 @@ esp_err_t bind_keyset(uint16_t group_id, uint16_t keyset_id)
169144
esp_err_t unbind_keyset(uint16_t group_id, uint16_t keyset_id)
170145
{
171146
size_t index = 0;
172-
FabricIndex fabric_index =
173-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
174-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
175-
#else
176-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
177-
#endif
147+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
178148
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
179149

180150
auto iter = group_data_provider->IterateGroupKeys(fabric_index);
@@ -196,12 +166,7 @@ esp_err_t unbind_keyset(uint16_t group_id, uint16_t keyset_id)
196166
esp_err_t add_keyset(uint16_t keyset_id, uint8_t key_policy, uint64_t validity_time, char *epoch_key_oct_str)
197167
{
198168
auto &controller_instance = esp_matter::controller::matter_controller_client::get_instance();
199-
FabricIndex fabric_index =
200-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
201-
controller_instance.get_commissioner()->GetFabricIndex();
202-
#else
203-
controller_instance.get_controller()->GetFabricIndex();
204-
#endif
169+
FabricIndex fabric_index = controller_instance.get_fabric_index();
205170

206171
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
207172
uint8_t compressed_fabric_id[sizeof(uint64_t)];
@@ -238,12 +203,7 @@ esp_err_t add_keyset(uint16_t keyset_id, uint8_t key_policy, uint64_t validity_t
238203

239204
esp_err_t remove_keyset(uint16_t keyset_id)
240205
{
241-
FabricIndex fabric_index =
242-
#ifdef CONFIG_ESP_MATTER_COMMISSIONER_ENABLE
243-
esp_matter::controller::matter_controller_client::get_instance().get_commissioner()->GetFabricIndex();
244-
#else
245-
esp_matter::controller::matter_controller_client::get_instance().get_controller()->GetFabricIndex();
246-
#endif
206+
FabricIndex fabric_index = esp_matter::controller::matter_controller_client::get_instance().get_fabric_index();
247207
GroupDataProvider *group_data_provider = chip::Credentials::GetGroupDataProvider();
248208

249209
size_t index = 0;

0 commit comments

Comments
 (0)