Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit b7f3563

Browse files
author
Jay Logue
committed
Support factory provisioning of product revision
-- Modified the ConfigurationManager to support storing the product revision value in persistent storage. This makes it possible for a factory provisioning process to set a device’s product revision without installing new firmware. The compile-time product revision value is now used as a default in the cases where no value is stored in flash.
1 parent 46649bb commit b7f3563

File tree

9 files changed

+88
-22
lines changed

9 files changed

+88
-22
lines changed

build/esp32/components/openweave/Kconfig

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,20 @@ menu "OpenWeave Device Layer"
416416
The device product id (in hex). This is a unique id assigned by the device vendor to identify the product or device type.
417417
Defaults to a Nest-assigned id designating a non-production or test "product".
418418

419-
config DEVICE_PRODUCT_REVISION
420-
int "Device Product Revision"
419+
config DEFAULT_DEVICE_PRODUCT_REVISION
420+
int "Default Device Product Revision"
421421
range 0 65535
422422
default 1
423423
help
424-
The device product revision. This number is assigned to device or product by the device vendor. The number is
425-
scoped to the device product id, and typically corresponds to a revision of the physical device, a change to its
426-
packaging, and/or a change to its marketing presentation. This value is generally *not* incremented for device
427-
software revisions.
424+
The default device product revision.
425+
426+
Product revisions are specific to a particular device vendor and product id, and typically
427+
correspond to a revision of the physical device, a change to its packaging, and/or a change
428+
to its marketing presentation. This value is generally *not* incremented for device software
429+
revisions.
430+
431+
This is a default value which is used when a product revision has not been stored in device
432+
persistent storage (e.g. by a factory provisioning process).
428433

429434
config DEVICE_FIRMWARE_REVISION
430435
string "Device Firmware Revision"

