Skip to content

Commit 7a70979

Browse files
lbouedrewmccalclaude
committed
Matter: add UniqueID attribute to BridgedDeviceBasicInformation cluster
UniqueID became a mandatory attribute in Matter 1.4 for the BridgedDeviceBasicInformation cluster. Its absence causes controllers such as Home Assistant to fail to create entities for bridged endpoints — the controller cannot stably identify a bridged device across re-pairings or bridge restarts, so it refuses to add it. Populate unique_id from SYSTEM_GetUnique() at construction time using the format "silabs-%016llx", giving each bridged endpoint a stable hardware-derived identity. Expose SetUniqueID()/GetUniqueID() so sketches can override the value. Co-Authored-By: Drew McCalmont <drewm@mcfamily.us> Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3e9897b commit 7a70979

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

libraries/Matter/src/Matter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::NodeLabel::
5454
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::VendorName::Id, CHAR_STRING, Device::DeviceDescStrSize, 0), /* VendorName */
5555
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::ProductName::Id, CHAR_STRING, Device::DeviceDescStrSize, 0), /* ProductName */
5656
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::SerialNumber::Id, CHAR_STRING, Device::DeviceDescStrSize, 0), /* SerialNumber */
57+
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::UniqueID::Id, CHAR_STRING, Device::DeviceDescStrSize, 0), /* UniqueID */
5758
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::Reachable::Id, BOOLEAN, 1, 0), /* Reachable */
5859
DECLARE_DYNAMIC_ATTRIBUTE(BridgedDeviceBasicInformation::Attributes::FeatureMap::Id, BITMAP32, 4, 0), /* FeatureMap */
5960
DECLARE_DYNAMIC_ATTRIBUTE_LIST_END(); /* ClusterRevision auto added by LIST_END */

libraries/Matter/src/Matter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

4545
using ::chip::CommandId;
4646

47-
extern EmberAfAttributeMetadata bridgedDeviceBasicAttrs[7];
47+
extern EmberAfAttributeMetadata bridgedDeviceBasicAttrs[8];
4848
extern EmberAfAttributeMetadata descriptorAttrs[6];
4949
extern EmberAfAttributeMetadata identifyAttrs[4];
5050
extern CommandId identifyIncomingCommands[2];

libraries/Matter/src/devices/MatterDevice.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "MatterDevice.h"
2323

2424
#include <cstdio>
25+
#include "em_system.h"
2526
#include <platform/CHIPDeviceLayer.h>
2627
#include <app-common/zap-generated/callback.h>
2728

@@ -45,6 +46,7 @@ Device::Device(const char* device_name) :
4546
chip::Platform::CopyString(this->vendor_name, "Silicon Labs");
4647
chip::Platform::CopyString(this->product_name, "Matter device");
4748
chip::Platform::CopyString(this->serial_number, "0000000042");
49+
snprintf(this->unique_id, sizeof(this->unique_id), "silabs-%016llx", (unsigned long long)SYSTEM_GetUnique());
4850
}
4951

5052
bool Device::IsReachable()
@@ -116,6 +118,16 @@ void Device::SetSerialNumber(const char* serialnumber)
116118
}
117119
}
118120

121+
void Device::SetUniqueID(const char* uniqueid)
122+
{
123+
bool changed = (strncmp(this->unique_id, uniqueid, sizeof(this->unique_id)) != 0);
124+
if (changed) {
125+
ChipLogProgress(DeviceLayer, "Device[%s]: New UniqueID=\"%s\"", this->device_name, uniqueid);
126+
chip::Platform::CopyString(this->unique_id, uniqueid);
127+
this->HandleDeviceStatusChanged(kChanged_UniqueID);
128+
}
129+
}
130+
119131
void Device::SetLocation(std::string location)
120132
{
121133
bool changed = (this->location.compare(location) != 0);
@@ -193,6 +205,9 @@ CHIP_ERROR Device::HandleReadBridgedDeviceBasicAttribute(ClusterId clusterId,
193205
} else if ((attributeId == SerialNumber::Id) && (maxReadLength == 32)) {
194206
MutableByteSpan zclNameSpan(buffer, maxReadLength);
195207
MakeZclCharString(zclNameSpan, this->GetSerialNumber());
208+
} else if ((attributeId == UniqueID::Id) && (maxReadLength == 32)) {
209+
MutableByteSpan zclNameSpan(buffer, maxReadLength);
210+
MakeZclCharString(zclNameSpan, this->GetUniqueID());
196211
} else if ((attributeId == ClusterRevision::Id) && (maxReadLength == 2)) {
197212
uint16_t rev = this->GetBridgedDeviceBasicInformationClusterRevision();
198213
memcpy(buffer, &rev, sizeof(rev));
@@ -225,6 +240,9 @@ void Device::HandleDeviceStatusChanged(Changed_t itemChangedMask)
225240
if (itemChangedMask & kChanged_SerialNumber) {
226241
ScheduleMatterReportingCallback(this->endpoint_id, BridgedDeviceBasicInformation::Id, BridgedDeviceBasicInformation::Attributes::SerialNumber::Id);
227242
}
243+
if (itemChangedMask & kChanged_UniqueID) {
244+
ScheduleMatterReportingCallback(this->endpoint_id, BridgedDeviceBasicInformation::Id, BridgedDeviceBasicInformation::Attributes::UniqueID::Id);
245+
}
228246
}
229247

230248
CHIP_ERROR Device::HandleReadIdentifyAttribute(ClusterId clusterId,

libraries/Matter/src/devices/MatterDevice.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ class Device
4848
kChanged_VendorName = 1u << 3,
4949
kChanged_ProductName = 1u << 4,
5050
kChanged_SerialNumber = 1u << 5,
51-
kChanged_Last = kChanged_SerialNumber,
51+
kChanged_UniqueID = 1u << 6,
52+
kChanged_Last = kChanged_UniqueID,
5253
} Changed;
5354

5455
enum device_type_t {
@@ -91,6 +92,7 @@ class Device
9192
void SetVendorName(const char* vendorname);
9293
void SetProductName(const char* productname);
9394
void SetSerialNumber(const char* serialnumber);
95+
void SetUniqueID(const char* uniqueid);
9496
void SetLocation(std::string location);
9597
void SetDeviceChangeCallback(void (*matter_device_change_cb)(void));
9698
void CallDeviceChangeCallback();
@@ -179,6 +181,11 @@ class Device
179181
return this->serial_number;
180182
}
181183

184+
inline char* GetUniqueID()
185+
{
186+
return this->unique_id;
187+
}
188+
182189
inline std::string GetLocation()
183190
{
184191
return this->location;
@@ -206,6 +213,7 @@ class Device
206213
char vendor_name[DeviceDescStrSize];
207214
char product_name[DeviceDescStrSize];
208215
char serial_number[DeviceDescStrSize];
216+
char unique_id[DeviceDescStrSize];
209217
std::string location;
210218
chip::EndpointId endpoint_id;
211219
chip::EndpointId parent_endpoint_id;

0 commit comments

Comments
 (0)