diff --git a/examples/lighting-app/qpg/BUILD.gn b/examples/lighting-app/qpg/BUILD.gn index 4745c5d1f26f55..01046f05aa99a6 100644 --- a/examples/lighting-app/qpg/BUILD.gn +++ b/examples/lighting-app/qpg/BUILD.gn @@ -62,6 +62,7 @@ qpg_executable("lighting_app") { ] deps = [ + ":factorydata_lib", ":sdk", "${chip_root}/examples/lighting-app/lighting-common", "${chip_root}/examples/lighting-app/lighting-common:color-format", @@ -153,3 +154,15 @@ group("qpg") { group("default") { deps = [ ":qpg" ] } + +static_library("factorydata_lib") { + libs = [ "${qpg_sdk_root}/Binaries/FactoryData/FactoryData_example/FactoryData_example.a" ] + public_configs = [ ":qpg_retain_factorydata" ] +} + +config("qpg_retain_factorydata") { + ldflags = [ + "-Wl,-u_binary_factory_data_bin_start", + "-Wl,-u_binary_factory_data_start", + ] +} diff --git a/examples/lighting-app/qpg/include/AppTask.h b/examples/lighting-app/qpg/include/AppTask.h index 510478fb9be3e3..f91eb971c2ca17 100644 --- a/examples/lighting-app/qpg/include/AppTask.h +++ b/examples/lighting-app/qpg/include/AppTask.h @@ -29,6 +29,8 @@ #include "timers.h" // provides FreeRTOS timer support #include +#include + #define APP_NAME "Lighting-app" class AppTask @@ -78,6 +80,8 @@ class AppTask bool mFunctionTimerActive; bool mSyncClusterToButtonAction; + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + static AppTask sAppTask; }; diff --git a/examples/lighting-app/qpg/include/CHIPProjectConfig.h b/examples/lighting-app/qpg/include/CHIPProjectConfig.h index 98f0f4f8992918..63b3c719c37100 100644 --- a/examples/lighting-app/qpg/include/CHIPProjectConfig.h +++ b/examples/lighting-app/qpg/include/CHIPProjectConfig.h @@ -50,7 +50,7 @@ * 0xFFF1: Test Vendor. */ #ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID -#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x10D0 #endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index 25b89e41b29ddc..e00e90ff8c6ce3 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -254,8 +254,11 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server PlatformMgr().ScheduleWork(InitServer, 0); - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + ReturnErrorOnFailure(mFactoryDataProvider.Init()); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); + + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); // Setup light err = LightingMgr().Init(); diff --git a/examples/lock-app/qpg/BUILD.gn b/examples/lock-app/qpg/BUILD.gn index 60bdcd4bf75ced..ac901678db266c 100644 --- a/examples/lock-app/qpg/BUILD.gn +++ b/examples/lock-app/qpg/BUILD.gn @@ -61,6 +61,7 @@ qpg_executable("lock_app") { ] deps = [ + ":factorydata_lib", ":sdk", "${chip_root}/examples/lock-app/lock-common", "${chip_root}/examples/providers:device_info_provider", @@ -151,3 +152,15 @@ group("qpg") { group("default") { deps = [ ":qpg" ] } + +static_library("factorydata_lib") { + libs = [ "${qpg_sdk_root}/Binaries/FactoryData/FactoryData_example/FactoryData_example.a" ] + public_configs = [ ":qpg_retain_factorydata" ] +} + +config("qpg_retain_factorydata") { + ldflags = [ + "-Wl,-u_binary_factory_data_bin_start", + "-Wl,-u_binary_factory_data_start", + ] +} diff --git a/examples/lock-app/qpg/include/AppTask.h b/examples/lock-app/qpg/include/AppTask.h index 005d0aeb9da6e0..997257ed8352bf 100644 --- a/examples/lock-app/qpg/include/AppTask.h +++ b/examples/lock-app/qpg/include/AppTask.h @@ -31,6 +31,8 @@ #include #include +#include + // Application-defined error codes in the CHIP_ERROR space. #define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x01) @@ -82,6 +84,8 @@ class AppTask bool mFunctionTimerActive; bool mSyncClusterToButtonAction; + chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; + static AppTask sAppTask; }; diff --git a/examples/lock-app/qpg/include/CHIPProjectConfig.h b/examples/lock-app/qpg/include/CHIPProjectConfig.h index cd3121bab0be33..6977241a195b00 100644 --- a/examples/lock-app/qpg/include/CHIPProjectConfig.h +++ b/examples/lock-app/qpg/include/CHIPProjectConfig.h @@ -48,7 +48,7 @@ * 0xFFF1: Test vendor. */ #ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID -#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0x10D0 #endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp index 80217ecf0437ff..993a91068049b9 100644 --- a/examples/lock-app/qpg/src/AppTask.cpp +++ b/examples/lock-app/qpg/src/AppTask.cpp @@ -140,8 +140,11 @@ CHIP_ERROR AppTask::Init() // Init ZCL Data Model and start server PlatformMgr().ScheduleWork(InitServer, 0); - // Initialize device attestation config - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); + ReturnErrorOnFailure(mFactoryDataProvider.Init()); + SetDeviceInstanceInfoProvider(&mFactoryDataProvider); + SetCommissionableDataProvider(&mFactoryDataProvider); + + SetDeviceAttestationCredentialsProvider(&mFactoryDataProvider); // Setup Bolt err = BoltLockMgr().Init(); diff --git a/src/platform/qpg/BUILD.gn b/src/platform/qpg/BUILD.gn index 6abc13b4513754..3e786aacceafdb 100644 --- a/src/platform/qpg/BUILD.gn +++ b/src/platform/qpg/BUILD.gn @@ -40,6 +40,8 @@ static_library("qpg") { "DeviceNetworkProvisioningDelegateImpl.h", "DiagnosticDataProviderImpl.cpp", "DiagnosticDataProviderImpl.h", + "FactoryDataProvider.cpp", + "FactoryDataProvider.h", "InetPlatformConfig.h", "Logging.cpp", "OTAImageProcessorImpl.cpp", @@ -52,6 +54,8 @@ static_library("qpg") { deps = [] + public = [ "${chip_root}/src/credentials/DeviceAttestationCredsProvider.h" ] + public_deps = [ "${chip_root}/src/platform:platform_base" ] public_configs = [] diff --git a/src/platform/qpg/FactoryDataProvider.cpp b/src/platform/qpg/FactoryDataProvider.cpp new file mode 100644 index 00000000000000..4adadd3688acf3 --- /dev/null +++ b/src/platform/qpg/FactoryDataProvider.cpp @@ -0,0 +1,360 @@ +/* + * + * 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 "FactoryDataProvider.h" +#include "CHIPDevicePlatformConfig.h" +#include +#include +#include +#include +#include + +#include "qvCHIP.h" + +namespace chip { +namespace { + +CHIP_ERROR LoadKeypairFromRaw(ByteSpan privateKey, ByteSpan publicKey, Crypto::P256Keypair & keypair) +{ + Crypto::P256SerializedKeypair serializedKeypair; + ReturnErrorOnFailure(serializedKeypair.SetLength(privateKey.size() + publicKey.size())); + memcpy(serializedKeypair.Bytes(), publicKey.data(), publicKey.size()); + memcpy(serializedKeypair.Bytes() + publicKey.size(), privateKey.data(), privateKey.size()); + return keypair.Deserialize(serializedKeypair); +} + +} // namespace + +namespace DeviceLayer { + +CHIP_ERROR FactoryDataProvider::Init() +{ + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::MapQorvoError(qvStatus_t qStatus) +{ + switch (qStatus) + { + case QV_STATUS_NO_ERROR: + return CHIP_NO_ERROR; + case QV_STATUS_BUFFER_TOO_SMALL: + return CHIP_ERROR_BUFFER_TOO_SMALL; + case QV_STATUS_INVALID_ARGUMENT: + return CHIP_ERROR_INVALID_ARGUMENT; + case QV_STATUS_INVALID_DATA: + return CHIP_ERROR_INVALID_DATA_LIST; + default: + break; + } + return CHIP_ERROR_INTERNAL; +} + +CHIP_ERROR FactoryDataProvider::GetCertificationDeclaration(MutableByteSpan & outBuffer) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_CERTIFICATION_DECLARATION, outBuffer.data(), outBuffer.size(), &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= CERTIFICATION_DECLARATION_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + outBuffer.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) +{ + out_firmware_info_buffer.reduce_size(0); + + return CHIP_NO_ERROR; +} + +CHIP_ERROR FactoryDataProvider::GetDeviceAttestationCert(MutableByteSpan & outBuffer) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_DEVICE_ATTESTATION_CERTIFICATE, outBuffer.data(), outBuffer.size(), &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= DEVICE_ATTESTATION_CERTIFICATE_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + outBuffer.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_PRODUCT_ATTESTATION_INTERMEDIATE_CERTIFICATE, outBuffer.data(), outBuffer.size(), + &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= PRODUCT_ATTESTATION_INTERMEDIATE_CERTIFICATE_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + outBuffer.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) +{ + Crypto::P256ECDSASignature signature; + Crypto::P256Keypair keypair; + + VerifyOrReturnError(IsSpanUsable(outSignBuffer), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(IsSpanUsable(messageToSign), CHIP_ERROR_INVALID_ARGUMENT); + VerifyOrReturnError(outSignBuffer.size() >= signature.Capacity(), CHIP_ERROR_BUFFER_TOO_SMALL); + + uint8_t qorvoDacPrivKeyBuffer[DEVICE_ATTESTATION_PRIVATE_KEY_LEN]; + uint8_t qorvoDacPubKeyBuffer[DEVICE_ATTESTATION_PUBLIC_KEY_LEN]; + MutableByteSpan qorvoDacPrivateKey(qorvoDacPrivKeyBuffer, DEVICE_ATTESTATION_PRIVATE_KEY_LEN); + MutableByteSpan qorvoDacPublicKey(qorvoDacPubKeyBuffer, DEVICE_ATTESTATION_PUBLIC_KEY_LEN); + qvStatus_t status; + uint32_t dataLength; + status = qvCHIP_FactoryDataGetValue(TAG_ID_DEVICE_ATTESTATION_PRIVATE_KEY, qorvoDacPrivateKey.data(), qorvoDacPrivateKey.size(), + &dataLength); + ; + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= DEVICE_ATTESTATION_PRIVATE_KEY_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + qorvoDacPrivateKey.reduce_size(dataLength); + } + ReturnErrorOnFailure(MapQorvoError(status)); + + status = qvCHIP_FactoryDataGetValue(TAG_ID_DEVICE_ATTESTATION_PUBLIC_KEY, qorvoDacPublicKey.data(), qorvoDacPublicKey.size(), + &dataLength); + ; + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= DEVICE_ATTESTATION_PUBLIC_KEY_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + qorvoDacPublicKey.reduce_size(dataLength); + } + ReturnErrorOnFailure(MapQorvoError(status)); + + // In a non-exemplary implementation, the public key is not needed here. It is used here merely because + // Crypto::P256Keypair is only (currently) constructable from raw keys if both private/public keys are present. + ReturnErrorOnFailure(LoadKeypairFromRaw(qorvoDacPrivateKey, qorvoDacPublicKey, keypair)); + ReturnErrorOnFailure(keypair.ECDSA_sign_msg(messageToSign.data(), messageToSign.size(), signature)); + + return CopySpanToMutableSpan(ByteSpan{ signature.ConstBytes(), signature.Length() }, outSignBuffer); +} + +CHIP_ERROR FactoryDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_SETUP_DISCRIMINATOR, (uint8_t *) &setupDiscriminator, SETUP_DISCRIMINATOR_LEN, + &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == SETUP_DISCRIMINATOR_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::SetSetupDiscriminator(uint16_t setupDiscriminator) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR FactoryDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_SPAKE2_ITERATION_COUNT, (uint8_t *) &iterationCount, SPAKE2_ITERATION_COUNT_LEN, + &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == SPAKE2_ITERATION_COUNT_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_SPAKE2_SALT, saltBuf.data(), saltBuf.size(), &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= SPAKE2_SALT_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + saltBuf.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) +{ + qvStatus_t status; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_SPAKE2_VERIFIER, verifierBuf.data(), verifierBuf.size(), (uint32_t *) &verifierLen); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(verifierLen <= SPAKE2_VERIFIER_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + verifierBuf.reduce_size(verifierLen); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetSetupPasscode(uint32_t & setupPasscode) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_SPAKE2_SETUP_PASSCODE, (uint8_t *) &setupPasscode, SETUP_PASSCODE_LEN, &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == SETUP_PASSCODE_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::SetSetupPasscode(uint32_t setupPasscode) +{ + return CHIP_ERROR_NOT_IMPLEMENTED; +} + +CHIP_ERROR FactoryDataProvider::GetVendorName(char * buf, size_t bufSize) +{ + return MapQorvoError(qvCHIP_FactoryDataGetValue(TAG_ID_VENDOR_NAME, (uint8_t *) buf, bufSize, NULL)); +} + +CHIP_ERROR FactoryDataProvider::GetVendorId(uint16_t & vendorId) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_VENDOR_ID, (uint8_t *) &vendorId, VENDOR_ID_LEN, &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == VENDOR_ID_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetProductName(char * buf, size_t bufSize) +{ + return MapQorvoError(qvCHIP_FactoryDataGetValue(TAG_ID_PRODUCT_NAME, (uint8_t *) buf, bufSize, NULL)); +} + +CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_PRODUCT_ID, (uint8_t *) &productId, PRODUCT_ID_LEN, &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == PRODUCT_ID_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize) +{ + return MapQorvoError(qvCHIP_FactoryDataGetValue(TAG_ID_SERIAL_NUMBER, (uint8_t *) buf, bufSize, NULL)); +} + +CHIP_ERROR FactoryDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) +{ + uint8_t buf[MANUFACTURING_DATE_LEN]; + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_MANUFACTURING_DATE, buf, MANUFACTURING_DATE_LEN, &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == MANUFACTURING_DATE_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + uint8_t * ptr = buf; + year = *(uint16_t *) ptr; + ptr += 2; + month = *ptr; + ptr += 1; + day = *ptr; + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetHardwareVersion(uint16_t & hardwareVersion) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_HARDWARE_VERSION, (uint8_t *) &hardwareVersion, HARDWARE_VERSION_LEN, &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength == HARDWARE_VERSION_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufSize) +{ + return MapQorvoError(qvCHIP_FactoryDataGetValue(TAG_ID_HARDWARE_VERSION_STRING, (uint8_t *) buf, bufSize, NULL)); +} + +CHIP_ERROR FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_ROTATING_DEVICE_ID, uniqueIdSpan.data(), uniqueIdSpan.size(), &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= ROTATING_DEVICE_ID_UNIQUE_ID_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + uniqueIdSpan.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +CHIP_ERROR FactoryDataProvider::GetEnableKey(MutableByteSpan & enableKey) +{ + qvStatus_t status; + uint32_t dataLength; + + status = qvCHIP_FactoryDataGetValue(TAG_ID_ENABLE_KEY, enableKey.data(), enableKey.size(), &dataLength); + if (status == QV_STATUS_NO_ERROR) + { + VerifyOrReturnError(dataLength <= ENABLE_KEY_LEN, CHIP_ERROR_INVALID_LIST_LENGTH); + enableKey.reduce_size(dataLength); + } + + return MapQorvoError(status); +} + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/qpg/FactoryDataProvider.h b/src/platform/qpg/FactoryDataProvider.h new file mode 100644 index 00000000000000..0c8ab970ae3dcf --- /dev/null +++ b/src/platform/qpg/FactoryDataProvider.h @@ -0,0 +1,71 @@ +/* + * + * 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 +#include + +#include "qvCHIP.h" + +namespace chip { +namespace DeviceLayer { + +class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentialsProvider, + public CommissionableDataProvider, + public DeviceInstanceInfoProvider +{ +public: + CHIP_ERROR Init(); + + // ===== Members functions that implement the DeviceAttestationCredentialsProvider + CHIP_ERROR GetCertificationDeclaration(MutableByteSpan & outBuffer) override; + CHIP_ERROR GetFirmwareInformation(MutableByteSpan & out_firmware_info_buffer) override; + CHIP_ERROR GetDeviceAttestationCert(MutableByteSpan & outBuffer) override; + CHIP_ERROR GetProductAttestationIntermediateCert(MutableByteSpan & outBuffer) override; + CHIP_ERROR SignWithDeviceAttestationKey(const ByteSpan & messageToSign, MutableByteSpan & outSignBuffer) override; + + // ===== Members functions that implement the CommissionableDataProvider + CHIP_ERROR GetSetupDiscriminator(uint16_t & setupDiscriminator) override; + CHIP_ERROR SetSetupDiscriminator(uint16_t setupDiscriminator) override; + CHIP_ERROR GetSpake2pIterationCount(uint32_t & iterationCount) override; + CHIP_ERROR GetSpake2pSalt(MutableByteSpan & saltBuf) override; + CHIP_ERROR GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen) override; + CHIP_ERROR GetSetupPasscode(uint32_t & setupPasscode) override; + CHIP_ERROR SetSetupPasscode(uint32_t setupPasscode) override; + + // ===== Members functions that implement the DeviceInstanceInfoProvider + 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; + + // ===== Members functions that are platform-specific + CHIP_ERROR GetEnableKey(MutableByteSpan & enableKey); + +protected: + static CHIP_ERROR MapQorvoError(qvStatus_t aStatus); +}; + +} // namespace DeviceLayer +} // namespace chip diff --git a/third_party/qpg_sdk/repo b/third_party/qpg_sdk/repo index e92a7eb78f7f8a..8aadeb12092272 160000 --- a/third_party/qpg_sdk/repo +++ b/third_party/qpg_sdk/repo @@ -1 +1 @@ -Subproject commit e92a7eb78f7f8aa4de774cdd973272767eab2e8a +Subproject commit 8aadeb120922720aba2bf0be8d5230d979856a4e