Skip to content

Commit 73bec6d

Browse files
Separate PersitentUniqueId and BasicInfo UniqueId
1 parent 934ac68 commit 73bec6d

File tree

4 files changed

+66
-60
lines changed

4 files changed

+66
-60
lines changed

examples/platform/silabs/provision/ProvisionStorageDefault.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -403,14 +403,14 @@ CHIP_ERROR Storage::GetManufacturingDate(uint8_t * value, size_t max, size_t & s
403403
return SilabsConfig::ReadConfigValueStr(SilabsConfig::kConfigKey_ManufacturingDate, (char *) value, max, size);
404404
}
405405

406-
CHIP_ERROR Storage::SetUniqueId(const uint8_t * value, size_t size)
406+
CHIP_ERROR Storage::SetPersistentUniqueId(const uint8_t * value, size_t size)
407407
{
408-
return SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_UniqueId, value, size);
408+
return SilabsConfig::WriteConfigValueBin(SilabsConfig::kConfigKey_PersistentUniqueId, value, size);
409409
}
410410

411-
CHIP_ERROR Storage::GetUniqueId(uint8_t * value, size_t max, size_t & size)
411+
CHIP_ERROR Storage::GetPersistentUniqueId(uint8_t * value, size_t max, size_t & size)
412412
{
413-
return SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_UniqueId, value, max, size);
413+
return SilabsConfig::ReadConfigValueBin(SilabsConfig::kConfigKey_PersistentUniqueId, value, max, size);
414414
}
415415

416416
//

examples/platform/silabs/provision/ProvisionStorageFlash.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ CHIP_ERROR DecodeTotal(Encoding::Buffer & reader, uint16_t & total)
7878
ReturnErrorOnFailure(reader.Get(sz));
7979
total = (0xffff == sz) ? sizeof(uint16_t) : sz;
8080
reader.in = reader.begin + total;
81-
ReturnErrorCodeIf(reader.in > reader.end, CHIP_ERROR_INTERNAL);
81+
VerifyOrReturnError(reader.in <= reader.end, CHIP_ERROR_INTERNAL);
8282
return CHIP_NO_ERROR;
8383
}
8484

