diff --git a/examples/common/pigweed/rpc_services/Device.h b/examples/common/pigweed/rpc_services/Device.h index b3b7508f70bbed..36749f07985a6f 100644 --- a/examples/common/pigweed/rpc_services/Device.h +++ b/examples/common/pigweed/rpc_services/Device.h @@ -112,7 +112,7 @@ class Device : public pw_rpc::nanopb::Device::Service { uint16_t vendor_id; - if (DeviceLayer::ConfigurationMgr().GetVendorId(vendor_id) == CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(vendor_id) == CHIP_NO_ERROR) { response.vendor_id = static_cast(vendor_id); } @@ -122,7 +122,7 @@ class Device : public pw_rpc::nanopb::Device::Service } uint16_t product_id; - if (DeviceLayer::ConfigurationMgr().GetProductId(product_id) == CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(product_id) == CHIP_NO_ERROR) { response.product_id = static_cast(product_id); } diff --git a/src/app/clusters/basic/basic.cpp b/src/app/clusters/basic/basic.cpp index c12a0c7bf72c88..7d628459b8cde6 100644 --- a/src/app/clusters/basic/basic.cpp +++ b/src/app/clusters/basic/basic.cpp @@ -91,14 +91,14 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib case VendorName::Id: { constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxVendorNameLength; char vendorName[kMaxLen + 1] = { 0 }; - status = ConfigurationMgr().GetVendorName(vendorName, sizeof(vendorName)); + status = GetDeviceInstanceInfoProvider()->GetVendorName(vendorName, sizeof(vendorName)); status = EncodeStringOnSuccess(status, aEncoder, vendorName, kMaxLen); break; } case VendorID::Id: { uint16_t vendorId = 0; - status = ConfigurationMgr().GetVendorId(vendorId); + status = GetDeviceInstanceInfoProvider()->GetVendorId(vendorId); if (status == CHIP_NO_ERROR) { status = aEncoder.Encode(vendorId); @@ -109,14 +109,14 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib case ProductName::Id: { constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxProductNameLength; char productName[kMaxLen + 1] = { 0 }; - status = ConfigurationMgr().GetProductName(productName, sizeof(productName)); + status = GetDeviceInstanceInfoProvider()->GetProductName(productName, sizeof(productName)); status = EncodeStringOnSuccess(status, aEncoder, productName, kMaxLen); break; } case ProductID::Id: { uint16_t productId = 0; - status = ConfigurationMgr().GetProductId(productId); + status = GetDeviceInstanceInfoProvider()->GetProductId(productId); if (status == CHIP_NO_ERROR) { status = aEncoder.Encode(productId); diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 39aa512596305d..6cdd65f91a1a07 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -565,7 +565,7 @@ void DefaultOTARequestor::NotifyUpdateApplied() { // Log the VersionApplied event uint16_t productId; - if (DeviceLayer::ConfigurationMgr().GetProductId(productId) != CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(productId) != CHIP_NO_ERROR) { ChipLogError(SoftwareUpdate, "Cannot get Product ID"); RecordErrorUpdateState(CHIP_ERROR_INCORRECT_STATE); @@ -722,10 +722,10 @@ CHIP_ERROR DefaultOTARequestor::SendQueryImageRequest(OperationalDeviceProxy & d QueryImage::Type args; uint16_t vendorId; - ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetVendorId(vendorId)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(vendorId)); args.vendorId = static_cast(vendorId); - ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetProductId(args.productId)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(args.productId)); ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(args.softwareVersion)); diff --git a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp index ba1d0baea170ef..5dff75ad84f79c 100644 --- a/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp +++ b/src/app/clusters/ota-requestor/ExtendedOTARequestorDriver.cpp @@ -18,6 +18,7 @@ #include "ExtendedOTARequestorDriver.h" #include "OTARequestorInterface.h" #include +#include namespace chip { namespace DeviceLayer { @@ -84,8 +85,8 @@ CHIP_ERROR ExtendedOTARequestorDriver::GetUserConsentSubject(chip::ota::UserCons } subject.requestorNodeId = fabricInfo->GetPeerId().GetNodeId(); - ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetVendorId(subject.requestorVendorId)); - ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetProductId(subject.requestorProductId)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(subject.requestorVendorId)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(subject.requestorProductId)); ReturnErrorOnFailure(DeviceLayer::ConfigurationMgr().GetSoftwareVersion(subject.requestorCurrentVersion)); subject.requestorTargetVersion = update.softwareVersion; subject.metadata = update.metadataForRequestor; diff --git a/src/app/server/Dnssd.cpp b/src/app/server/Dnssd.cpp index 664bda2f878fed..b05ef7a3fb07bc 100644 --- a/src/app/server/Dnssd.cpp +++ b/src/app/server/Dnssd.cpp @@ -29,9 +29,9 @@ #include #include #include +#include #include #if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID) -#include #include #endif #include @@ -298,7 +298,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi uint16_t value; uint32_t val32; - if (DeviceLayer::ConfigurationMgr().GetVendorId(value) != CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value) != CHIP_NO_ERROR) { ChipLogDetail(Discovery, "Vendor ID not known"); } @@ -307,7 +307,7 @@ CHIP_ERROR DnssdServer::Advertise(bool commissionableNode, chip::Dnssd::Commissi advertiseParameters.SetVendorId(chip::Optional::Value(value)); } - if (DeviceLayer::ConfigurationMgr().GetProductId(value) != CHIP_NO_ERROR) + if (DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(value) != CHIP_NO_ERROR) { ChipLogDetail(Discovery, "Product ID not known"); } diff --git a/src/app/server/OnboardingCodesUtil.cpp b/src/app/server/OnboardingCodesUtil.cpp index 28451e207dbd36..2d2ce20b5fbfe2 100644 --- a/src/app/server/OnboardingCodesUtil.cpp +++ b/src/app/server/OnboardingCodesUtil.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -121,17 +122,17 @@ CHIP_ERROR GetPayloadContents(chip::PayloadContents & aPayload, chip::Rendezvous return err; } - err = ConfigurationMgr().GetVendorId(aPayload.vendorID); + err = chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(aPayload.vendorID); if (err != CHIP_NO_ERROR) { - ChipLogError(AppServer, "ConfigurationMgr().GetVendorId() failed: %s", chip::ErrorStr(err)); + ChipLogError(AppServer, "GetDeviceInstanceInfoProvider()->GetVendorId() failed: %s", chip::ErrorStr(err)); return err; } - err = ConfigurationMgr().GetProductId(aPayload.productID); + err = chip::DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(aPayload.productID); if (err != CHIP_NO_ERROR) { - ChipLogError(AppServer, "ConfigurationMgr().GetProductId() failed: %s", chip::ErrorStr(err)); + ChipLogError(AppServer, "GetDeviceInstanceInfoProvider()->GetProductId() failed: %s", chip::ErrorStr(err)); return err; } diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 7b3be4d4b6bf4a..5d71e89e1eca51 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -85,10 +85,6 @@ 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 GetPrimaryMACAddress(MutableByteSpan buf) = 0; virtual CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf) = 0; virtual CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf) = 0; diff --git a/src/include/platform/DeviceInstanceInfoProvider.h b/src/include/platform/DeviceInstanceInfoProvider.h index 1735aac4fa9822..872ff93caf0b02 100644 --- a/src/include/platform/DeviceInstanceInfoProvider.h +++ b/src/include/platform/DeviceInstanceInfoProvider.h @@ -28,6 +28,50 @@ class DeviceInstanceInfoProvider DeviceInstanceInfoProvider() = default; virtual ~DeviceInstanceInfoProvider() = default; + /** + * @brief Obtain the Vendor Name from the device's factory data. + * + * @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 GetVendorName(char * buf, size_t bufSize) = 0; + + /** + * @brief Obtain the Vendor Id from the device's factory data. + * + * @param[out] vendorId Reference to location where the vendor id integer will be copied + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetVendorId(uint16_t & vendorId) = 0; + + /** + * @brief Obtain the Product Name from the device's factory data. + * + * @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 GetProductName(char * buf, size_t bufSize) = 0; + + /** + * @brief Obtain the Product Id from the device's factory data. + * + * @param[out] productId Reference to location where the product id integer will be copied + * @returns CHIP_NO_ERROR on success, or another CHIP_ERROR from the underlying implementation + * if access fails. + */ + virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0; + /** * @brief Obtain the Serial Number from the device's factory data. * diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index db479f90643b00..e83d3901a67aca 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -40,10 +40,8 @@ class ProvisioningDataSet; namespace Internal { -#if CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER template -class LegacyDeviceInstanceInfoProvider; -#endif // CHIP_USE_TRANSITIONAL_DEVICE_INSTANCE_INFO_PROVIDER +class GenericDeviceInstanceInfoProvider; #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER template @@ -64,10 +62,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager // ===== Methods that implement the ConfigurationManager abstract interface. CHIP_ERROR Init() override; - CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override; - 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 StoreHardwareVersion(uint16_t hardwareVer) override; CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override; CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override; @@ -129,9 +123,7 @@ 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 + friend GenericDeviceInstanceInfoProvider; #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER friend LegacyTemporaryCommissionableDataProvider; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 5c3044478626e0..f62507a014dd5c 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -36,12 +36,12 @@ #include #include #include +#include #include #include -#include -#include #include #include +#include #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include @@ -56,161 +56,6 @@ namespace Internal { static Optional sFirmwareBuildChipEpochTime; -#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 @@ -390,14 +235,9 @@ 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); + static GenericDeviceInstanceInfoProvider sGenericDeviceInstanceInfoProvider(*this); - SetDeviceInstanceInfoProvider(&sLegacyDeviceInstanceInfoProvider); -#endif + SetDeviceInstanceInfoProvider(&sGenericDeviceInstanceInfoProvider); #if CHIP_USE_TRANSITIONAL_COMMISSIONABLE_DATA_PROVIDER // Using a temporary singleton here because the overall GenericConfigurationManagerImpl is @@ -420,20 +260,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::Init() return err; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) -{ - vendorId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID); - return CHIP_NO_ERROR; -} - -template -CHIP_ERROR GenericConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ - productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); - return CHIP_NO_ERROR; -} - template CHIP_ERROR GenericConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer) { @@ -462,7 +288,8 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetFirmwareBuildChipEpo const char * date = CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_DATE; const char * time = CHIP_DEVICE_CONFIG_FIRMWARE_BUILD_TIME; uint32_t seconds; - auto good = CalendarToChipEpochTime(COMPUTE_BUILD_YEAR(date), COMPUTE_BUILD_MONTH(date), COMPUTE_BUILD_DAY(date), COMPUTE_BUILD_HOUR(time), COMPUTE_BUILD_MIN(time), COMPUTE_BUILD_SEC(time), seconds); + auto good = CalendarToChipEpochTime(COMPUTE_BUILD_YEAR(date), COMPUTE_BUILD_MONTH(date), COMPUTE_BUILD_DAY(date), + COMPUTE_BUILD_HOUR(time), COMPUTE_BUILD_MIN(time), COMPUTE_BUILD_SEC(time), seconds); if (good) { chipEpochTime = chip::System::Clock::Seconds32(seconds); @@ -504,22 +331,6 @@ CHIP_ERROR GenericConfigurationManagerImpl::GetSecondaryPairingHint return CHIP_NO_ERROR; } -template -CHIP_ERROR GenericConfigurationManagerImpl::GetVendorName(char * buf, size_t bufSize) -{ - ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); - strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME); - return CHIP_NO_ERROR; -} - -template -CHIP_ERROR GenericConfigurationManagerImpl::GetProductName(char * buf, size_t bufSize) -{ - ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); - strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); - return CHIP_NO_ERROR; -} - template CHIP_ERROR GenericConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize) { @@ -754,11 +565,11 @@ GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble deviceIdInfo.Init(); - err = GetVendorId(id); + err = GetDeviceInstanceInfoProvider()->GetVendorId(id); SuccessOrExit(err); deviceIdInfo.SetVendorId(id); - err = GetProductId(id); + err = GetDeviceInstanceInfoProvider()->GetProductId(id); SuccessOrExit(err); deviceIdInfo.SetProductId(id); @@ -856,7 +667,7 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() { uint16_t vendorId; - if (GetVendorId(vendorId) != CHIP_NO_ERROR) + if (deviceInstanceInfoProvider->GetVendorId(vendorId) != CHIP_NO_ERROR) { vendorId = 0; } @@ -865,7 +676,7 @@ void GenericConfigurationManagerImpl::LogDeviceConfig() { uint16_t productId; - if (GetProductId(productId) != CHIP_NO_ERROR) + if (deviceInstanceInfoProvider->GetProductId(productId) != CHIP_NO_ERROR) { productId = 0; } diff --git a/src/include/platform/internal/GenericDeviceInstanceInfoProvider.h b/src/include/platform/internal/GenericDeviceInstanceInfoProvider.h new file mode 100644 index 00000000000000..c47f87caab831e --- /dev/null +++ b/src/include/platform/internal/GenericDeviceInstanceInfoProvider.h @@ -0,0 +1,60 @@ +/* + * + * 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 { +namespace Internal { + +template +class GenericConfigurationManagerImpl; + +template +class GenericDeviceInstanceInfoProvider : public DeviceInstanceInfoProvider +{ + +public: + // GenericConfigurationManagerImpl will own a GenericDeviceInstanceInfoProvider which + // *refers back to that GenericConfigurationManagerImpl*, due to how CRTP-based + // storage APIs are defined. + // This circular dependency is NOT needed by DeviceInstanceInfoProvider, but required + // to keep generic code running. + GenericDeviceInstanceInfoProvider(GenericConfigurationManagerImpl & configManager) : + mGenericConfigManager(configManager) + {} + + CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override; + 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 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; +}; + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/include/platform/internal/GenericDeviceInstanceInfoProvider.ipp b/src/include/platform/internal/GenericDeviceInstanceInfoProvider.ipp new file mode 100644 index 00000000000000..4081c7c9e0da93 --- /dev/null +++ b/src/include/platform/internal/GenericDeviceInstanceInfoProvider.ipp @@ -0,0 +1,167 @@ +/* + * + * 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 + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::GetVendorId(uint16_t & vendorId) +{ + vendorId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID); + return CHIP_NO_ERROR; +} + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::GetProductId(uint16_t & productId) +{ + productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); + return CHIP_NO_ERROR; +} + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::GetVendorName(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); + strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_VENDOR_NAME); + return CHIP_NO_ERROR; +} + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::GetProductName(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); + strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); + + return CHIP_NO_ERROR; +} + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::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 GenericDeviceInstanceInfoProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) +{ + 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; +} + +template +CHIP_ERROR GenericDeviceInstanceInfoProvider::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 GenericDeviceInstanceInfoProvider::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 +CHIP_ERROR GenericDeviceInstanceInfoProvider::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; +} + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip diff --git a/src/lib/shell/commands/Config.cpp b/src/lib/shell/commands/Config.cpp index 8582bbefaaee3a..e29327b09fe672 100644 --- a/src/lib/shell/commands/Config.cpp +++ b/src/lib/shell/commands/Config.cpp @@ -45,7 +45,7 @@ static CHIP_ERROR ConfigGetVendorId(bool printHeader) streamer_t * sout = streamer_get(); uint16_t value16; - ReturnErrorOnFailure(ConfigurationMgr().GetVendorId(value16)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetVendorId(value16)); if (printHeader) { streamer_printf(sout, "VendorId: "); @@ -64,7 +64,7 @@ static CHIP_ERROR ConfigGetProductId(bool printHeader) streamer_t * sout = streamer_get(); uint16_t value16; - ReturnErrorOnFailure(ConfigurationMgr().GetProductId(value16)); + ReturnErrorOnFailure(DeviceLayer::GetDeviceInstanceInfoProvider()->GetProductId(value16)); if (printHeader) { streamer_printf(sout, "ProductId: "); diff --git a/src/platform/BUILD.gn b/src/platform/BUILD.gn index 3dde9e09081332..6bef6fa13b3c22 100644 --- a/src/platform/BUILD.gn +++ b/src/platform/BUILD.gn @@ -50,10 +50,6 @@ 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. @@ -152,12 +148,6 @@ 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", @@ -334,6 +324,8 @@ if (chip_device_platform != "none") { "../include/platform/internal/GenericConnectivityManagerImpl_Thread.ipp", "../include/platform/internal/GenericConnectivityManagerImpl_WiFi.h", "../include/platform/internal/GenericConnectivityManagerImpl_WiFi.ipp", + "../include/platform/internal/GenericDeviceInstanceInfoProvider.h", + "../include/platform/internal/GenericDeviceInstanceInfoProvider.ipp", "../include/platform/internal/GenericPlatformManagerImpl.h", "../include/platform/internal/GenericPlatformManagerImpl.ipp", "../include/platform/internal/GenericPlatformManagerImpl_FreeRTOS.h", diff --git a/src/platform/Darwin/BUILD.gn b/src/platform/Darwin/BUILD.gn index 41b7ada922ff64..4db52ae9b12e13 100644 --- a/src/platform/Darwin/BUILD.gn +++ b/src/platform/Darwin/BUILD.gn @@ -66,6 +66,8 @@ static_library("Darwin") { if (chip_disable_platform_kvs == false) { sources += [ + "DeviceInstanceInfoProviderImpl.cpp", + "DeviceInstanceInfoProviderImpl.h", "KeyValueStoreManagerImpl.h", "KeyValueStoreManagerImpl.mm", ] diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index 6960b1e3be6060..d6ff1e8b8bec94 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -234,24 +234,6 @@ void ConfigurationManagerImpl::InitiateFactoryReset() ChipLogError(DeviceLayer, "InitiateFactoryReset not implemented"); } -CHIP_ERROR ConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) -{ -#if CHIP_DISABLE_PLATFORM_KVS - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -#else // CHIP_DISABLE_PLATFORM_KVS - return ReadConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); -#endif // CHIP_DISABLE_PLATFORM_KVS -} - -CHIP_ERROR ConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ -#if CHIP_DISABLE_PLATFORM_KVS - return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; -#else // CHIP_DISABLE_PLATFORM_KVS - return ReadConfigValue(PosixConfig::kConfigKey_ProductId, productId); -#endif // CHIP_DISABLE_PLATFORM_KVS -} - CHIP_ERROR ConfigurationManagerImpl::StoreVendorId(uint16_t vendorId) { #if CHIP_DISABLE_PLATFORM_KVS diff --git a/src/platform/Darwin/ConfigurationManagerImpl.h b/src/platform/Darwin/ConfigurationManagerImpl.h index 533817da522aa1..9caaf4293fd0fd 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.h +++ b/src/platform/Darwin/ConfigurationManagerImpl.h @@ -41,9 +41,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreVendorId(uint16_t vendorId); CHIP_ERROR StoreProductId(uint16_t productId); - CHIP_ERROR GetVendorId(uint16_t & vendorId) override; - CHIP_ERROR GetProductId(uint16_t & productId) override; - // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); diff --git a/src/platform/Darwin/DeviceInstanceInfoProviderImpl.cpp b/src/platform/Darwin/DeviceInstanceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..6e1bb52f37d934 --- /dev/null +++ b/src/platform/Darwin/DeviceInstanceInfoProviderImpl.cpp @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 "DeviceInstanceInfoProviderImpl.h" + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetVendorId(uint16_t & vendorId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_VendorId, vendorId); +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_ProductId, productId); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Darwin/DeviceInstanceInfoProviderImpl.h b/src/platform/Darwin/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..0fd05e46dc5160 --- /dev/null +++ b/src/platform/Darwin/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider +{ +public: + CHIP_ERROR GetVendorId(uint16_t & vendorId) override; + CHIP_ERROR GetProductId(uint16_t & productId) override; + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Darwin/PosixConfig.h b/src/platform/Darwin/PosixConfig.h index ea4a7222568170..fe4c1dd48a4250 100644 --- a/src/platform/Darwin/PosixConfig.h +++ b/src/platform/Darwin/PosixConfig.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/Linux/BUILD.gn b/src/platform/Linux/BUILD.gn index 7f46aee3dcfc0b..29c232f2a97159 100644 --- a/src/platform/Linux/BUILD.gn +++ b/src/platform/Linux/BUILD.gn @@ -53,6 +53,8 @@ static_library("Linux") { "ConnectivityManagerImpl.h", "ConnectivityUtils.cpp", "ConnectivityUtils.h", + "DeviceInstanceInfoProviderImpl.cpp", + "DeviceInstanceInfoProviderImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index b0e7b8cfd37b65..68a624ae3ce066 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -327,16 +327,6 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) // TODO(#742): restart CHIP exe } -CHIP_ERROR ConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); -} - -CHIP_ERROR ConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_ProductId, productId); -} - CHIP_ERROR ConfigurationManagerImpl::StoreVendorId(uint16_t vendorId) { return WriteConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); diff --git a/src/platform/Linux/ConfigurationManagerImpl.h b/src/platform/Linux/ConfigurationManagerImpl.h index 7ab13fe46f8b1c..866710fc8faac9 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.h +++ b/src/platform/Linux/ConfigurationManagerImpl.h @@ -40,8 +40,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreVendorId(uint16_t vendorId); CHIP_ERROR StoreProductId(uint16_t productId); - CHIP_ERROR GetVendorId(uint16_t & vendorId) override; - CHIP_ERROR GetProductId(uint16_t & productId) override; CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; diff --git a/src/platform/Linux/DeviceInstanceInfoProviderImpl.cpp b/src/platform/Linux/DeviceInstanceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..db2f813d7e881a --- /dev/null +++ b/src/platform/Linux/DeviceInstanceInfoProviderImpl.cpp @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 "DeviceInstanceInfoProviderImpl.h" + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetVendorId(uint16_t & vendorId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_VendorId, vendorId); +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_ProductId, productId); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Linux/DeviceInstanceInfoProviderImpl.h b/src/platform/Linux/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..0fd05e46dc5160 --- /dev/null +++ b/src/platform/Linux/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider +{ +public: + CHIP_ERROR GetVendorId(uint16_t & vendorId) override; + CHIP_ERROR GetProductId(uint16_t & productId) override; + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Linux/PosixConfig.h b/src/platform/Linux/PosixConfig.h index c2965e2ea8b205..e8370a3e1c0a72 100644 --- a/src/platform/Linux/PosixConfig.h +++ b/src/platform/Linux/PosixConfig.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/Tizen/BUILD.gn b/src/platform/Tizen/BUILD.gn index dd876b6ad8fe1b..825224b90e1417 100644 --- a/src/platform/Tizen/BUILD.gn +++ b/src/platform/Tizen/BUILD.gn @@ -41,6 +41,8 @@ static_library("Tizen") { "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", + "DeviceInstanceInfoProviderImpl.cpp", + "DeviceInstanceInfoProviderImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", diff --git a/src/platform/Tizen/ConfigurationManagerImpl.cpp b/src/platform/Tizen/ConfigurationManagerImpl.cpp index 01e448f3255d6f..507c22cacdd8ac 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.cpp +++ b/src/platform/Tizen/ConfigurationManagerImpl.cpp @@ -70,16 +70,6 @@ CHIP_ERROR ConfigurationManagerImpl::Init(void) return error; } -CHIP_ERROR ConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); -} - -CHIP_ERROR ConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_ProductId, productId); -} - CHIP_ERROR ConfigurationManagerImpl::StoreVendorId(uint16_t vendorId) { return WriteConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); diff --git a/src/platform/Tizen/ConfigurationManagerImpl.h b/src/platform/Tizen/ConfigurationManagerImpl.h index a1da1f7e60f7a8..779fa93518a6a9 100644 --- a/src/platform/Tizen/ConfigurationManagerImpl.h +++ b/src/platform/Tizen/ConfigurationManagerImpl.h @@ -40,9 +40,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreVendorId(uint16_t vendorId); CHIP_ERROR StoreProductId(uint16_t productId); - CHIP_ERROR GetVendorId(uint16_t & vendorId) override; - CHIP_ERROR GetProductId(uint16_t & productId) override; - // This returns an instance of this class. static ConfigurationManagerImpl & GetDefaultInstance(); diff --git a/src/platform/Tizen/DeviceInstanceInfoProviderImpl.cpp b/src/platform/Tizen/DeviceInstanceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..a1eaa56cc15f08 --- /dev/null +++ b/src/platform/Tizen/DeviceInstanceInfoProviderImpl.cpp @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 "DeviceInstanceInfoProviderImpl.h" + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetVendorId(uint16_t & vendorId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_VendorId, vendorId); +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_ProductId, productId); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Tizen/DeviceInstanceInfoProviderImpl.h b/src/platform/Tizen/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..0fd05e46dc5160 --- /dev/null +++ b/src/platform/Tizen/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider +{ +public: + CHIP_ERROR GetVendorId(uint16_t & vendorId) override; + CHIP_ERROR GetProductId(uint16_t & productId) override; + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/Tizen/PosixConfig.h b/src/platform/Tizen/PosixConfig.h index aa5203bf989f7e..459dd98c2ae9c9 100644 --- a/src/platform/Tizen/PosixConfig.h +++ b/src/platform/Tizen/PosixConfig.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/android/AndroidConfig.h b/src/platform/android/AndroidConfig.h index 2d265ca6b9b6b7..d6f446d0fc4ee6 100644 --- a/src/platform/android/AndroidConfig.h +++ b/src/platform/android/AndroidConfig.h @@ -27,7 +27,7 @@ #include #include -#include +#include namespace chip { namespace DeviceLayer { diff --git a/src/platform/android/BUILD.gn b/src/platform/android/BUILD.gn index 510f5de71dd3c3..5e07ce67fca319 100644 --- a/src/platform/android/BUILD.gn +++ b/src/platform/android/BUILD.gn @@ -42,6 +42,8 @@ static_library("android") { "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", + "DeviceInstanceInfoProviderImpl.cpp", + "DeviceInstanceInfoProviderImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", diff --git a/src/platform/android/ConfigurationManagerImpl.cpp b/src/platform/android/ConfigurationManagerImpl.cpp index f8d69be236fcc6..5c42175148e641 100644 --- a/src/platform/android/ConfigurationManagerImpl.cpp +++ b/src/platform/android/ConfigurationManagerImpl.cpp @@ -158,38 +158,6 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) return; } -CHIP_ERROR ConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ - CHIP_ERROR err; - uint32_t u32ProductId = 0; - err = ReadConfigValue(AndroidConfig::kConfigKey_ProductId, u32ProductId); - - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); - } - else - { - productId = static_cast(u32ProductId); - } - - return CHIP_NO_ERROR; -} - -CHIP_ERROR ConfigurationManagerImpl::GetProductName(char * buf, size_t bufSize) -{ - CHIP_ERROR err; - size_t productNameSize = 0; // without counting null-terminator - err = ReadConfigValueStr(AndroidConfig::kConfigKey_ProductName, buf, bufSize, productNameSize); - if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) - { - ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); - strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); - } - - return CHIP_NO_ERROR; -} - CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersion(uint32_t & softwareVer) { CHIP_ERROR err; diff --git a/src/platform/android/ConfigurationManagerImpl.h b/src/platform/android/ConfigurationManagerImpl.h index c28c246d3ec534..45b93bdc76b618 100644 --- a/src/platform/android/ConfigurationManagerImpl.h +++ b/src/platform/android/ConfigurationManagerImpl.h @@ -40,8 +40,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp public: void InitializeWithObject(jobject managerObject); static ConfigurationManagerImpl & GetDefaultInstance(); - CHIP_ERROR GetProductId(uint16_t & productId) override; - CHIP_ERROR GetProductName(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/android/DeviceInstanceInfoProviderImpl.cpp b/src/platform/android/DeviceInstanceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..6d7b1bf4408350 --- /dev/null +++ b/src/platform/android/DeviceInstanceInfoProviderImpl.cpp @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 "DeviceInstanceInfoProviderImpl.h" + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetHardwareVersionString(char * buf, size_t bufSize) +{ + CHIP_ERROR err; + size_t hardwareVersionLen = 0; // without counting null-terminator + err = Internal::AndroidConfig::ReadConfigValueStr(Internal::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 err; +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId) +{ + productId = static_cast(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID); + return CHIP_NO_ERROR; +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductName(char * buf, size_t bufSize) +{ + ReturnErrorCodeIf(bufSize < sizeof(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME), CHIP_ERROR_BUFFER_TOO_SMALL); + strcpy(buf, CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_NAME); + + return CHIP_NO_ERROR; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/android/DeviceInstanceInfoProviderImpl.h b/src/platform/android/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..4fa49245d20882 --- /dev/null +++ b/src/platform/android/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider +{ +public: + 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; + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/fake/BUILD.gn b/src/platform/fake/BUILD.gn index ad2a45b51ea2fb..ab4fe755a1cfb9 100644 --- a/src/platform/fake/BUILD.gn +++ b/src/platform/fake/BUILD.gn @@ -25,6 +25,7 @@ static_library("fake") { "ConfigurationManagerImpl.h", "ConnectivityManagerImpl.cpp", "ConnectivityManagerImpl.h", + "DeviceInstanceInfoProviderImpl.h", "DiagnosticDataProviderImpl.cpp", "DiagnosticDataProviderImpl.h", "DnssdImpl.cpp", diff --git a/src/platform/fake/ConfigurationManagerImpl.h b/src/platform/fake/ConfigurationManagerImpl.h index f01d29f61465a9..40f53e0d0f3c9d 100644 --- a/src/platform/fake/ConfigurationManagerImpl.h +++ b/src/platform/fake/ConfigurationManagerImpl.h @@ -35,10 +35,6 @@ class ConfigurationManagerImpl : public ConfigurationManager private: CHIP_ERROR Init() override { return CHIP_NO_ERROR; } - CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } - 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 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 GetFirmwareBuildChipEpochTime(System::Clock::Seconds32 & buildTime) override diff --git a/src/platform/fake/DeviceInstanceInfoProviderImpl.h b/src/platform/fake/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..d1f16efbb0294e --- /dev/null +++ b/src/platform/fake/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider<> +{ +public: + CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + 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 GetSerialNumber(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override { return CHIP_ERROR_NOT_IMPLEMENTED; } + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/tests/TestConfigurationMgr.cpp b/src/platform/tests/TestConfigurationMgr.cpp index 9073f3f5ade5da..b0259d5fc44bbe 100644 --- a/src/platform/tests/TestConfigurationMgr.cpp +++ b/src/platform/tests/TestConfigurationMgr.cpp @@ -405,6 +405,46 @@ static void TestConfigurationMgr_GetFailSafeArmed(nlTestSuite * inSuite, void * NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); } +static void TestConfigurationMgr_GetVendorName(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + char buf[64]; + + err = GetDeviceInstanceInfoProvider()->GetVendorName(buf, 64); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, strlen(buf) > 0 && strlen(buf) <= ConfigurationManager::kMaxVendorNameLength); +} + +static void TestConfigurationMgr_GetVendorId(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint16_t vendorId; + + err = GetDeviceInstanceInfoProvider()->GetVendorId(vendorId); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, vendorId >= 0 && vendorId <= 0xfff4); +} + +static void TestConfigurationMgr_GetProductName(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + char buf[64]; + + err = GetDeviceInstanceInfoProvider()->GetProductName(buf, 64); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, strlen(buf) > 0 && strlen(buf) <= ConfigurationManager::kMaxProductNameLength); +} + +static void TestConfigurationMgr_GetProductId(nlTestSuite * inSuite, void * inContext) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + uint16_t productId; + + err = GetDeviceInstanceInfoProvider()->GetProductId(productId); + NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR); + NL_TEST_ASSERT(inSuite, productId >= 1 && productId <= 0xffff); +} + /** * Test Suite. It lists all the test functions. */ @@ -422,8 +462,12 @@ static const nlTest sTests[] = { NL_TEST_DEF("Test ConfigurationMgr::CountryCode", TestConfigurationMgr_CountryCode), NL_TEST_DEF("Test ConfigurationMgr::GetPrimaryMACAddress", TestConfigurationMgr_GetPrimaryMACAddress), NL_TEST_DEF("Test ConfigurationMgr::GetFailSafeArmed", TestConfigurationMgr_GetFailSafeArmed), + NL_TEST_DEF("Test ConfigurationMgr::GetVendorName", TestConfigurationMgr_GetVendorName), + NL_TEST_DEF("Test ConfigurationMgr::GetVendorId", TestConfigurationMgr_GetVendorId), + NL_TEST_DEF("Test ConfigurationMgr::GetProductName", TestConfigurationMgr_GetProductName), + NL_TEST_DEF("Test ConfigurationMgr::GetProductId", TestConfigurationMgr_GetProductId), NL_TEST_SENTINEL() -}; +}; // namespace /** * Set up the test suite. diff --git a/src/platform/webos/BUILD.gn b/src/platform/webos/BUILD.gn index cd837a03736c9f..06323b323528af 100644 --- a/src/platform/webos/BUILD.gn +++ b/src/platform/webos/BUILD.gn @@ -80,6 +80,8 @@ static_library("webos") { "ConnectivityUtils.h", "DeviceInfoProviderImpl.cpp", "DeviceInfoProviderImpl.h", + "DeviceInstanceInfoProviderImpl.cpp", + "DeviceInstanceInfoProviderImpl.h", "DeviceNetworkProvisioningDelegateImpl.cpp", "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", diff --git a/src/platform/webos/ConfigurationManagerImpl.cpp b/src/platform/webos/ConfigurationManagerImpl.cpp index a302ca0082c24b..769609406c9fd6 100644 --- a/src/platform/webos/ConfigurationManagerImpl.cpp +++ b/src/platform/webos/ConfigurationManagerImpl.cpp @@ -320,16 +320,6 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) // TODO(#742): restart CHIP exe } -CHIP_ERROR ConfigurationManagerImpl::GetVendorId(uint16_t & vendorId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); -} - -CHIP_ERROR ConfigurationManagerImpl::GetProductId(uint16_t & productId) -{ - return ReadConfigValue(PosixConfig::kConfigKey_ProductId, productId); -} - CHIP_ERROR ConfigurationManagerImpl::StoreVendorId(uint16_t vendorId) { return WriteConfigValue(PosixConfig::kConfigKey_VendorId, vendorId); diff --git a/src/platform/webos/ConfigurationManagerImpl.h b/src/platform/webos/ConfigurationManagerImpl.h index 12cbef9a9c347f..178fd6135fd758 100644 --- a/src/platform/webos/ConfigurationManagerImpl.h +++ b/src/platform/webos/ConfigurationManagerImpl.h @@ -40,8 +40,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp CHIP_ERROR StoreVendorId(uint16_t vendorId); CHIP_ERROR StoreProductId(uint16_t productId); - CHIP_ERROR GetVendorId(uint16_t & vendorId) override; - CHIP_ERROR GetProductId(uint16_t & productId) override; CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; diff --git a/src/platform/webos/DeviceInstanceInfoProviderImpl.cpp b/src/platform/webos/DeviceInstanceInfoProviderImpl.cpp new file mode 100644 index 00000000000000..48311037c30c29 --- /dev/null +++ b/src/platform/webos/DeviceInstanceInfoProviderImpl.cpp @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 "DeviceInstanceInfoProviderImpl.h" + +#include +#include +#include +#include + +namespace chip { +namespace DeviceLayer { + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetVendorId(uint16_t & vendorId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_VendorId, vendorId); +} + +CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId) +{ + return Internal::PosixConfig::ReadConfigValue(Internal::PosixConfig::kConfigKey_ProductId, productId); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/DeviceInstanceInfoProviderImpl.h b/src/platform/webos/DeviceInstanceInfoProviderImpl.h new file mode 100644 index 00000000000000..0fd05e46dc5160 --- /dev/null +++ b/src/platform/webos/DeviceInstanceInfoProviderImpl.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * All rights reserved. + * + * 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 + +namespace chip { +namespace DeviceLayer { + +class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInfoProvider +{ +public: + CHIP_ERROR GetVendorId(uint16_t & vendorId) override; + CHIP_ERROR GetProductId(uint16_t & productId) override; + +private: + friend DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl(); + static DeviceInstanceInfoProviderImpl sInstance; +}; + +inline DeviceInstanceInfoProviderImpl & DeviceInstanceInfoProviderMgrImpl() +{ + return DeviceInstanceInfoProviderImpl::sInstance; +} +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/webos/PosixConfig.h b/src/platform/webos/PosixConfig.h index 44823124667f3b..a7cd7028608421 100644 --- a/src/platform/webos/PosixConfig.h +++ b/src/platform/webos/PosixConfig.h @@ -26,7 +26,7 @@ #include #include -#include +#include namespace chip { namespace DeviceLayer {