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

Commit b8dbf8a

Browse files
author
Jay Logue
authored
Merge pull request #282 from openweave/feature/factory-prov-tool
Factory Provisioning Tool
2 parents 46649bb + 6a35c33 commit b8dbf8a

25 files changed

+2030
-41
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"

certs/development/device/test-dev-provisioning-data.csv

Lines changed: 257 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <Weave/DeviceLayer/ESP32/ESP32Config.h>
3232
#include <Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp>
3333

34+
#if WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
35+
#include <Weave/DeviceLayer/internal/FactoryProvisioning.ipp>
36+
#endif // WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
37+
3438
#include "esp_wifi.h"
3539
#include "nvs_flash.h"
3640
#include "nvs.h"
@@ -89,6 +93,21 @@ WEAVE_ERROR ConfigurationManagerImpl::_Init()
8993
err = gGroupKeyStore.Init();
9094
SuccessOrExit(err);
9195

96+
#if WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
97+
98+
{
99+
FactoryProvisioning factoryProv;
100+
uint8_t * const kInternalSRAM12Start = (uint8_t *)0x3FFAE000;
101+
uint8_t * const kInternalSRAM12End = kInternalSRAM12Start + (328 * 1024) - 1;
102+
103+
// Scan ESP32 Internal SRAM regions 1 and 2 for injected provisioning data and save
104+
// to persistent storage if found.
105+
err = factoryProv.ProvisionDeviceFromRAM(kInternalSRAM12Start, kInternalSRAM12End);
106+
SuccessOrExit(err);
107+
}
108+
109+
#endif // WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
110+
92111
// If the fail-safe was armed when the device last shutdown, initiate a factory reset.
93112
if (_GetFailSafeArmed(failSafeArmed) == WEAVE_NO_ERROR && failSafeArmed)
94113
{

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/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ noinst_HEADERS = \
7373
include/Weave/DeviceLayer/internal/EchoServer.h \
7474
include/Weave/DeviceLayer/internal/EventLogging.h \
7575
include/Weave/DeviceLayer/internal/FabricProvisioningServer.h \
76+
include/Weave/DeviceLayer/internal/FactoryProvisioning.h \
77+
include/Weave/DeviceLayer/internal/FactoryProvisioning.ipp \
7678
include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h \
7779
include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp \
7880
include/Weave/DeviceLayer/internal/GenericNetworkProvisioningServerImpl.h \

src/adaptations/device-layer/Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,8 @@ noinst_HEADERS = \
694694
include/Weave/DeviceLayer/internal/EchoServer.h \
695695
include/Weave/DeviceLayer/internal/EventLogging.h \
696696
include/Weave/DeviceLayer/internal/FabricProvisioningServer.h \
697+
include/Weave/DeviceLayer/internal/FactoryProvisioning.h \
698+
include/Weave/DeviceLayer/internal/FactoryProvisioning.ipp \
697699
include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.h \
698700
include/Weave/DeviceLayer/internal/GenericConfigurationManagerImpl.ipp \
699701
include/Weave/DeviceLayer/internal/GenericNetworkProvisioningServerImpl.h \

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,15 @@ class ConfigurationManager
8585
WEAVE_ERROR GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen);
8686

8787
WEAVE_ERROR StoreDeviceId(uint64_t deviceId);
88-
WEAVE_ERROR StoreSerialNumber(const char * serialNum);
88+
WEAVE_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen);
8989
WEAVE_ERROR StorePrimaryWiFiMACAddress(const uint8_t * buf);
9090
WEAVE_ERROR StorePrimary802154MACAddress(const uint8_t * buf);
91-
WEAVE_ERROR StoreManufacturingDate(const char * mfgDate);
91+
WEAVE_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen);
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);
95-
WEAVE_ERROR StorePairingCode(const char * pairingCode);
96+
WEAVE_ERROR StorePairingCode(const char * pairingCode, size_t pairingCodeLen);
9697
WEAVE_ERROR StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen);
9798
WEAVE_ERROR ClearServiceProvisioningData();
9899
WEAVE_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen);
@@ -280,9 +281,9 @@ inline WEAVE_ERROR ConfigurationManager::StoreDeviceId(uint64_t deviceId)
280281
return static_cast<ImplClass*>(this)->_StoreDeviceId(deviceId);
281282
}
282283

