From ade930c255c835787831bd7af0feee2f3be45ac7 Mon Sep 17 00:00:00 2001 From: Marcin Kajor Date: Tue, 19 Dec 2023 15:57:55 +0100 Subject: [PATCH] [nrf noup] [nrfconnect] Added FactoryDataProxy to facilitate dynamic assignments of FactoryDataProvider concrete types to to the generic pointer. Signed-off-by: Marcin Kajor --- src/platform/nrfconnect/FactoryDataProvider.h | 96 ++++++++++++++----- 1 file changed, 70 insertions(+), 26 deletions(-) diff --git a/src/platform/nrfconnect/FactoryDataProvider.h b/src/platform/nrfconnect/FactoryDataProvider.h index 15dae3ab7e..6aef47f440 100644 --- a/src/platform/nrfconnect/FactoryDataProvider.h +++ b/src/platform/nrfconnect/FactoryDataProvider.h @@ -102,10 +102,74 @@ struct ExternalFlashFactoryData uint8_t mFactoryDataBuffer[PM_FACTORY_DATA_SIZE]; }; +class FactoryDataProviderProxy : public chip::Credentials::DeviceAttestationCredentialsProvider, + public CommissionableDataProvider, + public DeviceInstanceInfoProvider +{ +public: + virtual CHIP_ERROR Init() { return CHIP_NO_ERROR; }; + + // ===== Members functions that are platform-specific + virtual CHIP_ERROR GetEnableKey(MutableByteSpan & enableKey) { return CHIP_NO_ERROR; } + + /** + * @brief Get the user data in CBOR format as MutableByteSpan + * + * @param userData MutableByteSpan object to obtain all user data in CBOR format + * @returns + * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. + * CHIP_ERROR_BUFFER_TOO_SMALL if provided MutableByteSpan is too small + */ + virtual CHIP_ERROR GetUserData(MutableByteSpan & userData) { return CHIP_NO_ERROR; } + + /** + * @brief Try to find user data key and return its value + * + * @param userKey A key name to be found + * @param buf Buffer to store value of found key + * @param len Length of the buffer. This value will be updated to the actual value if the key is read. + * @returns + * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. + * CHIP_ERROR_BUFFER_TOO_SMALL if provided buffer length is too small + */ + virtual CHIP_ERROR GetUserKey(const char * userKey, void * buf, size_t & len) { return CHIP_NO_ERROR; } + +protected: + // ===== Members functions that implement the DeviceAttestationCredentialsProvider + CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & outBuffer) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & outBuffer) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) override { return CHIP_NO_ERROR; }; + CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) override + { + return CHIP_NO_ERROR; + }; + + // ===== Members functions that implement the CommissionableDataProvider + CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override { return CHIP_NO_ERROR; }; + CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetSpake2pSalt(MutableByteSpan & saltBuf) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) override; + CHIP_ERROR GetSetupPasscode(uint32_t & setupPasscode) override { return CHIP_NO_ERROR; }; + CHIP_ERROR SetSetupPasscode(uint32_t setupPasscode) override { return CHIP_NO_ERROR; }; + + // ===== Members functions that implement the DeviceInstanceInfoProvider + CHIP_ERROR GetVendorName(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetVendorId(uint16_t & vendorId) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetProductName(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetProductId(uint16_t & productId) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override { return CHIP_NO_ERROR; }; + CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override { return CHIP_NO_ERROR; }; +}; template -class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentialsProvider, - public CommissionableDataProvider, - public DeviceInstanceInfoProvider +class FactoryDataProvider : public FactoryDataProviderProxy { public: CHIP_ERROR Init(); @@ -143,29 +207,9 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia CHIP_ERROR GetProductPrimaryColor(app::Clusters::BasicInformation::ColorEnum * primaryColor) override; // ===== Members functions that are platform-specific - CHIP_ERROR GetEnableKey(MutableByteSpan & enableKey); - - /** - * @brief Get the user data in CBOR format as MutableByteSpan - * - * @param userData MutableByteSpan object to obtain all user data in CBOR format - * @returns - * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. - * CHIP_ERROR_BUFFER_TOO_SMALL if provided MutableByteSpan is too small - */ - CHIP_ERROR GetUserData(MutableByteSpan & userData); - - /** - * @brief Try to find user data key and return its value - * - * @param userKey A key name to be found - * @param buf Buffer to store value of found key - * @param len Length of the buffer. This value will be updated to the actual value if the key is read. - * @returns - * CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND if factory data does not contain user field, or the value cannot be read out. - * CHIP_ERROR_BUFFER_TOO_SMALL if provided buffer length is too small - */ - CHIP_ERROR GetUserKey(const char * userKey, void * buf, size_t & len); + CHIP_ERROR GetEnableKey(MutableByteSpan & enableKey) override; + CHIP_ERROR GetUserData(MutableByteSpan & userData) override; + CHIP_ERROR GetUserKey(const char * userKey, void * buf, size_t & len) override; private: static constexpr uint16_t kFactoryDataPartitionSize = PM_FACTORY_DATA_SIZE;