From 7a70145b52ad92f096a54375532075c9ab185a93 Mon Sep 17 00:00:00 2001 From: eve-cxrp <80681009+eve-cxrp@users.noreply.github.com> Date: Tue, 9 Nov 2021 02:31:29 +0100 Subject: [PATCH] Bugfix termostat user interface value validation (#11058) * add support for boundry checks for thermostat-user-interface-configuration * add impl for boundry checks for thermostat-user-interface-configuration in all-clsuter-app * add check for size and remove static cast to unit8 * add support for ProAttribute hook for thermostat user interface configuration * remove preattribute hooks in all-cluster-app/linux * regen all * fix esp32 and mbed builds --- .../esp32/main/CMakeLists.txt | 3 +- examples/all-clusters-app/linux/main.cpp | 5 ++ examples/all-clusters-app/mbed/CMakeLists.txt | 1 + ...at-user-interface-configuration-server.cpp | 60 +++++++++++++++++++ src/app/zap-templates/templates/app/helper.js | 2 +- src/app/zap_cluster_list.py | 2 +- .../zap-generated/endpoint_config.h | 10 +++- 7 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp diff --git a/examples/all-clusters-app/esp32/main/CMakeLists.txt b/examples/all-clusters-app/esp32/main/CMakeLists.txt index d342e16e5beff0..0ac61d7f8bb0da 100644 --- a/examples/all-clusters-app/esp32/main/CMakeLists.txt +++ b/examples/all-clusters-app/esp32/main/CMakeLists.txt @@ -55,7 +55,8 @@ set(SRC_DIRS_LIST "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/media-playback-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-provider" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/target-navigator-server" - "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thermostat-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thermostat-server" + "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thermostat-user-interface-configuration-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/thread_network_diagnostics_server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/tv-channel-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/scenes" diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp index 4c3048e3225a71..8dba2d615719e7 100644 --- a/examples/all-clusters-app/linux/main.cpp +++ b/examples/all-clusters-app/linux/main.cpp @@ -16,12 +16,17 @@ * limitations under the License. */ +#include +#include #include +#include #include #include #include "AppMain.h" +using namespace chip; + bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::Command * commandObj) { emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS); diff --git a/examples/all-clusters-app/mbed/CMakeLists.txt b/examples/all-clusters-app/mbed/CMakeLists.txt index a05bf5cca47a4a..aac0a8268e44e5 100644 --- a/examples/all-clusters-app/mbed/CMakeLists.txt +++ b/examples/all-clusters-app/mbed/CMakeLists.txt @@ -120,6 +120,7 @@ target_sources(${APP_TARGET} PRIVATE ${APP_CLUSTERS}/scenes/scenes.cpp ${APP_CLUSTERS}/target-navigator-server/target-navigator-server.cpp ${APP_CLUSTERS}/thermostat-server/thermostat-server.cpp + ${APP_CLUSTERS}/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp ${APP_CLUSTERS}/tv-channel-server/tv-channel-server.cpp ${APP_CLUSTERS}/operational-credentials-server/operational-credentials-server.cpp ${APP_CLUSTERS}/test-cluster-server/test-cluster-server.cpp diff --git a/src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp b/src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp new file mode 100644 index 00000000000000..5759a1fe65c4e9 --- /dev/null +++ b/src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp @@ -0,0 +1,60 @@ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace chip; +using namespace chip::app; +using namespace chip::app::Clusters; + +Protocols::InteractionModel::Status MatterThermostatUserInterfaceConfigurationClusterServerPreAttributeChangedCallback( + const app::ConcreteAttributePath & attributePath, EmberAfAttributeType attributeType, uint16_t size, uint8_t * value) +{ + if (size != 0) + { + if (ThermostatUserInterfaceConfiguration::Attributes::TemperatureDisplayMode::Id == attributePath.mAttributeId) + { + EmberAfTemperatureDisplayMode mode = static_cast(chip::Encoding::Get8(value)); + if ((EMBER_ZCL_TEMPERATURE_DISPLAY_MODE_CELSIUS != mode) && (EMBER_ZCL_TEMPERATURE_DISPLAY_MODE_FAHRENHEIT != mode)) + { + return Protocols::InteractionModel::Status::Failure; + } + } + else if (ThermostatUserInterfaceConfiguration::Attributes::KeypadLockout::Id == attributePath.mAttributeId) + { + EmberAfKeypadLockout lockout = static_cast(chip::Encoding::Get8(value)); + if ((EMBER_ZCL_KEYPAD_LOCKOUT_NO_LOCKOUT != lockout) && (EMBER_ZCL_KEYPAD_LOCKOUT_LEVEL_ONE_LOCKOUT != lockout) && + (EMBER_ZCL_KEYPAD_LOCKOUT_LEVEL_TWO_LOCKOUT != lockout) && + (EMBER_ZCL_KEYPAD_LOCKOUT_LEVEL_THREE_LOCKOUT != lockout) && + (EMBER_ZCL_KEYPAD_LOCKOUT_LEVEL_FOUR_LOCKOUT != lockout) && (EMBER_ZCL_KEYPAD_LOCKOUT_LEVELFIVE_LOCKOUT != lockout)) + { + return Protocols::InteractionModel::Status::Failure; + } + } + else if (ThermostatUserInterfaceConfiguration::Attributes::ScheduleProgrammingVisibility::Id == attributePath.mAttributeId) + { + uint8_t prog = chip::Encoding::Get8(value); + if (prog > 1) + { + return Protocols::InteractionModel::Status::Failure; + } + } + } + + return Protocols::InteractionModel::Status::Success; +} diff --git a/src/app/zap-templates/templates/app/helper.js b/src/app/zap-templates/templates/app/helper.js index 4577cdf81406ec..a741b46ed6c434 100644 --- a/src/app/zap-templates/templates/app/helper.js +++ b/src/app/zap-templates/templates/app/helper.js @@ -106,7 +106,7 @@ var endpointClusterWithInit = [ 'Pump Configuration and Control', ]; var endpointClusterWithAttributeChanged = [ 'Identify', 'Door Lock', 'Pump Configuration and Control' ]; -var endpointClusterWithPreAttribute = [ 'IAS Zone' ]; +var endpointClusterWithPreAttribute = [ 'IAS Zone', 'Thermostat User Interface Configuration' ]; var endpointClusterWithMessageSent = [ 'IAS Zone' ]; /** diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 1bbbc01244077c..ff0d53a307a099 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -69,7 +69,7 @@ 'THERMOSTAT_CLUSTER': ['thermostat-server'], 'THREAD_NETWORK_DIAGNOSTICS_CLUSTER': ['thread_network_diagnostics_server'], 'WINDOW_COVERING_CLUSTER': ['window-covering-server'], - 'THERMOSTAT_UI_CONFIG_CLUSTER': [], + 'THERMOSTAT_UI_CONFIG_CLUSTER': ['thermostat-user-interface-configuration-server'], 'WIFI_NETWORK_DIAGNOSTICS_CLUSTER': ['wifi_network_diagnostics_server'], 'WAKE_ON_LAN_CLUSTER': [], 'ZLL_COMMISSIONING_CLUSTER': [] diff --git a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h index fff1319ed8f4fd..ecb85791eb497f 100644 --- a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h +++ b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h @@ -2566,6 +2566,9 @@ (EmberAfGenericClusterFunction) emberAfPumpConfigurationAndControlClusterServerInitCallback, \ (EmberAfGenericClusterFunction) MatterPumpConfigurationAndControlClusterServerAttributeChangedCallback, \ }; \ + const EmberAfGenericClusterFunction chipFuncArrayThermostatUserInterfaceConfigurationServer[] = { \ + (EmberAfGenericClusterFunction) MatterThermostatUserInterfaceConfigurationClusterServerPreAttributeChangedCallback, \ + }; \ const EmberAfGenericClusterFunction chipFuncArrayColorControlServer[] = { \ (EmberAfGenericClusterFunction) emberAfColorControlClusterServerInitCallback, \ }; \ @@ -2726,7 +2729,12 @@ 0x0201, ZAP_ATTRIBUTE_INDEX(292), 19, 34, ZAP_CLUSTER_MASK(SERVER), NULL \ }, /* Endpoint: 1, Cluster: Thermostat (server) */ \ { \ - 0x0204, ZAP_ATTRIBUTE_INDEX(311), 4, 5, ZAP_CLUSTER_MASK(SERVER), NULL \ + 0x0204, \ + ZAP_ATTRIBUTE_INDEX(311), \ + 4, \ + 5, \ + ZAP_CLUSTER_MASK(SERVER) | ZAP_CLUSTER_MASK(PRE_ATTRIBUTE_CHANGED_FUNCTION), \ + chipFuncArrayThermostatUserInterfaceConfigurationServer \ }, /* Endpoint: 1, Cluster: Thermostat User Interface Configuration (server) */ \ { 0x0300, \ ZAP_ATTRIBUTE_INDEX(315), \