@@ -87,8 +87,10 @@ CHIP_ERROR StoreDevice(MatterBridgedDevice *device, BridgedDeviceDataProvider *p
8787
8888 bridgedDevice.mEndpointId = device->GetEndpointId ();
8989 bridgedDevice.mDeviceType = device->GetDeviceType ();
90+ bridgedDevice.mUniqueIDLength = strlen (device->GetUniqueID ());
91+ memcpy (bridgedDevice.mUniqueID , device->GetUniqueID (), bridgedDevice.mUniqueIDLength );
9092 bridgedDevice.mNodeLabelLength = strlen (device->GetNodeLabel ());
91- memcpy (bridgedDevice.mNodeLabel , device->GetNodeLabel (), strlen (device-> GetNodeLabel ()) );
93+ memcpy (bridgedDevice.mNodeLabel , device->GetNodeLabel (), bridgedDevice. mNodeLabelLength );
9294
9395 /* Fill BT address information as a part of implementation specific user data. */
9496 bridgedDevice.mUserDataSize = sizeof (addr);
@@ -122,8 +124,8 @@ CHIP_ERROR StoreDevice(MatterBridgedDevice *device, BridgedDeviceDataProvider *p
122124 return CHIP_NO_ERROR;
123125}
124126
125- CHIP_ERROR AddMatterDevices (MatterBridgedDevice::DeviceType deviceTypes[], uint8_t count, const char *nodeLabel ,
126- BridgedDeviceDataProvider *provider, uint8_t indexes[] = nullptr ,
127+ CHIP_ERROR AddMatterDevices (MatterBridgedDevice::DeviceType deviceTypes[], uint8_t count, const char *uniqueID ,
128+ const char *nodeLabel, BridgedDeviceDataProvider *provider, uint8_t indexes[] = nullptr ,
127129 uint16_t endpointIds[] = nullptr )
128130{
129131 VerifyOrReturnError (provider != nullptr , CHIP_ERROR_INVALID_ARGUMENT, LOG_ERR (" No valid data provider!" ));
@@ -144,7 +146,7 @@ CHIP_ERROR AddMatterDevices(MatterBridgedDevice::DeviceType deviceTypes[], uint8
144146 uint8_t addedDevicesCount = 0 ;
145147 for (; addedDevicesCount < count; addedDevicesCount++) {
146148 newBridgedDevices[addedDevicesCount] = BleBridgedDeviceFactory::GetBridgedDeviceFactory ().Create (
147- deviceTypes[addedDevicesCount], nodeLabel);
149+ deviceTypes[addedDevicesCount], uniqueID, nodeLabel);
148150
149151 if (!newBridgedDevices[addedDevicesCount]) {
150152 LOG_ERR (" Cannot allocate Matter device of given type" );
@@ -199,6 +201,7 @@ CHIP_ERROR AddMatterDevices(MatterBridgedDevice::DeviceType deviceTypes[], uint8
199201struct BluetoothConnectionContext {
200202 MatterBridgedDevice::DeviceType deviceTypes[BridgeManager::kMaxBridgedDevicesPerProvider ];
201203 uint8_t count;
204+ char uniqueID[MatterBridgedDevice::kUniqueIDSize ] = { 0 };
202205 char nodeLabel[MatterBridgedDevice::kNodeLabelSize ] = { 0 };
203206 BLEBridgedDeviceProvider *provider;
204207 bt_addr_le_t address;
@@ -223,7 +226,7 @@ CHIP_ERROR BluetoothDeviceConnected(bool success, void *context)
223226 chip::Optional<uint16_t > endpointIds[BridgeManager::kMaxBridgedDevicesPerProvider ];
224227 /* AddMatterDevices takes the ownership of the passed provider object and will
225228 delete it in case the BridgeManager fails to accept this object. */
226- CHIP_ERROR err = AddMatterDevices (ctx->deviceTypes , ctx->count , ctx->nodeLabel , ctx->provider );
229+ CHIP_ERROR err = AddMatterDevices (ctx->deviceTypes , ctx->count , ctx->uniqueID , ctx-> nodeLabel , ctx->provider );
227230 chip::Platform::Delete (ctx);
228231
229232 return err;
@@ -232,6 +235,14 @@ CHIP_ERROR BluetoothDeviceConnected(bool success, void *context)
232235
233236BleBridgedDeviceFactory::BridgedDeviceFactory &BleBridgedDeviceFactory::GetBridgedDeviceFactory ()
234237{
238+ auto checkUniqueID = [](const char *uniqueID) {
239+ /* If node uniqueID is provided it must fit the maximum defined length */
240+ if (!uniqueID || (uniqueID && (strlen (uniqueID) < Nrf::MatterBridgedDevice::kUniqueIDSize ))) {
241+ return true ;
242+ }
243+ return false ;
244+ };
245+
235246 auto checkLabel = [](const char *nodeLabel) {
236247 /* If node label is provided it must fit the maximum defined length */
237248 if (!nodeLabel || (nodeLabel && (strlen (nodeLabel) < MatterBridgedDevice::kNodeLabelSize ))) {
@@ -243,47 +254,52 @@ BleBridgedDeviceFactory::BridgedDeviceFactory &BleBridgedDeviceFactory::GetBridg
243254 static BridgedDeviceFactory sBridgedDeviceFactory {
244255#ifdef CONFIG_BRIDGE_HUMIDITY_SENSOR_BRIDGED_DEVICE
245256 { MatterBridgedDevice::DeviceType::HumiditySensor,
246- [checkLabel](const char *nodeLabel) -> MatterBridgedDevice * {
247- if (!checkLabel (nodeLabel)) {
257+ [checkUniqueID, checkLabel](const char *uniqueID,
258+ const char *nodeLabel) -> Nrf::MatterBridgedDevice * {
259+ if (!checkUniqueID (uniqueID) || !checkLabel (nodeLabel)) {
248260 return nullptr ;
249261 }
250- return chip::Platform::New<HumiditySensorDevice>(nodeLabel);
262+ return chip::Platform::New<HumiditySensorDevice>(uniqueID, nodeLabel);
251263 } },
252264#endif
253265#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_BRIDGED_DEVICE
254266 { MatterBridgedDevice::DeviceType::OnOffLight,
255- [checkLabel](const char *nodeLabel) -> MatterBridgedDevice * {
256- if (!checkLabel (nodeLabel)) {
267+ [checkUniqueID, checkLabel](const char *uniqueID,
268+ const char *nodeLabel) -> Nrf::MatterBridgedDevice * {
269+ if (!checkUniqueID (uniqueID) || !checkLabel (nodeLabel)) {
257270 return nullptr ;
258271 }
259- return chip::Platform::New<OnOffLightDevice>(nodeLabel);
272+ return chip::Platform::New<OnOffLightDevice>(uniqueID, nodeLabel);
260273 } },
261274#endif
262275#ifdef CONFIG_BRIDGE_TEMPERATURE_SENSOR_BRIDGED_DEVICE
263276 { MatterBridgedDevice::DeviceType::TemperatureSensor,
264- [checkLabel](const char *nodeLabel) -> MatterBridgedDevice * {
265- if (!checkLabel (nodeLabel)) {
277+ [checkUniqueID, checkLabel](const char *uniqueID,
278+ const char *nodeLabel) -> Nrf::MatterBridgedDevice * {
279+ if (!checkUniqueID (uniqueID) || !checkLabel (nodeLabel)) {
266280 return nullptr ;
267281 }
268- return chip::Platform::New<TemperatureSensorDevice>(nodeLabel);
282+ return chip::Platform::New<TemperatureSensorDevice>(uniqueID, nodeLabel);
269283 } },
270284#endif
271285#ifdef CONFIG_BRIDGE_GENERIC_SWITCH_BRIDGED_DEVICE
272286 { MatterBridgedDevice::DeviceType::GenericSwitch,
273- [checkLabel](const char *nodeLabel) -> MatterBridgedDevice * {
274- if (!checkLabel (nodeLabel)) {
287+ [checkUniqueID, checkLabel](const char *uniqueID,
288+ const char *nodeLabel) -> Nrf::MatterBridgedDevice * {
289+ if (!checkUniqueID (uniqueID) || !checkLabel (nodeLabel)) {
275290 return nullptr ;
276291 }
277- return chip::Platform::New<GenericSwitchDevice>(nodeLabel);
292+ return chip::Platform::New<GenericSwitchDevice>(uniqueID, nodeLabel);
278293 } },
279294#endif
280295#ifdef CONFIG_BRIDGE_ONOFF_LIGHT_SWITCH_BRIDGED_DEVICE
281296 { MatterBridgedDevice::DeviceType::OnOffLightSwitch,
282- [checkLabel](const char *nodeLabel) -> MatterBridgedDevice * {
283- if (!checkLabel (nodeLabel)) {
297+ [checkUniqueID, checkLabel](const char *uniqueID,
298+ const char *nodeLabel) -> Nrf::MatterBridgedDevice * {
299+ if (!checkUniqueID (uniqueID) || !checkLabel (nodeLabel)) {
284300 return nullptr ;
285301 }
286- return chip::Platform::New<OnOffLightSwitchDevice>(nodeLabel);
302+ return chip::Platform::New<OnOffLightSwitchDevice>(uniqueID, nodeLabel);
287303 } },
288304#endif
289305 };
@@ -311,8 +327,8 @@ BleBridgedDeviceFactory::BleDataProviderFactory &BleBridgedDeviceFactory::GetDat
311327 return sDeviceDataProvider ;
312328}
313329
314- CHIP_ERROR BleBridgedDeviceFactory::CreateDevice (int deviceType, bt_addr_le_t btAddress, const char *nodeLabel ,
315- uint8_t index, uint16_t endpointId)
330+ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice (int deviceType, bt_addr_le_t btAddress, const char *uniqueID ,
331+ const char *nodeLabel, uint8_t index, uint16_t endpointId)
316332{
317333 CHIP_ERROR err;
318334
@@ -322,8 +338,8 @@ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice(int deviceType, bt_addr_le_t bt
322338 */
323339 BLEBridgedDeviceProvider *provider = BLEConnectivityManager::Instance ().FindBLEProvider (btAddress);
324340 if (provider) {
325- return AddMatterDevices (reinterpret_cast <MatterBridgedDevice::DeviceType *>(&deviceType), 1 , nodeLabel ,
326- provider, &index, &endpointId);
341+ return AddMatterDevices (reinterpret_cast <MatterBridgedDevice::DeviceType *>(&deviceType), 1 , uniqueID ,
342+ nodeLabel, provider, &index, &endpointId);
327343 }
328344
329345 ServiceUuid providerType;
@@ -342,8 +358,8 @@ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice(int deviceType, bt_addr_le_t bt
342358 /* Confirm that the first connection was done and this will be only the device recovery. */
343359 provider->ConfirmInitialConnection ();
344360 provider->InitializeBridgedDevice (btAddress, nullptr , nullptr );
345- err = AddMatterDevices (reinterpret_cast <MatterBridgedDevice::DeviceType *>(&deviceType), 1 , nodeLabel, provider ,
346- &index, &endpointId);
361+ err = AddMatterDevices (reinterpret_cast <MatterBridgedDevice::DeviceType *>(&deviceType), 1 , uniqueID, nodeLabel ,
362+ provider, &index, &endpointId);
347363
348364 if (err != CHIP_NO_ERROR) {
349365 return err;
@@ -359,7 +375,8 @@ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice(int deviceType, bt_addr_le_t bt
359375 return err;
360376}
361377
362- CHIP_ERROR BleBridgedDeviceFactory::CreateDevice (uint16_t uuid, bt_addr_le_t btAddress, const char *nodeLabel,
378+ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice (uint16_t uuid, bt_addr_le_t btAddress, const char *uniqueID,
379+ const char *nodeLabel,
363380 BLEConnectivityManager::ConnectionSecurityRequest *request)
364381{
365382 /* Check if there is already existing provider for given address.
@@ -396,6 +413,10 @@ CHIP_ERROR BleBridgedDeviceFactory::CreateDevice(uint16_t uuid, bt_addr_le_t btA
396413 contextPtr->deviceTypes [i] = deviceTypes[i];
397414 }
398415
416+ if (uniqueID) {
417+ strcpy (contextPtr->uniqueID , uniqueID);
418+ }
419+
399420 if (nodeLabel) {
400421 strcpy (contextPtr->nodeLabel , nodeLabel);
401422 }
0 commit comments