Skip to content

Commit

Permalink
Unify silabs device data provider (#26107)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Jun 15, 2023
1 parent a277a3d commit 1717666
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 482 deletions.
8 changes: 4 additions & 4 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,14 @@ source_set("siwx917-attestation-credentials") {
public_configs = [ ":attestation-credentials-config" ]
}

source_set("siwx917-factory-data-provider") {
source_set("silabs-factory-data-provider") {
if (siwx917_commissionable_data) {
defines = [ "SIWX917_USE_COMISSIONABLE_DATA=1" ]
}

sources = [
"SiWx917DeviceDataProvider.cpp",
"SiWx917DeviceDataProvider.h",
"${silabs_common_plat_dir}/SilabsDeviceDataProvider.cpp",
"${silabs_common_plat_dir}/SilabsDeviceDataProvider.h",
]

public_deps = [
Expand Down Expand Up @@ -291,7 +291,7 @@ source_set("siwx917-common") {

# Factory Data Provider
if (use_efr32_factory_data_provider) {
public_deps += [ ":siwx917-factory-data-provider" ]
public_deps += [ ":silabs-factory-data-provider" ]
}

public_deps += [
Expand Down
4 changes: 2 additions & 2 deletions examples/platform/silabs/SiWx917/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED

#include "SiWx917DeviceDataProvider.h"
#include "SilabsDeviceDataProvider.h"
#include "rsi_board.h"
#include "rsi_chip.h"
#include "siwx917_utils.h"
Expand Down Expand Up @@ -214,7 +214,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)
char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1];
chip::MutableCharSpan QRCode(qrCodeBuffer);

if (SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR)
if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR)
{
// Print setup info on LCD if available
#ifdef QR_CODE_ENABLED
Expand Down
70 changes: 0 additions & 70 deletions examples/platform/silabs/SiWx917/SiWx917DeviceDataProvider.h

This file was deleted.

8 changes: 4 additions & 4 deletions examples/platform/silabs/SiWx917/matter_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ using namespace ::chip::DeviceLayer;
#include <crypto/CHIPCryptoPAL.h>
// If building with the SiWx917-provided crypto backend, we can use the

#include "SiWx917DeviceDataProvider.h"
#include "SilabsDeviceDataProvider.h"

#if EFR32_OTA_ENABLED
void SilabsMatterConfig::InitOTARequestorHandler(System::Layer * systemLayer, void * appState)
Expand Down Expand Up @@ -112,11 +112,11 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
}
ReturnErrorOnFailure(PlatformMgr().InitChipStack());

SetDeviceInstanceInfoProvider(&SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider());
SetCommissionableDataProvider(&SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider());
SetDeviceInstanceInfoProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());
SetCommissionableDataProvider(&Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider());

#ifdef SIWX917_USE_COMISSIONABLE_DATA
err = SIWx917::SIWx917DeviceDataProvider::GetDeviceDataProvider().FlashFactoryData();
err = Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().FlashFactoryData();
if (err != CHIP_NO_ERROR)
{
SILABS_LOG("Flashing to the device failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,21 @@
* limitations under the License.
*/

#include "SiWx917DeviceDataProvider.h"
#include "DeviceConfig.h"
#include "siwx917_utils.h"
#include "SilabsDeviceDataProvider.h"
#include <crypto/CHIPCryptoPAL.h>
#include <lib/support/Base64.h>
#include <platform/silabs/SilabsConfig.h>
#include <setup_payload/Base38Decode.h>
#include <setup_payload/Base38Encode.h>
#include <setup_payload/QRCodeSetupPayloadGenerator.h>
#include <setup_payload/SetupPayload.h>

namespace chip {
namespace DeviceLayer {
namespace SIWx917 {
#include <string>
namespace Silabs {

// using namespace chip::Credentials;
using namespace chip::DeviceLayer::Internal;

// TODO Remove once Commander supports (doesn't erase) NVM3 for 917
#ifdef SIWX917_USE_COMISSIONABLE_DATA
void SIWx917DeviceDataProvider::setupPayload(uint8_t * outBuf)
{
Expand Down Expand Up @@ -167,7 +164,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::FlashFactoryData()
}
#endif

CHIP_ERROR SIWx917DeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator)
CHIP_ERROR SilabsDeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator)
{
CHIP_ERROR err;
uint32_t setupDiscriminator32;
Expand All @@ -186,9 +183,10 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSetupDiscriminator(uint16_t & setupDisc
return CHIP_NO_ERROR;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount)
CHIP_ERROR SilabsDeviceDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount)
{
CHIP_ERROR err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_Spake2pIterationCount, iterationCount);

#if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT) && CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_ITERATION_COUNT
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -199,7 +197,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pIterationCount(uint32_t & iterat
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf)
CHIP_ERROR SilabsDeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf)
{
static constexpr size_t kSpake2pSalt_MaxBase64Len = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length) + 1;

Expand All @@ -208,6 +206,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf)
size_t saltB64Len = 0;

err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_Spake2pSalt, saltB64, sizeof(saltB64), saltB64Len);

#if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_SALT)
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -230,7 +229,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pSalt(MutableByteSpan & saltBuf)
return CHIP_NO_ERROR;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen)
CHIP_ERROR SilabsDeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verifierBuf, size_t & verifierLen)
{
static constexpr size_t kSpake2pSerializedVerifier_MaxBase64Len =
BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_VerifierSerialized_Length) + 1;
Expand All @@ -241,6 +240,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verif

err = SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_Spake2pVerifier, verifierB64, sizeof(verifierB64),
verifierB64Len);

