Skip to content

Commit 3b41dbe

Browse files
author
rgoliver
authored
OTA: Add SetMetadataForProvider to requestor (project-chip#22005)
* OTA: Add SetMetadataForProvider to requestor Add a setter for the OTA MetadataForProvider, which is provided during the QueryImageRequest. * RPC: Add RPC to set ota metadata for provider Add an RPC to set the TLV data in metadata for provider, which is used during the SendQueryImageRequest.
1 parent 095f6b5 commit 3b41dbe

File tree

6 files changed

+45
-3
lines changed

6 files changed

+45
-3
lines changed

examples/common/pigweed/protos/device_service.options

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ chip.rpc.PairingInfo.qr_code max_size:256
55
chip.rpc.PairingInfo.qr_code_url max_size:256
66
chip.rpc.SpakeInfo.verifier max_size:97 // kSpake2p_VerifierSerialized_Length
77
chip.rpc.SpakeInfo.salt max_size:32 // kSpake2p_Max_PBKDF_Salt_Length
8+
chip.rpc.MetadataForProvider.tlv max_size:512 // length defined in chip spec 11.20.6.7

examples/common/pigweed/protos/device_service.proto

+5
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ message PairingState {
4141
bool pairing_enabled = 1;
4242
}
4343

44+
message MetadataForProvider {
45+
bytes tlv = 1;
46+
}
47+
4448
service Device {
4549
rpc FactoryReset(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
4650
rpc Reboot(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
4751
rpc TriggerOta(pw.protobuf.Empty) returns (pw.protobuf.Empty){}
52+
rpc SetOtaMetadataForProvider(MetadataForProvider) returns (pw.protobuf.Empty){}
4853
rpc GetDeviceInfo(pw.protobuf.Empty) returns (DeviceInfo){}
4954
rpc GetDeviceState(pw.protobuf.Empty) returns (DeviceState){}
5055
rpc SetPairingState(PairingState) returns (pw.protobuf.Empty){}

examples/common/pigweed/rpc_services/Device.h

+30-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
223223

224224
virtual pw::Status TriggerOta(const pw_protobuf_Empty & request, pw_protobuf_Empty & response)
225225
{
226-
#if CONFIG_CHIP_OTA_REQUESTOR
226+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
227227
chip::DeviceLayer::PlatformMgr().ScheduleWork(
228228
[](intptr_t) {
229229
chip::OTARequestorInterface * requestor = chip::GetRequestorInstance();
@@ -238,10 +238,33 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
238238
},
239239
reinterpret_cast<intptr_t>(nullptr));
240240
return pw::OkStatus();
241-
#else
241+
#else // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
242242
ChipLogError(AppServer, "Trigger OTA requested, but OTA requestor not compiled in.");
243243
return pw::Status::Unimplemented();
244-
#endif
244+
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
245+
}
246+
247+
virtual pw::Status SetOtaMetadataForProvider(const chip_rpc_MetadataForProvider & request, pw_protobuf_Empty & response)
248+
{
249+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
250+
chip::OTARequestorInterface * requestor = chip::GetRequestorInstance();
251+
if (requestor == nullptr)
252+
{
253+
ChipLogError(SoftwareUpdate, "Can't get the CASESessionManager");
254+
return pw::Status::Unavailable();
255+
}
256+
else if (sizeof(metadataForProviderBuffer) < request.tlv.size)
257+
{
258+
return pw::Status::ResourceExhausted();
259+
}
260+
memcpy(metadataForProviderBuffer, request.tlv.bytes, request.tlv.size);
261+
DeviceLayer::StackLock lock;
262+
requestor->SetMetadataForProvider(chip::ByteSpan(metadataForProviderBuffer, request.tlv.size));
263+
return pw::OkStatus();
264+
#else // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
265+
ChipLogError(AppServer, "OTA set metadata for provider requested, but OTA requestor not compiled in.");
266+
return pw::Status::Unimplemented();
267+
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
245268
}
246269

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

417440
private:
441+
#if CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
442+
static constexpr size_t kMaxMetadataForProviderLength = 512; // length defined in chip spec 11.20.6.7
443+
uint8_t metadataForProviderBuffer[kMaxMetadataForProviderLength];
444+
#endif // CHIP_DEVICE_CONFIG_ENABLE_OTA_REQUESTOR
418445
Internal::CommissionableDataProviderRpcWrapper mCommissionableDataProvider;
419446
};
420447

src/app/clusters/ota-requestor/DefaultOTARequestor.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -767,6 +767,7 @@ CHIP_ERROR DefaultOTARequestor::SendQueryImageRequest(Messaging::ExchangeManager
767767
args.location.SetValue(CharSpan("XX", strlen("XX")));
768768
}
769769

770+
args.metadataForProvider = mMetadataForProvider;
770771
Controller::OtaSoftwareUpdateProviderCluster cluster(exchangeMgr, sessionHandle, mProviderLocation.Value().endpoint);
771772

772773
return cluster.InvokeCommand(args, this, OnQueryImageResponse, OnQueryImageFailure);

src/app/clusters/ota-requestor/DefaultOTARequestor.h

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
9292

9393
void GetProviderLocation(Optional<ProviderLocationType> & providerLocation) override { providerLocation = mProviderLocation; }
9494

95+
// Set the metadata value for the provider to be used in the next query and OTA update process
96+
// NOTE: Does not persist across reboot.
97+
void SetMetadataForProvider(ByteSpan metadataForProvider) override { mMetadataForProvider.SetValue(metadataForProvider); }
98+
9599
// Add a default OTA provider to the cached list
96100
CHIP_ERROR AddDefaultOtaProvider(const ProviderLocationType & providerLocation) override;
97101

@@ -319,6 +323,7 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
319323
BDXDownloader * mBdxDownloader = nullptr; // TODO: this should be OTADownloader
320324
BDXMessenger mBdxMessenger; // TODO: ideally this is held by the application
321325
uint8_t mUpdateTokenBuffer[kMaxUpdateTokenLen];
326+
Optional<ByteSpan> mMetadataForProvider;
322327
ByteSpan mUpdateToken;
323328
uint32_t mCurrentVersion = 0;
324329
uint32_t mTargetVersion = 0;

src/app/clusters/ota-requestor/OTARequestorInterface.h

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ class OTARequestorInterface
203203
// Set the provider location to be used in the next query and OTA update process
204204
virtual void SetCurrentProviderLocation(ProviderLocationType providerLocation) = 0;
205205

206+
// Set the metadata value for the provider to be used in the next query and OTA update process
207+
virtual void SetMetadataForProvider(chip::ByteSpan metadataForProvider) = 0;
208+
206209
// If there is an OTA update in progress, returns the provider location for the current OTA update, otherwise, returns the
207210
// provider location that was last used
208211
virtual void GetProviderLocation(Optional<ProviderLocationType> & providerLocation) = 0;

0 commit comments

Comments
 (0)