Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2c70b2b

Browse files
Damian-Nordicadbridge
authored andcommittedNov 17, 2022
[platform] Move more product attributes to DeviceInstanceInfoProvider (project-chip#23385)
* [platform] Move more product attributes to DeviceInstanceInfoProvider Vendor and product identifiers were already moved from ConfigurationManager to DeviceInstanceInfoProvider to allow for easier integration with platform factory data providers as they may differ across devices running the same firmware. Somehow PartNumber, ProductURL and ProductLabel slipped unnoticed. Move accessors of these attributes to DeviceInstanceInfoProvider and update all implementations to preserve the existing behavior. Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no> * [nrfconnect] Read PartNumber, URL and Label from factory data Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no> * Code review * Remove obsolete definitions to fix the build Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
1 parent 9245df1 commit 2c70b2b

31 files changed

+248
-103
lines changed
 

‎scripts/tools/nrfconnect/generate_nrfconnect_chip_factory_data.py

+3
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ def generate_json(self):
298298
self._add_entry("vendor_name", self._args.vendor_name)
299299
self._add_entry("product_name", self._args.product_name)
300300
self._add_entry("product_label", self._args.product_label)
301+
self._add_entry("product_url", self._args.product_url)
301302
self._add_entry("part_number", self._args.part_number)
302303
self._add_entry("date", self._args.date)
303304
self._add_entry("hw_ver", self._args.hw_ver)
@@ -434,6 +435,8 @@ def base64_str(s): return base64.b64decode(s)
434435
the setup code. Discriminator is used during a discovery process.")
435436

436437
# optional keys
438+
optional_arguments.add_argument("--product_url", type=str,
439+
help="[string] provide link to product-specific web page")
437440
optional_arguments.add_argument("--product_label", type=str,
438441
help="[string] provide human-readable product label")
439442
optional_arguments.add_argument("--part_number", type=str,

‎scripts/tools/nrfconnect/nrfconnect_factory_data.schema

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@
6060
"type": "string",
6161
"maxLength": 64
6262
},
63+
"product_url": {
64+
"description": "link to product-specific web page",
65+
"type": "string",
66+
"maxLength": 256
67+
},
6368
"part_number": {
6469
"description": "human-readable vendor assigned part number",
6570
"type": "string",

‎scripts/tools/nrfconnect/tests/test_generate_factory_data.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ def test_generate_factory_data_all_specified(self):
155155
'--product_id', '0xABCD',
156156
'--vendor_name', 'Nordic Semiconductor ASA',
157157
'--product_name', 'Lock Gen2',
158-
'--product_label', 'Lock',
159158
'--part_number', 'PCA10056',
159+
'--product_url', 'https://example.com/lock',
160+
'--product_label', 'Lock',
160161
'--date', '2022-07-20',
161162
'--hw_ver', '101',
162163
'--hw_ver_str', 'v1.1',
@@ -181,8 +182,9 @@ def test_generate_factory_data_all_specified(self):
181182
self.assertEqual(factory_data.get('product_id'), 0xABCD)
182183
self.assertEqual(factory_data.get('vendor_name'), 'Nordic Semiconductor ASA')
183184
self.assertEqual(factory_data.get('product_name'), 'Lock Gen2')
184-
self.assertEqual(factory_data.get('product_label'), 'Lock')
185185
self.assertEqual(factory_data.get('part_number'), 'PCA10056')
186+
self.assertEqual(factory_data.get('product_url'), 'https://example.com/lock')
187+
self.assertEqual(factory_data.get('product_label'), 'Lock')
186188
self.assertEqual(factory_data.get('date'), '2022-07-20')
187189
self.assertEqual(factory_data.get('hw_ver'), 101)
188190
self.assertEqual(factory_data.get('hw_ver_str'), 'v1.1')

‎src/app/clusters/basic/basic.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib
191191
case PartNumber::Id: {
192192
constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxPartNumberLength;
193193
char partNumber[kMaxLen + 1] = { 0 };
194-
status = ConfigurationMgr().GetPartNumber(partNumber, sizeof(partNumber));
194+
status = GetDeviceInstanceInfoProvider()->GetPartNumber(partNumber, sizeof(partNumber));
195195

196196
// TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done
197197
if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
@@ -207,7 +207,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib
207207
case ProductURL::Id: {
208208
constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxProductURLLength;
209209
char productUrl[kMaxLen + 1] = { 0 };
210-
status = ConfigurationMgr().GetProductURL(productUrl, sizeof(productUrl));
210+
status = GetDeviceInstanceInfoProvider()->GetProductURL(productUrl, sizeof(productUrl));
211211

212212
// TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done
213213
if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
@@ -223,7 +223,7 @@ CHIP_ERROR BasicAttrAccess::Read(const ConcreteReadAttributePath & aPath, Attrib
223223
case ProductLabel::Id: {
224224
constexpr size_t kMaxLen = DeviceLayer::ConfigurationManager::kMaxProductLabelLength;
225225
char productLabel[kMaxLen + 1] = { 0 };
226-
status = ConfigurationMgr().GetProductLabel(productLabel, sizeof(productLabel));
226+
status = GetDeviceInstanceInfoProvider()->GetProductLabel(productLabel, sizeof(productLabel));
227227

228228
// TODO: Remove defaulting once proper runtime defaulting of unimplemented factory data is done
229229
if (status == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND || status == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)

‎src/include/platform/ConfigurationManager.h

-3
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,6 @@ class ConfigurationManager
116116
virtual CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) = 0;
117117
virtual CHIP_ERROR GetBootReason(uint32_t & bootReason) = 0;
118118
virtual CHIP_ERROR StoreBootReason(uint32_t bootReason) = 0;
119-
virtual CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) = 0;
120-
virtual CHIP_ERROR GetProductURL(char * buf, size_t bufSize) = 0;
121-
virtual CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) = 0;
122119
virtual CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) = 0;
123120
virtual CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) = 0;
124121
virtual CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) = 0;

