Skip to content

Commit 3db6cd0

Browse files
authored
Merge branch 'master' into tizen-update
2 parents df6251d + d31cb54 commit 3db6cd0

File tree

12 files changed

+123
-31
lines changed

12 files changed

+123
-31
lines changed

.github/workflows/examples-linux-standalone.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,21 @@ jobs:
202202
run: |
203203
./scripts/run_in_build_env.sh \
204204
"./scripts/build/build_examples.py \
205-
--target linux-x64-fabric-admin \
205+
--target linux-x64-fabric-admin-rpc \
206206
build"
207207
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
208208
linux debug fabric-admin \
209-
out/linux-x64-fabric-admin/fabric-admin \
209+
out/linux-x64-fabric-admin-rpc/fabric-admin \
210210
/tmp/bloat_reports/
211211
- name: Build example Fabric Bridge App
212212
run: |
213213
./scripts/run_in_build_env.sh \
214214
"./scripts/build/build_examples.py \
215-
--target linux-x64-fabric-bridge \
215+
--target linux-x64-fabric-bridge-no-ble-rpc \
216216
build"
217217
.environment/pigweed-venv/bin/python3 scripts/tools/memory/gh_sizes.py \
218218
linux debug fabric-bridge-app \
219-
out/linux-x64-fabric-bridge/fabric-bridge-app \
219+
out/linux-x64-fabric-bridge-no-ble-rpc/fabric-bridge-app \
220220
/tmp/bloat_reports/
221221
- name: Uploading Size Reports
222222
uses: ./.github/actions/upload-size-reports

examples/common/pigweed/protos/fabric_bridge_service.proto

+1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ message SynchronizedDevice {
1111

1212
service FabricBridge {
1313
rpc AddSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
14+
rpc RemoveSynchronizedDevice(SynchronizedDevice) returns (pw.protobuf.Empty){}
1415
}
1516

examples/common/pigweed/rpc_services/FabricBridge.h

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class FabricBridge : public pw_rpc::nanopb::FabricBridge::Service<FabricBridge>
3838
{
3939
return pw::Status::Unimplemented();
4040
}
41+
42+
virtual pw::Status RemoveSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
43+
{
44+
return pw::Status::Unimplemented();
45+
}
4146
};
4247

4348
} // namespace rpc

examples/fabric-admin/BUILD.gn

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ config("config") {
4646
defines += [ "CONFIG_USE_LOCAL_STORAGE" ]
4747
}
4848

49-
cflags = [ "-Wconversion" ]
50-
5149
if (chip_enable_pw_rpc) {
5250
defines += [ "PW_RPC_ENABLED" ]
5351
}
@@ -144,6 +142,10 @@ static_library("fabric-admin-utils") {
144142
]
145143

146144
deps += pw_build_LINK_DEPS
145+
} else {
146+
# The system_rpc_server.cc file is in pigweed and doesn't compile with
147+
# -Wconversion, remove check for RPC build only.
148+
cflags = [ "-Wconversion" ]
147149
}
148150

149151
if (chip_enable_transport_trace) {

examples/fabric-admin/args.gni

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ matter_log_json_payload_decode_full = true
3232
# make fabric-admin very strict by default
3333
chip_tlv_validate_char_string_on_read = true
3434
chip_tlv_validate_char_string_on_write = true
35+
chip_enable_ble = true

examples/fabric-admin/rpc/RpcClient.cpp

+45-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ constexpr uint32_t kDefaultChannelId = 1;
4141
// Fabric Bridge Client
4242
rpc::pw_rpc::nanopb::FabricBridge::Client fabricBridgeClient(rpc::client::GetDefaultRpcClient(), kDefaultChannelId);
4343
pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> addSynchronizedDeviceCall;
44+
pw::rpc::NanopbUnaryReceiver<::pw_protobuf_Empty> removeSynchronizedDeviceCall;
4445

4546
// Callback function to be called when the RPC response is received
4647
void OnAddDeviceResponseCompleted(const pw_protobuf_Empty & response, pw::Status status)
@@ -55,6 +56,19 @@ void OnAddDeviceResponseCompleted(const pw_protobuf_Empty & response, pw::Status
5556
}
5657
}
5758