@@ -118,7 +118,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
118118
{
119119
// New entry
120120
size_t temp_total = found.offset;
121-
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
121+
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
122122
// Copy entry
123123
ReturnErrorOnFailure(in.Get(page + temp_total, in.Size()));
124124
// Update total
@@ -138,7 +138,7 @@ CHIP_ERROR Set(uint16_t id, Encoding::Buffer & in)
138138
{
139139
// Size change, move to the end
140140
uint16_t temp_total = total - found.encoded_size;
141-
ReturnErrorCodeIf(temp_total + in.Size() > kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
141+
VerifyOrReturnError(temp_total + in.Size() <= kPageSize, CHIP_ERROR_INVALID_ARGUMENT);
142142
// Remove the entry
143143
memmove(page + found.offset, page + found.offset + found.encoded_size, temp_total);
144144
// Add the entry
@@ -470,14 +470,14 @@ CHIP_ERROR Storage::GetManufacturingDate(uint8_t * value, size_t max, size_t & s
470470
return Flash::Get(Parameters::ID::kManufacturingDate, value, max, size);
471471
}
472472

473-
CHIP_ERROR Storage::SetUniqueId(const uint8_t * value, size_t size)
473+
CHIP_ERROR Storage::SetPersistentUniqueId(const uint8_t * value, size_t size)
474474
{
475-
return Flash::Set(Parameters::ID::kUniqueId, value, size);
475+
return Flash::Set(Parameters::ID::kPersistentUniqueId, value, size);
476476
}
477477

478-
CHIP_ERROR Storage::GetUniqueId(uint8_t * value, size_t max, size_t & size)
478+
CHIP_ERROR Storage::GetPersistentUniqueId(uint8_t * value, size_t max, size_t & size)
479479
{
480-
return Flash::Get(Parameters::ID::kUniqueId, value, max, size);
480+
return Flash::Get(Parameters::ID::kPersistentUniqueId, value, max, size);
481481
}
482482

483483
//

src/platform/silabs/SilabsConfig.h

+38-34
Original file line numberDiff line numberDiff line change
@@ -120,42 +120,46 @@ class SilabsConfig
120120
static constexpr Key kConfigKey_hostname = SilabsConfigKey(kMatterFactory_KeyBase, 0x15);
121121
static constexpr Key kConfigKey_clientid = SilabsConfigKey(kMatterFactory_KeyBase, 0x16);
122122
static constexpr Key kConfigKey_Test_Event_Trigger_Key = SilabsConfigKey(kMatterFactory_KeyBase, 0x17);
123-
static constexpr Key kConfigKey_UniqueId = SilabsConfigKey(kMatterFactory_KeyBase, 0x1F);
124-
static constexpr Key kConfigKey_Creds_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x20);
125-
static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21);
126-
static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22);
127-
static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23);
128-
static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24);
129-
static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25);
130-
static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26);
131-
static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27);
132-
static constexpr Key kConfigKey_Provision_Request = SilabsConfigKey(kMatterFactory_KeyBase, 0x28);
133-
static constexpr Key kConfigKey_Provision_Version = SilabsConfigKey(kMatterFactory_KeyBase, 0x29);
134-
135-
static constexpr Key kOtaTlvEncryption_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x30);
123+
// kConfigKey_PersistentUniqueId is the inputkey in the generating of the Rotating Device ID
124+
// SHALL NOT be the same as the UniqueID attribute exposed in the Basic Information cluster.
125+
static constexpr Key kConfigKey_PersistentUniqueId = SilabsConfigKey(kMatterFactory_KeyBase, 0x1F);
126+
static constexpr Key kConfigKey_Creds_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x20);
127+
static constexpr Key kConfigKey_Creds_Base_Addr = SilabsConfigKey(kMatterFactory_KeyBase, 0x21);
128+
static constexpr Key kConfigKey_Creds_DAC_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x22);
129+
static constexpr Key kConfigKey_Creds_DAC_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x23);
130+
static constexpr Key kConfigKey_Creds_PAI_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x24);
131+
static constexpr Key kConfigKey_Creds_PAI_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x25);
132+
static constexpr Key kConfigKey_Creds_CD_Offset = SilabsConfigKey(kMatterFactory_KeyBase, 0x26);
133+
static constexpr Key kConfigKey_Creds_CD_Size = SilabsConfigKey(kMatterFactory_KeyBase, 0x27);
134+
static constexpr Key kConfigKey_Provision_Request = SilabsConfigKey(kMatterFactory_KeyBase, 0x28);
135+
static constexpr Key kConfigKey_Provision_Version = SilabsConfigKey(kMatterFactory_KeyBase, 0x29);
136+
static constexpr Key kOtaTlvEncryption_KeyId = SilabsConfigKey(kMatterFactory_KeyBase, 0x30);
136137

