Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matter support for fabric_filtered request (for Google compatibility) #19249

Merged
merged 1 commit into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Support for multiple PCA9685 with extended functionality (#18805)
- Zigbee decode Aqara 0000/FF01 attribute 03 as Temperature
- Berry bytes `get` and `set` work for 3 bytes values
- Matter support for fabric_filtered request (for Google compatibility)

### Breaking Changed

Expand Down
10 changes: 7 additions & 3 deletions lib/libesp32/berry_matter/src/embedded/Matter_Commissioning.be
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,22 @@ class Matter_Commisioning_Context
import crypto
# Validate Sigma1 Destination ID, p.162
# traverse all existing fabrics
tasmota.log("MTR: SEARCHING: destinationId=" + destinationId.tohex(), 4)
if tasmota.loglevel(4)
tasmota.log("MTR: SEARCHING: destinationId=" + destinationId.tohex(), 4)
end
for fabric : self.device.sessions.fabrics
if fabric.noc == nil || fabric.fabric_id == nil || fabric.device_id == nil continue end
# compute candidateDestinationId, Section 4.13.2.4.1, “Destination Identifier”
var destinationMessage = initiatorRandom + fabric.get_ca_pub() + fabric.fabric_id + fabric.device_id
var key = fabric.get_ipk_group_key()
tasmota.log("MTR: SIGMA1: destinationMessage=" + destinationMessage.tohex(), 4)
# tasmota.log("MTR: SIGMA1: destinationMessage=" + destinationMessage.tohex(), 4)
# tasmota.log("MTR: SIGMA1: key_ipk=" + key.tohex(), 4)
var h = crypto.HMAC_SHA256(key)
h.update(destinationMessage)
var candidateDestinationId = h.out()
tasmota.log("MTR: SIGMA1: candidateDestinationId=" + candidateDestinationId.tohex(), 4)
if tasmota.loglevel(4)
tasmota.log("MTR: SIGMA1: candidateDestinationId=" + candidateDestinationId.tohex(), 4)
end
if candidateDestinationId == destinationId
return fabric
end
Expand Down
2 changes: 1 addition & 1 deletion lib/libesp32/berry_matter/src/embedded/Matter_Device.be
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ class Matter_Device
var fabric = session.get_fabric()
var fabric_id = fabric.get_fabric_id().copy().reverse().tohex()
var vendor_name = fabric.get_admin_vendor_name()
tasmota.log(format("MTR: --- Commissioning complete for Fabric '%s' (Vendor %s) ---", fabric_id, vendor_name), 2)
tasmota.log(f"MTR: --- Commissioning complete for Fabric '{fabric_id}' (Vendor {vendor_name}) ---", 2)
self.stop_basic_commissioning() # by default close commissioning when it's complete
end

Expand Down
8 changes: 6 additions & 2 deletions lib/libesp32/berry_matter/src/embedded/Matter_IM.be
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class Matter_IM
ctx.endpoint = q.endpoint
ctx.cluster = q.cluster
ctx.attribute = q.attribute
ctx.fabric_filtered = query.fabric_filtered
ctx.status = matter.UNSUPPORTED_ATTRIBUTE #default error if returned `nil`

# expand endpoint
Expand Down Expand Up @@ -772,8 +773,11 @@ class Matter_IM
ctx.attribute = q.attribute
attr_req.push(str(ctx))
end
tasmota.log(format("MTR: >Subscribe (%6i) %s (min=%i, max=%i, keep=%i) sub=%i",
msg.session.local_session_id, attr_req.concat(" "), sub.min_interval, sub.max_interval, query.keep_subscriptions ? 1 : 0, sub.subscription_id), 3)
tasmota.log(format("MTR: >Subscribe (%6i) %s (min=%i, max=%i, keep=%i) sub=%i fabric_filtered=%s",
msg.session.local_session_id, attr_req.concat(" "), sub.min_interval, sub.max_interval, query.keep_subscriptions ? 1 : 0, sub.subscription_id, query.fabric_filtered), 3)
if query.event_requests != nil && size(query.event_requests) > 0
tasmota.log(f"MTR: >Subscribe (%6i) event_requests_size={size(query.event_requests)}", 3)
end

var ret = self._inner_process_read_request(msg.session, query, true #-no_log-#)
# ret is of type `Matter_ReportDataMessage`
Expand Down
1 change: 1 addition & 0 deletions lib/libesp32/berry_matter/src/embedded/Matter_Path.be
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class Matter_Path
s += (self.cluster != nil ? format("%04X/", self.cluster) : "****/")
s += (self.attribute != nil ? format("%04X", self.attribute) : "")
s += (self.command != nil ? format("%04X", self.command) : "")
if self.fabric_filtered s += "!" end
if self.attribute == nil && self.command == nil s += "****" end
return s
except .. as e, m
Expand Down
8 changes: 6 additions & 2 deletions lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Root.be
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ class Matter_Plugin_Root : Matter_Plugin

if attribute == 0x0000 # ---------- NOCs / list[NOCStruct] ----------
var nocl = TLV.Matter_TLV_array() # NOCs, p.711
for loc_fabric: self.device.sessions.active_fabrics()
var fabs = ctx.fabric_filtered ? [session.get_fabric()] : self.device.sessions.active_fabrics()
for loc_fabric: fabs
if loc_fabric == nil continue end
var nocs = nocl.add_struct(nil)
nocs.add_TLV(1, TLV.B2, loc_fabric.get_noc()) # NOC
nocs.add_TLV(2, TLV.B2, loc_fabric.get_icac()) # ICAC
Expand All @@ -164,7 +166,9 @@ class Matter_Plugin_Root : Matter_Plugin
return nocl
elif attribute == 0x0001 # ---------- Fabrics / list[FabricDescriptorStruct] ----------
var fabrics = TLV.Matter_TLV_array() # Fabrics, p.711
for loc_fabric: self.device.sessions.active_fabrics()
var fabs = ctx.fabric_filtered ? [session.get_fabric()] : self.device.sessions.active_fabrics()
for loc_fabric: fabs
if loc_fabric == nil continue end
var root_ca_tlv = TLV.parse(loc_fabric.get_ca())
var fab = fabrics.add_struct(nil) # encoding see p.303
fab.add_TLV(1, TLV.B2, root_ca_tlv.findsubval(9)) # RootPublicKey
Expand Down
3 changes: 2 additions & 1 deletion lib/libesp32/berry_matter/src/embedded/Matter_Session.be
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ class Matter_Session : Matter_Expirable
def get_icac() return self._fabric.icac end
def get_ipk_epoch_key() return self._fabric.ipk_epoch_key end
def get_fabric_id() return self._fabric.fabric_id end
def get_device_id() return self._fabric.device_id end
def get_fabric_index() return self._fabric ? self._fabric.fabric_index : nil end
def get_device_id() return self._fabric ? self._fabric.device_id : nil end
def get_fabric_compressed() return self._fabric.fabric_compressed end
def get_fabric_label() return self._fabric.fabric_label end
def get_admin_subject() return self._fabric.admin_subject end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ be_local_closure(Matter_Commisioning_Context_find_fabric_by_destination_id, /*
( &(const bvalue[19]) { /* constants */
/* K0 */ be_nested_str_weak(crypto),
/* K1 */ be_nested_str_weak(tasmota),
/* K2 */ be_nested_str_weak(log),
/* K3 */ be_nested_str_weak(MTR_X3A_X20SEARCHING_X3A_X20destinationId_X3D),
/* K4 */ be_nested_str_weak(tohex),
/* K5 */ be_nested_str_weak(device),
/* K6 */ be_nested_str_weak(sessions),
/* K7 */ be_nested_str_weak(fabrics),
/* K8 */ be_nested_str_weak(noc),
/* K9 */ be_nested_str_weak(fabric_id),
/* K10 */ be_nested_str_weak(device_id),
/* K11 */ be_nested_str_weak(get_ca_pub),
/* K12 */ be_nested_str_weak(get_ipk_group_key),
/* K13 */ be_nested_str_weak(MTR_X3A_X20SIGMA1_X3A_X20destinationMessage_X3D),
/* K2 */ be_nested_str_weak(loglevel),
/* K3 */ be_nested_str_weak(log),
/* K4 */ be_nested_str_weak(MTR_X3A_X20SEARCHING_X3A_X20destinationId_X3D),
/* K5 */ be_nested_str_weak(tohex),
/* K6 */ be_nested_str_weak(device),
/* K7 */ be_nested_str_weak(sessions),
/* K8 */ be_nested_str_weak(fabrics),
/* K9 */ be_nested_str_weak(noc),
/* K10 */ be_nested_str_weak(fabric_id),
/* K11 */ be_nested_str_weak(device_id),
/* K12 */ be_nested_str_weak(get_ca_pub),
/* K13 */ be_nested_str_weak(get_ipk_group_key),
/* K14 */ be_nested_str_weak(HMAC_SHA256),
/* K15 */ be_nested_str_weak(update),
/* K16 */ be_nested_str_weak(out),
Expand All @@ -89,77 +89,80 @@ be_local_closure(Matter_Commisioning_Context_find_fabric_by_destination_id, /*
}),
be_str_weak(find_fabric_by_destination_id),
&be_const_str_solidified,
( &(const binstruction[70]) { /* code */
( &(const binstruction[73]) { /* code */
0xA40E0000, // 0000 IMPORT R3 K0
0xB8120200, // 0001 GETNGBL R4 K1
0x8C100902, // 0002 GETMET R4 R4 K2
0x8C180304, // 0003 GETMET R6 R1 K4
0x7C180200, // 0004 CALL R6 1
0x001A0606, // 0005 ADD R6 K3 R6
0x541E0003, // 0006 LDINT R7 4
0x7C100600, // 0007 CALL R4 3
0x60100010, // 0008 GETGBL R4 G16
0x88140105, // 0009 GETMBR R5 R0 K5
0x88140B06, // 000A GETMBR R5 R5 K6
0x88140B07, // 000B GETMBR R5 R5 K7
0x7C100200, // 000C CALL R4 1
0xA8020032, // 000D EXBLK 0 #0041
0x5C140800, // 000E MOVE R5 R4
0x7C140000, // 000F CALL R5 0
0x88180B08, // 0010 GETMBR R6 R5 K8
0x4C1C0000, // 0011 LDNIL R7
0x1C180C07, // 0012 EQ R6 R6 R7
0x741A0007, // 0013 JMPT R6 #001C
0x88180B09, // 0014 GETMBR R6 R5 K9
0x4C1C0000, // 0015 LDNIL R7
0x1C180C07, // 0016 EQ R6 R6 R7
0x741A0003, // 0017 JMPT R6 #001C
0x88180B0A, // 0018 GETMBR R6 R5 K10
0x4C1C0000, // 0019 LDNIL R7
0x1C180C07, // 001A EQ R6 R6 R7
0x781A0000, // 001B JMPF R6 #001D
0x7001FFF0, // 001C JMP #000E
0x8C180B0B, // 001D GETMET R6 R5 K11
0x7C180200, // 001E CALL R6 1
0x00180406, // 001F ADD R6 R2 R6
0x881C0B09, // 0020 GETMBR R7 R5 K9
0x00180C07, // 0021 ADD R6 R6 R7
0x881C0B0A, // 0022 GETMBR R7 R5 K10
0x00180C07, // 0023 ADD R6 R6 R7
0x8C1C0B0C, // 0024 GETMET R7 R5 K12
0x7C1C0200, // 0025 CALL R7 1
0xB8220200, // 0026 GETNGBL R8 K1
0x8C201102, // 0027 GETMET R8 R8 K2
0x8C280D04, // 0028 GETMET R10 R6 K4
0x7C280200, // 0029 CALL R10 1
0x002A1A0A, // 002A ADD R10 K13 R10
0x542E0003, // 002B LDINT R11 4
0x7C200600, // 002C CALL R8 3
0x8C20070E, // 002D GETMET R8 R3 K14
0x5C280E00, // 002E MOVE R10 R7
0x7C200400, // 002F CALL R8 2
0x8C24110F, // 0030 GETMET R9 R8 K15
0x5C2C0C00, // 0031 MOVE R11 R6
0x7C240400, // 0032 CALL R9 2
0x8C241110, // 0033 GETMET R9 R8 K16
0x7C240200, // 0034 CALL R9 1
0xB82A0200, // 0035 GETNGBL R10 K1
0x8C281502, // 0036 GETMET R10 R10 K2
0x8C301304, // 0037 GETMET R12 R9 K4
0x7C300200, // 0038 CALL R12 1
0x0032220C, // 0039 ADD R12 K17 R12
0x54360003, // 003A LDINT R13 4
0x7C280600, // 003B CALL R10 3
0x1C281201, // 003C EQ R10 R9 R1
0x782A0001, // 003D JMPF R10 #0040
0xA8040001, // 003E EXBLK 1 1
0x80040A00, // 003F RET 1 R5
0x7001FFCC, // 0040 JMP #000E
0x58100012, // 0041 LDCONST R4 K18
0xAC100200, // 0042 CATCH R4 1 0
0xB0080000, // 0043 RAISE 2 R0 R0
0x4C100000, // 0044 LDNIL R4
0x80040800, // 0045 RET 1 R4
0x541A0003, // 0003 LDINT R6 4
0x7C100400, // 0004 CALL R4 2
0x78120006, // 0005 JMPF R4 #000D
0xB8120200, // 0006 GETNGBL R4 K1
0x8C100903, // 0007 GETMET R4 R4 K3
0x8C180305, // 0008 GETMET R6 R1 K5
0x7C180200, // 0009 CALL R6 1
0x001A0806, // 000A ADD R6 K4 R6
0x541E0003, // 000B LDINT R7 4
0x7C100600, // 000C CALL R4 3
0x60100010, // 000D GETGBL R4 G16
0x88140106, // 000E GETMBR R5 R0 K6
0x88140B07, // 000F GETMBR R5 R5 K7
0x88140B08, // 0010 GETMBR R5 R5 K8
0x7C100200, // 0011 CALL R4 1
0xA8020030, // 0012 EXBLK 0 #0044
0x5C140800, // 0013 MOVE R5 R4
0x7C140000, // 0014 CALL R5 0
0x88180B09, // 0015 GETMBR R6 R5 K9
0x4C1C0000, // 0016 LDNIL R7
0x1C180C07, // 0017 EQ R6 R6 R7
0x741A0007, // 0018 JMPT R6 #0021
0x88180B0A, // 0019 GETMBR R6 R5 K10
0x4C1C0000, // 001A LDNIL R7
0x1C180C07, // 001B EQ R6 R6 R7
0x741A0003, // 001C JMPT R6 #0021
0x88180B0B, // 001D GETMBR R6 R5 K11
0x4C1C0000, // 001E LDNIL R7
0x1C180C07, // 001F EQ R6 R6 R7
0x781A0000, // 0020 JMPF R6 #0022
0x7001FFF0, // 0021 JMP #0013
0x8C180B0C, // 0022 GETMET R6 R5 K12
0x7C180200, // 0023 CALL R6 1
0x00180406, // 0024 ADD R6 R2 R6
0x881C0B0A, // 0025 GETMBR R7 R5 K10
0x00180C07, // 0026 ADD R6 R6 R7
0x881C0B0B, // 0027 GETMBR R7 R5 K11
0x00180C07, // 0028 ADD R6 R6 R7
0x8C1C0B0D, // 0029 GETMET R7 R5 K13
0x7C1C0200, // 002A CALL R7 1
0x8C20070E, // 002B GETMET R8 R3 K14
0x5C280E00, // 002C MOVE R10 R7
0x7C200400, // 002D CALL R8 2
0x8C24110F, // 002E GETMET R9 R8 K15
0x5C2C0C00, // 002F MOVE R11 R6
0x7C240400, // 0030 CALL R9 2
0x8C241110, // 0031 GETMET R9 R8 K16
0x7C240200, // 0032 CALL R9 1
0xB82A0200, // 0033 GETNGBL R10 K1
0x8C281502, // 0034 GETMET R10 R10 K2
0x54320003, // 0035 LDINT R12 4
0x7C280400, // 0036 CALL R10 2
0x782A0006, // 0037 JMPF R10 #003F
0xB82A0200, // 0038 GETNGBL R10 K1
0x8C281503, // 0039 GETMET R10 R10 K3
0x8C301305, // 003A GETMET R12 R9 K5
0x7C300200, // 003B CALL R12 1
0x0032220C, // 003C ADD R12 K17 R12
0x54360003, // 003D LDINT R13 4
0x7C280600, // 003E CALL R10 3
0x1C281201, // 003F EQ R10 R9 R1
0x782A0001, // 0040 JMPF R10 #0043
0xA8040001, // 0041 EXBLK 1 1
0x80040A00, // 0042 RET 1 R5
0x7001FFCE, // 0043 JMP #0013
0x58100012, // 0044 LDCONST R4 K18
0xAC100200, // 0045 CATCH R4 1 0
0xB0080000, // 0046 RAISE 2 R0 R0
0x4C100000, // 0047 LDNIL R4
0x80040800, // 0048 RET 1 R4
})
)
);
Expand Down
Loading