283-
inline WEAVE_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum)
284+
inline WEAVE_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum, size_t serialNumLen)
284285
{
285-
return static_cast<ImplClass*>(this)->_StoreSerialNumber(serialNum);
286+
return static_cast<ImplClass*>(this)->_StoreSerialNumber(serialNum, serialNumLen);
286287
}
287288

288289
inline WEAVE_ERROR ConfigurationManager::StorePrimaryWiFiMACAddress(const uint8_t * buf)
@@ -295,9 +296,14 @@ inline WEAVE_ERROR ConfigurationManager::StorePrimary802154MACAddress(const uint
295296
return static_cast<ImplClass*>(this)->_StorePrimary802154MACAddress(buf);
296297
}
297298

298-
inline WEAVE_ERROR ConfigurationManager::StoreManufacturingDate(const char * mfgDate)
299+
inline WEAVE_ERROR ConfigurationManager::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen)
299300
{
300-
return static_cast<ImplClass*>(this)->_StoreManufacturingDate(mfgDate);
301+
return static_cast<ImplClass*>(this)->_StoreManufacturingDate(mfgDate, mfgDateLen);
302+
}
303+
304+
inline WEAVE_ERROR ConfigurationManager::StoreProductRevision(uint16_t productRev)
305+
{
306+
return static_cast<ImplClass*>(this)->_StoreProductRevision(productRev);
301307
}
302308

303309
inline WEAVE_ERROR ConfigurationManager::StoreFabricId(uint64_t fabricId)
@@ -315,9 +321,9 @@ inline WEAVE_ERROR ConfigurationManager::StoreDevicePrivateKey(const uint8_t * k
315321
return static_cast<ImplClass*>(this)->_StoreDevicePrivateKey(key, keyLen);
316322
}
317323

318-
inline WEAVE_ERROR ConfigurationManager::StorePairingCode(const char * pairingCode)
324+
inline WEAVE_ERROR ConfigurationManager::StorePairingCode(const char * pairingCode, size_t pairingCodeLen)
319325
{
320-
return static_cast<ImplClass*>(this)->_StorePairingCode(pairingCode);
326+
return static_cast<ImplClass*>(this)->_StorePairingCode(pairingCode, pairingCodeLen);
321327
}
322328

323329
inline WEAVE_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen)

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: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,18 @@
105105
#define WEAVE_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE 256
106106
#endif
107107

108+
/**
109+
* WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
110+
*
111+
* Enable the device factory provisioning feature.
112+
*
113+
* The factory provisioning feature allows factory or developer-supplied provisioning information
114+
* to be injected into a device at boot time and automatically stored in persistent storage.
115+
*/
116+
#ifndef WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING
117+
#define WEAVE_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING 1
118+
#endif
119+
108120
// -------------------- Device Identification Configuration --------------------
109121

110122
/**
@@ -127,15 +139,20 @@
127139
#endif
128140

129141
/**
130-
* WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
142+
* WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION
143+
*
144+
* The default product revision number assigned to the device or product by the device vendor.
145+
*
146+
* Product revisions are specific to a particular device vendor and product id, and typically
147+
* correspond to a revision of the physical device, a change to its packaging, and/or a change
148+
* to its marketing presentation. This value is generally *not* incremented for device software
149+
* revisions.
131150
*
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.
151+
* This is a default value which is used when a product revision has not been stored in device
152+
* persistent storage (e.g. by a factory provisioning process).
136153
*/
137-
#ifndef WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION
138-
#define WEAVE_DEVICE_CONFIG_DEVICE_PRODUCT_REVISION 1
154+
#ifndef WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION
155+
#define WEAVE_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION 1
139156
#endif
140157

141158
/**

0 commit comments

Comments
 (0)