Skip to content

Commit

Permalink
RPC: Add RPC to set ota metadata for provider
Browse files Browse the repository at this point in the history
Add an RPC to set the TLV data in metadata for provider,
which is used during the SendQueryImageRequest.
  • Loading branch information
Rob Oliver committed Aug 22, 2022
1 parent 4711f98 commit 003593e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/common/pigweed/protos/device_service.options
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ chip.rpc.PairingInfo.qr_code max_size:256
chip.rpc.PairingInfo.qr_code_url max_size:256
chip.rpc.SpakeInfo.verifier max_size:97 // kSpake2p_VerifierSerialized_Length
chip.rpc.SpakeInfo.salt max_size:32 // kSpake2p_Max_PBKDF_Salt_Length
chip.rpc.MetadataForProvider.tlv max_size:512 // length defined in chip spec 11.20.6.7
5 changes: 5 additions & 0 deletions examples/common/pigweed/protos/device_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ message PairingState {
bool pairing_enabled = 1;
}

message MetadataForProvider {
bytes tlv = 1;
}

service Device {
rpc FactoryReset(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc Reboot(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc TriggerOta(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
rpc SetOtaMetadataForProvider(MetadataForProvider) returns (pw.protobuf.Empty){}
rpc GetDeviceInfo(pw.protobuf.Empty) returns (DeviceInfo){}
rpc GetDeviceState(pw.protobuf.Empty) returns (DeviceState){}
rpc SetPairingState(PairingState) returns (pw.protobuf.Empty){}
Expand Down
33 changes: 30 additions & 3 deletions examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>

virtual pw::Status TriggerOta(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
{
#if CONFIG_CHIP_OTA_REQUESTOR
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
chip::DeviceLayer::PlatformMgr().ScheduleWork(
[](intptr_t) {
chip::OTARequestorInterface * requestor = chip::GetRequestorInstance();
Expand All @@ -238,10 +238,33 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
},
reinterpret_cast<intptr_t>(nullptr));
return pw::OkStatus();
#else
#else // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
ChipLogError(AppServer, "Trigger OTA requested, but OTA requestor not compiled in.");
return pw::Status::Unimplemented();
#endif
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
}

virtual pw::Status SetOtaMetadataForProvider(const chip_rpc_MetadataForProvider & request, pw_protobuf_Empty & response)
{
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
chip::OTARequestorInterface * requestor = chip::GetRequestorInstance();
if (requestor == nullptr)
{
ChipLogError(SoftwareUpdate, "Can't get the CASESessionManager");
return pw::Status::Unavailable();
}
else if (sizeof(metadataForProviderBuffer) < request.tlv.size)
{
return pw::Status::ResourceExhausted();
}
memcpy(metadataForProviderBuffer, request.tlv.bytes, request.tlv.size);
DeviceLayer::StackLock lock;
requestor->SetMetadataForProvider(chip::ByteSpan(metadataForProviderBuffer, request.tlv.size));
return pw::OkStatus();
#else // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
ChipLogError(AppServer, "OTA set metadata for provider requested, but OTA requestor not compiled in.");
return pw::Status::Unimplemented();
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
}

virtual pw::Status SetPairingState(const chip_rpc_PairingState & request, pw_protobuf_Empty & response)
Expand Down Expand Up @@ -415,6 +438,10 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
}

private:
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
static constexpr size_t kMaxMetadataForProviderLength = 512; // length defined in chip spec 11.20.6.7
uint8_t metadataForProviderBuffer[kMaxMetadataForProviderLength];
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
Internal::CommissionableDataProviderRpcWrapper mCommissionableDataProvider;
};

Expand Down

0 comments on commit 003593e

Please sign in to comment.