59+
// Callback function to be called when the RPC response is received
60+
void OnRemoveDeviceResponseCompleted(const pw_protobuf_Empty & response, pw::Status status)
61+
{
62+
if (status.ok())
63+
{
64+
ChipLogProgress(NotSpecified, "RemoveSynchronizedDevice RPC call succeeded!");
65+
}
66+
else
67+
{
68+
ChipLogProgress(NotSpecified, "RemoveSynchronizedDevice RPC call failed with status: %d", status.code());
69+
}
70+
}
71+
5872
} // namespace
5973

6074
CHIP_ERROR InitRpcClient(uint16_t rpcServerPort)
@@ -76,11 +90,41 @@ CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId)
7690
chip_rpc_SynchronizedDevice device;
7791
device.node_id = nodeId;
7892

79-
// The RPC will remain active as long as `addSynchronizedDeviceCall` is alive.
93+
// By assigning the returned call to the global 'addSynchronizedDeviceCall', the RPC
94+
// call is kept alive until it completes. When a response is received, it
95+
// will be logged by the handler function and the call will complete.
8096
addSynchronizedDeviceCall = fabricBridgeClient.AddSynchronizedDevice(device, OnAddDeviceResponseCompleted);
8197

8298
if (!addSynchronizedDeviceCall.active())
8399
{
100+
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
101+
return CHIP_ERROR_INTERNAL;
102+
}
103+
104+
return CHIP_NO_ERROR;
105+
}
106+
107+
CHIP_ERROR RemoveSynchronizedDevice(chip::NodeId nodeId)
108+
{
109+
ChipLogProgress(NotSpecified, "RemoveSynchronizedDevice");
110+
111+
if (removeSynchronizedDeviceCall.active())
112+
{
113+
ChipLogError(NotSpecified, "Remove Synchronized Device operation is in progress\n");
114+
return CHIP_ERROR_BUSY;
115+
}
116+
117+
chip_rpc_SynchronizedDevice device;
118+
device.node_id = nodeId;
119+
120+
// By assigning the returned call to the global 'removeSynchronizedDeviceCall', the RPC
121+
// call is kept alive until it completes. When a response is received, it
122+
// will be logged by the handler function and the call will complete.
123+
removeSynchronizedDeviceCall = fabricBridgeClient.RemoveSynchronizedDevice(device, OnRemoveDeviceResponseCompleted);
124+
125+
if (!removeSynchronizedDeviceCall.active())
126+
{
127+
// The RPC call was not sent. This could occur due to, for example, an invalid channel ID. Handle if necessary.
84128
return CHIP_ERROR_INTERNAL;
85129
}
86130

examples/fabric-admin/rpc/RpcClient.h

+15
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,18 @@ CHIP_ERROR InitRpcClient(uint16_t rpcServerPort);
4646
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
4747
*/
4848
CHIP_ERROR AddSynchronizedDevice(chip::NodeId nodeId);
49+
50+
/**
51+
* @brief Removes a synchronized device from the RPC client.
52+
*
53+
* This function attempts to remove a device identified by its `nodeId` from the synchronized device list.
54+
* It logs the progress and checks if a `RemoveSynchronizedDevice` operation is already in progress.
55+
* If an operation is in progress, it returns `CHIP_ERROR_BUSY`.
56+
*
57+
* @param nodeId The Node ID of the device to be removed.
58+
* @return CHIP_ERROR An error code indicating the success or failure of the operation.
59+
* - CHIP_NO_ERROR: The RPC command was successfully sent.
60+
* - CHIP_ERROR_BUSY: Another operation is currently in progress.
61+
* - CHIP_ERROR_INTERNAL: An internal error occurred while activating the RPC call.
62+
*/
63+
CHIP_ERROR RemoveSynchronizedDevice(chip::NodeId nodeId);

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ executable("fabric-bridge-app") {
4646
"${chip_root}/src/lib",
4747
]
4848

49-
cflags = [ "-Wconversion" ]
50-
5149
include_dirs = [ "include" ]
5250

5351
if (bridge_enable_pw_rpc) {
@@ -87,6 +85,10 @@ executable("fabric-bridge-app") {
8785
"${chip_root}/examples/common",
8886
"${chip_root}/examples/platform/linux",
8987
]
88+
} else {
89+
# The system_rpc_server.cc file is in pigweed and doesn't compile with
90+
# -Wconversion, remove check for RPC build only.
91+
cflags = [ "-Wconversion" ]
9092
}
9193

9294
output_dir = root_out_dir

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

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class FabricBridge final : public chip::rpc::FabricBridge
4343
{
4444
public:
4545
pw::Status AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response) override;
46+
pw::Status RemoveSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response) override;
4647
};
4748

