Skip to content

Commit 3a3b6ed

Browse files
authored
[Fabric-Sync] Add the IPC support between Fabric_Admin and Fabric_Bridge (#33603)
* Add the RPC support between Fabric_Admin and Fabric_Bridge * Add bridge_enable_pw_rpc build flag * Address review comments * Add RpcClientProcessor * Update API comments
1 parent a2dddd1 commit 3a3b6ed

27 files changed

+1149
-7
lines changed

examples/common/pigweed/BUILD.gn

+14
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ pw_proto_library("button_service") {
8080
prefix = "button_service"
8181
}
8282

83+
pw_proto_library("fabric_admin_service") {
84+
sources = [ "protos/fabric_admin_service.proto" ]
85+
deps = [ "$dir_pw_protobuf:common_protos" ]
86+
strip_prefix = "protos"
87+
prefix = "fabric_admin_service"
88+
}
89+
90+
pw_proto_library("fabric_bridge_service") {
91+
sources = [ "protos/fabric_bridge_service.proto" ]
92+
deps = [ "$dir_pw_protobuf:common_protos" ]
93+
strip_prefix = "protos"
94+
prefix = "fabric_bridge_service"
95+
}
96+
8397
pw_proto_library("lighting_service") {
8498
sources = [ "protos/lighting_service.proto" ]
8599
deps = [ "$dir_pw_protobuf:common_protos" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
syntax = "proto3";
2+
3+
import 'pw_protobuf_protos/common.proto';
4+
5+
package chip.rpc;
6+
7+
// Define the message for a synchronized end device with necessary fields
8+
message DeviceInfo {
9+
uint64 node_id = 1;
10+
}
11+
12+
// Define the response message to convey the status of the operation
13+
message OperationStatus {
14+
bool success = 1;
15+
}
16+
17+
service FabricAdmin {
18+
rpc OpenCommissioningWindow(DeviceInfo) returns (OperationStatus){}
19+
}
20+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
syntax = "proto3";
2+
3+
import 'pw_protobuf_protos/common.proto';
4+
5+
package chip.rpc;
6+
7+
// Define the message for a synchronized end device with necessary fields
8+
message SynchronizedDevice {
9+
uint64 node_id = 1;
10+
}
11+
12+
service FabricBridge {
13+
rpc AddSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
14+
}
15+

examples/common/pigweed/rpc_console/py/BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ pw_python_package("chip_rpc") {
4646
"${chip_root}/examples/common/pigweed:descriptor_service.python",
4747
"${chip_root}/examples/common/pigweed:device_service.python",
4848
"${chip_root}/examples/common/pigweed:echo_service.python",
49+
"${chip_root}/examples/common/pigweed:fabric_admin_service.python",
50+
"${chip_root}/examples/common/pigweed:fabric_bridge_service.python",
4951
"${chip_root}/examples/common/pigweed:lighting_service.python",
5052
"${chip_root}/examples/common/pigweed:locking_service.python",
5153
"${chip_root}/examples/common/pigweed:ot_cli_service.python",

examples/common/pigweed/rpc_console/py/chip_rpc/console.py

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
from descriptor_service import descriptor_service_pb2
5454
from device_service import device_service_pb2
5555
from echo_service import echo_pb2
56+
from fabric_admin_service import fabric_admin_service_pb2
57+
from fabric_bridge_service import fabric_bridge_service_pb2
5658
from lighting_service import lighting_service_pb2
5759
from locking_service import locking_service_pb2
5860
from ot_cli_service import ot_cli_service_pb2
@@ -136,6 +138,8 @@ def show_console(device: str, baudrate: int,
136138
descriptor_service_pb2,
137139
device_service_pb2,
138140
echo_pb2,
141+
fabric_admin_service_pb2,
142+
fabric_bridge_service_pb2,
139143
lighting_service_pb2,
140144
locking_service_pb2,
141145
ot_cli_service_pb2,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "app/util/attribute-storage.h"
22+
#include "fabric_admin_service/fabric_admin_service.rpc.pb.h"
23+
#include "pigweed/rpc_services/internal/StatusUtils.h"
24+
#include <app-common/zap-generated/attributes/Accessors.h>
25+
#include <app-common/zap-generated/ids/Attributes.h>
26+
#include <app-common/zap-generated/ids/Clusters.h>
27+
#include <platform/PlatformManager.h>
28+
29+
namespace chip {
30+
namespace rpc {
31+
32+
class FabricAdmin : public pw_rpc::nanopb::FabricAdmin::Service<FabricAdmin>
33+
{
34+
public:
35+
virtual ~FabricAdmin() = default;
36+
37+
virtual pw::Status OpenCommissioningWindow(const chip_rpc_DeviceInfo & request, chip_rpc_OperationStatus & response)
38+
{
39+
return pw::Status::Unimplemented();
40+
}
41+
};
42+
43+
} // namespace rpc
44+
} // namespace chip
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (c) 2024 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include "app/util/attribute-storage.h"
22+
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
23+
#include "pigweed/rpc_services/internal/StatusUtils.h"
24+
#include <app-common/zap-generated/attributes/Accessors.h>
25+
#include <app-common/zap-generated/ids/Attributes.h>
26+
#include <app-common/zap-generated/ids/Clusters.h>
27+
#include <platform/PlatformManager.h>
28+
29+
namespace chip {
30+
namespace rpc {
31+
32+
class FabricBridge : public pw_rpc::nanopb::FabricBridge::Service<FabricBridge>
33+
{
34+
public:
35+
virtual ~FabricBridge() = default;
36+
37+
virtual pw::Status AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
38+
{
39+
return pw::Status::Unimplemented();
40+
}
41+
};
42+
43+
} // namespace rpc
44+
} // namespace chip

examples/fabric-admin/BUILD.gn

+47
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,18 @@ import("${chip_root}/src/lib/core/core.gni")
2222

2323
assert(chip_build_tools)
2424

25+
import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")
26+
27+
if (chip_enable_pw_rpc) {
28+
import("//build_overrides/pigweed.gni")
29+
import("$dir_pw_build/target_types.gni")
30+
}
31+
2532
config("config") {
2633
include_dirs = [
2734
".",
2835
"${chip_root}/examples/common",
36+
"${chip_root}/examples/platform/linux",
2937
"${chip_root}/zzz_generated/app-common/app-common",
3038
"${chip_root}/zzz_generated/chip-tool",
3139
"${chip_root}/src/lib",
@@ -39,6 +47,10 @@ config("config") {
3947
}
4048

4149
cflags = [ "-Wconversion" ]
50+
51+
if (chip_enable_pw_rpc) {
52+
defines += [ "PW_RPC_ENABLED" ]
53+
}
4254
}
4355

4456
static_library("fabric-admin-utils") {
@@ -59,6 +71,7 @@ static_library("fabric-admin-utils") {
5971
"commands/common/HexConversion.h",
6072
"commands/common/RemoteDataModelLogger.cpp",
6173
"commands/common/RemoteDataModelLogger.h",
74+
"commands/fabric-sync/FabricSyncCommand.cpp",
6275
"commands/pairing/OpenCommissioningWindowCommand.cpp",
6376
"commands/pairing/OpenCommissioningWindowCommand.h",
6477
"commands/pairing/PairingCommand.cpp",
@@ -95,6 +108,40 @@ static_library("fabric-admin-utils") {
95108

96109
public_configs = [ ":config" ]
97110

111+
if (chip_enable_pw_rpc) {
112+
defines = [
113+
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
114+
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
115+
]
116+
117+
sources += [
118+
"${chip_root}/examples/platform/linux/RpcClientProcessor.cpp",
119+
"${chip_root}/examples/platform/linux/RpcClientProcessor.h",
120+
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
121+
"rpc/RpcClient.cpp",
122+
"rpc/RpcClient.h",
123+
"rpc/RpcServer.cpp",
124+
"rpc/RpcServer.h",
125+
]
126+
127+
deps += [
128+
"$dir_pw_hdlc:default_addresses",
129+
"$dir_pw_hdlc:rpc_channel_output",
130+
"$dir_pw_log",
131+
"$dir_pw_rpc:server",
132+
"$dir_pw_rpc/system_server:facade",
133+
"$dir_pw_rpc/system_server:socket",
134+
"$dir_pw_stream:socket_stream",
135+
"$dir_pw_sync:mutex",
136+
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
137+
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
138+
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
139+
"${chip_root}/examples/common/pigweed:rpc_services",
140+
]
141+
142+
deps += pw_build_LINK_DEPS
143+
}
144+
98145
if (chip_enable_transport_trace) {
99146
public_deps +=
100147
[ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include <commands/common/Commands.h>
22+
#include <commands/fabric-sync/FabricSyncCommand.h>
23+
24+
void registerCommandsFabricSync(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
25+
{
26+
const char * clusterName = "FabricSync";
27+
28+
commands_list clusterCommands = {
29+
make_unique<FabricSyncAddDeviceCommand>(credsIssuerConfig),
30+
};
31+
32+
commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for fabric synchronization.");
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#include "FabricSyncCommand.h"
20+
#include <commands/common/RemoteDataModelLogger.h>
21+
#include <thread>
22+
#include <unistd.h>
23+
24+
#if defined(PW_RPC_ENABLED)
25+
#include "pw_assert/check.h"
26+
#include "pw_hdlc/decoder.h"
27+
#include "pw_hdlc/default_addresses.h"
28+
#include "pw_hdlc/rpc_channel.h"
29+
#include "pw_rpc/client.h"
30+
#include "pw_stream/socket_stream.h"
31+
32+
#include <rpc/RpcClient.h>
33+
#endif
34+
35+
using namespace ::chip;
36+
37+
CHIP_ERROR FabricSyncAddDeviceCommand::RunCommand(NodeId remoteId)
38+
{
39+
#if defined(PW_RPC_ENABLED)
40+
AddSynchronizedDevice(remoteId);
41+
return CHIP_NO_ERROR;
42+
#else
43+
return CHIP_ERROR_NOT_IMPLEMENTED;
44+
#endif
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2024 Project CHIP Authors
3+
* All rights reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
#pragma once
20+
21+
#include <commands/common/CHIPCommand.h>
22+
23+
class FabricSyncAddDeviceCommand : public CHIPCommand
24+
{
25+
public:
26+
FabricSyncAddDeviceCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-device", credIssuerCommands)
27+
{
28+
AddArgument("nodeid", 0, UINT64_MAX, &mNodeId);
29+
}
30+
31+
/////////// CHIPCommand Interface /////////
32+
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }
33+
34+
chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }
35+
36+
private:
37+
chip::NodeId mNodeId;
38+
39+
CHIP_ERROR RunCommand(NodeId remoteId);
40+
};

0 commit comments

Comments
 (0)