Skip to content

Commit

Permalink
Bugfix termostat user interface value validation (#11058)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
eve-cxrp authored Nov 9, 2021
1 parent fde6a17 commit 9b24191
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 4 deletions.
3 changes: 2 additions & 1 deletion examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions examples/all-clusters-app/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@
* limitations under the License.
*/

#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/ids/Clusters.h>
#include <app/Command.h>
#include <app/ConcreteAttributePath.h>
#include <app/clusters/identify-server/identify-server.h>
#include <app/util/af.h>

#include "AppMain.h"

using namespace chip;

bool emberAfBasicClusterMfgSpecificPingCallback(chip::app::Command * commandObj)
{
emberAfSendDefaultResponse(emberAfCurrentCommand(), EMBER_ZCL_STATUS_SUCCESS);
Expand Down
1 change: 1 addition & 0 deletions examples/all-clusters-app/mbed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <app/util/af.h>

#include <app/util/af-event.h>
#include <app/util/attribute-storage.h>

#include <app-common/zap-generated/attribute-id.h>
#include <app-common/zap-generated/attribute-type.h>
#include <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/callback.h>
#include <app-common/zap-generated/cluster-id.h>
#include <app-common/zap-generated/cluster-objects.h>
#include <app-common/zap-generated/command-id.h>
#include <app-common/zap-generated/enums.h>
#include <app-common/zap-generated/ids/Attributes.h>
#include <app/CommandHandler.h>
#include <app/ConcreteAttributePath.h>
#include <app/ConcreteCommandPath.h>
#include <app/util/error-mapping.h>
#include <lib/core/CHIPEncoding.h>

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<EmberAfTemperatureDisplayMode>(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<EmberAfKeypadLockout>(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;
}
2 changes: 1 addition & 1 deletion src/app/zap-templates/templates/app/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app/zap_cluster_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': []
Expand Down
10 changes: 9 additions & 1 deletion zzz_generated/all-clusters-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b24191

Please sign in to comment.