4849
pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
@@ -64,6 +65,21 @@ pw::Status FabricBridge::AddSynchronizedDevice(const chip_rpc_SynchronizedDevice
6465
return pw::OkStatus();
6566
}
6667

68+
pw::Status FabricBridge::RemoveSynchronizedDevice(const chip_rpc_SynchronizedDevice & request, pw_protobuf_Empty & response)
69+
{
70+
NodeId nodeId = request.node_id;
71+
ChipLogProgress(NotSpecified, "Received RemoveSynchronizedDevice: " ChipLogFormatX64, ChipLogValueX64(nodeId));
72+
73+
int removed_idx = DeviceMgr().RemoveDeviceByNodeId(nodeId);
74+
if (removed_idx < 0)
75+
{
76+
ChipLogError(NotSpecified, "Failed to remove device with nodeId=0x" ChipLogFormatX64, ChipLogValueX64(nodeId));
77+
return pw::Status::NotFound();
78+
}
79+
80+
return pw::OkStatus();
81+
}
82+
6783
FabricBridge fabric_bridge_service;
6884
#endif // defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
6985

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

+3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ using namespace chip::app::Clusters::AdministratorCommissioning;
4747
namespace {
4848

4949
constexpr uint16_t kPollIntervalMs = 100;
50+
51+
#if defined(PW_RPC_FABRIC_BRIDGE_SERVICE) && PW_RPC_FABRIC_BRIDGE_SERVICE
5052
constexpr uint16_t kRetryIntervalS = 3;
53+
#endif
5154

5255
bool KeyboardHit()
5356
{

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHsm_P256_trustm.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,16 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
252252

253253
return_status = trustm_ecdh_derive_secret(OPTIGA_KEY_ID_E100, (uint8_t *) remote_key, (uint16_t) rem_pubKeyLen + 3,
254254
out_secret.Bytes(), (uint8_t) secret_length);
255-
256255
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
256+
out_secret.SetLength(secret_length);
257+
error = CHIP_NO_ERROR;
257258

258259
exit:
259260
if (error != CHIP_NO_ERROR)
260261
{
261262
trustm_close();
262263
}
263-
return out_secret.SetLength(secret_length);
264+
return error;
264265
#endif
265266
}
266267

@@ -295,7 +296,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_hash_signature(const uint8_t * hash, si
295296
(uint8_t *) bytes, (uint8_t) kP256_PublicKey_Length);
296297

297298
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
298-
299+
error = CHIP_NO_ERROR;
299300
exit:
300301
if (error != CHIP_NO_ERROR)
301302
{
@@ -407,7 +408,7 @@ CHIP_ERROR P256PublicKey::ECDSA_validate_msg_signature(const uint8_t * msg, size
407408
(uint8_t *) bytes, (uint8_t) kP256_PublicKey_Length);
408409

409410
VerifyOrExit(return_status == OPTIGA_LIB_SUCCESS, error = CHIP_ERROR_INTERNAL);
410-
411+
error = CHIP_NO_ERROR;
411412
exit:
412413
if (error != CHIP_NO_ERROR)
413414
{

src/platform/Infineon/crypto/trustm/CHIPCryptoPALHsm_utils_trustm.cpp

+20-18
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,9 @@ optiga_lib_status_t deriveKey_HKDF(const uint8_t * salt, uint16_t salt_length, c
426426
break;
427427
}
428428

429-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
429+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
430430
;
431+
431432
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
432433
{
433434
// optiga_crypt_hkdf failed
@@ -539,8 +540,9 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
539540
break;
540541
}
541542

542-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
543+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
543544
;
545+
544546
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
545547
{
546548
// optiga_crypt_hkdf failed
@@ -578,8 +580,9 @@ optiga_lib_status_t optiga_crypt_rng(uint8_t * random_data, uint16_t random_data
578580
break;
579581
}
580582

581-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
583+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
582584
;
585+
583586
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
584587
{
585588
// optiga_crypt_random failed
@@ -626,7 +629,7 @@ optiga_lib_status_t trustm_ecc_keygen(uint16_t optiga_key_id, uint8_t key_type,
626629
break;
627630
}
628631

629-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
632+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
630633
;
631634

632635
} while (0);
@@ -696,8 +699,10 @@ optiga_lib_status_t trustm_hash(uint8_t * msg, uint16_t msg_length, uint8_t * di
696699
optiga_lib_print_message("optiga_crypt_hash api returns error !!!", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
697700
break;
698701
}
699-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
702+
703+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
700704
;
705+
701706
} while (0);
702707

703708
if (p_local_crypt)
@@ -729,7 +734,8 @@ optiga_lib_status_t trustm_ecdsa_sign(optiga_key_id_t optiga_key_id, uint8_t * d
729734
OPTIGA_UTIL_SERVICE_COLOR);
730735
break;
731736
}
732-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
737+
738+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
733739
;
734740

735741
for (i = (*signature_length - 1); i >= 0; i--)
@@ -803,8 +809,10 @@ optiga_lib_status_t trustm_ecdsa_verify(uint8_t * digest, uint8_t digest_length,
803809
OPTIGA_UTIL_SERVICE_COLOR);
804810
break;
805811
}
806-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
812+
813+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
807814
;
815+
808816
} while (0);
809817

810818
if (p_local_crypt)
@@ -852,14 +860,6 @@ CHIP_ERROR trustmGetCertificate(uint16_t optiga_oid, uint8_t * buf, uint16_t * b
852860

853861
memcpy(buf, ifx_cert_hex, ifx_cert_hex_len);
854862
*buflen = ifx_cert_hex_len;
855-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
856-
;
857-
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
858-
{
859-
// optiga_util_read_data failed
860-
optiga_lib_print_message("optiga_util_read_data failed", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
861-
break;
862-
}
863863
} while (0);
864864

865865
if (p_local_util)
@@ -896,8 +896,10 @@ optiga_lib_status_t trustm_ecdh_derive_secret(optiga_key_id_t optiga_key_id, uin
896896
optiga_lib_print_message("optiga_crypt_ecdh api returns error !!!", OPTIGA_UTIL_SERVICE, OPTIGA_UTIL_SERVICE_COLOR);
897897
break;
898898
}
899-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
899+
900+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
900901
;
902+
901903
} while (0);
902904

903905
if (p_local_crypt)
@@ -957,7 +959,7 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
957959
}
958960
}
959961

960-
while (optiga_lib_status == OPTIGA_LIB_BUSY)
962+
while (p_local_crypt->instance_state != OPTIGA_LIB_INSTANCE_FREE)
961963
;
962964

963965
if (OPTIGA_LIB_SUCCESS != optiga_lib_status)
@@ -978,4 +980,4 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
978980
optiga_crypt_destroy(p_local_crypt);
979981
}
980982
return return_status;
981-
}
983+
}

0 commit comments

Comments
 (0)