From c6ca0997559c64e93f6b0c75c20e9ccf9ac9290b Mon Sep 17 00:00:00 2001 From: Dimitri Mizenko Date: Wed, 27 Oct 2021 17:37:38 +0200 Subject: [PATCH 1/3] add support for boundry checks for thermostat-user-interface-configuration --- ...at-user-interface-configuration-server.cpp | 55 +++++++++++++++++++ src/app/zap_cluster_list.py | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-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..152791b52b5833 --- /dev/null +++ b/src/app/clusters/thermostat-user-interface-configuration-server/thermostat-user-interface-configuration-server.cpp @@ -0,0 +1,55 @@ +#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 (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 = static_cast(chip::Encoding::Get8(value)); + if (prog > 1) + { + return Protocols::InteractionModel::Status::Failure; + } + } + return Protocols::InteractionModel::Status::Success; +} \ No newline at end of file diff --git a/src/app/zap_cluster_list.py b/src/app/zap_cluster_list.py index 1539aeb7a9c6b9..1c801664ecf51b 100755 --- a/src/app/zap_cluster_list.py +++ b/src/app/zap_cluster_list.py @@ -67,7 +67,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': [] From 30fc7fe92755f7eee0d45e12fd3f5a9f65c97fca Mon Sep 17 00:00:00 2001 From: Dimitri Mizenko Date: Wed, 27 Oct 2021 17:38:15 +0200 Subject: [PATCH 2/3] add impl for boundry checks for thermostat-user-interface-configuration in all-clsuter-app --- examples/all-clusters-app/linux/main.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/examples/all-clusters-app/linux/main.cpp b/examples/all-clusters-app/linux/main.cpp index d2a4cf2a27dd95..70b2a2ee94df61 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); @@ -42,6 +47,22 @@ Identify gIdentify1 = { EMBER_ZCL_IDENTIFY_IDENTIFY_TYPE_VISIBLE_LED, }; +Protocols::InteractionModel::Status MatterPreAttributeChangeCallback(const app::ConcreteAttributePath & attributePath, uint8_t mask, + uint8_t type, uint16_t size, uint8_t * value) +{ + Protocols::InteractionModel::Status status = Protocols::InteractionModel::Status::Success; + if (attributePath.mClusterId == app::Clusters::Thermostat::Id) + { + status = MatterThermostatClusterServerPreAttributeChangedCallback(attributePath, type, size, value); + } + else if (attributePath.mClusterId == app::Clusters::ThermostatUserInterfaceConfiguration::Id) + { + status = + MatterThermostatUserInterfaceConfigurationClusterServerPreAttributeChangedCallback(attributePath, type, size, value); + } + return status; +} + int main(int argc, char * argv[]) { VerifyOrDie(ChipLinuxAppInit(argc, argv) == 0); From 94ac716119ce3277ae9dcfe9f2d770776fee6f20 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Wed, 27 Oct 2021 15:39:49 +0000 Subject: [PATCH 3/3] Restyled by whitespace --- .../thermostat-user-interface-configuration-server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 152791b52b5833..0aa2079aa3f266 100644 --- 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 @@ -52,4 +52,4 @@ Protocols::InteractionModel::Status MatterThermostatUserInterfaceConfigurationCl } } return Protocols::InteractionModel::Status::Success; -} \ No newline at end of file +}