Skip to content

Commit 8997720

Browse files
shubhamdppull[bot]
authored andcommitted
[ESP32] Fix namespace for unique id and added rotating device id (#22063)
unique id key in chip-factory namespace Unique-id should be changed after every factory reset and to do that it should be stored in chip-config namespace. Earlier it was stored in chip-factory which is not erased on factory reset.
1 parent e9483b3 commit 8997720

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

scripts/tools/generate_esp32_chip_factory_bin.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
'encoding': 'string',
141141
'value': None,
142142
},
143-
'unique-id': {
143+
'rd-id-uid': {
144144
'type': 'data',
145145
'encoding': 'hex2bin',
146146
'value': None,
@@ -260,7 +260,7 @@ def validate_args(args):
260260
check_str_range(args.product_name, 1, 32, 'Product name')
261261
check_str_range(args.hw_ver_str, 1, 64, 'Hardware version string')
262262
check_str_range(args.mfg_date, 8, 16, 'Manufacturing date')
263-
check_str_range(args.unique_id, 32, 32, 'Unique id')
263+
check_str_range(args.rd_id_uid, 32, 32, 'Rotating device Unique id')
264264

265265
logging.info('Discriminator:{} Passcode:{}'.format(args.discriminator, args.passcode))
266266

@@ -295,8 +295,8 @@ def populate_factory_data(args, spake2p_params):
295295

296296
if args.serial_num is not None:
297297
FACTORY_DATA['serial-num']['value'] = args.serial_num
298-
if args.unique_id is not None:
299-
FACTORY_DATA['unique-id']['value'] = args.unique_id
298+
if args.rd_id_uid is not None:
299+
FACTORY_DATA['rd-id-uid']['value'] = args.rd_id_uid
300300
if args.mfg_date is not None:
301301
FACTORY_DATA['mfg-date']['value'] = args.mfg_date
302302
if args.vendor_id is not None:
@@ -460,8 +460,8 @@ def any_base_int(s): return int(s, 0)
460460
parser.add_argument('--hw-ver-str', type=str, required=False, help='Hardware version string')
461461
parser.add_argument('--mfg-date', type=str, required=False, help='Manufacturing date in format YYYY-MM-DD')
462462
parser.add_argument('--serial-num', type=str, required=False, help='Serial number')
463-
parser.add_argument('--unique-id', type=str, required=False,
464-
help='128-bit unique identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"')
463+
parser.add_argument('--rd-id-uid', type=str, required=False,
464+
help='128-bit unique identifier for generating rotating device identifier, provide 32-byte hex string, e.g. "1234567890abcdef1234567890abcdef"')
465465

466466
# These will be used by DeviceInfoProvider
467467
parser.add_argument('--calendar-types', type=str, nargs='+', required=False,

src/platform/ESP32/ESP32Config.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ const ESP32Config::Key ESP32Config::kConfigKey_VendorId = { kConfig
7272
const ESP32Config::Key ESP32Config::kConfigKey_VendorName = { kConfigNamespace_ChipFactory, "vendor-name" };
7373
const ESP32Config::Key ESP32Config::kConfigKey_ProductId = { kConfigNamespace_ChipFactory, "product-id" };
7474
const ESP32Config::Key ESP32Config::kConfigKey_ProductName = { kConfigNamespace_ChipFactory, "product-name" };
75-
const ESP32Config::Key ESP32Config::kConfigKey_UniqueId = { kConfigNamespace_ChipFactory, "unique-id" };
7675
const ESP32Config::Key ESP32Config::kConfigKey_SupportedCalTypes = { kConfigNamespace_ChipFactory, "cal-types" };
7776
const ESP32Config::Key ESP32Config::kConfigKey_SupportedLocaleSize = { kConfigNamespace_ChipFactory, "locale-sz" };
77+
const ESP32Config::Key ESP32Config::kConfigKey_RotatingDevIdUniqueId = { kConfigNamespace_ChipFactory, "rd-id-uid" };
7878

7979
// Keys stored in the chip-config namespace
8080
const ESP32Config::Key ESP32Config::kConfigKey_ServiceConfig = { kConfigNamespace_ChipConfig, "service-config" };
@@ -85,6 +85,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_FailSafeArmed = { kConfigNam
8585
const ESP32Config::Key ESP32Config::kConfigKey_WiFiStationSecType = { kConfigNamespace_ChipConfig, "sta-sec-type" };
8686
const ESP32Config::Key ESP32Config::kConfigKey_RegulatoryLocation = { kConfigNamespace_ChipConfig, "reg-location" };
8787
const ESP32Config::Key ESP32Config::kConfigKey_CountryCode = { kConfigNamespace_ChipConfig, "country-code" };
88+
const ESP32Config::Key ESP32Config::kConfigKey_UniqueId = { kConfigNamespace_ChipConfig, "unique-id" };
8889

8990
// Keys stored in the Chip-counters namespace
9091
const ESP32Config::Key ESP32Config::kCounterKey_RebootCount = { kConfigNamespace_ChipCounters, "reboot-count" };

src/platform/ESP32/ESP32Config.h

+12-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class ESP32Config
5353

5454
// Key definitions for well-known keys.
5555
static const Key kConfigKey_SerialNum;
56-
static const Key kConfigKey_UniqueId;
5756
static const Key kConfigKey_MfrDeviceId;
5857
static const Key kConfigKey_MfrDeviceCert;
5958
static const Key kConfigKey_MfrDeviceICACerts;
@@ -62,15 +61,7 @@ class ESP32Config
6261
static const Key kConfigKey_HardwareVersionString;
6362
static const Key kConfigKey_ManufacturingDate;
6463
static const Key kConfigKey_SetupPinCode;
65-
static const Key kConfigKey_ServiceConfig;
66-
static const Key kConfigKey_PairedAccountId;
67-
static const Key kConfigKey_ServiceId;
68-
static const Key kConfigKey_LastUsedEpochKeyId;
69-
static const Key kConfigKey_FailSafeArmed;
70-
static const Key kConfigKey_WiFiStationSecType;
7164
static const Key kConfigKey_SetupDiscriminator;
72-
static const Key kConfigKey_RegulatoryLocation;
73-
static const Key kConfigKey_CountryCode;
7465
static const Key kConfigKey_Spake2pIterationCount;
7566
static const Key kConfigKey_Spake2pSalt;
7667
static const Key kConfigKey_Spake2pVerifier;
@@ -85,6 +76,18 @@ class ESP32Config
8576
static const Key kConfigKey_ProductName;
8677
static const Key kConfigKey_SupportedCalTypes;
8778
static const Key kConfigKey_SupportedLocaleSize;
79+
static const Key kConfigKey_RotatingDevIdUniqueId;
80+
81+
// CHIP Config keys
82+
static const Key kConfigKey_ServiceConfig;
83+
static const Key kConfigKey_PairedAccountId;
84+
static const Key kConfigKey_ServiceId;
85+
static const Key kConfigKey_LastUsedEpochKeyId;
86+
static const Key kConfigKey_FailSafeArmed;
87+
static const Key kConfigKey_WiFiStationSecType;
88+
static const Key kConfigKey_RegulatoryLocation;
89+
static const Key kConfigKey_CountryCode;
90+
static const Key kConfigKey_UniqueId;
8891

8992
// CHIP Counter keys
9093
static const Key kCounterKey_RebootCount;

src/platform/ESP32/ESP32FactoryDataProvider.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,13 @@ CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersionString(char * buf, size_t
198198
CHIP_ERROR ESP32FactoryDataProvider::GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan)
199199
{
200200
ChipError err = CHIP_ERROR_WRONG_KEY_TYPE;
201-
#if CHIP_ENABLE_ROTATING_DEVICE_ID && defined(CHIP_DEVICE_CONFIG_ROTATING_DEVICE_ID_UNIQUE_ID)
201+
#if CHIP_ENABLE_ROTATING_DEVICE_ID
202202
static_assert(ConfigurationManager::kRotatingDeviceIDUniqueIDLength >= ConfigurationManager::kMinRotatingDeviceIDUniqueIDLength,
203203
"Length of unique ID for rotating device ID is smaller than minimum.");
204204

205205
size_t uniqueIdLen = 0;
206-
err = ESP32Config::ReadConfigValueBin(ESP32Config::kConfigKey_UniqueId, uniqueIdSpan.data(), uniqueIdSpan.size(), uniqueIdLen);
206+
err = ESP32Config::ReadConfigValueBin(ESP32Config::kConfigKey_RotatingDevIdUniqueId, uniqueIdSpan.data(), uniqueIdSpan.size(),
207+
uniqueIdLen);
207208
ReturnErrorOnFailure(err);
208209
uniqueIdSpan.reduce_size(uniqueIdLen);
209210
#endif

0 commit comments

Comments
 (0)