#if defined(CHIP_DEVICE_CONFIG_USE_TEST_SPAKE2P_VERIFIER)
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -262,13 +262,15 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSpake2pVerifier(MutableByteSpan & verif
return CHIP_NO_ERROR;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBuf)
CHIP_ERROR SilabsDeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadBuf)
{
CHIP_ERROR err = CHIP_NO_ERROR;
uint8_t payloadBitSet[kTotalPayloadDataSizeInBytes] = { 0 };
size_t bitSetLen = 0;

err = SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_SetupPayloadBitSet, payloadBitSet, kTotalPayloadDataSizeInBytes,
bitSetLen);

#if defined(CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE) && CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand Down Expand Up @@ -300,18 +302,19 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetSetupPayload(MutableCharSpan & payloadB
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetVendorName(char * buf, size_t bufSize)
CHIP_ERROR SilabsDeviceDataProvider::GetVendorName(char * buf, size_t bufSize)
{
size_t vendorNameLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_VendorName, buf, bufSize, vendorNameLen);
}

CHIP_ERROR SIWx917DeviceDataProvider::GetVendorId(uint16_t & vendorId)
CHIP_ERROR SilabsDeviceDataProvider::GetVendorId(uint16_t & vendorId)
{
ChipError err = CHIP_NO_ERROR;
uint32_t vendorId32 = 0;

err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_VendorId, vendorId32);

#if defined(CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID) && CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -325,18 +328,19 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetVendorId(uint16_t & vendorId)
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetProductName(char * buf, size_t bufSize)
CHIP_ERROR SilabsDeviceDataProvider::GetProductName(char * buf, size_t bufSize)
{
size_t productNameLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ProductName, buf, bufSize, productNameLen);
}

CHIP_ERROR SIWx917DeviceDataProvider::GetProductId(uint16_t & productId)
CHIP_ERROR SilabsDeviceDataProvider::GetProductId(uint16_t & productId)
{
ChipError err = CHIP_NO_ERROR;
uint32_t productId32 = 0;

err = SilabsConfig::ReadConfigValue(SilabsConfig::kConfigKey_ProductId, productId32);

#if defined(CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID) && CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID
if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND)
{
Expand All @@ -350,7 +354,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetProductId(uint16_t & productId)
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersionString(char * buf, size_t bufSize)
CHIP_ERROR SilabsDeviceDataProvider::GetHardwareVersionString(char * buf, size_t bufSize)
{
size_t hardwareVersionStringLen = 0; // without counting null-terminator
CHIP_ERROR err =
Expand All @@ -365,7 +369,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersionString(char * buf, size_
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
CHIP_ERROR SilabsDeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVersion)
{
CHIP_ERROR err;
uint32_t hardwareVersion32;
Expand All @@ -383,7 +387,7 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetHardwareVersion(uint16_t & hardwareVers
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan)
CHIP_ERROR SilabsDeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan)
{
ChipError err = CHIP_ERROR_WRONG_KEY_TYPE;
#if CHIP_ENABLE_ROTATING_DEVICE_ID
Expand Down Expand Up @@ -411,13 +415,13 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpa
return err;
}

CHIP_ERROR SIWx917DeviceDataProvider::GetSerialNumber(char * buf, size_t bufSize)
CHIP_ERROR SilabsDeviceDataProvider::GetSerialNumber(char * buf, size_t bufSize)
{
size_t serialNumberLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_SerialNum, buf, bufSize, serialNumberLen);
}

CHIP_ERROR SIWx917DeviceDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day)
CHIP_ERROR SilabsDeviceDataProvider::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day)
{
CHIP_ERROR err;
constexpr uint8_t kDateStringLength = 10; // YYYY-MM-DD
Expand Down Expand Up @@ -452,15 +456,32 @@ CHIP_ERROR SIWx917DeviceDataProvider::GetManufacturingDate(uint16_t & year, uint
ChipLogError(DeviceLayer, "Invalid manufacturing date: %s", dateStr);
}
return err;
return CHIP_ERROR_NOT_IMPLEMENTED;
}

SIWx917DeviceDataProvider & SIWx917DeviceDataProvider::GetDeviceDataProvider()
CHIP_ERROR SilabsDeviceDataProvider::GetPartNumber(char * buf, size_t bufSize)
{
size_t partNumberLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_PartNumber, buf, bufSize, partNumberLen);
}

CHIP_ERROR SilabsDeviceDataProvider::GetProductURL(char * buf, size_t bufSize)
{
size_t productUrlLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ProductURL, buf, bufSize, productUrlLen);
}

CHIP_ERROR SilabsDeviceDataProvider::GetProductLabel(char * buf, size_t bufSize)
{
size_t productLabelLen = 0; // without counting null-terminator
return SilabsConfig::ReadConfigValueStr(SilabsConfig::KConfigKey_ProductLabel, buf, bufSize, productLabelLen);
}

SilabsDeviceDataProvider & SilabsDeviceDataProvider::GetDeviceDataProvider()
{
static SIWx917DeviceDataProvider sDataProvider;
static SilabsDeviceDataProvider sDataProvider;
return sDataProvider;
}

} // namespace SIWx917
} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip
Loading

0 comments on commit 1717666

Please sign in to comment.