‎src/include/platform/DeviceInstanceInfoProvider.h

+28-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class DeviceInstanceInfoProvider
3131
/**
3232
* @brief Obtain the Vendor Name from the device's factory data.
3333
*
34-
* @param[in, out] buf Buffer to copy string.
34+
* @param[out] buf Buffer to copy string.
3535
* On CHIP_NO_ERROR return from this function this buffer will be null-terminated.
3636
* On error CHIP_ERROR_BUFFER_TOO_SMALL there is no guarantee that buffer will be null-terminated.
3737
* @param[in] bufSize Size of data, including the null terminator, that can be written to buf.
@@ -72,6 +72,33 @@ class DeviceInstanceInfoProvider
7272
*/
7373
virtual CHIP_ERROR GetProductId(uint16_t & productId) = 0;
7474

75+
/**
76+
* @brief Obtain Part Number from the device factory data.
77+
*
78+
* @param[out] buf Buffer to store the null-terminated result string.
79+
* @param[in] bufSize Size of the buffer. The buffer should allow for fitting in Part Number
80+
* (max 32 characters) and the null terminator.
81+
**/
82+
virtual CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) = 0;
83+
84+
/**
85+
* @brief Obtain Product URL from the device factory data.
86+
*
87+
* @param[out] buf Buffer to store the null-terminated result string.
88+
* @param[in] bufSize Size of the buffer. The buffer should allow for fitting in Product URL
89+
* (max 256 characters) and the null terminator.
90+
**/
91+
virtual CHIP_ERROR GetProductURL(char * buf, size_t bufSize) = 0;
92+
93+
/**
94+
* @brief Obtain Product Label from the device factory data.
95+
*
96+
* @param[out] buf Buffer to store the null-terminated result string.
97+
* @param[in] bufSize Size of the buffer. The buffer should allow for fitting in Product Label
98+
* (max 64 characters) and the null terminator.
99+
**/
100+
virtual CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) = 0;
101+
75102
/**
76103
* @brief Obtain the Serial Number from the device's factory data.
77104
*

‎src/include/platform/internal/GenericConfigurationManagerImpl.h

-3
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager
100100
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
101101
CHIP_ERROR GetBootReason(uint32_t & bootReason) override;
102102
CHIP_ERROR StoreBootReason(uint32_t bootReason) override;
103-
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
104-
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
105-
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
106103
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
107104
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override;
108105
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override;

‎src/include/platform/internal/GenericConfigurationManagerImpl.ipp

-18
Original file line numberDiff line numberDiff line change
@@ -481,24 +481,6 @@ CHIP_ERROR GenericConfigurationManagerImpl<ImplClass>::StoreBootReason(uint32_t
481481
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
482482
}
483483

484-
template <class ConfigClass>
485-
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetPartNumber(char * buf, size_t bufSize)
486-
{
487-
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
488-
}
489-
490-
template <class ConfigClass>
491-
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetProductURL(char * buf, size_t bufSize)
492-
{
493-
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
494-
}
495-
496-
template <class ConfigClass>
497-
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetProductLabel(char * buf, size_t bufSize)
498-
{
499-
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
500-
}
501-
502484
template <class ConfigClass>
503485
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetUniqueId(char * buf, size_t bufSize)
504486
{

‎src/include/platform/internal/GenericDeviceInstanceInfoProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class GenericDeviceInstanceInfoProvider : public DeviceInstanceInfoProvider
4545
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
4646
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
4747
CHIP_ERROR GetProductId(uint16_t & productId) override;
48+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
49+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
50+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
4851
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
4952
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
5053
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;

‎src/include/platform/internal/GenericDeviceInstanceInfoProvider.ipp

+36
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,42 @@ CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetProductName(char *
5252
return CHIP_NO_ERROR;
5353
}
5454

55+
template <class ConfigClass>
56+
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetPartNumber(char * buf, size_t bufSize)
57+
{
58+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
59+
}
60+
61+
template <class ConfigClass>
62+
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetProductURL(char * buf, size_t bufSize)
63+
{
64+
#if CHIP_DEVICE_LAYER_TARGET_ESP32
65+
CHIP_ERROR err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_ProductURL, buf, bufSize, bufSize);
66+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
67+
{
68+
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
69+
}
70+
return err;
71+
#else
72+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
73+
#endif
74+
}
75+
76+
template <class ConfigClass>
77+
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetProductLabel(char * buf, size_t bufSize)
78+
{
79+
#if CHIP_DEVICE_LAYER_TARGET_ESP32
80+
CHIP_ERROR err = mGenericConfigManager.ReadConfigValueStr(ConfigClass::kConfigKey_ProductLabel, buf, bufSize, bufSize);
81+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
82+
{
83+
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
84+
}
85+
return err;
86+
#else
87+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
88+
#endif
89+
}
90+
5591
template <class ConfigClass>
5692
CHIP_ERROR GenericDeviceInstanceInfoProvider<ConfigClass>::GetSerialNumber(char * buf, size_t bufSize)
5793
{

‎src/platform/Ameba/FactoryDataProvider.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId)
330330
return CHIP_NO_ERROR;
331331
}
332332

333+
CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
334+
{
335+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
336+
}
337+
338+
CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize)
339+
{
340+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
341+
}
342+
343+
CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)
344+
{
345+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
346+
}
347+
333348
CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize)
334349
{
335350
ChipError err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;

‎src/platform/Ameba/FactoryDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia
5050
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
5151
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
5252
CHIP_ERROR GetProductId(uint16_t & productId) override;
53+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
54+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
55+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
5356
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
5457
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
5558
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;

‎src/platform/ESP32/ConfigurationManagerImpl.cpp

-20
Original file line numberDiff line numberDiff line change
@@ -185,26 +185,6 @@ CHIP_ERROR ConfigurationManagerImpl::StoreTotalOperationalHours(uint32_t totalOp
185185
return WriteConfigValue(ESP32Config::kCounterKey_TotalOperationalHours, totalOperationalHours);
186186
}
187187

188-
CHIP_ERROR ConfigurationManagerImpl::GetProductURL(char * buf, size_t bufSize)
189-
{
190-
CHIP_ERROR err = ReadConfigValueStr(ESP32Config::kConfigKey_ProductURL, buf, bufSize, bufSize);
191-
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
192-
{
193-
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
194-
}
195-
return err;
196-
}
197-
198-
CHIP_ERROR ConfigurationManagerImpl::GetProductLabel(char * buf, size_t bufSize)
199-
{
200-
CHIP_ERROR err = ReadConfigValueStr(ESP32Config::kConfigKey_ProductLabel, buf, bufSize, bufSize);
201-
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
202-
{
203-
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
204-
}
205-
return err;
206-
}
207-
208188
CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t bufSize)
209189
{
210190
memset(buf, 0, bufSize);

‎src/platform/ESP32/ConfigurationManagerImpl.h

-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
5353
CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override;
5454
CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override;
5555
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override;
56-
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
57-
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
5856
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize);
5957
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
6058
static ConfigurationManagerImpl & GetDefaultInstance();

‎src/platform/ESP32/ESP32FactoryDataProvider.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,26 @@ CHIP_ERROR ESP32FactoryDataProvider::GetProductId(uint16_t & productId)
189189
return err;
190190
}
191191

192+
CHIP_ERROR ESP32FactoryDataProvider::GetProductURL(char * buf, size_t bufSize)
193+
{
194+
CHIP_ERROR err = ESP32Config::ReadConfigValueStr(ESP32Config::kConfigKey_ProductURL, buf, bufSize, bufSize);
195+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
196+
{
197+
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
198+
}
199+
return err;
200+
}
201+
202+
CHIP_ERROR ESP32FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)
203+
{
204+
CHIP_ERROR err = ESP32Config::ReadConfigValueStr(ESP32Config::kConfigKey_ProductLabel, buf, bufSize, bufSize);
205+
if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND)
206+
{
207+
return CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND;
208+
}
209+
return err;
210+
}
211+
192212
CHIP_ERROR ESP32FactoryDataProvider::GetHardwareVersionString(char * buf, size_t bufSize)
193213
{
194214
size_t hardwareVersionStringLen = 0; // without counting null-terminator

‎src/platform/ESP32/ESP32FactoryDataProvider.h

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class ESP32FactoryDataProvider : public CommissionableDataProvider,
6666
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
6767
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
6868
CHIP_ERROR GetProductId(uint16_t & productId) override;
69+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
70+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
6971
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
7072
CHIP_ERROR GetRotatingDeviceIdUniqueId(MutableByteSpan & uniqueIdSpan) override;
7173
#endif // CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER

‎src/platform/android/ConfigurationManagerImpl.cpp

-18
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,6 @@ CHIP_ERROR ConfigurationManagerImpl::GetSoftwareVersionString(char * buf, size_t
191191
return CHIP_NO_ERROR;
192192
}
193193

194-
CHIP_ERROR ConfigurationManagerImpl::GetPartNumber(char * buf, size_t bufSize)
195-
{
196-
size_t dateLen;
197-
return ReadConfigValueStr(AndroidConfig::kConfigKey_PartNumber, buf, bufSize, dateLen);
198-
}
199-
200-
CHIP_ERROR ConfigurationManagerImpl::GetProductURL(char * buf, size_t bufSize)
201-
{
202-
size_t dateLen;
203-
return ReadConfigValueStr(AndroidConfig::kConfigKey_ProductURL, buf, bufSize, dateLen);
204-
}
205-
206-
CHIP_ERROR ConfigurationManagerImpl::GetProductLabel(char * buf, size_t bufSize)
207-
{
208-
size_t dateLen;
209-
return ReadConfigValueStr(AndroidConfig::kConfigKey_ProductLabel, buf, bufSize, dateLen);
210-
}
211-
212194
CHIP_ERROR ConfigurationManagerImpl::GetUniqueId(char * buf, size_t bufSize)
213195
{
214196
size_t dateLen;

‎src/platform/android/ConfigurationManagerImpl.h

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
4242
static ConfigurationManagerImpl & GetDefaultInstance();
4343
CHIP_ERROR GetSoftwareVersionString(char * buf, size_t bufSize) override;
4444
CHIP_ERROR GetSoftwareVersion(uint32_t & softwareVer) override;
45-
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
46-
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
47-
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
4845
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override;
4946

5047
private:

‎src/platform/android/DeviceInstanceInfoProviderImpl.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductId(uint16_t & productId)
5555
return CHIP_NO_ERROR;
5656
}
5757

58+
CHIP_ERROR DeviceInstanceInfoProviderImpl::GetPartNumber(char * buf, size_t bufSize)
59+
{
60+
size_t dateLen;
61+
return Internal::AndroidConfig::ReadConfigValueStr(Internal::AndroidConfig::kConfigKey_PartNumber, buf, bufSize, dateLen);
62+
}
63+
64+
CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductURL(char * buf, size_t bufSize)
65+
{
66+
size_t dateLen;
67+
return Internal::AndroidConfig::ReadConfigValueStr(Internal::AndroidConfig::kConfigKey_ProductURL, buf, bufSize, dateLen);
68+
}
69+
70+
CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductLabel(char * buf, size_t bufSize)
71+
{
72+
size_t dateLen;
73+
return Internal::AndroidConfig::ReadConfigValueStr(Internal::AndroidConfig::kConfigKey_ProductLabel, buf, bufSize, dateLen);
74+
}
75+
5876
CHIP_ERROR DeviceInstanceInfoProviderImpl::GetProductName(char * buf, size_t bufSize)
5977
{
6078
CHIP_ERROR err;

‎src/platform/android/DeviceInstanceInfoProviderImpl.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class DeviceInstanceInfoProviderImpl : public Internal::GenericDeviceInstanceInf
2929
public:
3030
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
3131
CHIP_ERROR GetProductId(uint16_t & productId) override;
32+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
33+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
34+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
3235
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
3336

3437
DeviceInstanceInfoProviderImpl(ConfigurationManagerImpl & configManager) :

‎src/platform/fake/ConfigurationManagerImpl.h

-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ class ConfigurationManagerImpl : public ConfigurationManager
8282
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
8383
CHIP_ERROR GetBootReason(uint32_t & bootReason) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
8484
CHIP_ERROR StoreBootReason(uint32_t bootReason) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
85-
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
86-
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
87-
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
8885
CHIP_ERROR GetUniqueId(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
8986
CHIP_ERROR StoreUniqueId(const char * uniqueId, size_t uniqueIdLen) override { return CHIP_ERROR_NOT_IMPLEMENTED; }
9087
CHIP_ERROR GenerateUniqueId(char * buf, size_t bufSize) override { return CHIP_ERROR_NOT_IMPLEMENTED; }

‎src/platform/nrfconnect/FactoryDataParser.c

+12
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,18 @@ bool ParseFactoryData(uint8_t * buffer, uint16_t bufferSize, struct FactoryData
149149
{
150150
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->product_name);
151151
}
152+
else if (strncmp("part_number", (const char *) currentString.value, currentString.len) == 0)
153+
{
154+
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->part_number);
155+
}
156+
else if (strncmp("product_url", (const char *) currentString.value, currentString.len) == 0)
157+
{
158+
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->product_url);
159+
}
160+
else if (strncmp("product_label", (const char *) currentString.value, currentString.len) == 0)
161+
{
162+
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->product_label);
163+
}
152164
else if (strncmp("enable_key", (const char *) currentString.value, currentString.len) == 0)
153165
{
154166
res = res && zcbor_bstr_decode(states, (struct zcbor_string *) &factoryData->enable_key);

‎src/platform/nrfconnect/FactoryDataParser.h

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ struct FactoryData
4242
uint16_t product_id;
4343
struct FactoryDataString vendor_name;
4444
struct FactoryDataString product_name;
45+
struct FactoryDataString part_number;
46+
struct FactoryDataString product_url;
47+
struct FactoryDataString product_label;
4548
uint16_t hw_ver;
4649
struct FactoryDataString hw_ver_str;
4750
struct FactoryDataString rd_uid;

‎src/platform/nrfconnect/FactoryDataProvider.cpp

+33-27
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ CHIP_ERROR LoadKeypairFromRaw(ByteSpan privateKey, ByteSpan publicKey, Crypto::P
3737
memcpy(serializedKeypair.Bytes() + publicKey.size(), privateKey.data(), privateKey.size());
3838
return keypair.Deserialize(serializedKeypair);
3939
}
40+
41+
CHIP_ERROR GetFactoryDataString(const FactoryDataString & str, char * buf, size_t bufSize)
42+
{
43+
ReturnErrorCodeIf(bufSize < str.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
44+
ReturnErrorCodeIf(!str.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
45+
46+
memcpy(buf, str.data, str.len);
47+
buf[str.len] = 0;
48+
49+
return CHIP_NO_ERROR;
50+
}
51+
4052
} // namespace
4153

4254
namespace DeviceLayer {
@@ -230,13 +242,7 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::SetSetupPasscode(uint32_t setu
230242
template <class FlashFactoryData>
231243
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetVendorName(char * buf, size_t bufSize)
232244
{
233-
ReturnErrorCodeIf(bufSize < mFactoryData.vendor_name.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
234-
ReturnErrorCodeIf(!mFactoryData.vendor_name.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
235-
236-
memcpy(buf, mFactoryData.vendor_name.data, mFactoryData.vendor_name.len);
237-
buf[mFactoryData.vendor_name.len] = 0;
238-
239-
return CHIP_NO_ERROR;
245+
return GetFactoryDataString(mFactoryData.vendor_name, buf, bufSize);
240246
}
241247

242248
template <class FlashFactoryData>
@@ -250,13 +256,7 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetVendorId(uint16_t & vendorI
250256
template <class FlashFactoryData>
251257
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetProductName(char * buf, size_t bufSize)
252258
{
253-
ReturnErrorCodeIf(bufSize < mFactoryData.product_name.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
254-
ReturnErrorCodeIf(!mFactoryData.product_name.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
255-
256-
memcpy(buf, mFactoryData.product_name.data, mFactoryData.product_name.len);
257-
buf[mFactoryData.product_name.len] = 0;
258-
259-
return CHIP_NO_ERROR;
259+
return GetFactoryDataString(mFactoryData.product_name, buf, bufSize);
260260
}
261261

262262
template <class FlashFactoryData>
@@ -268,15 +268,27 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetProductId(uint16_t & produc
268268
}
269269

270270
template <class FlashFactoryData>
271-
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetSerialNumber(char * buf, size_t bufSize)
271+
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetPartNumber(char * buf, size_t bufSize)
272272
{
273-
ReturnErrorCodeIf(bufSize < mFactoryData.sn.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
274-
ReturnErrorCodeIf(!mFactoryData.sn.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
273+
return GetFactoryDataString(mFactoryData.part_number, buf, bufSize);
274+
}
275275

276-
memcpy(buf, mFactoryData.sn.data, mFactoryData.sn.len);
277-
buf[mFactoryData.sn.len] = 0;
276+
template <class FlashFactoryData>
277+
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetProductURL(char * buf, size_t bufSize)
278+
{
279+
return GetFactoryDataString(mFactoryData.product_url, buf, bufSize);
280+
}
278281

279-
return CHIP_NO_ERROR;
282+
template <class FlashFactoryData>
283+
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetProductLabel(char * buf, size_t bufSize)
284+
{
285+
return GetFactoryDataString(mFactoryData.product_label, buf, bufSize);
286+
}
287+
288+
template <class FlashFactoryData>
289+
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetSerialNumber(char * buf, size_t bufSize)
290+
{
291+
return GetFactoryDataString(mFactoryData.sn, buf, bufSize);
280292
}
281293

282294
template <class FlashFactoryData>
@@ -300,13 +312,7 @@ CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetHardwareVersion(uint16_t &
300312
template <class FlashFactoryData>
301313
CHIP_ERROR FactoryDataProvider<FlashFactoryData>::GetHardwareVersionString(char * buf, size_t bufSize)
302314
{
303-
ReturnErrorCodeIf(bufSize < mFactoryData.hw_ver_str.len + 1, CHIP_ERROR_BUFFER_TOO_SMALL);
304-
ReturnErrorCodeIf(!mFactoryData.hw_ver_str.data, CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND);
305-
306-
memcpy(buf, mFactoryData.hw_ver_str.data, mFactoryData.hw_ver_str.len);
307-
buf[mFactoryData.hw_ver_str.len] = 0;
308-
309-
return CHIP_NO_ERROR;
315+
return GetFactoryDataString(mFactoryData.hw_ver_str, buf, bufSize);
310316
}
311317

312318
template <class FlashFactoryData>

‎src/platform/nrfconnect/FactoryDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia
9999
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
100100
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
101101
CHIP_ERROR GetProductId(uint16_t & productId) override;
102+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
103+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
104+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
102105
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
103106
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
104107
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;

‎src/platform/nxp/k32w/k32w0/K32W0FactoryDataProvider.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,21 @@ CHIP_ERROR K32W0FactoryDataProvider::GetProductId(uint16_t & productId)
294294
return CHIP_NO_ERROR;
295295
}
296296

297+
CHIP_ERROR K32W0FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
298+
{
299+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
300+
}
301+
302+
CHIP_ERROR K32W0FactoryDataProvider::GetProductURL(char * buf, size_t bufSize)
303+
{
304+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
305+
}
306+
307+
CHIP_ERROR K32W0FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)
308+
{
309+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
310+
}
311+
297312
CHIP_ERROR K32W0FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize)
298313
{
299314
return CHIP_ERROR_NOT_IMPLEMENTED;

‎src/platform/nxp/k32w/k32w0/K32W0FactoryDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class K32W0FactoryDataProvider : public CommissionableDataProvider,
6666
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
6767
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
6868
CHIP_ERROR GetProductId(uint16_t & productId) override;
69+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
70+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
71+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
6972
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
7073
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
7174
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;

‎src/platform/nxp/mw320/FactoryDataProvider.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,21 @@ CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId)
289289
return CHIP_NO_ERROR;
290290
}
291291

292+
CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
293+
{
294+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
295+
}
296+
297+
CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize)
298+
{
299+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
300+
}
301+
302+
CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)
303+
{
304+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
305+
}
306+
292307
CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize)
293308
{
294309
return CHIP_ERROR_NOT_IMPLEMENTED;

‎src/platform/nxp/mw320/FactoryDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ class FactoryDataProvider : public CommissionableDataProvider,
6666
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
6767
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
6868
CHIP_ERROR GetProductId(uint16_t & productId) override;
69+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
70+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
71+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
6972
CHIP_ERROR GetHardwareVersionString(char * buf, size_t bufSize) override;
7073
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
7174
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;

‎src/platform/qpg/FactoryDataProvider.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,21 @@ CHIP_ERROR FactoryDataProvider::GetProductId(uint16_t & productId)
281281
return MapQorvoError(status);
282282
}
283283

284+
CHIP_ERROR FactoryDataProvider::GetPartNumber(char * buf, size_t bufSize)
285+
{
286+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
287+
}
288+
289+
CHIP_ERROR FactoryDataProvider::GetProductURL(char * buf, size_t bufSize)
290+
{
291+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
292+
}
293+
294+
CHIP_ERROR FactoryDataProvider::GetProductLabel(char * buf, size_t bufSize)
295+
{
296+
return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
297+
}
298+
284299
CHIP_ERROR FactoryDataProvider::GetSerialNumber(char * buf, size_t bufSize)
285300
{
286301
return MapQorvoError(qvCHIP_FactoryDataGetValue(TAG_ID_SERIAL_NUMBER, (uint8_t *) buf, bufSize, NULL));

‎src/platform/qpg/FactoryDataProvider.h

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class FactoryDataProvider : public chip::Credentials::DeviceAttestationCredentia
5454
CHIP_ERROR GetVendorId(uint16_t & vendorId) override;
5555
CHIP_ERROR GetProductName(char * buf, size_t bufSize) override;
5656
CHIP_ERROR GetProductId(uint16_t & productId) override;
57+
CHIP_ERROR GetPartNumber(char * buf, size_t bufSize) override;
58+
CHIP_ERROR GetProductURL(char * buf, size_t bufSize) override;
59+
CHIP_ERROR GetProductLabel(char * buf, size_t bufSize) override;
5760
CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize) override;
5861
CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & day) override;
5962
CHIP_ERROR GetHardwareVersion(uint16_t & hardwareVersion) override;

0 commit comments

Comments
 (0)
Please sign in to comment.