Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTA] Use ConfigurationManager as the source of truth for Basic cluster attributes #13849

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/common/pigweed/rpc_services/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Device : public pw_rpc::nanopb::Device::Service<Device>
response.product_id = CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID;
}

uint16_t software_version;
uint32_t software_version;
if (DeviceLayer::ConfigurationMgr().GetSoftwareVersion(software_version) == CHIP_NO_ERROR)
{
response.software_version = software_version;
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/basic/basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void emberAfBasicClusterServerInitCallback(chip::EndpointId endpoint)
VerifyOrdo(EMBER_ZCL_STATUS_SUCCESS == status, ChipLogError(Zcl, "Error setting Software Version String: 0x%02x", status));
}

uint16_t softwareVersion;
uint32_t softwareVersion;
if (ConfigurationMgr().GetSoftwareVersion(softwareVersion) == CHIP_NO_ERROR)
{
status = Attributes::SoftwareVersion::Set(endpoint, softwareVersion);
Expand Down
25 changes: 14 additions & 11 deletions src/app/clusters/ota-requestor/OTARequestor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,11 @@ void OTARequestor::ApplyUpdate()
void OTARequestor::NotifyUpdateApplied(uint32_t version)
{
// New version is executing so update where applicable
VerifyOrReturn(Basic::Attributes::SoftwareVersion::Set(kRootEndpointId, version) == EMBER_ZCL_STATUS_SUCCESS);
carol-apple marked this conversation as resolved.
Show resolved Hide resolved
mCurrentVersion = version;

// Log the VersionApplied event
uint16_t productId;
VerifyOrReturn(Basic::Attributes::ProductID::Get(kRootEndpointId, &productId) == EMBER_ZCL_STATUS_SUCCESS);
VerifyOrReturn(DeviceLayer::ConfigurationMgr().GetProductId(productId) == CHIP_NO_ERROR);
OtaRequestorServerOnVersionApplied(version, productId);

ConnectToProvider(kNotifyUpdateApplied);
Expand Down Expand Up @@ -505,28 +504,32 @@ CHIP_ERROR OTARequestor::SendQueryImageRequest(OperationalDeviceProxy & devicePr
constexpr OTADownloadProtocol kProtocolsSupported[] = { OTADownloadProtocol::kBDXSynchronous };
QueryImage::Type args;

VerifyOrReturnError(Basic::Attributes::VendorID::Get(kRootEndpointId, &args.vendorId) == EMBER_ZCL_STATUS_SUCCESS,
CHIP_ERROR_READ_FAILED);
uint16_t vendorId;
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetVendorId(vendorId));
args.vendorId = static_cast<VendorId>(vendorId);
andy31415 marked this conversation as resolved.
Show resolved Hide resolved

VerifyOrReturnError(Basic::Attributes::ProductID::Get(kRootEndpointId, &args.productId) == EMBER_ZCL_STATUS_SUCCESS,
CHIP_ERROR_READ_FAILED);
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetProductId(args.productId));

VerifyOrReturnError(Basic::Attributes::SoftwareVersion::Get(kRootEndpointId, &args.softwareVersion) == EMBER_ZCL_STATUS_SUCCESS,
CHIP_ERROR_READ_FAILED);
ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(args.softwareVersion));

args.protocolsSupported = kProtocolsSupported;
args.requestorCanConsent.SetValue(mOtaRequestorDriver->CanConsent());

uint16_t hardwareVersion;
if (Basic::Attributes::HardwareVersion::Get(kRootEndpointId, &hardwareVersion) == EMBER_ZCL_STATUS_SUCCESS)
if (DeviceLayer::ConfigurationMgr().GetHardwareVersion(hardwareVersion) == CHIP_NO_ERROR)
{
args.hardwareVersion.SetValue(hardwareVersion);
}

char location[DeviceLayer::ConfigurationManager::kMaxLocationLength];
if (Basic::Attributes::Location::Get(kRootEndpointId, MutableCharSpan(location)) == EMBER_ZCL_STATUS_SUCCESS)
size_t codeLen = 0;
if ((DeviceLayer::ConfigurationMgr().GetCountryCode(location, sizeof(location), codeLen) == CHIP_NO_ERROR) && (codeLen > 0))
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
{
args.location.SetValue(CharSpan(location));
args.location.SetValue(CharSpan(location, codeLen));
}
else
{
args.location.SetValue(CharSpan("XX", strlen("XX")));
}

Controller::OtaSoftwareUpdateProviderCluster cluster;
Expand Down
2 changes: 1 addition & 1 deletion src/app/clusters/ota-requestor/OTARequestor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class OTARequestor : public OTARequestorInterface, public BDXDownloader::StateDe
mBdxDownloader = downloader;

uint32_t version;
VerifyOrDie(app::Clusters::Basic::Attributes::SoftwareVersion::Get(kRootEndpointId, &version) == EMBER_ZCL_STATUS_SUCCESS);
ReturnOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(version));
mCurrentVersion = version;

OtaRequestorServerSetUpdateState(mCurrentUpdateState);
Expand Down
2 changes: 1 addition & 1 deletion src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class ConfigurationManager
virtual CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) = 0;
virtual CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) = 0;
virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0;
virtual CHIP_ERROR GetSoftwareVersion(uint16_t & softwareVer) = 0;
virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) = 0;
virtual CHIP_ERROR GetSetupPinCode(uint32_t & setupPinCode) = 0;
virtual CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) = 0;
// Lifetime counter is monotonic counter that is incremented only in the case of a factory reset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVer) override;
CHIP_ERROR StoreHardwareVersion(uint16_t hardwareVer) override;
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersion(uint16_t & softwareVer) override;
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) override;
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override;
Expand Down Expand Up @@ -157,7 +157,7 @@ inline CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetProductId(uin
}

template <class ConfigClass>
inline CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSoftwareVersion(uint16_t & softwareVer)
inline CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetSoftwareVersion(uint32_t & softwareVer)
{
softwareVer = static_cast<uint32_t>(CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION);
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/PlatformManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void PlatformManagerImpl::HandleDeviceRebooted(intptr_t arg)
// The StartUp event SHALL be emitted by a Node after completing a boot or reboot process
if (platformManagerDelegate != nullptr)
{
uint16_t softwareVersion;
uint32_t softwareVersion;

ReturnOnFailure(ConfigurationMgr().GetSoftwareVersion(softwareVersion));
platformManagerDelegate->OnStartUp(softwareVersion);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ CHIP_ERROR ConfigurationManagerImpl::GetProductName(char * buf, size_t bufSize)
return CHIP_NO_ERROR;
}

CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint16_t & softwareVer)
CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer)
{
CHIP_ERROR err;
uint32_t u32SoftwareVer = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override;
CHIP_ERROR GetSoftwareVersion(uint16_t & softwareVer) override;
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
CHIP_ERROR GetNodeLabel(char * buf, size_t bufSize) override;
CHIP_ERROR StoreNodeLabel(const char * buf, size_t bufSize) override;
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/fake/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ConfigurationManagerImpl : public ConfigurationManager
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR StoreHardwareVersion(uint16_t hardwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GetSoftwareVersion(uint16_t & softwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
Expand Down