Skip to content

Commit 1a0c5e1

Browse files
adigieArekBalysNordic
authored andcommitted
applications: matter_bridge: Add Kconfigs for enabling migration
* Add Kconfig to enable bridged device data migration from old pre 2.7.0 scheme to new scheme version 2. * Add Kconfig to enable briddged device data migration from version 1 to 2. Signed-off-by: Adrian Gielniewski <[email protected]>
1 parent 6ace92f commit 1a0c5e1

File tree

5 files changed

+59
-1
lines changed

5 files changed

+59
-1
lines changed

applications/matter_bridge/doc/matter_bridge_description.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,16 @@ CONFIG_BRIDGE_MAX_BRIDGED_DEVICES_NUMBER
496496
CONFIG_BRIDGE_MAX_DYNAMIC_ENDPOINTS_NUMBER
497497
Set the maximum number of dynamic endpoints supported by the Bridge.
498498

499+
.. _CONFIG_BRIDGE_MIGRATE_PRE_2_7_0:
500+
501+
CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
502+
Enable migration of bridged device data stored in old scheme from pre nRF SDK 2.7.0 releases.
503+
504+
.. _CONFIG_BRIDGE_MIGRATE_VERSION_1:
505+
506+
CONFIG_BRIDGE_MIGRATE_VERSION_1
507+
Enable migration of bridged device data stored in version 1 of new scheme.
508+
499509
.. _matter_bridge_app_bridged_support_configs:
500510

501511
Bridged device configuration

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@ IPC radio firmware
230230
Matter Bridge
231231
-------------
232232

233+
* Added:
234+
235+
* Support for the ``UniqueID`` attribute in the Bridged Device Basic Information cluster.
236+
* Version 2 of bridged device data scheme containing ``UniqueID``.
237+
* Kconfig options :ref:`CONFIG_BRIDGE_MIGRATE_PRE_2_7_0 <CONFIG_BRIDGE_MIGRATE_PRE_2_7_0>` and :ref:`CONFIG_BRIDGE_MIGRATE_VERSION_1 <CONFIG_BRIDGE_MIGRATE_VERSION_1>` to enable migration from older data schemes.
238+
233239
|no_changes_yet_note|
234240

235241
nRF5340 Audio

samples/matter/common/src/bridge/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ config BRIDGE_AGGREGATOR_ENDPOINT_ID
2020
int "Id of an endpoint implementing Aggregator device type functionality"
2121
default 1
2222

23+
config BRIDGE_MIGRATE_PRE_2_7_0
24+
bool "Enable migration of bridged device data stored in old scheme from pre nRF SDK 2.7.0 releases"
25+
26+
config BRIDGE_MIGRATE_VERSION_1
27+
bool "Enable migration of bridged device data stored in version 1 of new scheme"
28+
default y
29+
2330
if BRIDGED_DEVICE_BT
2431

2532
config BRIDGE_BT_RECOVERY_MAX_INTERVAL

