diff --git a/examples/common/pigweed/rpc_services/Device.h b/examples/common/pigweed/rpc_services/Device.h index d7d06d3bfc3842..3a0ca6f617cec8 100644 --- a/examples/common/pigweed/rpc_services/Device.h +++ b/examples/common/pigweed/rpc_services/Device.h @@ -28,6 +28,7 @@ #include "platform/ConfigurationManager.h" #include "platform/DiagnosticDataProvider.h" #include "platform/PlatformManager.h" +#include #include namespace chip { @@ -141,7 +142,7 @@ class Device : public pw_rpc::nanopb::Device::Service response.has_pairing_info = true; } - if (DeviceLayer::ConfigurationMgr().GetSerialNumber(response.serial_number, sizeof(response.serial_number)) == + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetSerialNumber(response.serial_number, sizeof(response.serial_number)) == CHIP_NO_ERROR) { snprintf(response.serial_number, sizeof(response.serial_number), CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER); diff --git a/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp index bbb4e91ba68e3a..8893b3616ed594 100644 --- a/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp +++ b/examples/lighting-app/cyw30739/src/ZclCallbacks.cpp @@ -20,6 +20,7 @@ #include "LightingManager.h" #include #include +#include using namespace chip; using namespace chip::app::Clusters; @@ -32,7 +33,7 @@ void emberAfBasicClusterInitCallback(EndpointId endpoint) uint8_t dayOfMonth; char cString[16] = "00000000"; - if (ConfigurationMgr().GetManufacturingDate(year, month, dayOfMonth) == CHIP_NO_ERROR) + if (GetDeviceInstanceInfoProvider()->GetManufacturingDate(year, month, dayOfMonth) == CHIP_NO_ERROR) { snprintf(cString, sizeof(cString), "%04u%02u%02u", year, month, dayOfMonth); } diff --git a/examples/lock-app/cyw30739/src/ZclCallbacks.cpp b/examples/lock-app/cyw30739/src/ZclCallbacks.cpp index 35db42f3482d4a..d49b6734d30fc3 100644 --- a/examples/lock-app/cyw30739/src/ZclCallbacks.cpp +++ b/examples/lock-app/cyw30739/src/ZclCallbacks.cpp @@ -20,6 +20,7 @@ #include #include #include +#include using namespace chip; using namespace chip::app::Clusters; @@ -32,7 +33,7 @@ void emberAfBasicClusterInitCallback(EndpointId endpoint) uint8_t dayOfMonth; char cString[16] = "00000000"; - if (ConfigurationMgr().GetManufacturingDate(year, month, dayOfMonth) == CHIP_NO_ERROR) + if (GetDeviceInstanceInfoProvider()->GetManufacturingDate(year, month, dayOfMonth) == CHIP_NO_ERROR) { snprintf(cString, sizeof(cString), "%04u%02u%02u", year, month, dayOfMonth); } diff --git a/src/app/clusters/basic/basic.cpp b/src/app/clusters/basic/basic.cpp index 0d5b9a91a812b3..c12a0c7bf72c88 100644 --- a/src/app/clusters/basic/basic.cpp +++ b/src/app/clusters/basic/basic.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -125,7 +126,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib case HardwareVersion::Id: { uint16_t hardwareVersion = 0; - status = ConfigurationMgr().GetHardwareVersion(hardwareVersion); + status = GetDeviceInstanceInfoProvider()->GetHardwareVersion(hardwareVersion); if (status == CHIP_NO_ERROR) { status = aEncoder.Encode(hardwareVersion); @@ -136,7 +137,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib case HardwareVersionString::Id: { constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxHardwareVersionStringLength; char hardwareVersionString[kMaxLen + 1] = { 0 }; - status = ConfigurationMgr().GetHardwareVersionString(hardwareVersionString, sizeof(hardwareVersionString)); + status = GetDeviceInstanceInfoProvider()->GetHardwareVersionString(hardwareVersionString, sizeof(hardwareVersionString)); status = EncodeStringOnSuccess(status, aEncoder, hardwareVersionString, kMaxLen); break; } @@ -165,7 +166,8 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib uint16_t manufacturingYear; uint8_t manufacturingMonth; uint8_t manufacturingDayOfMonth; - status = ConfigurationMgr().GetManufacturingDate(manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); + status = + GetDeviceInstanceInfoProvider()->GetManufacturingDate(manufacturingYear, manufacturingMonth, manufacturingDayOfMonth); // TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) @@ -237,7 +239,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib case SerialNumber::Id: { constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxSerialNumberLength; char serialNumberString[kMaxLen + 1] = { 0 }; - status = ConfigurationMgr().GetSerialNumber(serialNumberString, sizeof(serialNumberString)); + status = GetDeviceInstanceInfoProvider()->GetSerialNumber(serialNumberString, sizeof(serialNumberString)); // TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 86a9076678d22d..f36bf5d1a96439 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -733,7 +734,7 @@ CHIP_ERROR DefaultOTARequestor::SendQueryImageRequest(OperationalDeviceProxy & d args.requestorCanConsent.SetValue(!Basic::IsLocalConfigDisabled() && mOtaRequestorDriver->CanConsent()); uint16_t hardwareVersion; - if (DeviceLayer::ConfigurationMgr().GetHardwareVersion(hardwareVersion) == CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetHardwareVersion(hardwareVersion) == CHIP_NO_ERROR) { args.hardwareVersion.SetValue(hardwareVersion); } diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index 6423c1c8f0704c..664bda2f878fed 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -31,6 +31,7 @@ #include #include #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) +#include #include #endif #include @@ -498,7 +499,8 @@ CHIP_ERROR DnssdServer::GenerateRotatingDeviceId(char rotatingDeviceIdHexBuffer[ MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); size_t rotatingDeviceIdValueOutputSize = 0; - ReturnErrorOnFailure(chip::DeviceLayer::ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan)); + ReturnErrorOnFailure( + chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan)); ReturnErrorOnFailure( chip::DeviceLayer::ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter)); additionalDataPayloadParams.rotatingDeviceIdUniqueId = rotatingDeviceIdUniqueIdSpan; diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 027e0a547d2311..b58b22dae2a3a5 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -85,27 +85,20 @@ class ConfigurationManager kMaxLanguageTagLength = 5 // ISO 639-1 standard language codes }; - virtual CHIP_ERROR GetVendorName(char * buf, size_t bufSize) = 0; - virtual CHIP_ERROR GetVendorId(uint16_t & vendorId) = 0; - virtual CHIP_ERROR GetProductName(char * buf, size_t bufSize) = 0; - virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0; - virtual CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) = 0; - virtual CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVer) = 0; - virtual CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) = 0; - virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) = 0; - virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0; - 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(uint32_t & softwareVer) = 0; + virtual CHIP_ERROR GetVendorName(char * buf, size_t bufSize) = 0; + virtual CHIP_ERROR GetVendorId(uint16_t & vendorId) = 0; + virtual CHIP_ERROR GetProductName(char * buf, size_t bufSize) = 0; + virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0; + virtual CHIP_ERROR GetPrimaryMACAddress(MutableByteSpan buf) = 0; + virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0; + virtual CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) = 0; + virtual CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) = 0; + virtual CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) = 0; #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) // Lifetime counter is monotonic counter that is incremented upon each commencement of advertising - virtual CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) = 0; - virtual CHIP_ERROR IncrementLifetimeCounter() = 0; - // Unique ID is identifier utilized for the rotating device ID calculation purpose as an input key. It is separate identifier - // from the Basic cluster unique ID. - virtual CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) = 0; - virtual CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) = 0; + virtual CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) = 0; + virtual CHIP_ERROR IncrementLifetimeCounter() = 0; + virtual CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) = 0; #endif virtual CHIP_ERROR GetRegulatoryLocation(uint8_t & location) = 0; virtual CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) = 0; diff --git a/src/include/platform/DeviceInstanceInfoProvider.h b/src/include/platform/DeviceInstanceInfoProvider.h new file mode 100644 index 00000000000000..1735aac4fa9822 --- /dev/null +++ b/src/include/platform/DeviceInstanceInfoProvider.h @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#pragma once + +#include +#include + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProvider +{ +public: + DeviceInstanceInfoProvider() = default; + virtual ~DeviceInstanceInfoProvider() = default; + + /** + * @brief Obtain the Serial Number from the device's factory data. + * + * The SerialNumber attribute specifies a human readable serial number + * + * @param[in, out] buf Buffer to copy string. + * On CHIP_NO_ERROR return from this function this buffer will be null-terminated. + * On error CHIP_ERROR_BUFFER_TOO_SMALL there is no guarantee that buffer will be null-terminated. + * @param[in] bufSize Size of data, including the null terminator, that can be written to buf. + * This size should be +1 higher than maximum possible string. + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) = 0; + + /** + * @brief Obtain a manufacturing date from the device's factory data. + * + * The ManufacturingDate attribute specifies the date that the Node was manufactured. + * Output values are returned in ISO 8601, where: + * The first month of the year is January and its returning value is equal to 1. + * The first day of a month starts from 1. + * + * @param[out] year Reference to location where manufacturing year will be stored + * @param[out] month 1-based value [range 1-12] Reference to location where manufacturing month will be stored + * @param[out] day 1-based value [range 1-31] Reference to location where manufacturing day will be stored + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) = 0; + + /** + * @brief Obtain a Hardware Version from the device's factory data. + * + * @param[out] hardwareVersion Reference to location where the hardware version integer will be copied + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) = 0; + + /** + * @brief Obtain a Hardware Version String from the device's factory data. + * + * The HardwareVersionString can be used to provide a more user-friendly value than that + * represented by the HardwareVersion attribute. + * + * @param[in, out] buf Buffer to copy string. + * On CHIP_NO_ERROR return from this function this buffer will be null-terminated. + * On error CHIP_ERROR_BUFFER_TOO_SMALL there is no guarantee that buffer will be null-terminated. + * @param[in] bufSize Size of data, including the null terminator, that can be written to buf. + * This size should be +1 higher than maximum possible string. + * @returns CHIP_NO_ERROR on success, CHIP_ERROR_BUFFER_TOO_SMALL if the buffer was too small to fit string and null + * terminating. or another CHIP_ERROR from the underlying implementation if access fails. + */ + virtual CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) = 0; + + /** + * @brief Obtain a Rotating Device ID Unique ID from the device's factory data. + * + * The unique identifier consists of a randomly-generated 128-bit or longer octet string which + * was programmed during factory provisioning or delivered to the device by the vendor using + * secure means after a software update. + * + * @param[out] uniqueIdSpan Reference to location where the Rotating Device ID Unique ID will be copied + * According to specification input size of span buffer should be declared with at least 16 Bytes + * length The size of uniqueIdSpan is reduced to actual value on success + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) = 0; +}; + +/** + * Instance getter for the global DeviceInstanceInfoProvider. + * + * Callers have to externally synchronize usage of this function. + * + * @return The pointer to global device instance info provider. Assume never null. + */ +DeviceInstanceInfoProvider * GetDeviceInstanceInfoProvider(); + +/** + * Instance setter for the global DeviceInstanceInfoProvider. + * + * Callers have to externally synchronize usage of this function. + * + * If the `provider` is nullptr, no change is done. + * + * @param[in] provider the DeviceInstanceInfoProvider pointer to start returning with the getter + */ +void SetDeviceInstanceInfoProvider(DeviceInstanceInfoProvider * provider); + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index e42386d28f48bd..43ceb552cfc927 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -40,6 +40,11 @@ class ProvisioningDataSet; namespace Internal { +#if CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER +template +class LegacyDeviceInstanceInfoProvider; +#endif // CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER + #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER template class LegacyTemporaryCommissionableDataProvider; @@ -63,23 +68,18 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR GetVendorId(uint16_t & vendorId) override; CHIP_ERROR GetProductName(char * buf, size_t bufSize) override; CHIP_ERROR GetProductId(uint16_t & productId) override; - CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override; - 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(uint32_t & softwareVer) override; CHIP_ERROR StoreSoftwareVersion(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; CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override; CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) override; - CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) override; CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) override; #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) override; CHIP_ERROR IncrementLifetimeCounter() override; - CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override; CHIP_ERROR SetRotatingDeviceIdUniqueId(const ByteSpan & uniqueIdSpan) override; #endif CHIP_ERROR GetFailSafeArmed(bool & val) override; @@ -127,6 +127,10 @@ class GenericConfigurationManagerImpl : public ConfigurationManager uint8_t mRotatingDeviceIdUniqueId[kRotatingDeviceIDUniqueIDLength] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID; #endif +#if CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER + friend LegacyDeviceInstanceInfoProvider; +#endif // CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER + #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER friend LegacyTemporaryCommissionableDataProvider; #endif // CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index eb10c2a46d46ea..4122abcb26bc50 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -52,6 +53,161 @@ namespace chip { namespace DeviceLayer { namespace Internal { +#if CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER +template +class LegacyDeviceInstanceInfoProvider : public DeviceInstanceInfoProvider +{ + +public: + // GenericConfigurationManagerImpl will own a LegacyDeviceInstanceInfoProvider which + // *refers back to that GenericConfigurationManagerImpl*, due to how CRTP-based + // storage APIs are defined. This is a bit unclean, but only applicable to the + // transition path when `CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER` is true. + // This circular dependency is NOT needed by DeviceInstanceInfoProvider, but required + // to keep legacy code running. + LegacyDeviceInstanceInfoProvider(GenericConfigurationManagerImpl & configManager) : + mGenericConfigManager(configManager) + {} + + CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override; + CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override; + CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override; + CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override; + CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override; + +private: + GenericConfigurationManagerImpl & mGenericConfigManager; +}; + +template +CHIP_ERROR LegacyDeviceInstanceInfoProvider::GetSerialNumber(char * buf, size_t bufSize) +{ + ChipError err = CHIP_NO_ERROR; + size_t serialNumLen = 0; // without counting null-terminator + + err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_SerialNum, buf, bufSize, serialNumLen); + +#ifdef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER + if (CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER[0] != 0 && err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + ReturnErrorCodeIf(sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) > bufSize, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER)); + serialNumLen = sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) - 1; + } +#endif // CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER + ReturnErrorOnFailure(err); + + ReturnErrorCodeIf(serialNumLen >= bufSize, CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(buf[serialNumLen] != 0, CHIP_ERROR_INVALID_STRING_LENGTH); + + return err; +} + +template +CHIP_ERROR LegacyDeviceInstanceInfoProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) +{ +#if CHIP_DEVICE_LAYER_TARGET_FAKE + return CHIP_ERROR_NOT_IMPLEMENTED; +#else + + CHIP_ERROR err; + enum + { + kDateStringLength = 10 // YYYY-MM-DD + }; + char dateStr[kDateStringLength + 1]; + size_t dateLen; + char * parseEnd; + + err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_ManufacturingDate, dateStr, sizeof(dateStr), dateLen); + SuccessOrExit(err); + + VerifyOrExit(dateLen == kDateStringLength, err = CHIP_ERROR_INVALID_ARGUMENT); + + // Cast does not lose information, because we then check that we only parsed + // 4 digits, so our number can't be bigger than 9999. + year = static_cast(strtoul(dateStr, &parseEnd, 10)); + VerifyOrExit(parseEnd == dateStr + 4, err = CHIP_ERROR_INVALID_ARGUMENT); + + // Cast does not lose information, because we then check that we only parsed + // 2 digits, so our number can't be bigger than 99. + month = static_cast(strtoul(dateStr + 5, &parseEnd, 10)); + VerifyOrExit(parseEnd == dateStr + 7, err = CHIP_ERROR_INVALID_ARGUMENT); + + // Cast does not lose information, because we then check that we only parsed + // 2 digits, so our number can't be bigger than 99. + day = static_cast(strtoul(dateStr + 8, &parseEnd, 10)); + VerifyOrExit(parseEnd == dateStr + 10, err = CHIP_ERROR_INVALID_ARGUMENT); + +exit: + if (err != CHIP_NO_ERROR && err != CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + ChipLogError(DeviceLayer, "Invalid manufacturing date: %s", dateStr); + } + return err; +#endif +} + +template +CHIP_ERROR LegacyDeviceInstanceInfoProvider::GetHardwareVersion(uint16_t & hardwareVersion) +{ + ChipError err = CHIP_NO_ERROR; + uint32_t valInt = 0; + + err = mGenericConfigManager.ReadConfigValue(ConfigClass::kConfigKey_HardwareVersion, valInt); + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + hardwareVersion = static_cast(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION); + err = CHIP_NO_ERROR; + } + else + { + hardwareVersion = static_cast(valInt); + } + + return err; +} + +template +CHIP_ERROR LegacyDeviceInstanceInfoProvider::GetHardwareVersionString(char * buf, size_t bufSize) +{ +#if CHIP_DEVICE_LAYER_TARGET_ANDROID + CHIP_ERROR err; + size_t hardwareVersionLen = 0; // without counting null-terminator + err = ConfigClass::ReadConfigValueStr(ConfigClass::kConfigKey_HardwareVersionString, buf, bufSize, hardwareVersionLen); + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); + strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); + } + + return err; +#else + ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); + strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); + return CHIP_NO_ERROR; +#endif +} + +template +CHIP_ERROR LegacyDeviceInstanceInfoProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) +{ + ChipError err = CHIP_ERROR_WRONG_KEY_TYPE; +#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) + static_assert(ConfigurationManager::kRotatingDeviceIDUniqueIDLength >= ConfigurationManager::kMinRotatingDeviceIDUniqueIDLength, + "Length of unique ID for rotating device ID is smaller than minimum."); + constexpr uint8_t uniqueId[] = CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID; + + ReturnErrorCodeIf(sizeof(uniqueId) > uniqueIdSpan.size(), CHIP_ERROR_BUFFER_TOO_SMALL); + ReturnErrorCodeIf(sizeof(uniqueId) != ConfigurationManager::kRotatingDeviceIDUniqueIDLength, CHIP_ERROR_BUFFER_TOO_SMALL); + memcpy(uniqueIdSpan.data(), uniqueId, sizeof(uniqueId)); + uniqueIdSpan.reduce_size(sizeof(uniqueId)); + return CHIP_NO_ERROR; +#endif + return err; +} +#endif // CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER + #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER // Legacy version of CommissionableDataProvider used for a grace period @@ -231,6 +387,15 @@ CHIP_ERROR GenericConfigurationManagerImpl::Init() mLifetimePersistedCounter.Init(CHIP_CONFIG_LIFETIIME_PERSISTED_COUNTER_KEY); #endif +#if CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER + // Using a temporary singleton here because the overall GenericConfigurationManagerImpl is + // a singleton. This is TEMPORARY code to set the table for clients to set their own + // implementation properly, without loss of functionality for legacy in the meantime. + static LegacyDeviceInstanceInfoProvider sLegacyDeviceInstanceInfoProvider(*this); + + SetDeviceInstanceInfoProvider(&sLegacyDeviceInstanceInfoProvider); +#endif + #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER // Using a temporary singleton here because the overall GenericConfigurationManagerImpl is // a singleton. This is TEMPORARY code to set the table for clients to set their own @@ -264,13 +429,15 @@ CHIP_ERROR GenericConfigurationManagerImpl::Init() err = FailSafeContext::LoadFromStorage(fabricIndex, addNocCommandInvoked, updateNocCommandInvoked); if (err == CHIP_NO_ERROR) { - DeviceControlServer::DeviceControlSvr().GetFailSafeContext().ScheduleFailSafeCleanup(fabricIndex, addNocCommandInvoked, updateNocCommandInvoked); + DeviceControlServer::DeviceControlSvr().GetFailSafeContext().ScheduleFailSafeCleanup(fabricIndex, addNocCommandInvoked, + updateNocCommandInvoked); } else { // This should not happen, but we should not fail system init based on it! - ChipLogError(DeviceLayer, "Failed to load fail-safe context from storage (err= %" CHIP_ERROR_FORMAT "), cleaning-up!", err.Format()); - (void)SetFailSafeArmed(false); + ChipLogError(DeviceLayer, "Failed to load fail-safe context from storage (err= %" CHIP_ERROR_FORMAT "), cleaning-up!", + err.Format()); + (void) SetFailSafeArmed(false); err = CHIP_NO_ERROR; } } @@ -350,31 +517,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetSoftwareVersionStrin return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetSerialNumber(char * buf, size_t bufSize) -{ - CHIP_ERROR err; - size_t serialNumLen = 0; // without counting null-terminator - err = ReadConfigValueStr(ConfigClass::kConfigKey_SerialNum, buf, bufSize, serialNumLen); - -#ifdef CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER - if (CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER[0] != 0 && err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - ReturnErrorCodeIf(sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) > bufSize, CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(buf, CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER, sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER)); - serialNumLen = sizeof(CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER) - 1; - err = CHIP_NO_ERROR; - } -#endif // CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER - - ReturnErrorOnFailure(err); - - ReturnErrorCodeIf(serialNumLen >= bufSize, CHIP_ERROR_BUFFER_TOO_SMALL); - ReturnErrorCodeIf(buf[serialNumLen] != 0, CHIP_ERROR_INVALID_STRING_LENGTH); - - return err; -} - template CHIP_ERROR GenericConfigurationManagerImpl::StoreSerialNumber(const char * serialNum, size_t serialNumLen) { @@ -422,81 +564,12 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetPrimary802154MACAddr #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD } -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetHardwareVersionString(char * buf, size_t bufSize) -{ - ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); - strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); - return CHIP_NO_ERROR; -} - -template -inline CHIP_ERROR GenericConfigurationManagerImpl::GetHardwareVersion(uint16_t & hardwareVer) -{ - CHIP_ERROR err; - uint32_t val; - - err = ReadConfigValue(ConfigClass::kConfigKey_HardwareVersion, val); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - hardwareVer = static_cast(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION); - err = CHIP_NO_ERROR; - } - else - { - hardwareVer = static_cast(val); - } - - return err; -} - template inline CHIP_ERROR GenericConfigurationManagerImpl::StoreHardwareVersion(uint16_t hardwareVer) { return WriteConfigValue(ConfigClass::kConfigKey_HardwareVersion, static_cast(hardwareVer)); } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetManufacturingDate(uint16_t & year, uint8_t & month, - uint8_t & dayOfMonth) -{ - CHIP_ERROR err; - enum - { - kDateStringLength = 10 // YYYY-MM-DD - }; - char dateStr[kDateStringLength + 1]; - size_t dateLen; - char * parseEnd; - - err = ReadConfigValueStr(ConfigClass::kConfigKey_ManufacturingDate, dateStr, sizeof(dateStr), dateLen); - SuccessOrExit(err); - - VerifyOrExit(dateLen == kDateStringLength, err = CHIP_ERROR_INVALID_ARGUMENT); - - // Cast does not lose information, because we then check that we only parsed - // 4 digits, so our number can't be bigger than 9999. - year = static_cast(strtoul(dateStr, &parseEnd, 10)); - VerifyOrExit(parseEnd == dateStr + 4, err = CHIP_ERROR_INVALID_ARGUMENT); - - // Cast does not lose information, because we then check that we only parsed - // 2 digits, so our number can't be bigger than 99. - month = static_cast(strtoul(dateStr + 5, &parseEnd, 10)); - VerifyOrExit(parseEnd == dateStr + 7, err = CHIP_ERROR_INVALID_ARGUMENT); - - // Cast does not lose information, because we then check that we only parsed - // 2 digits, so our number can't be bigger than 99. - dayOfMonth = static_cast(strtoul(dateStr + 8, &parseEnd, 10)); - VerifyOrExit(parseEnd == dateStr + 10, err = CHIP_ERROR_INVALID_ARGUMENT); - -exit: - if (err != CHIP_NO_ERROR && err != CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - ChipLogError(DeviceLayer, "Invalid manufacturing date: %s", dateStr); - } - return err; -} - template CHIP_ERROR GenericConfigurationManagerImpl::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) { @@ -646,17 +719,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::SetRotatingDeviceIdUniq return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) -{ - static_assert(kRotatingDeviceIDUniqueIDLength >= kMinRotatingDeviceIDUniqueIDLength, - "Length of unique ID for rotating device ID is smaller than minimum."); - ReturnErrorCodeIf(sizeof(mRotatingDeviceIdUniqueId) > uniqueIdSpan.size(), CHIP_ERROR_BUFFER_TOO_SMALL); - ReturnErrorCodeIf(sizeof(mRotatingDeviceIdUniqueId) != kRotatingDeviceIDUniqueIDLength, CHIP_ERROR_BUFFER_TOO_SMALL); - memcpy(uniqueIdSpan.data(), mRotatingDeviceIdUniqueId, sizeof(mRotatingDeviceIdUniqueId)); - uniqueIdSpan = uniqueIdSpan.SubSpan(0, sizeof(mRotatingDeviceIdUniqueId)); - return CHIP_NO_ERROR; -} #endif // CHIP_ENABLE_ROTATING_DEVICE_ID template @@ -773,9 +835,11 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() ChipLogProgress(DeviceLayer, "Device Configuration:"); + DeviceInstanceInfoProvider * deviceInstanceInfoProvider = GetDeviceInstanceInfoProvider(); + { char serialNum[ConfigurationManager::kMaxSerialNumberLength + 1]; - err = GetSerialNumber(serialNum, sizeof(serialNum)); + err = deviceInstanceInfoProvider->GetSerialNumber(serialNum, sizeof(serialNum)); ChipLogProgress(DeviceLayer, " Serial Number: %s", (err == CHIP_NO_ERROR) ? serialNum : "(not set)"); } @@ -799,7 +863,7 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() { uint16_t hardwareVer; - if (GetHardwareVersion(hardwareVer) != CHIP_NO_ERROR) + if (deviceInstanceInfoProvider->GetHardwareVersion(hardwareVer) != CHIP_NO_ERROR) { hardwareVer = 0; } @@ -823,14 +887,14 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() { setupDiscriminator = 0xFFFF; } - ChipLogProgress(DeviceLayer, " Setup Discriminator (0xFFFF for UNKNOWN/ERROR): %u (0x%X)", - setupDiscriminator, setupDiscriminator); + ChipLogProgress(DeviceLayer, " Setup Discriminator (0xFFFF for UNKNOWN/ERROR): %u (0x%X)", setupDiscriminator, + setupDiscriminator); } { uint16_t year; uint8_t month, dayOfMonth; - err = GetManufacturingDate(year, month, dayOfMonth); + err = deviceInstanceInfoProvider->GetManufacturingDate(year, month, dayOfMonth); if (err == CHIP_NO_ERROR) { ChipLogProgress(DeviceLayer, " Manufacturing Date: %04u/%02u/%02u", year, month, dayOfMonth); diff --git a/src/lib/shell/commands/Config.cpp b/src/lib/shell/commands/Config.cpp index 2f355df34407ae..8582bbefaaee3a 100644 --- a/src/lib/shell/commands/Config.cpp +++ b/src/lib/shell/commands/Config.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using chip::DeviceLayer::ConfigurationMgr; @@ -82,7 +83,7 @@ static CHIP_ERROR ConfigGetHardwareVersion(bool printHeader) streamer_t * sout = streamer_get(); uint16_t value16; - ReturnErrorOnFailure(ConfigurationMgr().GetHardwareVersion(value16)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetHardwareVersion(value16)); if (printHeader) { streamer_printf(sout, "HardwareVersion: "); diff --git a/src/platform/Ameba/BLEManagerImpl.cpp b/src/platform/Ameba/BLEManagerImpl.cpp index 1116db19b359ef..a6c6f179907623 100755 --- a/src/platform/Ameba/BLEManagerImpl.cpp +++ b/src/platform/Ameba/BLEManagerImpl.cpp @@ -24,8 +24,9 @@ /* this file behaves like a config.h, comes first */ #include -#include #include +#include +#include #include #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE @@ -1042,7 +1043,7 @@ void BLEManagerImpl::HandleC3CharRead(TBTCONFIG_CALLBACK_DATA * p_data) uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {}; MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); - err = ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); + err = DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); SuccessOrExit(err); err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter); SuccessOrExit(err); diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index b4d717a0040b60..89af9d84165d7e 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -56,6 +56,10 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { # Enable including the additional data in the advertisement packets chip_enable_additional_data_advertising = false + # Enable default/generic test-mode DeviceInstanceInfoProvider in GenericConfigurationManagerImpl + # === FOR TRANSITION UNTIL ALL EXAMPLES PROVIDE THEIR OWN === + chip_use_transitional_device_instance_info_provider = true + # Enable default/generic test-mode CommissionableDataProvider in GenericConfigurationManagerImpl # === FOR TRANSITION UNTIL ALL EXAMPLES PROVIDE THEIR OWN === # Linux platform has already transitioned. @@ -154,6 +158,12 @@ if (chip_device_platform != "none" && chip_device_platform != "external") { defines += [ "CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER=0" ] } + if (chip_use_transitional_device_instance_info_provider) { + defines += [ "CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER=1" ] + } else { + defines += [ "CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER=0" ] + } + if (chip_device_platform == "cc13x2_26x2") { defines += [ "CHIP_DEVICE_LAYER_TARGET_CC13X2_26X2=1", @@ -303,6 +313,7 @@ if (chip_device_platform != "none") { "../include/platform/ConfigurationManager.h", "../include/platform/ConnectivityManager.h", "../include/platform/DeviceControlServer.h", + "../include/platform/DeviceInstanceInfoProvider.h", "../include/platform/FailSafeContext.h", "../include/platform/GeneralUtils.h", "../include/platform/KeyValueStoreManager.h", @@ -339,6 +350,7 @@ if (chip_device_platform != "none") { "CommissionableDataProvider.cpp", "DeviceControlServer.cpp", "DeviceInfoProvider.cpp", + "DeviceInstanceInfoProvider.cpp", "DiagnosticDataProvider.cpp", "Entropy.cpp", "FailSafeContext.cpp", diff --git a/src/platform/DeviceInstanceInfoProvider.cpp b/src/platform/DeviceInstanceInfoProvider.cpp new file mode 100644 index 00000000000000..5ac7a3726fa404 --- /dev/null +++ b/src/platform/DeviceInstanceInfoProvider.cpp @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +namespace chip { +namespace DeviceLayer { + +namespace { + +DeviceInstanceInfoProvider * gDeviceInstanceInfoProvider = nullptr; + +} // namespace + +DeviceInstanceInfoProvider * GetDeviceInstanceInfoProvider() +{ + VerifyOrDie(gDeviceInstanceInfoProvider != nullptr); + return gDeviceInstanceInfoProvider; +} + +void SetDeviceInstanceInfoProvider(DeviceInstanceInfoProvider * provider) +{ + if (provider == nullptr) + { + return; + } + + gDeviceInstanceInfoProvider = provider; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index 3b82453434b76f..ee2e4331c3f51f 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -1076,7 +1077,7 @@ void BLEManagerImpl::HandleC3CharRead(struct ble_gatt_char_context * param) uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {}; MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); - err = ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); + err = DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); SuccessOrExit(err); err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter); SuccessOrExit(err); diff --git a/src/platform/Linux/bluez/Helper.cpp b/src/platform/Linux/bluez/Helper.cpp index 14662980eda747..1337c4e69a1003 100644 --- a/src/platform/Linux/bluez/Helper.cpp +++ b/src/platform/Linux/bluez/Helper.cpp @@ -67,6 +67,7 @@ #include #include +#include #include #include @@ -1205,7 +1206,7 @@ static void UpdateAdditionalDataCharacteristic(BluezGattCharacteristic1 * charac uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {}; MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); - err = ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); + err = GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); SuccessOrExit(err); err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter); SuccessOrExit(err); diff --git a/src/platform/Zephyr/BLEManagerImpl.cpp b/src/platform/Zephyr/BLEManagerImpl.cpp index 5e7f3310c7b761..c506c012a7d946 100644 --- a/src/platform/Zephyr/BLEManagerImpl.cpp +++ b/src/platform/Zephyr/BLEManagerImpl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #if CHIP_ENABLE_ADDITIONAL_DATA_ADVERTISING #include @@ -581,7 +582,7 @@ CHIP_ERROR BLEManagerImpl::PrepareC3CharData() uint8_t rotatingDeviceIdUniqueId[ConfigurationManager::kRotatingDeviceIDUniqueIDLength] = {}; MutableByteSpan rotatingDeviceIdUniqueIdSpan(rotatingDeviceIdUniqueId); - err = ConfigurationMgr().GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); + err = DeviceLayer::GetDeviceInstanceInfoProvider()->GetRotatingDeviceIdUniqueId(rotatingDeviceIdUniqueIdSpan); SuccessOrExit(err); err = ConfigurationMgr().GetLifetimeCounter(additionalDataPayloadParams.rotatingDeviceIdLifetimeCounter); SuccessOrExit(err); diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index a34fc504e2c50d..f8d69be236fcc6 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -223,20 +223,6 @@ CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t return CHIP_NO_ERROR; } -CHIP_ERROR ConfigurationManagerImpl::GetHardwareVersionString(char * buf, size_t bufSize) -{ - CHIP_ERROR err; - size_t hardwareVersionLen = 0; // without counting null-terminator - err = ReadConfigValueStr(AndroidConfig::kConfigKey_HardwareVersionString, buf, bufSize, hardwareVersionLen); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING), CHIP_ERROR_BUFFER_TOO_SMALL); - strcpy(buf, CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_HARDWARE_VERSION_STRING); - } - - return CHIP_NO_ERROR; -} - CHIP_ERROR ConfigurationManagerImpl::GetPartNumber(char * buf, size_t bufSize) { size_t dateLen; diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index 42c5c30c4b174c..c28c246d3ec534 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -42,7 +42,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp static ConfigurationManagerImpl & GetDefaultInstance(); CHIP_ERROR GetProductId(uint16_t & productId) override; 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(uint32_t & softwareVer) override; CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override; diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index 9e0c4b26588552..c65c525973cb87 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -39,26 +39,18 @@ class ConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR GetVendorId(uint16_t & vendorId) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetProductName(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetProductId(uint16_t & productId) override { return CHIP_ERROR_NOT_IMPLEMENTED; } - CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } - 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(uint32_t & softwareVer) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR StoreSoftwareVersion(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; } CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) override { return CHIP_ERROR_NOT_IMPLEMENTED; } - CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) override - { - return CHIP_ERROR_NOT_IMPLEMENTED; - } CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; } #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) CHIP_ERROR GetLifetimeCounter(uint16_t & lifetimeCounter) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR IncrementLifetimeCounter() override { return CHIP_ERROR_NOT_IMPLEMENTED; } - CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override { return CHIP_ERROR_NOT_IMPLEMENTED; } #endif CHIP_ERROR GetFailSafeArmed(bool & val) override { return CHIP_ERROR_NOT_IMPLEMENTED; } CHIP_ERROR SetFailSafeArmed(bool val) override { return CHIP_ERROR_NOT_IMPLEMENTED; } diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp index fc29e0dc7633aa..1337140fc493d7 100644 --- a/src/platform/tests/TestConfigurationMgr.cpp +++ b/src/platform/tests/TestConfigurationMgr.cpp @@ -34,6 +34,7 @@ #include #include +#include using namespace chip; using namespace chip::Logging; @@ -73,7 +74,7 @@ static void TestConfigurationMgr_SerialNumber(nlTestSuite * inSuite, void * inCo err = ConfigurationMgr().StoreSerialNumber(serialNumber, strlen(serialNumber)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = ConfigurationMgr().GetSerialNumber(buf, 64); + err = GetDeviceInstanceInfoProvider()->GetSerialNumber(buf, 64); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, strlen(buf) == 12); @@ -82,7 +83,7 @@ static void TestConfigurationMgr_SerialNumber(nlTestSuite * inSuite, void * inCo err = ConfigurationMgr().StoreSerialNumber(serialNumber, 5); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = ConfigurationMgr().GetSerialNumber(buf, 64); + err = GetDeviceInstanceInfoProvider()->GetSerialNumber(buf, 64); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, strlen(buf) == 5); @@ -127,7 +128,7 @@ static void TestConfigurationMgr_ManufacturingDate(nlTestSuite * inSuite, void * err = ConfigurationMgr().StoreManufacturingDate(mfgDate, strlen(mfgDate)); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = ConfigurationMgr().GetManufacturingDate(year, month, dayOfMonth); + err = GetDeviceInstanceInfoProvider()->GetManufacturingDate(year, month, dayOfMonth); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, year == 2008); @@ -143,7 +144,7 @@ static void TestConfigurationMgr_HardwareVersion(nlTestSuite * inSuite, void * i err = ConfigurationMgr().StoreHardwareVersion(1234); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); - err = ConfigurationMgr().GetHardwareVersion(hardwareVer); + err = GetDeviceInstanceInfoProvider()->GetHardwareVersion(hardwareVer); NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); NL_TEST_ASSERT(inSuite, hardwareVer == 1234);