Skip to content

Commit f7da53c

Browse files
authored
Merge branch 'master' into camera-webrtc-provider
2 parents 2c6e618 + d1213a0 commit f7da53c

20 files changed

+167
-139
lines changed

examples/common/pigweed/BUILD.gn

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

83+
pw_proto_library("fabric_sync_common") {
84+
sources = [ "protos/fabric_sync_common.proto" ]
85+
strip_prefix = "protos"
86+
prefix = "fabric_sync_common"
87+
}
88+
8389
pw_proto_library("fabric_admin_service") {
8490
sources = [ "protos/fabric_admin_service.proto" ]
8591
inputs = [ "protos/fabric_admin_service.options" ]
86-
deps = [ "$dir_pw_protobuf:common_protos" ]
92+
deps = [
93+
":fabric_sync_common",
94+
"$dir_pw_protobuf:common_protos",
95+
]
8796
strip_prefix = "protos"
8897
prefix = "fabric_admin_service"
8998
}
9099

91100
pw_proto_library("fabric_bridge_service") {
92101
sources = [ "protos/fabric_bridge_service.proto" ]
93102
inputs = [ "protos/fabric_bridge_service.options" ]
94-
deps = [ "$dir_pw_protobuf:common_protos" ]
103+
deps = [
104+
":fabric_sync_common",
105+
"$dir_pw_protobuf:common_protos",
106+
]
95107
strip_prefix = "protos"
96108
prefix = "fabric_bridge_service"
97109
}

examples/common/pigweed/protos/fabric_admin_service.proto

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
syntax = "proto3";
22

33
import 'pw_protobuf_protos/common.proto';
4+
import 'fabric_sync_common/fabric_sync_common.proto';
45

56
package chip.rpc;
67

