Skip to content

Commit

Permalink
[Fabric-Sync] Add the IPC support between Fabric_Admin and Fabric_Bri…
Browse files Browse the repository at this point in the history
…dge (#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
  • Loading branch information
yufengwangca authored and pull[bot] committed Jun 18, 2024
1 parent 2510da5 commit b0cc318
Show file tree
Hide file tree
Showing 27 changed files with 1,149 additions and 7 deletions.
14 changes: 14 additions & 0 deletions examples/common/pigweed/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ pw_proto_library("button_service") {
prefix = "button_service"
}

pw_proto_library("fabric_admin_service") {
sources = [ "protos/fabric_admin_service.proto" ]
deps = [ "$dir_pw_protobuf:common_protos" ]
strip_prefix = "protos"
prefix = "fabric_admin_service"
}

pw_proto_library("fabric_bridge_service") {
sources = [ "protos/fabric_bridge_service.proto" ]
deps = [ "$dir_pw_protobuf:common_protos" ]
strip_prefix = "protos"
prefix = "fabric_bridge_service"
}

pw_proto_library("lighting_service") {
sources = [ "protos/lighting_service.proto" ]
deps = [ "$dir_pw_protobuf:common_protos" ]
Expand Down
20 changes: 20 additions & 0 deletions examples/common/pigweed/protos/fabric_admin_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
syntax = "proto3";

import 'pw_protobuf_protos/common.proto';

package chip.rpc;

// Define the message for a synchronized end device with necessary fields
message DeviceInfo {
uint64 node_id = 1;
}

// Define the response message to convey the status of the operation
message OperationStatus {
bool success = 1;
}

service FabricAdmin {
rpc OpenCommissioningWindow(DeviceInfo) returns (OperationStatus){}
}

15 changes: 15 additions & 0 deletions examples/common/pigweed/protos/fabric_bridge_service.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";

import 'pw_protobuf_protos/common.proto';

package chip.rpc;

// Define the message for a synchronized end device with necessary fields
message SynchronizedDevice {
uint64 node_id = 1;
}

service FabricBridge {
rpc AddSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
}

2 changes: 2 additions & 0 deletions examples/common/pigweed/rpc_console/py/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ pw_python_package("chip_rpc") {
"${chip_root}/examples/common/pigweed:descriptor_service.python",
"${chip_root}/examples/common/pigweed:device_service.python",
"${chip_root}/examples/common/pigweed:echo_service.python",
"${chip_root}/examples/common/pigweed:fabric_admin_service.python",
"${chip_root}/examples/common/pigweed:fabric_bridge_service.python",
"${chip_root}/examples/common/pigweed:lighting_service.python",
"${chip_root}/examples/common/pigweed:locking_service.python",
"${chip_root}/examples/common/pigweed:ot_cli_service.python",
Expand Down
4 changes: 4 additions & 0 deletions examples/common/pigweed/rpc_console/py/chip_rpc/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
from descriptor_service import descriptor_service_pb2
from device_service import device_service_pb2
from echo_service import echo_pb2
from fabric_admin_service import fabric_admin_service_pb2
from fabric_bridge_service import fabric_bridge_service_pb2
from lighting_service import lighting_service_pb2
from locking_service import locking_service_pb2
from ot_cli_service import ot_cli_service_pb2
Expand Down Expand Up @@ -136,6 +138,8 @@ def show_console(device: str, baudrate: int,
descriptor_service_pb2,
device_service_pb2,
echo_pb2,
fabric_admin_service_pb2,
fabric_bridge_service_pb2,
lighting_service_pb2,
locking_service_pb2,
ot_cli_service_pb2,
Expand Down
44 changes: 44 additions & 0 deletions examples/common/pigweed/rpc_services/FabricAdmin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "app/util/attribute-storage.h"
#include "fabric_admin_service/fabric_admin_service.rpc.pb.h"
#include "pigweed/rpc_services/internal/StatusUtils.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <platform/PlatformManager.h>

namespace chip {
namespace rpc {

class FabricAdmin : public pw_rpc::nanopb::FabricAdmin::Service<FabricAdmin>
{
public:
virtual ~FabricAdmin() = default;

virtual pw::Status OpenCommissioningWindow(const chip_rpc_DeviceInfo & request, chip_rpc_OperationStatus & response)
{
return pw::Status::Unimplemented();
}
};

} // namespace rpc
} // namespace chip
44 changes: 44 additions & 0 deletions examples/common/pigweed/rpc_services/FabricBridge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include "app/util/attribute-storage.h"
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
#include "pigweed/rpc_services/internal/StatusUtils.h"
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <platform/PlatformManager.h>

namespace chip {
namespace rpc {

class FabricBridge : public pw_rpc::nanopb::FabricBridge::Service<FabricBridge>
{
public:
virtual ~FabricBridge() = default;

virtual pw::Status AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
{
return pw::Status::Unimplemented();
}
};

} // namespace rpc
} // namespace chip
47 changes: 47 additions & 0 deletions examples/fabric-admin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ import("${chip_root}/src/lib/core/core.gni")

assert(chip_build_tools)

import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni")

if (chip_enable_pw_rpc) {
import("//build_overrides/pigweed.gni")
import("$dir_pw_build/target_types.gni")
}

config("config") {
include_dirs = [
".",
"${chip_root}/examples/common",
"${chip_root}/examples/platform/linux",
"${chip_root}/zzz_generated/app-common/app-common",
"${chip_root}/zzz_generated/chip-tool",
"${chip_root}/src/lib",
Expand All @@ -39,6 +47,10 @@ config("config") {
}

cflags = [ "-Wconversion" ]

if (chip_enable_pw_rpc) {
defines += [ "PW_RPC_ENABLED" ]
}
}

static_library("fabric-admin-utils") {
Expand All @@ -59,6 +71,7 @@ static_library("fabric-admin-utils") {
"commands/common/HexConversion.h",
"commands/common/RemoteDataModelLogger.cpp",
"commands/common/RemoteDataModelLogger.h",
"commands/fabric-sync/FabricSyncCommand.cpp",
"commands/pairing/OpenCommissioningWindowCommand.cpp",
"commands/pairing/OpenCommissioningWindowCommand.h",
"commands/pairing/PairingCommand.cpp",
Expand Down Expand Up @@ -95,6 +108,40 @@ static_library("fabric-admin-utils") {

public_configs = [ ":config" ]

if (chip_enable_pw_rpc) {
defines = [
"PW_RPC_FABRIC_ADMIN_SERVICE=1",
"PW_RPC_FABRIC_BRIDGE_SERVICE=1",
]

sources += [
"${chip_root}/examples/platform/linux/RpcClientProcessor.cpp",
"${chip_root}/examples/platform/linux/RpcClientProcessor.h",
"${chip_root}/examples/platform/linux/system_rpc_server.cc",
"rpc/RpcClient.cpp",
"rpc/RpcClient.h",
"rpc/RpcServer.cpp",
"rpc/RpcServer.h",
]

deps += [
"$dir_pw_hdlc:default_addresses",
"$dir_pw_hdlc:rpc_channel_output",
"$dir_pw_log",
"$dir_pw_rpc:server",
"$dir_pw_rpc/system_server:facade",
"$dir_pw_rpc/system_server:socket",
"$dir_pw_stream:socket_stream",
"$dir_pw_sync:mutex",
"${chip_root}/config/linux/lib/pw_rpc:pw_rpc",
"${chip_root}/examples/common/pigweed:fabric_admin_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:fabric_bridge_service.nanopb_rpc",
"${chip_root}/examples/common/pigweed:rpc_services",
]

deps += pw_build_LINK_DEPS
}

if (chip_enable_transport_trace) {
public_deps +=
[ "${chip_root}/examples/common/tracing:trace_handlers_decoder" ]
Expand Down
33 changes: 33 additions & 0 deletions examples/fabric-admin/commands/fabric-sync/Commands.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#pragma once

#include <commands/common/Commands.h>
#include <commands/fabric-sync/FabricSyncCommand.h>

void registerCommandsFabricSync(Commands & commands, CredentialIssuerCommands * credsIssuerConfig)
{
const char * clusterName = "FabricSync";

commands_list clusterCommands = {
make_unique<FabricSyncAddDeviceCommand>(credsIssuerConfig),
};

commands.RegisterCommandSet(clusterName, clusterCommands, "Commands for fabric synchronization.");
}
45 changes: 45 additions & 0 deletions examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "FabricSyncCommand.h"
#include <commands/common/RemoteDataModelLogger.h>
#include <thread>
#include <unistd.h>

#if defined(PW_RPC_ENABLED)
#include "pw_assert/check.h"
#include "pw_hdlc/decoder.h"
#include "pw_hdlc/default_addresses.h"
#include "pw_hdlc/rpc_channel.h"
#include "pw_rpc/client.h"
#include "pw_stream/socket_stream.h"

#include <rpc/RpcClient.h>
#endif

using namespace ::chip;

CHIP_ERROR FabricSyncAddDeviceCommand::RunCommand(NodeId remoteId)
{
#if defined(PW_RPC_ENABLED)
AddSynchronizedDevice(remoteId);
return CHIP_NO_ERROR;
#else
return CHIP_ERROR_NOT_IMPLEMENTED;
#endif
}
40 changes: 40 additions & 0 deletions examples/fabric-admin/commands/fabric-sync/FabricSyncCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#pragma once

#include <commands/common/CHIPCommand.h>

class FabricSyncAddDeviceCommand : public CHIPCommand
{
public:
FabricSyncAddDeviceCommand(CredentialIssuerCommands * credIssuerCommands) : CHIPCommand("add-device", credIssuerCommands)
{
AddArgument("nodeid", 0, UINT64_MAX, &mNodeId);
}

/////////// CHIPCommand Interface /////////
CHIP_ERROR RunCommand() override { return RunCommand(mNodeId); }

chip::System::Clock::Timeout GetWaitDuration() const override { return chip::System::Clock::Seconds16(1); }

private:
chip::NodeId mNodeId;

CHIP_ERROR RunCommand(NodeId remoteId);
};
Loading

0 comments on commit b0cc318

Please sign in to comment.