From 903e149bd636a5cd1a8821864cb073b4f7a9d3d8 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 22 Jul 2021 16:51:47 -0400 Subject: [PATCH] [hotfix] Fix regression / crash caused by #7873 (#8054) (#8580) * [python] Add static_assert to CommandStatus * Change EndpointId to uint16 in Python delegate * Fix findIndexFromEndpoint * Add more static_asserts * Update src/controller/python/chip/interaction_model/Delegate.h Co-authored-by: Boris Zbarsky Co-authored-by: Boris Zbarsky Co-authored-by: Song Guo --- src/app/util/attribute-storage.cpp | 4 ++-- src/controller/python/chip/interaction_model/Delegate.h | 2 ++ src/controller/python/chip/interaction_model/delegate.py | 8 +++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/app/util/attribute-storage.cpp b/src/app/util/attribute-storage.cpp index 0220a977f84e2f..c3a24f1f448aee 100644 --- a/src/app/util/attribute-storage.cpp +++ b/src/app/util/attribute-storage.cpp @@ -883,7 +883,7 @@ static uint16_t findClusterEndpointIndex(EndpointId endpoint, ClusterId clusterI if (emberAfFindClusterWithMfgCode(endpoint, clusterId, mask, manufacturerCode) == NULL) { - return 0xFF; + return 0xFFFF; } for (i = 0; i < emberAfEndpointCount(); i++) @@ -913,7 +913,7 @@ static uint16_t findIndexFromEndpoint(EndpointId endpoint, bool ignoreDisabledEn return epi; } } - return 0xFF; + return 0xFFFF; } bool emberAfEndpointIsEnabled(EndpointId endpoint) diff --git a/src/controller/python/chip/interaction_model/Delegate.h b/src/controller/python/chip/interaction_model/Delegate.h index 2b0901efc8ac93..52f2167cdd5ea7 100644 --- a/src/controller/python/chip/interaction_model/Delegate.h +++ b/src/controller/python/chip/interaction_model/Delegate.h @@ -17,6 +17,8 @@ #pragma once +#include + #include #include diff --git a/src/controller/python/chip/interaction_model/delegate.py b/src/controller/python/chip/interaction_model/delegate.py index a65dd82b5bc0a1..e66f8c53065002 100644 --- a/src/controller/python/chip/interaction_model/delegate.py +++ b/src/controller/python/chip/interaction_model/delegate.py @@ -24,12 +24,14 @@ import typing from dataclasses import dataclass +# The type should match CommandStatus in interaction_model/Delegate.h +# CommandStatus should not contain padding IMCommandStatus = Struct( "ProtocolId" / Int32ul, "ProtocolCode" / Int16ul, - "EndpointId" / Int8ul, - "ClusterId" / Int16ul, - "CommandId" / Int8ul, + "EndpointId" / Int16ul, + "ClusterId" / Int32ul, + "CommandId" / Int32ul, "CommandIndex" / Int8ul, )