78
// Define the message for a synchronized end device with necessary fields
89
message DeviceCommissioningWindowInfo {
9-
uint64 node_id = 1;
10+
ScopedNode id = 1;
1011
uint32 commissioning_timeout = 2;
1112
uint32 discriminator = 3;
1213
uint32 iterations = 4;
@@ -25,7 +26,7 @@ message DeviceCommissioningInfo {
2526
}
2627

2728
message KeepActiveParameters {
28-
uint64 node_id = 1;
29+
ScopedNode id = 1;
2930
uint32 stay_active_duration_ms = 2;
3031
uint32 timeout_ms = 3;
3132
}

examples/common/pigweed/protos/fabric_bridge_service.proto

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
syntax = "proto3";
22

33
import 'pw_protobuf_protos/common.proto';
4+
import 'fabric_sync_common/fabric_sync_common.proto';
45

56
package chip.rpc;
67

78
// Define the message for a synchronized end device with necessary fields
89
message SynchronizedDevice {
9-
uint64 node_id = 1;
10+
ScopedNode id = 1;
1011

1112
optional string unique_id = 2;
1213
optional string vendor_name = 3;
@@ -22,12 +23,12 @@ message SynchronizedDevice {
2223
}
2324

2425
message KeepActiveChanged {
25-
uint64 node_id = 1;
26+
ScopedNode id = 1;
2627
uint32 promised_active_duration_ms = 2;
2728
}
2829

2930
message AdministratorCommissioningChanged {
30-
uint64 node_id = 1;
31+
ScopedNode id = 1;
3132
uint32 window_status = 2;
3233
optional uint32 opener_fabric_index = 3;
3334
optional uint32 opener_vendor_id = 4;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
syntax = "proto3";
2+
3+
message ScopedNode {
4+
uint64 node_id = 1;
5+
uint32 fabric_index = 2;
6+
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pw_python_package("chip_rpc") {
4848
"${chip_root}/examples/common/pigweed:echo_service.python",
4949
"${chip_root}/examples/common/pigweed:fabric_admin_service.python",
5050
"${chip_root}/examples/common/pigweed:fabric_bridge_service.python",
51+
"${chip_root}/examples/common/pigweed:fabric_sync_common.python",
5152
"${chip_root}/examples/common/pigweed:lighting_service.python",
5253
"${chip_root}/examples/common/pigweed:locking_service.python",
5354
"${chip_root}/examples/common/pigweed:ot_cli_service.python",

examples/fabric-admin/commands/pairing/PairingCommand.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,8 @@ void PairingCommand::OnCurrentFabricRemove(void * context, NodeId nodeId, CHIP_E
567567

568568
#if defined(PW_RPC_ENABLED)
569569
app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(command->CurrentCommissioner().GetFabricIndex(), nodeId);
570-
RemoveSynchronizedDevice(nodeId);
570+
ScopedNodeId scopedNodeId(nodeId, command->CurrentCommissioner().GetFabricIndex());
571+
RemoveSynchronizedDevice(scopedNodeId);
571572
#endif
572573
}
573574
else

examples/fabric-admin/device_manager/DeviceSubscription.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,10 @@ CHIP_ERROR DeviceSubscription::StartSubscription(OnDoneCallback onDoneCallback,
215215
mNodeId = nodeId;
216216

217217
#if defined(PW_RPC_ENABLED)
218-
mCurrentAdministratorCommissioningAttributes = chip_rpc_AdministratorCommissioningChanged_init_default;
219-
mCurrentAdministratorCommissioningAttributes.node_id = nodeId;
218+
mCurrentAdministratorCommissioningAttributes = chip_rpc_AdministratorCommissioningChanged_init_default;
219+
mCurrentAdministratorCommissioningAttributes.has_id = true;
220+
mCurrentAdministratorCommissioningAttributes.id.node_id = nodeId;
221+
mCurrentAdministratorCommissioningAttributes.id.fabric_index = controller.GetFabricIndex();
220222
mCurrentAdministratorCommissioningAttributes.window_status =
221223
static_cast<uint32_t>(Clusters::AdministratorCommissioning::CommissioningWindowStatusEnum::kWindowNotOpen);
222224
#endif

examples/fabric-admin/device_manager/DeviceSynchronization.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,12 @@ void DeviceSynchronizer::StartDeviceSynchronization(Controller::DeviceController
205205
mNodeId = nodeId;
206206

207207
#if defined(PW_RPC_ENABLED)
208-
mCurrentDeviceData = chip_rpc_SynchronizedDevice_init_default;
209-
mCurrentDeviceData.node_id = nodeId;
210-
mCurrentDeviceData.has_is_icd = true;
211-
mCurrentDeviceData.is_icd = deviceIsIcd;
208+
mCurrentDeviceData = chip_rpc_SynchronizedDevice_init_default;
209+
mCurrentDeviceData.has_id = true;
210+
mCurrentDeviceData.id.node_id = nodeId;
211+
mCurrentDeviceData.id.fabric_index = controller->GetFabricIndex();
212+
mCurrentDeviceData.has_is_icd = true;
213+
mCurrentDeviceData.is_icd = deviceIsIcd;
212214
#endif
213215

214216
ReturnOnFailure(controller->GetConnectedDevice(nodeId, &mOnDeviceConnectedCallback, &mOnDeviceConnectionFailureCallback));

examples/fabric-admin/rpc/RpcClient.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,14 @@ CHIP_ERROR AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & data)
144144
return WaitForResponse(call);
145145
}
146146

147-
CHIP_ERROR RemoveSynchronizedDevice(NodeId nodeId)
147+
CHIP_ERROR RemoveSynchronizedDevice(ScopedNodeId scopedNodeId)
148148
{
149149
ChipLogProgress(NotSpecified, "RemoveSynchronizedDevice");
150150

151151
chip_rpc_SynchronizedDevice device = chip_rpc_SynchronizedDevice_init_default;
152-
device.node_id = nodeId;
152+
device.has_id = true;
153+
device.id.node_id = scopedNodeId.GetNodeId();
154+
device.id.fabric_index = scopedNodeId.GetFabricIndex();
153155

154156
// The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler
155157
// function and the call will complete.
@@ -164,12 +166,14 @@ CHIP_ERROR RemoveSynchronizedDevice(NodeId nodeId)
164166
return WaitForResponse(call);
165167
}
166168

167-
CHIP_ERROR ActiveChanged(NodeId nodeId, uint32_t promisedActiveDurationMs)
169+
CHIP_ERROR ActiveChanged(ScopedNodeId scopedNodeId, uint32_t promisedActiveDurationMs)
168170
{
169171
ChipLogProgress(NotSpecified, "ActiveChanged");
170172

171173
chip_rpc_KeepActiveChanged parameters;
172-
parameters.node_id = nodeId;
174+
parameters.has_id = true;
175+
parameters.id.node_id = scopedNodeId.GetNodeId();
176+
parameters.id.fabric_index = scopedNodeId.GetFabricIndex();
173177
parameters.promised_active_duration_ms = promisedActiveDurationMs;
174178

175179
// The RPC call is kept alive until it completes. When a response is received, it will be logged by the handler

examples/fabric-admin/rpc/RpcClient.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#pragma once
2020

21+
#include <lib/core/ScopedNodeId.h>
2122
#include <platform/CHIPDeviceLayer.h>
2223

2324
#include "fabric_bridge_service/fabric_bridge_service.rpc.pb.h"
@@ -57,25 +58,25 @@ CHIP_ERROR AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & data);
5758
* It logs the progress and checks if a `RemoveSynchronizedDevice` operation is already in progress.
5859
* If an operation is in progress, it returns `CHIP_ERROR_BUSY`.
5960
*
60-
* @param nodeId The Node ID of the device to be removed.
61+
* @param scopedNodeId The Scoped Node ID of the device to be removed.
6162
* @return CHIP_ERROR An error code indicating the success or failure of the operation.
6263
* - CHIP_NO_ERROR: The RPC command was successfully processed.
6364
* - CHIP_ERROR_BUSY: Another operation is currently in progress.
6465
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
6566
*/
66-
CHIP_ERROR RemoveSynchronizedDevice(chip::NodeId nodeId);
67+
CHIP_ERROR RemoveSynchronizedDevice(chip::ScopedNodeId scopedNodeId);
6768

6869
/**
6970
* @brief Received StayActiveResponse on behalf of client that previously called KeepActive
7071
*
71-
* @param nodeId The Node ID of the device we recieved a StayActiveResponse.
72+
* @param scopedNodeId The Scoped Node ID of the device we recieved a StayActiveResponse.
7273
* @param promisedActiveDurationMs the computed duration (in milliseconds) that the ICD intends to stay active for.
7374
* @return CHIP_ERROR An error code indicating the success or failure of the operation.
7475
* - CHIP_NO_ERROR: The RPC command was successfully processed.
7576
* - CHIP_ERROR_BUSY: Another operation is currently in progress.
7677
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
7778
*/
78-
CHIP_ERROR ActiveChanged(chip::NodeId nodeId, uint32_t promisedActiveDurationMs);
79+
CHIP_ERROR ActiveChanged(chip::ScopedNodeId scopedNodeId, uint32_t promisedActiveDurationMs);
7980

8081
/**
8182
* @brief CADMIN attribute has changed of one of the bridged devices that was previously added.

examples/fabric-admin/rpc/RpcServer.cpp

+39-22
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,40 @@ namespace {
4242

4343
#if defined(PW_RPC_FABRIC_ADMIN_SERVICE) && PW_RPC_FABRIC_ADMIN_SERVICE
4444

45+
struct ScopedNodeIdHasher
46+
{
47+
std::size_t operator()(const chip::ScopedNodeId & scopedNodeId) const
48+
{
49+
std::size_t h1 = std::hash<uint64_t>{}(scopedNodeId.GetFabricIndex());
50+
std::size_t h2 = std::hash<uint64_t>{}(scopedNodeId.GetNodeId());
51+
// Bitshifting h2 reduces collisions when fabricIndex == nodeId.
52+
return h1 ^ (h2 << 1);
53+
}
54+
};
55+
4556
class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
4657
{
4758
public:
4859
void OnCheckInCompleted(const app::ICDClientInfo & clientInfo) override
4960
{
5061
// Accessing mPendingCheckIn should only be done while holding ChipStackLock
5162
assertChipStackLockedByCurrentThread();
52-
NodeId nodeId = clientInfo.peer_node.GetNodeId();
53-
auto it = mPendingCheckIn.find(nodeId);
63+
ScopedNodeId scopedNodeId = clientInfo.peer_node;
64+
auto it = mPendingCheckIn.find(scopedNodeId);
5465
VerifyOrReturn(it != mPendingCheckIn.end());
5566

5667
KeepActiveDataForCheckIn checkInData = it->second;
5768
// Removed from pending map as check-in from this node has occured and we will handle the pending KeepActive
5869
// request.
59-
mPendingCheckIn.erase(nodeId);
70+
mPendingCheckIn.erase(scopedNodeId);
6071

6172
auto timeNow = System::SystemClock().GetMonotonicTimestamp();
6273
if (timeNow > checkInData.mRequestExpiryTimestamp)
6374
{
64-
ChipLogError(
65-
NotSpecified,
66-
"ICD check-in for device we have been waiting, came after KeepActive expiry. Reqeust dropped for Node ID: 0x%lx",
67-
nodeId);
75+
ChipLogError(NotSpecified,
76+
"ICD check-in for device we have been waiting, came after KeepActive expiry. Request dropped for ID: "
77+
"[%d:0x " ChipLogFormatX64 "]",
78+
scopedNodeId.GetFabricIndex(), ChipLogValueX64(scopedNodeId.GetNodeId()));
6879
return;
6980
}
7081

@@ -74,7 +85,7 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
7485
// there is no mechanism for us to communicate with the client that sent out the KeepActive
7586
// command that there was a failure, we simply fail silently. After spec issue is
7687
// addressed, we can implement what spec defines here.
77-
auto onDone = [=](uint32_t promisedActiveDuration) { ActiveChanged(nodeId, promisedActiveDuration); };
88+
auto onDone = [=](uint32_t promisedActiveDuration) { ActiveChanged(scopedNodeId, promisedActiveDuration); };
7889
CHIP_ERROR err = StayActiveSender::SendStayActiveCommand(checkInData.mStayActiveDurationMs, clientInfo.peer_node,
7990
app::InteractionModelEngine::GetInstance(), onDone);
8091
if (err != CHIP_NO_ERROR)
@@ -86,7 +97,10 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
8697
pw::Status OpenCommissioningWindow(const chip_rpc_DeviceCommissioningWindowInfo & request,
8798
chip_rpc_OperationStatus & response) override
8899
{
89-
NodeId nodeId = request.node_id;
100+
VerifyOrReturnValue(request.has_id, pw::Status::InvalidArgument());
101+
// TODO(#35875): OpenDeviceCommissioningWindow uses the same controller every time and doesn't currently accept
102+
// FabricIndex. For now we are dropping fabric index from the scoped node id.
103+
NodeId nodeId = request.id.node_id;
90104
uint32_t commissioningTimeoutSec = request.commissioning_timeout;
91105
uint32_t iterations = request.iterations;
92106
uint16_t discriminator = request.discriminator;
@@ -149,18 +163,19 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
149163

150164
pw::Status KeepActive(const chip_rpc_KeepActiveParameters & request, pw_protobuf_Empty & response) override
151165
{
152-
ChipLogProgress(NotSpecified, "Received KeepActive request: 0x%lx, %u", request.node_id, request.stay_active_duration_ms);
153-
// TODO(#33221): We should really be using ScopedNode, but that requires larger fix in communication between
154-
// fabric-admin and fabric-bridge. For now we make the assumption that there is only one fabric used by
155-
// fabric-admin.
166+
VerifyOrReturnValue(request.has_id, pw::Status::InvalidArgument());
167+
ScopedNodeId scopedNodeId(request.id.node_id, request.id.fabric_index);
168+
ChipLogProgress(NotSpecified, "Received KeepActive request: Id[%d, 0x" ChipLogFormatX64 "], %u",
169+
scopedNodeId.GetFabricIndex(), ChipLogValueX64(scopedNodeId.GetNodeId()), request.stay_active_duration_ms);
170+
156171
KeepActiveWorkData * data =
157-
Platform::New<KeepActiveWorkData>(this, request.node_id, request.stay_active_duration_ms, request.timeout_ms);
172+
Platform::New<KeepActiveWorkData>(this, scopedNodeId, request.stay_active_duration_ms, request.timeout_ms);
158173
VerifyOrReturnValue(data, pw::Status::Internal());
159174
DeviceLayer::PlatformMgr().ScheduleWork(KeepActiveWork, reinterpret_cast<intptr_t>(data));
160175
return pw::OkStatus();
161176
}
162177

163-
void ScheduleSendingKeepActiveOnCheckIn(NodeId nodeId, uint32_t stayActiveDurationMs, uint32_t timeoutMs)
178+
void ScheduleSendingKeepActiveOnCheckIn(ScopedNodeId scopedNodeId, uint32_t stayActiveDurationMs, uint32_t timeoutMs)
164179
{
165180
// Accessing mPendingCheckIn should only be done while holding ChipStackLock
166181
assertChipStackLockedByCurrentThread();
@@ -170,14 +185,14 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
170185
KeepActiveDataForCheckIn checkInData = { .mStayActiveDurationMs = stayActiveDurationMs,
171186
.mRequestExpiryTimestamp = expiryTimestamp };
172187

173-
auto it = mPendingCheckIn.find(nodeId);
188+
auto it = mPendingCheckIn.find(scopedNodeId);
174189
if (it != mPendingCheckIn.end())
175190
{
176191
checkInData.mStayActiveDurationMs = std::max(checkInData.mStayActiveDurationMs, it->second.mStayActiveDurationMs);
177192
checkInData.mRequestExpiryTimestamp = std::max(checkInData.mRequestExpiryTimestamp, it->second.mRequestExpiryTimestamp);
178193
}
179194

180-
mPendingCheckIn[nodeId] = checkInData;
195+
mPendingCheckIn[scopedNodeId] = checkInData;
181196
}
182197

183198
private:
@@ -189,27 +204,29 @@ class FabricAdmin final : public rpc::FabricAdmin, public IcdManager::Delegate
189204

190205
struct KeepActiveWorkData
191206
{
192-
KeepActiveWorkData(FabricAdmin * fabricAdmin, NodeId nodeId, uint32_t stayActiveDurationMs, uint32_t timeoutMs) :
193-
mFabricAdmin(fabricAdmin), mNodeId(nodeId), mStayActiveDurationMs(stayActiveDurationMs), mTimeoutMs(timeoutMs)
207+
KeepActiveWorkData(FabricAdmin * fabricAdmin, ScopedNodeId scopedNodeId, uint32_t stayActiveDurationMs,
208+
uint32_t timeoutMs) :
209+
mFabricAdmin(fabricAdmin),
210+
mScopedNodeId(scopedNodeId), mStayActiveDurationMs(stayActiveDurationMs), mTimeoutMs(timeoutMs)
194211
{}
195212

196213
FabricAdmin * mFabricAdmin;
197-
NodeId mNodeId;
214+
ScopedNodeId mScopedNodeId;
198215
uint32_t mStayActiveDurationMs;
199216
uint32_t mTimeoutMs;
200217
};
201218

202219
static void KeepActiveWork(intptr_t arg)
203220
{
204221
KeepActiveWorkData * data = reinterpret_cast<KeepActiveWorkData *>(arg);
205-
data->mFabricAdmin->ScheduleSendingKeepActiveOnCheckIn(data->mNodeId, data->mStayActiveDurationMs, data->mTimeoutMs);
222+
data->mFabricAdmin->ScheduleSendingKeepActiveOnCheckIn(data->mScopedNodeId, data->mStayActiveDurationMs, data->mTimeoutMs);
206223
Platform::Delete(data);
207224
}
208225

209226
// Modifications to mPendingCheckIn should be done on the MatterEventLoop thread
210227
// otherwise we would need a mutex protecting this data to prevent race as this
211228
// data is accessible by both RPC thread and Matter eventloop.
212-
std::unordered_map<NodeId, KeepActiveDataForCheckIn> mPendingCheckIn;
229+
std::unordered_map<ScopedNodeId, KeepActiveDataForCheckIn, ScopedNodeIdHasher> mPendingCheckIn;
213230
};
214231

215232
FabricAdmin fabric_admin_service;

examples/fabric-bridge-app/fabric-bridge-common/include/BridgedDevice.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class BridgedDevice
4949
std::optional<chip::VendorId> openerVendorId = std::nullopt;
5050
};
5151

52-
BridgedDevice(chip::NodeId nodeId);
52+
BridgedDevice(chip::ScopedNodeId scopedNodeId);
5353
virtual ~BridgedDevice() = default;
5454

5555
[[nodiscard]] bool IsReachable() const { return mReachable; }
@@ -62,7 +62,7 @@ class BridgedDevice
6262

6363
inline void SetEndpointId(chip::EndpointId id) { mEndpointId = id; };
6464
inline chip::EndpointId GetEndpointId() { return mEndpointId; };
65-
inline chip::NodeId GetNodeId() { return mNodeId; };
65+
inline chip::ScopedNodeId GetScopedNodeId() { return mScopedNodeId; };
6666
inline void SetParentEndpointId(chip::EndpointId id) { mParentEndpointId = id; };
6767
inline chip::EndpointId GetParentEndpointId() { return mParentEndpointId; };
6868

@@ -80,7 +80,7 @@ class BridgedDevice
8080
bool mReachable = false;
8181
bool mIsIcd = false;
8282

83-
chip::NodeId mNodeId = 0;
83+
chip::ScopedNodeId mScopedNodeId;
8484
chip::EndpointId mEndpointId = 0;
8585
chip::EndpointId mParentEndpointId = 0;
8686

0 commit comments

Comments
 (0)