137138
// Matter Config Keys
138-
static constexpr Key kConfigKey_ServiceConfig = SilabsConfigKey(kMatterConfig_KeyBase, 0x01);
139-
static constexpr Key kConfigKey_PairedAccountId = SilabsConfigKey(kMatterConfig_KeyBase, 0x02);
140-
static constexpr Key kConfigKey_ServiceId = SilabsConfigKey(kMatterConfig_KeyBase, 0x03);
141-
static constexpr Key kConfigKey_LastUsedEpochKeyId = SilabsConfigKey(kMatterConfig_KeyBase, 0x05);
142-
static constexpr Key kConfigKey_FailSafeArmed = SilabsConfigKey(kMatterConfig_KeyBase, 0x06);
143-
static constexpr Key kConfigKey_GroupKey = SilabsConfigKey(kMatterConfig_KeyBase, 0x07);
144-
static constexpr Key kConfigKey_HardwareVersion = SilabsConfigKey(kMatterConfig_KeyBase, 0x08);
145-
static constexpr Key kConfigKey_RegulatoryLocation = SilabsConfigKey(kMatterConfig_KeyBase, 0x09);
146-
static constexpr Key kConfigKey_CountryCode = SilabsConfigKey(kMatterConfig_KeyBase, 0x0A);
147-
static constexpr Key kConfigKey_WiFiSSID = SilabsConfigKey(kMatterConfig_KeyBase, 0x0C);
148-
static constexpr Key kConfigKey_WiFiPSK = SilabsConfigKey(kMatterConfig_KeyBase, 0x0D);
149-
static constexpr Key kConfigKey_WiFiSEC = SilabsConfigKey(kMatterConfig_KeyBase, 0x0E);
150-
static constexpr Key kConfigKey_GroupKeyBase = SilabsConfigKey(kMatterConfig_KeyBase, 0x0F);
151-
static constexpr Key kConfigKey_LockUser = SilabsConfigKey(kMatterConfig_KeyBase, 0x10);
152-
static constexpr Key kConfigKey_Credential = SilabsConfigKey(kMatterConfig_KeyBase, 0x11);
153-
static constexpr Key kConfigKey_LockUserName = SilabsConfigKey(kMatterConfig_KeyBase, 0x12);
154-
static constexpr Key kConfigKey_CredentialData = SilabsConfigKey(kMatterConfig_KeyBase, 0x13);
155-
static constexpr Key kConfigKey_UserCredentials = SilabsConfigKey(kMatterConfig_KeyBase, 0x14);
156-
static constexpr Key kConfigKey_WeekDaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x15);
157-
static constexpr Key kConfigKey_YearDaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x16);
158-
static constexpr Key kConfigKey_HolidaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x17);
139+
static constexpr Key kConfigKey_ServiceConfig = SilabsConfigKey(kMatterConfig_KeyBase, 0x01);
140+
static constexpr Key kConfigKey_PairedAccountId = SilabsConfigKey(kMatterConfig_KeyBase, 0x02);
141+
static constexpr Key kConfigKey_ServiceId = SilabsConfigKey(kMatterConfig_KeyBase, 0x03);
142+
static constexpr Key kConfigKey_LastUsedEpochKeyId = SilabsConfigKey(kMatterConfig_KeyBase, 0x05);
143+
static constexpr Key kConfigKey_FailSafeArmed = SilabsConfigKey(kMatterConfig_KeyBase, 0x06);
144+
static constexpr Key kConfigKey_GroupKey = SilabsConfigKey(kMatterConfig_KeyBase, 0x07);
145+
static constexpr Key kConfigKey_HardwareVersion = SilabsConfigKey(kMatterConfig_KeyBase, 0x08);
146+
static constexpr Key kConfigKey_RegulatoryLocation = SilabsConfigKey(kMatterConfig_KeyBase, 0x09);
147+
static constexpr Key kConfigKey_CountryCode = SilabsConfigKey(kMatterConfig_KeyBase, 0x0A);
148+
static constexpr Key kConfigKey_WiFiSSID = SilabsConfigKey(kMatterConfig_KeyBase, 0x0C);
149+
static constexpr Key kConfigKey_WiFiPSK = SilabsConfigKey(kMatterConfig_KeyBase, 0x0D);
150+
static constexpr Key kConfigKey_WiFiSEC = SilabsConfigKey(kMatterConfig_KeyBase, 0x0E);
151+
static constexpr Key kConfigKey_GroupKeyBase = SilabsConfigKey(kMatterConfig_KeyBase, 0x0F);
152+
static constexpr Key kConfigKey_LockUser = SilabsConfigKey(kMatterConfig_KeyBase, 0x10);
153+
static constexpr Key kConfigKey_Credential = SilabsConfigKey(kMatterConfig_KeyBase, 0x11);
154+
static constexpr Key kConfigKey_LockUserName = SilabsConfigKey(kMatterConfig_KeyBase, 0x12);
155+
static constexpr Key kConfigKey_CredentialData = SilabsConfigKey(kMatterConfig_KeyBase, 0x13);
156+
static constexpr Key kConfigKey_UserCredentials = SilabsConfigKey(kMatterConfig_KeyBase, 0x14);
157+
static constexpr Key kConfigKey_WeekDaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x15);
158+
static constexpr Key kConfigKey_YearDaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x16);
159+
static constexpr Key kConfigKey_HolidaySchedules = SilabsConfigKey(kMatterConfig_KeyBase, 0x17);
160+
// UniqueId exposed in the Basic Information cluster. It is cleared on factoryreset
161+
// We will generate a random ID, if none was previously provided.
162+
static constexpr Key kConfigKey_UniqueId = SilabsConfigKey(kMatterConfig_KeyBase, 0x18);
159163
static constexpr Key kConfigKey_OpKeyMap = SilabsConfigKey(kMatterConfig_KeyBase, 0x20);
160164
static constexpr Key kConfigKey_BootCount = SilabsConfigKey(kMatterConfig_KeyBase, 0x21);
161165
static constexpr Key kConfigKey_TotalOperationalHours = SilabsConfigKey(kMatterConfig_KeyBase, 0x22);