src/adaptations/device-layer/ESP32/ESP32Config.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ namespace Weave {
3232
namespace DeviceLayer {
3333
namespace Internal {
3434

35+
// *** CAUTION ***: Changing the names or namespaces of these values will *break* existing devices.
36+
3537
// NVS namespaces used to store device configuration information.
3638
const char ESP32Config::kConfigNamespace_WeaveFactory[] = "weave-factory";
3739
const char ESP32Config::kConfigNamespace_WeaveConfig[] = "weave-config";
@@ -42,6 +44,7 @@ const ESP32Config::Key ESP32Config::kConfigKey_SerialNum = { kConf
4244
const ESP32Config::Key ESP32Config::kConfigKey_DeviceId = { kConfigNamespace_WeaveFactory, "device-id" };
4345
const ESP32Config::Key ESP32Config::kConfigKey_DeviceCert = { kConfigNamespace_WeaveFactory, "device-cert" };
4446
const ESP32Config::Key ESP32Config::kConfigKey_DevicePrivateKey = { kConfigNamespace_WeaveFactory, "device-key" };
47+
const ESP32Config::Key ESP32Config::kConfigKey_ProductRevision = { kConfigNamespace_WeaveFactory, "product-rev" };
4548
const ESP32Config::Key ESP32Config::kConfigKey_ManufacturingDate = { kConfigNamespace_WeaveFactory, "mfg-date" };
4649
const ESP32Config::Key ESP32Config::kConfigKey_PairingCode = { kConfigNamespace_WeaveFactory, "pairing-code" };
4750

src/adaptations/device-layer/include/Weave/DeviceLayer/ConfigurationManager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class ConfigurationManager
8989
WEAVE_ERROR StorePrimaryWiFiMACAddress(const uint8_t * buf);
9090
WEAVE_ERROR StorePrimary802154MACAddress(const uint8_t * buf);
9191
WEAVE_ERROR StoreManufacturingDate(const char * mfgDate);
92+
WEAVE_ERROR StoreProductRevision(uint16_t productRev);
9293
WEAVE_ERROR StoreFabricId(uint64_t fabricId);
9394
WEAVE_ERROR StoreDeviceCertificate(const uint8_t * cert, size_t certLen);
9495
WEAVE_ERROR StoreDevicePrivateKey(const uint8_t * key, size_t keyLen);
@@ -300,6 +301,11 @@ inline WEAVE_ERROR ConfigurationManager::StoreManufacturingDate(const char * mfg
300301
return static_cast<ImplClass*>(this)->_StoreManufacturingDate(mfgDate);
301302
}
302303

304+
inline WEAVE_ERROR ConfigurationManager::StoreProductRevision(uint16_t productRev)
305+
{
306+
return static_cast<ImplClass*>(this)->_StoreProductRevision(productRev);
307+
}
308+
303309
inline WEAVE_ERROR ConfigurationManager::StoreFabricId(uint64_t fabricId)
304310
{
305311
return static_cast<ImplClass*>(this)->_StoreFabricId(fabricId);

src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/ESP32Config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ESP32Config
5656
static const Key kConfigKey_DeviceId;
5757
static const Key kConfigKey_DeviceCert;
5858
static const Key kConfigKey_DevicePrivateKey;
59+
static const Key kConfigKey_ProductRevision;
5960
static const Key kConfigKey_ManufacturingDate;
6061
static const Key kConfigKey_PairingCode;
6162
static const Key kConfigKey_FabricId;

src/adaptations/device-layer/include/Weave/DeviceLayer/ESP32/WeaveDevicePlatformConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define WEAVE_DEVICE_CONFIG_SERVICE_DIRECTORY_CACHE_SIZE CONFIG_SERVICE_DIRECTORY_CACHE_SIZE
4040
#define WEAVE_DEVICE_CONFIG_DEVICE_VENDOR_ID CONFIG_DEVICE_VENDOR_ID
4141
#define WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_ID CONFIG_DEVICE_PRODUCT_ID
42-
#define WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION CONFIG_DEVICE_PRODUCT_REVISION
42+
#define WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION
4343
#define WEAVE_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION CONFIG_DEVICE_FIRMWARE_REVISION
4444
#define WEAVE_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL CONFIG_WIFI_STATION_RECONNECT_INTERVAL
4545
#define WEAVE_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS CONFIG_MAX_SCAN_NETWORKS_RESULTS

src/adaptations/device-layer/include/Weave/DeviceLayer/WeaveDeviceConfig.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,20 @@
127127
#endif
128128

129129
/**
130-
* WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
130+
* WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION
131131
*
132-
* The product revision number assigned to device or product by the device vendor. This
133-
* number is scoped to the device product id, and typically corresponds to a revision of the
134-
* physical device, a change to its packaging, and/or a change to its marketing presentation.
135-
* This value is generally *not* incremented for device software revisions.
132+
* The default product revision number assigned to the device or product by the device vendor.
133+
*
134+
* Product revisions are specific to a particular device vendor and product id, and typically
135+
* correspond to a revision of the physical device, a change to its packaging, and/or a change
136+
* to its marketing presentation. This value is generally *not* incremented for device software
137+
* revisions.
138+
*
139+
* This is a default value which is used when a product revision has not been stored in device
140+
* persistent storage (e.g. by a factory provisioning process).
136141
*/
137-
#ifndef WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
138-
#define WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1
142+
#ifndef WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION
143+
#define WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION 1
139144
#endif
140145

141146
/**

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class GenericConfigurationManagerImpl
5050
WEAVE_ERROR _GetVendorId(uint16_t & vendorId);
5151
WEAVE_ERROR _GetProductId(uint16_t & productId);
5252
WEAVE_ERROR _GetProductRevision(uint16_t & productRev);
53+
WEAVE_ERROR _StoreProductRevision(uint16_t productRev);
5354
WEAVE_ERROR _GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen);
5455
WEAVE_ERROR _GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth,
5556
uint8_t & hour, uint8_t & minute, uint8_t & second);
@@ -125,13 +126,6 @@ inline WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetProductId(uin
125126
return WEAVE_NO_ERROR;
126127
}
127128

128-
template<class ImplClass>
129-
inline WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetProductRevision(uint16_t & productRev)
130-
{
131-
productRev = (uint16_t)WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION;
132-
return WEAVE_NO_ERROR;
133-
}
134-
135129

136130

137131

src/adaptations/device-layer/include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_StorePrimary802154MACAd
211211
return WEAVE_ERROR_UNSUPPORTED_WEAVE_FEATURE;
212212
}
213213

214+
template<class ImplClass>
215+
inline WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetProductRevision(uint16_t & productRev)
216+
{
217+
WEAVE_ERROR err;
218+
uint32_t val;
219+
220+
err = Impl()->ReadConfigValue(ImplClass::kConfigKey_ProductRevision, val);
221+
if (err == WEAVE_DEVICE_ERROR_CONFIG_NOT_FOUND)
222+
{
223+
productRev = (uint16_t)WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION;
224+
err = WEAVE_NO_ERROR;
225+
}
226+
else
227+
{
228+
productRev = (uint16_t)val;
229+
}
230+
231+
return err;
232+
}
233+
234+
template<class ImplClass>
235+
inline WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_StoreProductRevision(uint16_t productRev)
236+
{
237+
return Impl()->WriteConfigValue(ImplClass::kConfigKey_ProductRevision, (uint32_t)productRev);
238+
}
239+
214240
template<class ImplClass>
215241
WEAVE_ERROR GenericConfigurationManagerImpl<ImplClass>::_GetManufacturingDate(uint16_t& year, uint8_t& month, uint8_t& dayOfMonth)
216242
{
@@ -679,7 +705,7 @@ void GenericConfigurationManagerImpl<ImplClass>::LogDeviceConfig()
679705
WeaveLogProgress(DeviceLayer, " Device Id: %016" PRIX64, FabricState.LocalNodeId);
680706

681707
{
682-
char serialNum[ConfigurationManager::kMaxSerialNumberLength];
708+
char serialNum[ConfigurationManager::kMaxSerialNumberLength + 1];
683709
size_t serialNumLen;
684710
err = Impl()->_GetSerialNumber(serialNum, sizeof(serialNum), serialNumLen);
685711
WeaveLogProgress(DeviceLayer, " Serial Number: %s", (err == WEAVE_NO_ERROR) ? serialNum : "(not set)");
@@ -704,6 +730,29 @@ void GenericConfigurationManagerImpl<ImplClass>::LogDeviceConfig()
704730
WeaveLogProgress(DeviceLayer, " Product Id: %" PRIu16 " (0x%" PRIX16 ")", productId, productId);
705731
}
706732

733+
{
734+
uint16_t productRev;
735+
if (Impl()->_GetProductRevision(productRev) != WEAVE_NO_ERROR)
736+
{
737+
productRev = 0;
738+
}
739+
WeaveLogProgress(DeviceLayer, " Product Revision: %" PRIu16, productRev);
740+
}
741+
742+
{
743+
uint16_t year;
744+
uint8_t month, dayOfMonth;
745+
err = Impl()->_GetManufacturingDate(year, month, dayOfMonth);
746+
if (err == WEAVE_NO_ERROR)
747+
{
748+
WeaveLogProgress(DeviceLayer, " Manufacturing Date: %04" PRIu16 "/%02" PRIu8 "/%02" PRIu8, year, month, dayOfMonth);
749+
}
750+
else
751+
{
752+
WeaveLogProgress(DeviceLayer, " Manufacturing Date: (not set)");
753+
}
754+
}
755+
707756
if (FabricState.FabricId != kFabricIdNotSpecified)
708757
{
709758
WeaveLogProgress(DeviceLayer, " Fabric Id: %016" PRIX64, FabricState.FabricId);

src/adaptations/device-layer/include/Weave/DeviceLayer/nRF5/nRF5Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ class NRF5Config
5858
{
5959
public:
6060

61+
// *** CAUTION ***: Changing the FDS file or record ids of these values will *break* existing devices.
62+
6163
// Limits/definitions imposed by the Nordic SDK
6264
static constexpr uint16_t kFDSFileIdMin = 0x0000; /**< Minimum value that can be used for a FDS file id (per Nordic SDK) */
6365
static constexpr uint16_t kFDSFileIdMax = 0xBFFF; /**< Maximum value that can be used for a FDS file id (per Nordic SDK) */
@@ -90,6 +92,7 @@ class NRF5Config
9092
static constexpr Key kConfigKey_LastUsedEpochKeyId = NRF5ConfigKey(kFileId_WeaveConfig, 0x000C);
9193
static constexpr Key kConfigKey_FailSafeArmed = NRF5ConfigKey(kFileId_WeaveConfig, 0x000D);
9294
static constexpr Key kConfigKey_GroupKey = NRF5ConfigKey(kFileId_WeaveConfig, 0x000E);
95+
static constexpr Key kConfigKey_ProductRevision = NRF5ConfigKey(kFileId_WeaveFactory, 0x000F);
9396

9497
// Range of FDS record keys used to store Weave persisted counter values.
9598
static constexpr uint16_t kPersistedCounterRecordKeyBase = kFDSRecordKeyMin;

0 commit comments

Comments
 (0)