samples/matter/common/src/bridge/bridge_storage_manager.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Nrf::PersistentStorageNode CreateIndexNode(uint8_t bridgedDeviceIndex, Nrf::Pers
3737
namespace Nrf
3838
{
3939

40+
#ifdef CONFIG_BRIDGE_MIGRATE_VERSION_1
4041
template <> bool BridgeStorageManager::LoadBridgedDevice(BridgedDeviceV1 &device, uint8_t index)
4142
{
4243
Nrf::PersistentStorageNode id = CreateIndexNode(index, &mBridgedDevice);
@@ -102,6 +103,7 @@ template <> bool BridgeStorageManager::LoadBridgedDevice(BridgedDeviceV1 &device
102103

103104
return true;
104105
}
106+
#endif
105107

106108
template <> bool BridgeStorageManager::LoadBridgedDevice(BridgedDeviceV2 &device, uint8_t index)
107109
{
@@ -197,6 +199,7 @@ bool BridgeStorageManager::Init()
197199
return MigrateData();
198200
}
199201

202+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
200203
bool BridgeStorageManager::MigrateDataOldScheme(uint8_t bridgedDeviceIndex)
201204
{
202205
BridgedDevice device;
@@ -250,7 +253,9 @@ bool BridgeStorageManager::MigrateDataOldScheme(uint8_t bridgedDeviceIndex)
250253

251254
return true;
252255
}
256+
#endif
253257

258+
#ifdef CONFIG_BRIDGE_MIGRATE_VERSION_1
254259
bool BridgeStorageManager::MigrateDataVersion1(uint8_t bridgedDeviceIndex)
255260
{
256261
BridgedDeviceV1 v1;
@@ -292,6 +297,7 @@ bool BridgeStorageManager::MigrateDataVersion1(uint8_t bridgedDeviceIndex)
292297

293298
return true;
294299
}
300+
#endif
295301

296302
bool BridgeStorageManager::MigrateData()
297303
{
@@ -323,13 +329,25 @@ bool BridgeStorageManager::MigrateData()
323329
/* Migrate all devices */
324330
for (size_t i = 0; i < indexesCount; i++) {
325331
if (!versionPresent) {
332+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
326333
if (!MigrateDataOldScheme(indexes[i])) {
327334
return false;
328335
}
336+
#else
337+
/* Migration not enabled */
338+
LOG_ERR("Migration of old data scheme not enabled.");
339+
return false;
340+
#endif
329341
} else if (version == 1) {
342+
#ifdef CONFIG_BRIDGE_MIGRATE_VERSION_1
330343
if (!MigrateDataVersion1(indexes[i])) {
331344
return false;
332345
}
346+
#else
347+
/* Migration not enabled */
348+
LOG_ERR("Migration of data scheme version 1 not enabled.");
349+
return false;
350+
#endif
333351
}
334352
}
335353
}
@@ -369,6 +387,7 @@ bool BridgeStorageManager::LoadBridgedDevicesIndexes(uint8_t *indexes, uint8_t m
369387
return Nrf::GetPersistentStorage().NonSecureLoad(&mBridgedDevicesIndexes, indexes, maxCount, count);
370388
}
371389

390+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
372391
bool BridgeStorageManager::LoadBridgedDeviceEndpointId(uint16_t &endpointId, uint8_t bridgedDeviceIndex)
373392
{
374393
Nrf::PersistentStorageNode id = CreateIndexNode(bridgedDeviceIndex, &mBridgedDeviceEndpointId);
@@ -411,6 +430,7 @@ bool BridgeStorageManager::RemoveBridgedDeviceType(uint8_t bridgedDeviceIndex)
411430

412431
return Nrf::GetPersistentStorage().NonSecureRemove(&id);
413432
}
433+
#endif
414434

415435
bool BridgeStorageManager::StoreBridgedDevice(BridgedDevice &device, uint8_t index)
416436
{
@@ -454,6 +474,7 @@ bool BridgeStorageManager::RemoveBridgedDevice(uint8_t index)
454474
return Nrf::GetPersistentStorage().NonSecureRemove(&id);
455475
}
456476

477+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
457478
#ifdef CONFIG_BRIDGED_DEVICE_BT
458479
bool BridgeStorageManager::LoadBtAddress(bt_addr_le_t &addr, uint8_t bridgedDeviceIndex)
459480
{
@@ -469,5 +490,6 @@ bool BridgeStorageManager::RemoveBtAddress(uint8_t bridgedDeviceIndex)
469490
return Nrf::GetPersistentStorage().NonSecureRemove(&id);
470491
}
471492
#endif
493+
#endif
472494

473495
} /* namespace Nrf */

samples/matter/common/src/bridge/bridge_storage_manager.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class BridgeStorageManager {
3434
public:
3535
static inline constexpr auto kMaxUserDataSize = 128u;
3636

37+
#ifdef CONFIG_BRIDGE_MIGRATE_VERSION_1
3738
struct BridgedDeviceV1 {
3839
uint16_t mEndpointId;
3940
uint16_t mDeviceType;
@@ -42,6 +43,7 @@ class BridgeStorageManager {
4243
size_t mUserDataSize = 0;
4344
uint8_t *mUserData = nullptr;
4445
};
46+
#endif
4547

4648
struct BridgedDeviceV2 {
4749
uint16_t mEndpointId;
@@ -62,13 +64,16 @@ class BridgeStorageManager {
6264
BridgeStorageManager()
6365
: mBridge("br", strlen("br")), mBridgedDevicesCount("brd_cnt", strlen("brd_cnt"), &mBridge),
6466
mBridgedDevicesIndexes("brd_ids", strlen("brd_ids"), &mBridge),
65-
mBridgedDevice("brd", strlen("brd"), &mBridge), mVersion("ver", strlen("ver"), &mBridge),
67+
mBridgedDevice("brd", strlen("brd"), &mBridge), mVersion("ver", strlen("ver"), &mBridge)
68+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
69+
,
6670
mBridgedDeviceEndpointId("eid", strlen("eid"), &mBridgedDevice),
6771
mBridgedDeviceNodeLabel("label", strlen("label"), &mBridgedDevice),
6872
mBridgedDeviceType("type", strlen("type"), &mBridgedDevice)
6973
#ifdef CONFIG_BRIDGED_DEVICE_BT
7074
,
7175
mBt("bt", strlen("bt"), &mBridgedDevice), mBtAddress("addr", strlen("addr"), &mBt)
76+
#endif
7277
#endif
7378
{
7479
}
@@ -173,6 +178,7 @@ class BridgeStorageManager {
173178
*/
174179
bool MigrateData();
175180

181+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
176182
/**
177183
* @brief Migrate bridged device data at given index.
178184
*
@@ -184,7 +190,9 @@ class BridgeStorageManager {
184190
* @return false an error occurred
185191
*/
186192
bool MigrateDataOldScheme(uint8_t bridgedDeviceIndex);
193+
#endif
187194

195+
#ifdef CONFIG_BRIDGE_MIGRATE_VERSION_1
188196
/**
189197
* @brief Migrate bridged device data at given index.
190198
*
@@ -195,10 +203,12 @@ class BridgeStorageManager {
195203
* @return false an error occurred
196204
*/
197205
bool MigrateDataVersion1(uint8_t bridgedDeviceIndex);
206+
#endif
198207

199208
/* The below methods are deprecated and used only for the migration purposes between the older scheme versions.
200209
*/
201210

211+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
202212
/**
203213
* @brief Load bridged device endpoint id from settings
204214
*
@@ -278,6 +288,7 @@ class BridgeStorageManager {
278288
* @return false an error occurred
279289
*/
280290
bool RemoveBtAddress(uint8_t bridgedDeviceIndex);
291+
#endif
281292
#endif
282293

283294
Nrf::PersistentStorageNode mBridge;
@@ -286,6 +297,7 @@ class BridgeStorageManager {
286297
Nrf::PersistentStorageNode mBridgedDevice;
287298
Nrf::PersistentStorageNode mVersion;
288299

300+
#ifdef CONFIG_BRIDGE_MIGRATE_PRE_2_7_0
289301
/* The below fields are deprecated and used only for the migration purposes between the older scheme versions.
290302
*/
291303
Nrf::PersistentStorageNode mBridgedDeviceEndpointId;
@@ -295,6 +307,7 @@ class BridgeStorageManager {
295307
Nrf::PersistentStorageNode mBt;
296308
Nrf::PersistentStorageNode mBtAddress;
297309
#endif
310+
#endif
298311
};
299312

300313
} /* namespace Nrf */

0 commit comments

Comments
 (0)