src/platform/silabs/provision/ProvisionStorage.h

+17-15
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ enum ID : uint16_t
6262
kCertToolPath = 0x0137,
6363
kPylinkLib = 0x0138,
6464
// Instance Info,
65-
kSerialNumber = 0x0141,
66-
kVendorId = 0x0142,
67-
kVendorName = 0x0143,
68-
kProductId = 0x0144,
69-
kProductName = 0x0145,
70-
kProductLabel = 0x0146,
71-
kProductUrl = 0x0147,
72-
kPartNumber = 0x0148,
73-
kHwVersion = 0x0151,
74-
kHwVersionStr = 0x0152,
75-
kManufacturingDate = 0x0153,
76-
kUniqueId = 0x0154,
65+
kSerialNumber = 0x0141,
66+
kVendorId = 0x0142,
67+
kVendorName = 0x0143,
68+
kProductId = 0x0144,
69+
kProductName = 0x0145,
70+
kProductLabel = 0x0146,
71+
kProductUrl = 0x0147,
72+
kPartNumber = 0x0148,
73+
kHwVersion = 0x0151,
74+
kHwVersionStr = 0x0152,
75+
kManufacturingDate = 0x0153,
76+
kPersistentUniqueId = 0x0154,
7777
// Commissionable Data,
7878
kDiscriminator = 0x0161,
7979
kSpake2pPasscode = 0x0162,
@@ -143,7 +143,7 @@ struct Storage : public GenericStorage,
143143
static constexpr size_t kPartNumberLengthMax = 32;
144144
static constexpr size_t kHardwareVersionStrLengthMax = 32;
145145
static constexpr size_t kManufacturingDateLengthMax = 11; // yyyy-mm-dd + \0
146-
static constexpr size_t kUniqueIdLengthMax = 16;
146+
static constexpr size_t kPersistentUniqueIdMaxLength = 16;
147147
static constexpr size_t kSpake2pVerifierB64LengthMax = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_VerifierSerialized_Length) + 1;
148148
static constexpr size_t kSpake2pSaltB64LengthMax = BASE64_ENCODED_LEN(chip::Crypto::kSpake2p_Max_PBKDF_Salt_Length) + 1;
149149
static constexpr size_t kFirmwareInfoSizeMax = 32;
@@ -259,8 +259,10 @@ struct Storage : public GenericStorage,
259259
CHIP_ERROR SetHardwareVersionString(const char * value, size_t len);
260260
CHIP_ERROR SetManufacturingDate(const char * value, size_t len);
261261
CHIP_ERROR GetManufacturingDate(uint8_t * value, size_t max, size_t & size);
262-
CHIP_ERROR SetUniqueId(const uint8_t * value, size_t size);
263-
CHIP_ERROR GetUniqueId(uint8_t * value, size_t max, size_t & size);
262+
// PersistentUniqueId is used to generate the RotatingUniqueId
263+
// This PersistentUniqueId SHALL NOT be the same as the UniqueID attribute exposed in the Basic Information cluster.
264+
CHIP_ERROR SetPersistentUniqueId(const uint8_t * value, size_t size);
265+
CHIP_ERROR GetPersistentUniqueId(uint8_t * value, size_t max, size_t & size);
264266
// CommissionableDataProvider
265267
CHIP_ERROR SetSetupDiscriminator(uint16_t value);
266268
CHIP_ERROR SetSpake2pIterationCount(uint32_t value);

0 commit comments

Comments
 (0)