Skip to content

Commit e8186eb

Browse files
tehampsonrestyled-commitssaurabhst
authored
fabric-bridge: Add ECOINFO to dynamic bridged endpoints (project-chip#34811)
--------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: saurabhst <s.kumar9@samsung.com>
1 parent a0fac9f commit e8186eb

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed

examples/fabric-bridge-app/fabric-bridge-common/BUILD.gn

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,24 @@ config("config") {
1919
include_dirs = [ "include" ]
2020
}
2121

22-
chip_data_model("fabric-bridge-common") {
22+
chip_data_model("fabric-bridge-common-zap") {
2323
zap_file = "fabric-bridge-app.zap"
2424
is_server = true
2525
cflags = [ "-DDYNAMIC_ENDPOINT_COUNT=16" ]
2626
}
2727

28+
# This includes all the clusters that only exist on the dynamic endpoint.
29+
source_set("fabric-bridge-common") {
30+
public_configs = [ ":config" ]
31+
32+
sources = [
33+
"${chip_root}/src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp",
34+
"${chip_root}/src/app/clusters/ecosystem-information-server/ecosystem-information-server.h",
35+
]
36+
37+
public_deps = [ ":fabric-bridge-common-zap" ]
38+
}
39+
2840
source_set("fabric-bridge-lib") {
2941
public_configs = [ ":config" ]
3042

examples/fabric-bridge-app/fabric-bridge-common/src/BridgedDeviceManager.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@ DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(bridgedDeviceBasicAttrs)
112112
kSoftwareVersionSize, 0),
113113
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
114114

115+
// Declare Ecosystem Information cluster attributes
116+
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(ecosystemInformationBasicAttrs)
117+
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::RemovedOn::Id, EPOCH_US, kNodeLabelSize, ATTRIBUTE_MASK_NULLABLE),
118+
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::DeviceDirectory::Id, ARRAY, kDescriptorAttributeArraySize, 0),
119+
DECLARE_DYNAMIC_ATTRIBUTE(EcosystemInformation::Attributes::LocationDirectory::Id, ARRAY, kDescriptorAttributeArraySize, 0),
120+
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END();
121+
115122
// Declare Administrator Commissioning cluster attributes
116123
DECLARE_DYNAMIC_ATTRIBUTE_LIST_BEGIN(AdministratorCommissioningAttrs)
117124
DECLARE_DYNAMIC_ATTRIBUTE(AdministratorCommissioning::Attributes::WindowStatus::Id, ENUM8, 1, 0),
@@ -131,6 +138,7 @@ constexpr CommandId administratorCommissioningCommands[] = {
131138
DECLARE_DYNAMIC_CLUSTER_LIST_BEGIN(bridgedNodeClusters)
132139
DECLARE_DYNAMIC_CLUSTER(Descriptor::Id, descriptorAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
133140
DECLARE_DYNAMIC_CLUSTER(BridgedDeviceBasicInformation::Id, bridgedDeviceBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
141+
DECLARE_DYNAMIC_CLUSTER(EcosystemInformation::Id, ecosystemInformationBasicAttrs, ZAP_CLUSTER_MASK(SERVER), nullptr, nullptr),
134142
DECLARE_DYNAMIC_CLUSTER(AdministratorCommissioning::Id, AdministratorCommissioningAttrs, ZAP_CLUSTER_MASK(SERVER),
135143
administratorCommissioningCommands, nullptr) DECLARE_DYNAMIC_CLUSTER_LIST_END;
136144

examples/fabric-bridge-app/linux/RpcServer.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "pw_rpc_system_server/rpc_server.h"
2121
#include "pw_rpc_system_server/socket.h"
2222

23+
#include <app/clusters/ecosystem-information-server/ecosystem-information-server.h>
2324
#include <lib/core/CHIPError.h>
2425

2526
#include <string>
@@ -62,6 +63,10 @@ pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice
6263
return pw::Status::Unknown();
6364
}
6465

66+
CHIP_ERROR err = EcosystemInformation::EcosystemInformationServer::Instance().AddEcosystemInformationClusterToEndpoint(
67+
device->GetEndpointId());
68+
VerifyOrDie(err == CHIP_NO_ERROR);
69+
6570
return pw::OkStatus();
6671
}
6772

examples/fabric-bridge-app/linux/main.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include <app/AttributeAccessInterfaceRegistry.h>
2727
#include <app/CommandHandlerInterfaceRegistry.h>
28+
#include <app/clusters/ecosystem-information-server/ecosystem-information-server.h>
2829

2930
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
3031
#include "RpcClient.h"
@@ -35,8 +36,15 @@
3536
#include <sys/ioctl.h>
3637
#include <thread>
3738

38-
using namespace chip;
39+
// This is declared here and not in a header because zap/embr assumes all clusters
40+
// are defined in a static endpoint in the .zap file. From there, the codegen will
41+
// automatically use PluginApplicationCallbacksHeader.jinja to declare and call
42+
// the respective Init callbacks. However, because EcosystemInformation cluster is only
43+
// ever on a dynamic endpoint, this doesn't get declared and called for us, so we
44+
// need to declare and call it ourselves where the application is initialized.
45+
void MatterEcosystemInformationPluginServerInitCallback();
3946

47+
using namespace chip;
4048
using namespace chip::app;
4149
using namespace chip::app::Clusters;
4250
using namespace chip::app::Clusters::AdministratorCommissioning;
@@ -177,6 +185,7 @@ void ApplicationInit()
177185
{
178186
ChipLogDetail(NotSpecified, "Fabric-Bridge: ApplicationInit()");
179187

188+
MatterEcosystemInformationPluginServerInitCallback();
180189
CommandHandlerInterfaceRegistry::RegisterCommandHandler(&gAdministratorCommissioningCommandHandler);
181190
registerAttributeAccessOverride(&gBridgedDeviceBasicInformationAttributes);
182191

src/app/clusters/ecosystem-information-server/ecosystem-information-server.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ EcosystemInformationServer & EcosystemInformationServer::Instance()
243243
return mInstance;
244244
}
245245

246+
CHIP_ERROR EcosystemInformationServer::AddEcosystemInformationClusterToEndpoint(EndpointId aEndpoint)
247+
{
248+
VerifyOrReturnError((aEndpoint != kRootEndpointId && aEndpoint != kInvalidEndpointId), CHIP_ERROR_INVALID_ARGUMENT);
249+
auto it = mDevicesMap.find(aEndpoint);
250+
// We expect that the device has not been previously added.
251+
VerifyOrReturnError((it == mDevicesMap.end()), CHIP_ERROR_INCORRECT_STATE);
252+
// This create an empty DeviceInfo in mDevicesMap.
253+
mDevicesMap[aEndpoint] = DeviceInfo();
254+
return CHIP_NO_ERROR;
255+
}
256+
246257
CHIP_ERROR EcosystemInformationServer::AddDeviceInfo(EndpointId aEndpoint, std::unique_ptr<EcosystemDeviceStruct> aDevice)
247258
{
248259
VerifyOrReturnError(aDevice, CHIP_ERROR_INVALID_ARGUMENT);

src/app/clusters/ecosystem-information-server/ecosystem-information-server.h

+19-1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ class EcosystemInformationServer
150150
public:
151151
static EcosystemInformationServer & Instance();
152152

153+
/**
154+
* @brief Add EcosystemInformation Cluster to endpoint so we respond appropriately on endpoint
155+
*
156+
* EcosystemInformation cluster is only ever on dynamic bridge endpoint. If cluster is added
157+
* to a new endpoint, but does not contain any ecosystem information presently,
158+
* this is called to let ECOINFO cluster code know it is supposed to provide blank attribute
159+
* information on this endpoint.
160+
*
161+
* This approach was intentionally taken instead of relying on emberAfDeviceTypeListFromEndpoint
162+
* to keep this cluster more unit testable. This does add burden to application but is worth
163+
* the trade-off.
164+
*
165+
* @param[in] aEndpoint Which endpoint is the device being added to the device directory.
166+
* @return #CHIP_NO_ERROR on success.
167+
* @return Other CHIP_ERROR associated with issue.
168+
*/
169+
CHIP_ERROR AddEcosystemInformationClusterToEndpoint(EndpointId aEndpoint);
170+
153171
/**
154172
* @brief Adds device as entry to DeviceDirectory list Attribute.
155173
*
@@ -187,7 +205,7 @@ class EcosystemInformationServer
187205
private:
188206
struct DeviceInfo
189207
{
190-
Optional<uint64_t> mRemovedOn;
208+
Optional<uint64_t> mRemovedOn = NullOptional;
191209
std::vector<std::unique_ptr<EcosystemDeviceStruct>> mDeviceDirectory;
192210
// Map key is using the UniqueLocationId
193211
std::map<std::string, std::unique_ptr<EcosystemLocationStruct>> mLocationDirectory;

0 commit comments

Comments
 (0)