diff --git a/CMakeLists.txt b/CMakeLists.txt index d4e500f9ef..b7e39908a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 Nordic Semiconductor +# Copyright (c) 2019 - 2020 Nordic Semiconductor # # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic # @@ -15,3 +15,4 @@ add_subdirectory_ifdef(CONFIG_MPSL mpsl) add_subdirectory_ifdef(CONFIG_BSD_LIBRARY bsdlib) add_subdirectory_ifdef(CONFIG_NRFXLIB_CRYPTO crypto) add_subdirectory_ifdef(CONFIG_NORDIC_SECURITY_BACKEND nrf_security) +add_subdirectory_ifdef(CONFIG_ZIGBEE zboss) diff --git a/CODEOWNERS b/CODEOWNERS index 1b3497985e..e765c061f4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -27,4 +27,5 @@ doc/* @b-gent /mpsl/ @joerchan @rugeGerritsen /nfc/ @anangl @grochu /nrf_security/ @frkv @tejlmand +/zboss/ @tomchy /zephyr/ @carlescufi diff --git a/Kconfig.nrfxlib b/Kconfig.nrfxlib index d1adc98edd..ac7ea5736c 100644 --- a/Kconfig.nrfxlib +++ b/Kconfig.nrfxlib @@ -1,5 +1,5 @@ # -# Copyright (c) 2019 Nordic Semiconductor +# Copyright (c) 2019 - 2020 Nordic Semiconductor # # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic # @@ -12,5 +12,6 @@ rsource "ble_controller/Kconfig" rsource "mpsl/Kconfig" rsource "crypto/Kconfig" rsource "nrf_security/Kconfig" +rsource "zboss/Kconfig" endmenu diff --git a/zboss/CMakeLists.txt b/zboss/CMakeLists.txt new file mode 100644 index 0000000000..9a6d092aa9 --- /dev/null +++ b/zboss/CMakeLists.txt @@ -0,0 +1,98 @@ +# +# Copyright (c) 2020 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic +# + +include(${NRFXLIB_DIR}/common.cmake) + +# Define a separate interface library for Nordic's extensions to ZBOSS stack +zephyr_interface_library_named(zboss-extensions) + +# Common includes, not related to ZBOSS source code. +target_include_directories(zboss-extensions INTERFACE + src/zb_error + include/addons +) + +# Suppress bitfield compatibility warning. +# This has to be included in all files, that uses ZBOSS headers. +# Those options will be inherited by the ZBOSS target as well as everything +# that links to it. +target_compile_options(zboss-extensions INTERFACE + -Wno-packed-bitfield-compat +) + +# Add compile-time definition, indicating which ZBOSS library will be linked +# This definition adjusts ZBOSS headers, by making non-applicable API for +# a given Zigbee role invisible. +# Those options will be inherited by the ZBOSS target as well as everything +# that links to it. +if (CONFIG_ZIGBEE_ROLE_END_DEVICE) + target_compile_definitions(zboss-extensions INTERFACE + ZB_ED_ROLE + ) +endif() + + +# Create a library for Nordic's extensions to ZBOSS stack. +# The target name is generated based on the path and is not meant to be +# explicitly linked in other modules. +# It will be pulled if the module links to the ZBOSS interface library. +zephyr_library() + +# Add source files +zephyr_library_sources(src/zb_error/zb_error_to_string.c) + +# Link with ZBOSS extensions interface library, which is linked to the main +# ZBOSS interface library. +zephyr_library_link_libraries(zboss) + +# Precompiled libraries -only part. +# Use the CONFIG_ZBOSS_SOURCES_AVAILABLE Kconfig option is defined in ZBOSS +# platform module to check if user uses ZOI repositories for building +# application. +# If so, the user still may select libraries from nrfxlib to link with +# verified state of ZBOSS (CONFIG_ZBOSS_LIBRARY_PRECOMPILED symbol). +if ((NOT DEFINED CONFIG_ZBOSS_SOURCES_AVAILABLE) OR + (CONFIG_ZBOSS_LIBRARY_PRECOMPILED)) + + nrfxlib_calculate_lib_path(lib_path) + set(ZBOSS_LIB_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${lib_path}) + if(NOT EXISTS ${ZBOSS_LIB_PATH}) + message(WARNING "This combination of SoC and floating point ABI is not supported by the ZBOSS lib." + "(${ZBOSS_LIB_PATH} doesn't exist.)") + endif() + + # Define an interface library for Nordic's ZBOSS stack. + # This library contains official ZBOSS headers, platform-specific configuration + # and links to Nordic's extensions of ZBOSS API. + # This target definition is defined in both - nrfxlib and ZBOSS platform for + # NCS due to the lack of control on the order of Zephyr module inclusion. + zephyr_interface_library_named(zboss) + + # Extend ZBOSS interface libraries by headers placed in nrfxlib. + target_include_directories(zboss INTERFACE + include + include/zcl + include/ha + include/se + include/osif + ) + + # Include the static library to the ZBOSS interface definition and select + # ZBOSS configuration header file by defining compile-time definition. + if (CONFIG_ZIGBEE_ROLE_COORDINATOR OR CONFIG_ZIGBEE_ROLE_ROUTER) + target_link_libraries(zboss INTERFACE ${ZBOSS_LIB_PATH}/libzboss.a) + target_compile_definitions(zboss INTERFACE LIBZBOSS_CONFIG_FILE="libzboss_config.h") + elseif (CONFIG_ZIGBEE_ROLE_END_DEVICE) + target_link_libraries(zboss INTERFACE ${ZBOSS_LIB_PATH}/libzboss.ed.a) + target_compile_definitions(zboss INTERFACE LIBZBOSS_CONFIG_FILE="libzboss_config.ed.h") + else() + message( FATAL_ERROR "Unsupported Zigbee role. Exiting." ) + endif() + + # Link with Nordic's ZBOSS extensions as well as common compile time options + # and definitions. + target_link_libraries(zboss INTERFACE zboss-extensions) +endif() diff --git a/zboss/Kconfig b/zboss/Kconfig new file mode 100644 index 0000000000..fa56b8c37e --- /dev/null +++ b/zboss/Kconfig @@ -0,0 +1,10 @@ +# +# Copyright (c) 2020 Nordic Semiconductor +# +# SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic +# + +config APP_LINK_WITH_ZBOSS + bool + help + Link application with ZBOSS library diff --git a/zboss/include/addons/zboss_api_addons.h b/zboss/include/addons/zboss_api_addons.h new file mode 100644 index 0000000000..fbde08380f --- /dev/null +++ b/zboss/include/addons/zboss_api_addons.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZBOSS_API_ADDONS_H__ +#define ZBOSS_API_ADDONS_H__ + +#include "zboss_api.h" + +#include "zboss_api_zcl_addons.h" +#include "zboss_api_af_addons.h" + + +#endif /* ZBOSS_API_ADDONS_H__ */ diff --git a/zboss/include/addons/zboss_api_af_addons.h b/zboss/include/addons/zboss_api_af_addons.h new file mode 100644 index 0000000000..fd8ffb8f93 --- /dev/null +++ b/zboss/include/addons/zboss_api_af_addons.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZBOSS_API_AF_ADDONS_H__ +#define ZBOSS_API_AF_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zboss_api_af_addons */ +/*! @{ */ + +/**@brief Redefinition of __CAT__ as variadic macro. + * + * @param[IN] a Mandatory argument to concatenate. + * @param[IN] b Mandatory argument to concatenate. + * @param[IN] ... Optional argument to concatenate. + */ +#define __CAT_VA__(a, b, ...) a## __VA_ARGS__## b + +/**@brief Redefinition of ZB_AF_SIMPLE_DESC_TYPE as variadic macro. + * + * @param[IN] ... Optional argument to concatenate to the type name. + */ +#define ZB_AF_SIMPLE_DESC_TYPE_VA(in_num, out_num, ...) __CAT_VA__(zb_af_simple_desc_, _t, __VA_ARGS__) + +/**@brief Redefinition of ZB_DECLARE_SIMPLE_DESC as variadic macro. + * + * @param[IN] in_clusters_count Number of input clusters. + * @param[IN] out_clusters_count Number of output clusters. + * @param[IN] ... Optional argument to concatenate to the type name. + */ +#define ZB_DECLARE_SIMPLE_DESC_VA(in_clusters_count, out_clusters_count, ...) \ + typedef ZB_PACKED_PRE struct zb_af_simple_desc_## __VA_ARGS__## _s \ + { \ + zb_uint8_t endpoint; /* Endpoint */ \ + zb_uint16_t app_profile_id; /* Application profile identifier */ \ + zb_uint16_t app_device_id; /* Application device identifier */ \ + zb_bitfield_t app_device_version:4; /* Application device version */ \ + zb_bitfield_t reserved:4; /* Reserved */ \ + zb_uint8_t app_input_cluster_count; /* Application input cluster count */ \ + zb_uint8_t app_output_cluster_count; /* Application output cluster count */ \ + /* Application input and output cluster list */ \ + zb_uint16_t app_cluster_list[(in_clusters_count) + (out_clusters_count)]; \ + zb_uint8_t cluster_encryption[((in_clusters_count) + (out_clusters_count) + 7)/8]; \ + } ZB_PACKED_STRUCT zb_af_simple_desc_## __VA_ARGS__## _t + +/**@brief Redefinition of ZBOSS_DECLARE_DEVICE_CTX_N_EP as variadic macro. + * + * @param[IN] device_ctx_name Device context variable name. + * @param[IN] ... Variables holding context for endpoints. + */ +#define ZBOSS_DECLARE_DEVICE_CTX_EP_VA(device_ctx_name, ...) \ + zb_af_endpoint_desc_t *ep_list_##device_ctx_name[] = { \ + __VA_ARGS__ \ + }; \ + ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \ + (ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))) + + + +/** @} */ + +#endif /* ZBOSS_API_AF_ADDONS_H__ */ diff --git a/zboss/include/addons/zboss_api_zcl_addons.h b/zboss/include/addons/zboss_api_zcl_addons.h new file mode 100644 index 0000000000..b90d8f5a9c --- /dev/null +++ b/zboss/include/addons/zboss_api_zcl_addons.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZBOSS_API_ZCL_ADDONS_H__ +#define ZBOSS_API_ZCL_ADDONS_H__ + +#include "zboss_api.h" + +#include "zcl/zb_zcl_basic_addons.h" +#include "zcl/zb_zcl_color_control_addons.h" +#include "zcl/zb_zcl_door_lock_addons.h" +#include "zcl/zb_zcl_groups_addons.h" +#include "zcl/zb_zcl_identify_addons.h" +#include "zcl/zb_zcl_level_control_addons.h" +#include "zcl/zb_zcl_scenes_addons.h" +#include "zcl/zb_zcl_on_off_addons.h" +#include "zcl/zb_zcl_temp_measurement_addons.h" + +#endif /* ZBOSS_API_ZCL_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_basic_addons.h b/zboss/include/addons/zcl/zb_zcl_basic_addons.h new file mode 100644 index 0000000000..78c58789cb --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_basic_addons.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_BASIC_ADDONS_H__ +#define ZB_ZCL_BASIC_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_basic_addons */ +/*! @{ */ + +/** @brief Basic cluster attributes according to ZCL Spec 3.2.2.2 */ +typedef struct +{ + zb_uint8_t zcl_version; + zb_uint8_t app_version; + zb_uint8_t stack_version; + zb_uint8_t hw_version; + zb_char_t mf_name[32]; + zb_char_t model_id[32]; + zb_char_t date_code[16]; + zb_uint8_t power_source; + zb_char_t location_id[15]; + zb_uint8_t ph_env; + zb_char_t sw_ver[17]; +} zb_zcl_basic_attrs_ext_t; + +/** @} */ + +#endif /* ZB_ZCL_BASIC_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_color_control_addons.h b/zboss/include/addons/zcl/zb_zcl_color_control_addons.h new file mode 100644 index 0000000000..c47c43080b --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_color_control_addons.h @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_COLOR_CONTROL_ADDONS_H__ +#define ZB_ZCL_COLOR_CONTROL_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_color_control_addons */ +/*! @{ */ + +/**@brief Color information set for Color cluster attributes according to ZCL Spec 5.2.2.2.1. */ +typedef struct +{ + zb_uint8_t current_hue; + zb_uint8_t current_saturation; + zb_uint8_t color_mode; + zb_uint8_t options; + zb_uint8_t enhanced_color_mode; + zb_uint16_t color_capabilities; +} zb_zcl_color_ctrl_attrs_set_color_inf_t; + +/**@brief Color information extended set for Color cluster attributes according to ZCL Spec 5.2.2.2.1. */ +typedef struct +{ + zb_uint8_t current_hue; + zb_uint8_t current_saturation; + zb_uint16_t remaining_time; + zb_uint16_t current_X; + zb_uint16_t current_Y; + zb_uint16_t color_temperature; + zb_uint8_t color_mode; + zb_uint8_t options; + zb_uint16_t enhanced_current_hue; + zb_uint8_t enhanced_color_mode; + zb_uint8_t color_loop_active; + zb_uint8_t color_loop_direction; + zb_uint16_t color_loop_time; + zb_uint16_t color_loop_start_enhanced_hue; + zb_uint16_t color_loop_stored_enhanced_hue; + zb_uint16_t color_capabilities; + zb_uint16_t color_temp_physical_min_mireds; + zb_uint16_t color_temp_physical_max_mireds; + zb_uint16_t couple_color_temp_to_level_min_mireds; + zb_uint16_t start_up_color_temp_mireds; +} zb_zcl_color_ctrl_attrs_set_color_inf_ext_t; + +/**@brief Defined primaries information attribute set for Color cluster attributes according to ZCL Spec 5.2.2.2.2. */ +typedef struct +{ + zb_uint8_t number_primaries; +} zb_zcl_color_ctrl_attrs_set_defined_primaries_inf_t; + +/**@brief Defined primaries information extended attribute set for Color cluster attributes according to ZCL Spec 5.2.2.2.2. */ +typedef struct +{ + zb_uint8_t number_primaries; + zb_uint16_t primary_1_X; + zb_uint16_t primary_1_Y; + zb_uint8_t primary_1_intensity; + zb_uint16_t primary_2_X; + zb_uint16_t primary_2_Y; + zb_uint8_t primary_2_intensity; + zb_uint16_t primary_3_X; + zb_uint16_t primary_3_Y; + zb_uint8_t primary_3_intensity; +} zb_zcl_color_ctrl_attrs_set_defined_primaries_inf_ext_t; + +/**@brief Color cluster extended attributes according to ZCL Spec 5.2.2.2.3. */ +typedef struct +{ + zb_uint16_t primary_4_X; + zb_uint16_t primary_4_Y; + zb_uint8_t primary_4_intensity; + zb_uint16_t primary_5_X; + zb_uint16_t primary_5_Y; + zb_uint8_t primary_5_intensity; + zb_uint16_t primary_6_X; + zb_uint16_t primary_6_Y; + zb_uint8_t primary_6_intensity; +} zb_zcl_color_ctrl_attrs_set_add_prim_inf_ext_t; + +/**@brief Color cluster attributes according to ZCL Spec 5.2.2.2. */ +typedef struct +{ + zb_zcl_color_ctrl_attrs_set_color_inf_t set_color_info; + zb_zcl_color_ctrl_attrs_set_defined_primaries_inf_t set_defined_primaries_info; +} zb_zcl_color_control_attrs_t; + +/**@brief Color cluster extended attributes according to ZCL Spec 5.2.2.2. */ +typedef struct +{ + zb_zcl_color_ctrl_attrs_set_color_inf_ext_t set_color_info; + zb_zcl_color_ctrl_attrs_set_defined_primaries_inf_ext_t set_defined_primaries_info; + zb_zcl_color_ctrl_attrs_set_add_prim_inf_ext_t set_additional_defined_primaries_info; +} zb_zcl_color_control_attrs_ext_t; + +/**@brief Macro equivalent to @ref ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_HUE_SATURATION_REQ, but command is sent without APS ACK. */ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_HUE_SATURATION_REQ_NO_APS_ACK(buffer, addr, dst_addr_mode,\ + dst_ep, ep, prfl_id, def_resp, cb, hue, saturation, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (hue)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (saturation)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_SEND_COMMAND_SHORT_WITHOUT_ACK((buffer), ptr, (zb_addr_u *)(&(addr), dst_addr_mode, \ + dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb, 0); \ +} + +/** @} */ + +#endif /* ZB_ZCL_COLOR_CONTROL_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_door_lock_addons.h b/zboss/include/addons/zcl/zb_zcl_door_lock_addons.h new file mode 100644 index 0000000000..fe4456ac8b --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_door_lock_addons.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_DOOR_LOCK_ADDONS_H__ +#define ZB_ZCL_DOOR_LOCK_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_door_lock_addons */ +/*! @{ */ + +/**@brief Door Lock cluster attributes according to ZCL Spec 7.3.2.10. */ +typedef struct +{ + zb_uint8_t lock_state; + zb_uint8_t lock_type; + zb_bool_t actuator_enabled; +} zb_zcl_door_lock_attrs_t; + +/** @} */ + +#endif /* ZB_ZCL_DOOR_LOCK_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_groups_addons.h b/zboss/include/addons/zcl/zb_zcl_groups_addons.h new file mode 100644 index 0000000000..3eb4c79e60 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_groups_addons.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_GROUPS_ADDONS_H__ +#define ZB_ZCL_GROUPS_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_groups_addons */ +/*! @{ */ + +/**@brief Groups cluster attributes according to ZCL Spec 3.6.2.2. */ +typedef struct +{ + zb_uint8_t name_support; +} zb_zcl_groups_attrs_t; + +/** @} */ + +#endif /* ZB_ZCL_GROUPS_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_identify_addons.h b/zboss/include/addons/zcl/zb_zcl_identify_addons.h new file mode 100644 index 0000000000..61ea6a5363 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_identify_addons.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_IDENTIFY_ADDONS_H__ +#define ZB_ZCL_IDENTIFY_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_identify_addons */ +/*! @{ */ + +/**@brief Macro equivalent to @ref ZB_ZCL_IDENTIFY_SEND_TRIGGER_VARIANT, but command is sent without APS ACK. */ +#define ZB_ZCL_IDENTIFY_SEND_TRIGGER_VARIANT_REQ_NO_APS_ACK( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, def_resp, cb, effect_id, effect_var) \ +{ \ + zb_uint8_t * ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IDENTIFY_TRIGGER_EFFECT_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (effect_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (effect_var)); \ + ZB_ZCL_SEND_COMMAND_SHORT_WITHOUT_ACK((buffer), ptr, (zb_addr_u *)(&(addr), dst_addr_mode, \ + dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_IDENTIFY, cb, 0); \ +} + +/** @} */ + +#endif /* ZB_ZCL_IDENTIFY_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_level_control_addons.h b/zboss/include/addons/zcl/zb_zcl_level_control_addons.h new file mode 100644 index 0000000000..9ae0c7f9c5 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_level_control_addons.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_LEVEL_CONTROL_ADDONS_H__ +#define ZB_ZCL_LEVEL_CONTROL_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_level_control_addons */ +/*! @{ */ + +/**@brief Level Control cluster attributes according to ZCL Spec 3.10.2.3. */ +typedef struct +{ + zb_uint8_t current_level; + zb_uint16_t remaining_time; +} zb_zcl_level_control_attrs_t; + +/**@brief Macro equivalent to @ref ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD, but command is sent without APS ACK. */ +#define ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD_NO_APS_ACK(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time, \ + cmd_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), cmd_id); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_SEND_COMMAND_SHORT_WITHOUT_ACK((buffer), ptr, \ + (zb_addr_u *)(&(addr), dst_addr_mode, \ + dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, cb, 0); \ +} + +/**@brief Macro equivalent to @ref ZB_ZCL_LEVEL_CONTROL_SEND_STEP_REQ, but command is sent without APS ACK. */ +#define ZB_ZCL_LEVEL_CONTROL_SEND_STEP_REQ_NO_APS_ACK(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD_NO_APS_ACK(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP); \ +} + +/** @} */ + +#endif /* ZB_ZCL_LEVEL_CONTROL_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_on_off_addons.h b/zboss/include/addons/zcl/zb_zcl_on_off_addons.h new file mode 100644 index 0000000000..dd977b4536 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_on_off_addons.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_ON_OFF_ADDONS_H__ +#define ZB_ZCL_ON_OFF_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_on_off_addons */ +/*! @{ */ + +/**@brief On/Off cluster attributes according to ZCL Spec 3.8.2.2. */ +typedef struct +{ + zb_bool_t on_off; + zb_bool_t global_scene_ctrl; + zb_uint16_t on_time; + zb_uint16_t off_wait_time; +} zb_zcl_on_off_attrs_ext_t; + +/**@brief Macro equivalent to @ref ZB_ZCL_ON_OFF_SEND_REQ, but command is sent without APS ACK. */ +#define ZB_ZCL_ON_OFF_SEND_REQ_NO_APS_ACK( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, command_id, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), command_id); \ + ZB_ZCL_SEND_COMMAND_SHORT_WITHOUT_ACK((buffer), ptr, (zb_addr_u *)(&(addr), \ + dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ON_OFF, cb, 0); \ +} + +/** @} */ + +#endif /* ZB_ZCL_ON_OFF_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_scenes_addons.h b/zboss/include/addons/zcl/zb_zcl_scenes_addons.h new file mode 100644 index 0000000000..4a16aa95b9 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_scenes_addons.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_SCENES_ADDONS_H__ +#define ZB_ZCL_SCENES_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_scenes_addons */ +/*! @{ */ + +/* Scene cluster attributes according to ZCL Spec 3.7.2.2. */ +typedef struct +{ + zb_uint8_t scene_count; + zb_uint8_t current_scene; + zb_uint8_t scene_valid; + zb_uint8_t name_support; + zb_uint16_t current_group; +} zb_zcl_scenes_attrs_t; + +/** @} */ + +#endif /* ZB_ZCL_SCENES_ADDONS_H__ */ diff --git a/zboss/include/addons/zcl/zb_zcl_temp_measurement_addons.h b/zboss/include/addons/zcl/zb_zcl_temp_measurement_addons.h new file mode 100644 index 0000000000..38e33f0691 --- /dev/null +++ b/zboss/include/addons/zcl/zb_zcl_temp_measurement_addons.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_ZCL_TEMP_MEASUREMENT_ADDONS_H__ +#define ZB_ZCL_TEMP_MEASUREMENT_ADDONS_H__ + +#include "zboss_api.h" + +/*! \addtogroup zb_zcl_temp_measurement_addons */ +/*! @{ */ + +/**@brief Temperature Measurement cluster attributes according to ZCL Spec 4.4.2.1.1. */ +typedef struct +{ + zb_int16_t measure_value; + zb_int16_t min_measure_value; + zb_int16_t max_measure_value; + zb_uint16_t tolerance; +} zb_zcl_temp_measurement_attrs_t; + +/** @} */ + +#endif /* ZB_ZCL_TEMP_MEASUREMENT_ADDONS_H__ */ diff --git a/zboss/include/ha/zb_ha_combined_interface.h b/zboss/include/ha/zb_ha_combined_interface.h new file mode 100644 index 0000000000..d11d67cbc6 --- /dev/null +++ b/zboss/include/ha/zb_ha_combined_interface.h @@ -0,0 +1,201 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Combined interface device declaration +*/ +#ifndef ZB_HA_COMBINED_INTERFACE_H +#define ZB_HA_COMBINED_INTERFACE_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_COMBINED_INTERFACE || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + @defgroup ha_combined_interface Combined Interface + @addtogroup ha_combined_interface + @ingroup ZB_HA_DEVICES + @{ + @details + Combined Interface device has 3 clusters (see spec 7.4.8): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_OOSC + + Combined Interface device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/combined_interface/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/combined_interface/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/combined_interface/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/combined_interface/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The Combined Interface device sample can be found in /application/HA_samples/combined_interface +*/ + +#define ZB_HA_DEVICE_VER_COMBINED_INTERFACE 0 /*!< Combined interface device version */ + +/** @cond internals_doc */ +#define ZB_HA_COMBINED_INTERFACE_IN_CLUSTER_NUM 2 /*!< Combined interface IN (server) clusters number */ + +#define ZB_HA_COMBINED_INTERFACE_OUT_CLUSTER_NUM 3 /*!< Combined interface OUT (client) clusters number */ + +#define ZB_HA_COMBINED_INTERFACE_CLUSTER_NUM \ + (ZB_HA_COMBINED_INTERFACE_IN_CLUSTER_NUM + ZB_HA_COMBINED_INTERFACE_OUT_CLUSTER_NUM) + +/*! @brief Number of attribute for reporting on Combined interface device */ +#define ZB_HA_COMBINED_INTERFACE_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/** @brief Declare cluster list for Combined interface device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_COMBINED_INTERFACE_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @brief Declare simple descriptor for Combined interface device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_COMBINED_INTERFACE_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_COMBINED_INTERFACE_DEVICE_ID, \ + ZB_HA_DEVICE_VER_COMBINED_INTERFACE, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG \ + } \ + } + +/** @brief Declare endpoint for Combined Interface device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_COMBINED_INTERFACE_EP(ep_name, ep_id, cluster_list) \ + \ + ZB_ZCL_DECLARE_COMBINED_INTERFACE_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_COMBINED_INTERFACE_IN_CLUSTER_NUM, ZB_HA_COMBINED_INTERFACE_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +/** @brief Declare Combined Interface device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_COMBINED_INTERFACE_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_COMBINED_INTERFACE */ + +#endif /* ZB_HA_COMBINED_INTERFACE_H */ diff --git a/zboss/include/ha/zb_ha_config.h b/zboss/include/ha/zb_ha_config.h new file mode 100644 index 0000000000..3ee0f09d81 --- /dev/null +++ b/zboss/include/ha/zb_ha_config.h @@ -0,0 +1,71 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA configuration +*/ + +//#ifndef ZB_HA_CONFIG_H +#define ZB_HA_CONFIG_H 1 + +#include "zb_vendor.h" + +#if defined ZB_ENABLE_HA || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/* Specify a list of devices that should be supported */ +#define xZB_ALL_DEVICE_SUPPORT /* Attention! use this macro in testing purposes */ + +/* Normally startup attribute sets should be processed */ +/* TODO Re-enable HA SAS processing when appropriate */ +#define xZB_ENABLE_HA_SAS + +/* NK: why Gateway is always defined? */ +#define xZB_HA_DEFINE_DEVICE_GATEWAY + + +#include "zb_ha_device_config.h" +#include "zcl/zb_zcl_config.h" + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_ENABLE_HA */ + +//#endif /* ZB_HA_CONFIG_H */ diff --git a/zboss/include/ha/zb_ha_configuration_tool.h b/zboss/include/ha/zb_ha_configuration_tool.h new file mode 100644 index 0000000000..8ffa33aa72 --- /dev/null +++ b/zboss/include/ha/zb_ha_configuration_tool.h @@ -0,0 +1,205 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Configuration tool device declaration +*/ + +#ifndef ZB_HA_CONFIGURATION_TOOL_H +#define ZB_HA_CONFIGURATION_TOOL_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_CONFIGURATION_TOOL || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + @defgroup ha_configuration_tool Configuration Tool + @ingroup ZB_HA_DEVICES + @{ + @details + Configuration Tool device has 3 clusters (see spec 7.4.6): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_GROUPS + + Configuration Tool device sample + + @par Example + + - Declaring clusters + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/configuration_tool/sample_zc.c COMMON_DECLARATION + + - Registering device list + + @snippet HA_samples/configuration_tool/sample_zc.c REGISTER + + - Example of command handler + + @snippet HA_samples/configuration_tool/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/configuration_tool/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Configuration Tool device samples can be found in /application/HA_samples/configuration_tool +*/ + +#define ZB_HA_DEVICE_VER_CONFIGURATION_TOOL 0 /*!< Configuration tool device version */ + +/** @cond internals_doc */ +#define ZB_HA_CONFIGURATION_TOOL_IN_CLUSTER_NUM 2 /*!< Configuration tool IN (server) clusters number */ +#define ZB_HA_CONFIGURATION_TOOL_OUT_CLUSTER_NUM 3 /*!< Configuration tool OUT (client) clusters number */ + +#define ZB_HA_CONFIGURATION_TOOL_CLUSTER_NUM \ + (ZB_HA_CONFIGURATION_TOOL_IN_CLUSTER_NUM + ZB_HA_CONFIGURATION_TOOL_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Configuration tool device */ +#define ZB_HA_CONFIGURATION_TOOL_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/** @brief Declare cluster list for Configuration tool device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_CONFIGURATION_TOOL_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + +/** @cond internals_doc */ + +/** + @brief Declare simple descriptor for Configuration tool device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters + +*/ +#define ZB_ZCL_DECLARE_CONFIGURATION_TOOL_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_CONFIGURATION_TOOL_DEVICE_ID, \ + ZB_HA_DEVICE_VER_CONFIGURATION_TOOL, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for Configuration tool device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_CONFIGURATION_TOOL_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_CONFIGURATION_TOOL_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_CONFIGURATION_TOOL_IN_CLUSTER_NUM, ZB_HA_CONFIGURATION_TOOL_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +/** @brief Declare Configuration Tool device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. + */ +#define ZB_HA_DECLARE_CONFIGURATION_TOOL_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_CONFIGURATION_TOOL */ + +#endif /* ZB_HA_CONFIGURATION_TOOL_H */ diff --git a/zboss/include/ha/zb_ha_custom_attr.h b/zboss/include/ha/zb_ha_custom_attr.h new file mode 100644 index 0000000000..5b57309dfd --- /dev/null +++ b/zboss/include/ha/zb_ha_custom_attr.h @@ -0,0 +1,190 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Window Covering device definition +*/ + +#if ! defined ZB_HA_CUSTOM_ATTR_H +#define ZB_HA_CUSTOM_ATTR_H + +/******************* Specific definitions for window covering device **************************/ + +#if defined ZB_HA_DEFINE_DEVICE_WINDOW_COVERING || defined DOXYGEN + +/** @cond (DOXYGEN_HA_SECTION && internals_doc)*/ + +/** @addtogroup ha_api + * @{ + */ + +#define ZB_HA_DEVICE_VER_CUSTOM_ATTR 0 + +#define ZB_HA_CUSTOM_ATTR_IN_CLUSTER_NUM 6 +#define ZB_HA_CUSTOM_ATTR_OUT_CLUSTER_NUM 0 + +#define ZB_HA_CUSTOM_ATTR_CLUSTER_NUM (ZB_HA_CUSTOM_ATTR_IN_CLUSTER_NUM + \ + ZB_HA_CUSTOM_ATTR_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on custom attr device */ +#define ZB_HA_CUSTOM_ATTR_REPORT_ATTR_COUNT \ + (ZB_ZCL_CUSTOM_ATTR_REPORT_ATTR_COUNT) + +/*! + @brief Declare cluster list for custom attr device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param window_covering_attr_list - attribute list for Window covering cluster + @param custom_attr_attr_list - attribute list for Custom Attributes cluster + */ +#define ZB_HA_DECLARE_CUSTOM_ATTR_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list, \ + window_covering_attr_list, \ + custom_attr_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + ZB_ZCL_ARRAY_SIZE(window_covering_attr_list, zb_zcl_attr_t), \ + (window_covering_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_CUSTOM_ATTR, \ + ZB_ZCL_ARRAY_SIZE(custom_attr_attr_list, zb_zcl_attr_t), \ + (custom_attr_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! + @brief Declare simple descriptor for custom attr device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_CUSTOM_ATTR_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_CUSTOM_ATTR_DEVICE_ID, \ + ZB_HA_DEVICE_VER_CUSTOM_ATTR, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_CUSTOM_ATTR \ + } \ + } + +/*! + @brief Declare endpoint for custom attr device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_CUSTOM_ATTR_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_CUSTOM_ATTR_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_CUSTOM_ATTR_IN_CLUSTER_NUM, ZB_HA_CUSTOM_ATTR_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, 20); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_ZCL_ARRAY_SIZE(ep_name, zb_af_endpoint_desc_t), \ + 20, reporting_info## device_ctx_name, 0, NULL) + + +#define ZB_HA_DECLARE_CUSTOM_ATTR_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_CUSTOM_ATTR */ + +#endif /* ! defined ZB_HA_CUSTOM_ATTR_H */ diff --git a/zboss/include/ha/zb_ha_device_config.h b/zboss/include/ha/zb_ha_device_config.h new file mode 100644 index 0000000000..aff8ba211a --- /dev/null +++ b/zboss/include/ha/zb_ha_device_config.h @@ -0,0 +1,518 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA devices configuration +*/ + +#ifndef ZB_HA_DEVICE_CONFIG_H +#define ZB_HA_DEVICE_CONFIG_H 1 + +#if defined ZB_ENABLE_HA || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/*! @defgroup ha_config_params HA Device types */ +/*! @{ + */ + +/** @brief HA Device identifiers. */ +enum zb_ha_standard_devs_e +{ + /*! General On/Off switch */ + ZB_HA_ON_OFF_SWITCH_DEVICE_ID = 0x0000, + /*! Level Control Switch */ + ZB_HA_LEVEL_CONTROL_SWITCH_DEVICE_ID = 0x0001, + /*! General On/Off output */ + ZB_HA_ON_OFF_OUTPUT_DEVICE_ID = 0x0002, + /*! Level Controllable Output */ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_DEVICE_ID = 0x0003, + /*! Scene Selector */ + ZB_HA_SCENE_SELECTOR_DEVICE_ID = 0x0004, + /*! Configuration Tool */ + ZB_HA_CONFIGURATION_TOOL_DEVICE_ID = 0x0005, + /*! Remote Control */ + ZB_HA_REMOTE_CONTROL_DEVICE_ID = 0x0006, + /*! Combined Interface */ + ZB_HA_COMBINED_INTERFACE_DEVICE_ID = 0x0007, + /*! Range Extender */ + ZB_HA_RANGE_EXTENDER_DEVICE_ID = 0x0008, + /*! Mains Power Outlet */ + ZB_HA_MAINS_POWER_OUTLET_DEVICE_ID = 0x0009, + /*! Door lock client */ + ZB_HA_DOOR_LOCK_DEVICE_ID = 0x000A, + /*! Door lock controller */ + ZB_HA_DOOR_LOCK_CONTROLLER_DEVICE_ID = 0x000B, + /*! Simple Sensor device */ + ZB_HA_SIMPLE_SENSOR_DEVICE_ID = 0x000C, + /*! Consumption Awareness Device */ + ZB_HA_CONSUMPTION_AWARENESS_DEVICE_ID = 0x000D, + /*! Home Gateway */ + ZB_HA_HOME_GATEWAY_DEVICE_ID = 0x0050, + /*! Smart plug */ + ZB_HA_SMART_PLUG_DEVICE_ID = 0x0051, + /*! White Goods */ + ZB_HA_WHITE_GOODS_DEVICE_ID = 0x0052, + /*! Meter Interface */ + ZB_HA_METER_INTERFACE_DEVICE_ID = 0x0053, + /* Lightning */ + /*! On/Off Light Device */ + ZB_HA_ON_OFF_LIGHT_DEVICE_ID = 0x0100, + /*! Dimmable Light Device */ + ZB_HA_DIMMABLE_LIGHT_DEVICE_ID = 0x0101, + /*! Color Dimmable Light Device */ + ZB_HA_COLOR_DIMMABLE_LIGHT_DEVICE_ID = 0x0102, + /*! Dimmer Switch Device */ + ZB_HA_DIMMER_SWITCH_DEVICE_ID = 0x0104, + /*! Color Dimmer Switch Device */ + ZB_HA_COLOR_DIMMER_SWITCH_DEVICE_ID = 0x0105, + /*! Shade */ + ZB_HA_SHADE_DEVICE_ID = 0x0200, + /*! Shade controller */ + ZB_HA_SHADE_CONTROLLER_DEVICE_ID = 0x0201, + /*! Window Covering client*/ + ZB_HA_WINDOW_COVERING_DEVICE_ID = 0x0202, + /*! Window Covering controller */ + ZB_HA_WINDOW_COVERING_CONTROLLER_DEVICE_ID = 0x0203, + /* HVAC */ + /*! Heating/Cooling Unit device */ + ZB_HA_HEATING_COOLING_UNIT_DEVICE_ID = 0x0300, + /*! Thermostat Device */ + ZB_HA_THERMOSTAT_DEVICE_ID = 0x0301, + /*! Temperature Sensor */ + ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID = 0x0302, + /* IAS */ + /*! IAS Control and Indicating Equipment */ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_ID = 0x0400, + /*! IAS Ancillary Control Equipment */ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_ID = 0x0401, + /*! IAS Zone */ + ZB_HA_IAS_ZONE_ID = 0x0402, + /*! IAS Warning Device */ + ZB_HA_IAS_WARNING_DEVICE_ID = 0x0403, + /*! Custom HA device for test */ + ZB_HA_TEST_DEVICE_ID = 0xfff0, + /*! Custom Tunnel device (should declared in private profile) */ + ZB_HA_CUSTOM_TUNNEL_DEVICE_ID = 0xfff1, + /*! Custom Attributes Device */ + ZB_HA_CUSTOM_ATTR_DEVICE_ID = 0xfff2 +}; + + +/** @cond internals_doc */ +/* Define supported devices here */ +#ifdef ZB_ALL_DEVICE_SUPPORT +#define ZB_HA_DEFINE_DEVICE_ON_OFF_SWITCH +#define ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT +#define ZB_HA_DEFINE_DEVICE_DOOR_LOCK +#define ZB_HA_DEFINE_DEVICE_DOOR_LOCK_CONTROLLER +#define ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR +#define ZB_HA_DEFINE_DEVICE_COMBINED_INTERFACE +#define ZB_HA_DEFINE_DEVICE_SCENE_SELECTOR +#define ZB_HA_DEFINE_DEVICE_CONFIGURATION_TOOL +#define ZB_HA_DEFINE_DEVICE_MAINS_POWER_OUTLET +#define ZB_HA_DEFINE_DEVICE_RANGE_EXTENDER +#define ZB_HA_DEFINE_DEVICE_LEVEL_CONTROL_SWITCH +#define ZB_HA_DEFINE_DEVICE_LEVEL_CONTROLLABLE_OUTPUT +#define ZB_HA_DEFINE_DEVICE_WINDOW_COVERING +#define ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER +#define ZB_HA_DEFINE_DEVICE_SHADE +#define ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER + /* HVAC */ +#define ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR +/* IAS*/ +#define ZB_HA_DEFINE_DEVICE_IAS_CONTROL_INDICATING_EQUIPMENT +#define ZB_HA_DEFINE_DEVICE_IAS_ANCILLARY_CONTROL_EQUIPMENT +#define ZB_HA_DEFINE_DEVICE_IAS_ZONE +#define ZB_HA_DEFINE_DEVICE_IAS_WARNING_DEVICE + +#define ZB_HA_DEFINE_DEVICE_CUSTOM_ATTR +#define ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT +#define ZB_HA_DEFINE_DEVICE_DIMMER_SWITCH + +#define ZB_HA_DEFINE_DEVICE_SMART_PLUG +#define ZB_HA_DEFINE_DEVICE_THERMOSTAT + +#define ZB_HA_DEFINE_DEVICE_TEST_DEVICE + +/************** Custome Devices ******************/ +/* Define device support for custom security sensor */ +#define ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_SENSOR +/* this device definition - for coordinator (CIE) role, need for test + * only - remove it in release build */ +#define ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_CONTROL +/* Define device support for Low Cost Gateway */ +#define ZB_HA_DEFINE_DEVICE_GATEWAY + + + +#define ZB_ZCL_SUPPORT_CLUSTER_DRLC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_PRICE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TUNNELING 1 +#define ZB_ZCL_SUPPORT_CLUSTER_MESSAGING 1 + +#define ZB_ZCL_SUPPORT_CLUSTER_METER_IDENTIFICATION 1 + +#endif /* ZB_ALL_DEVICE_SUPPORT */ + +//#define ZB_HA_DEFINE_DEVICE_SMART_PLUG + +/*********************** HA devices to cluster configuration **********************/ + +#ifdef ZB_HA_DEFINE_DEVICE_ON_OFF_SWITCH +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF_SWITCH_CONFIG 1 + +#endif /* ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT */ + + +#ifdef ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 + +#endif /* ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT */ + +#ifdef ZB_HA_DEFINE_DEVICE_BASIC_LIGHT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#endif /* ZB_HA_DEFINE_DEVICE_BASIC_LIGHT */ + + +#ifdef ZB_HA_DEFINE_DEVICE_DOOR_LOCK +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_DOOR_LOCK 1 + +#endif /* ZB_HA_DEFINE_DEVICE_DOOR_LOCK */ + + +#ifdef ZB_HA_DEFINE_DEVICE_DOOR_LOCK_CONTROLLER +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_DOOR_LOCK 1 + +#endif /* ZB_HA_DEFINE_DEVICE_DOOR_LOCK_CONTROLLER */ + + +#ifdef ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_BINARY_INPUT 1 +#endif /* ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR */ + + +#ifdef ZB_HA_DEFINE_DEVICE_COMBINED_INTERFACE +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF_SWITCH_CONFIG 1 +#endif /* ZB_HA_DEFINE_DEVICE_COMBINED_INTERFACE */ + + +#ifdef ZB_HA_DEFINE_DEVICE_SCENE_SELECTOR +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#endif /* ZB_HA_DEFINE_DEVICE_SCENE_SELECTOR */ + + +#ifdef ZB_HA_DEFINE_DEVICE_CONFIGURATION_TOOL +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#endif /* ZB_HA_DEFINE_DEVICE_CONFIGURATION_TOOL */ + + +#ifdef ZB_HA_DEFINE_DEVICE_MAINS_POWER_OUTLET +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 + +#endif /* ZB_HA_DEFINE_DEVICE_MAINS_POWER_OUTLET */ + + +#ifdef ZB_HA_DEFINE_DEVICE_RANGE_EXTENDER +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#endif /* ZB_HA_DEFINE_DEVICE_RANGE_EXTENDER */ + + +#ifdef ZB_HA_DEFINE_DEVICE_LEVEL_CONTROL_SWITCH +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_LEVEL_CONTROL_SWITCH */ + + +#ifdef ZB_HA_DEFINE_DEVICE_LEVEL_CONTROLLABLE_OUTPUT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 + +#endif /* ZB_HA_DEFINE_DEVICE_LEVEL_CONTROLLABLE_OUTPUT */ + + +#ifdef ZB_HA_DEFINE_DEVICE_WINDOW_COVERING +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_WINDOW_COVERING 1 + +#endif /* ZB_HA_DEFINE_DEVICE_WINDOW_COVERING */ + +#ifdef ZB_HA_DEFINE_DEVICE_CUSTOM_ATTR +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_WINDOW_COVERING 1 +#define ZB_ZCL_SUPPORT_CLUSTER_CUSTOM_ATTR 1 +#endif /* ZB_HA_DEFINE_DEVICE_CUSTOM_ATTR */ + +#ifdef ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT */ + +#ifdef ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_DIMMER_SWITCH */ + +#ifdef ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER +#define ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_WINDOW_COVERING 1 +#endif /* ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER */ + +#ifdef ZB_HA_DEFINE_DEVICE_SHADE +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SHADE_CONFIG 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_SHADE */ + +#ifdef ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER */ + + /* HVAC */ + +#ifdef ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TEMP_MEASUREMENT 1 +#endif /* ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR */ + +/* IAS*/ + +#ifdef ZB_HA_DEFINE_DEVICE_IAS_CONTROL_INDICATING_EQUIPMENT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ACE 1 +//#define ZB_ZCL_SUPPORT_CLUSTER_IAS_WD 1 +//#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#endif /* ZB_HA_DEFINE_DEVICE_IAS_CONTROL_INDICATING_EQUIPMENT */ + +#ifdef ZB_HA_DEFINE_DEVICE_IAS_ANCILLARY_CONTROL_EQUIPMENT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +//#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ACE 1 +#endif /* ZB_HA_DEFINE_DEVICE_IAS_ANCILLARY_CONTROL_EQUIPMENT */ + +#ifdef ZB_HA_DEFINE_DEVICE_IAS_ZONE +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +#endif /* ZB_HA_DEFINE_DEVICE_IAS_ZONE */ + +#ifdef ZB_HA_DEFINE_DEVICE_IAS_WARNING_DEVICE +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_WD 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#endif /* ZB_HA_DEFINE_DEVICE_IAS_WARNING_DEVICE */ + +#ifdef ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_SENSOR +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TEMP_MEASUREMENT 1 + +#define ZB_ZCL_SUPPORT_CLUSTER_POWER_CONFIG 1 +#define ZB_ZCL_SUPPORT_CLUSTER_POLL_CONTROL 1 +#define ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ILLUMINANCE_MEASUREMENT 1 +#define ZB_ZCL_SUPPORT_CLUSTER_REL_HUMIDITY_MEASUREMENT 1 +#endif /* ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_SENSOR */ + +#ifdef ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_CONTROL +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +//#define ZB_ZCL_SUPPORT_CLUSTER_POLL_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_CUSTOM_SECURITY_CONTROL */ + +#ifdef ZB_HA_DEFINE_DEVICE_THERMOSTAT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_THERMOSTAT 1 +#define ZB_ZCL_SUPPORT_CLUSTER_THERMOSTAT_UI_CONFIG 1 +#define ZB_ZCL_SUPPORT_CLUSTER_FAN_CONTROL 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ELECTRICAL_MEASUREMENT 1 +#endif /* ZB_HA_DEFINE_DEVICE_THERMOSTAT */ + +#ifdef ZB_HA_DEFINE_DEVICE_GATEWAY +/* + * Gateway supports many clusters, but in the client role and in general it's + * not necessary to define their support with ZB_ZCL_SUPPORT_CLUSTER_xxx. + * Such defines are necessary only for clusters in the server role. + * The only exception is poll control cluster for now. + */ +#define ZB_ZCL_SUPPORT_CLUSTER_POLL_CONTROL 1 +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ZONE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TIME 1 +#define ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS_CLIENT 1 +#define ZB_ZCL_SUPPORT_CLUSTER_EN50523_APPLIANCE_EVENTS_AND_ALERTS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_POWER_CONFIG 1 +#define ZB_ZCL_SUPPORT_CLUSTER_REL_HUMIDITY_MEASUREMENT 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TEMP_MEASUREMENT 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_METERING 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IAS_ACE 1 +/* + * Gateway uses EZ mode only for Gemtek smartplug, which is + * currently excluded from build. + */ +/* #define ZB_HA_SUPPORT_EZ_MODE 1 */ +#endif /* ZB_HA_DEFINE_DEVICE_GATEWAY */ + +/* Custome device should not be declared as a part of HA, keep it + * here foe simplicity */ +#ifdef ZB_PROFILE_DEFINE_DEVICE_CUSTOM_TUNNEL +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_TUNNEL 1 +#endif + +#ifdef ZB_HA_DEFINE_DEVICE_SMART_PLUG +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_METERING 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +/* FIXME: Are Scenes really needed? */ +/* #define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 */ +#define ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE 1 +#endif /* ZB_HA_DEFINE_DEVICE_SMART_PLUG */ + + +#ifdef ZB_HA_DEFINE_DEVICE_CUSTOM_DIMMABLE_LIGHT +#define ZB_ZCL_SUPPORT_CLUSTER_BASIC 1 +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#define ZB_ZCL_SUPPORT_CLUSTER_SCENES 1 +#define ZB_ZCL_SUPPORT_CLUSTER_GROUPS 1 +#define ZB_ZCL_SUPPORT_CLUSTER_ON_OFF 1 +#define ZB_ZCL_SUPPORT_CLUSTER_LEVEL_CONTROL 1 +#define ZB_ZCL_SUPPORT_CLUSTER_COLOR_CONTROL 1 +#endif /* ZB_HA_DEFINE_DEVICE_CUSTOM_DIMMABLE_LIGHT */ + +/* BDB uses identify */ +#if defined ZB_BDB_MODE && !defined ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY +#define ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY 1 +#endif + +/** @endcond */ + +/** @} */ /* ha_api */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + + +#endif /* ZB_ENABLE_HA */ + +#endif /* ZB_HA_DEVICE_CONFIG_H */ diff --git a/zboss/include/ha/zb_ha_dimmable_light.h b/zboss/include/ha/zb_ha_dimmable_light.h new file mode 100644 index 0000000000..fb10c40c10 --- /dev/null +++ b/zboss/include/ha/zb_ha_dimmable_light.h @@ -0,0 +1,220 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA Dimmable Light device definition +*/ + +#if ! defined ZB_HA_DIMMABLE_LIGHT_H +#define ZB_HA_DIMMABLE_LIGHT_H + +#if defined ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT Dimmable Light + * @ingroup ZB_HA_DEVICES + * @{ + @details + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + +*/ + +/******************* Specific definitions for window covering device **************************/ + +#define ZB_HA_DEVICE_VER_DIMMABLE_LIGHT 1 /*!< Dimmable light device version */ + +/** @cond internals_doc */ + +#define ZB_HA_DIMMABLE_LIGHT_IN_CLUSTER_NUM 6 /*!< Dimmable Light IN (server) clusters number */ +#define ZB_HA_DIMMABLE_LIGHT_OUT_CLUSTER_NUM 0 /*!< Dimmable Light OUT (client) clusters number */ + +/** Dimmable light total (IN+OUT) cluster number */ +#define ZB_HA_DIMMABLE_LIGHT_CLUSTER_NUM \ + (ZB_HA_DIMMABLE_LIGHT_IN_CLUSTER_NUM + ZB_HA_DIMMABLE_LIGHT_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Dimmable Light device */ +#define ZB_HA_DIMMABLE_LIGHT_REPORT_ATTR_COUNT \ + (ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT + ZB_ZCL_LEVEL_CONTROL_REPORT_ATTR_COUNT) + +#define ZB_HA_DIMMABLE_LIGHT_CVC_ATTR_COUNT 1 + +/** @endcond */ + +/*! + @brief Declare cluster list for Dimmable Light device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param on_off_attr_list - attribute list for On/Off cluster + @param level_control_attr_list - attribute list for Level Control cluster + */ +#define ZB_HA_DECLARE_DIMMABLE_LIGHT_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list, \ + on_off_attr_list, \ + level_control_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(level_control_attr_list, zb_zcl_attr_t), \ + (level_control_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! @cond internals_doc */ +/*! + @brief Declare simple descriptor for Dimmable Light device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_HA_DIMMABLE_LIGHT_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_DIMMABLE_LIGHT_DEVICE_ID, \ + ZB_HA_DEVICE_VER_DIMMABLE_LIGHT, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + } \ + } + +/*! @endcond */ + +/*! + @brief Declare endpoint for Dimmable Light device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +/* TODO: add scenes? */ +#define ZB_HA_DECLARE_DIMMABLE_LIGHT_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_HA_DIMMABLE_LIGHT_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_DIMMABLE_LIGHT_IN_CLUSTER_NUM, ZB_HA_DIMMABLE_LIGHT_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_DIMMABLE_LIGHT_REPORT_ATTR_COUNT); \ + ZBOSS_DEVICE_DECLARE_LEVEL_CONTROL_CTX(cvc_alarm_info## device_ctx_name, \ + ZB_HA_DIMMABLE_LIGHT_CVC_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_DIMMABLE_LIGHT_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, \ + ZB_HA_DIMMABLE_LIGHT_CVC_ATTR_COUNT, \ + cvc_alarm_info## device_ctx_name) + +/** + @brief Declare application's device context for Dimmable Light device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_DIMMABLE_LIGHT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_DIMMABLE_LIGHT */ + +#endif /* ! defined ZB_HA_DIMMABLE_LIGHT_H */ diff --git a/zboss/include/ha/zb_ha_dimmer_switch.h b/zboss/include/ha/zb_ha_dimmer_switch.h new file mode 100644 index 0000000000..1126ec9669 --- /dev/null +++ b/zboss/include/ha/zb_ha_dimmer_switch.h @@ -0,0 +1,207 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Dimmer Switch device definition +*/ + +#ifndef ZB_HA_DIMMER_SWITCH_H +#define ZB_HA_DIMMER_SWITCH_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_DIMMER_SWITCH || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_DIMMER_SWITCH Dimmer Switch + * @ingroup ZB_HA_DEVICES + * @{ + @details + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + +*/ + +#define ZB_HA_DEVICE_VER_DIMMER_SWITCH 0 /*!< Dimmer Switch device version */ + +/** @cond internals_doc */ + +#define ZB_HA_DIMMER_SWITCH_IN_CLUSTER_NUM 2 /*!< Dimmer Switch IN (server) clusters number */ +#define ZB_HA_DIMMER_SWITCH_OUT_CLUSTER_NUM 5 /*!< Dimmer Switch OUT (client) clusters number */ + +/** Dimmer switch total (IN+OUT) cluster number */ +#define ZB_HA_DIMMER_SWITCH_CLUSTER_NUM \ + (ZB_HA_DIMMER_SWITCH_IN_CLUSTER_NUM + ZB_HA_DIMMER_SWITCH_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Dimmer Switch device */ +#define ZB_HA_DIMMER_SWITCH_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/** @brief Declare cluster list for Dimmer Switch device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_DIMMER_SWITCH_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for Dimmer switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_DIMMER_SWITCH_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_DIMMER_SWITCH_DEVICE_ID, \ + ZB_HA_DEVICE_VER_DIMMER_SWITCH, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for Dimmer Switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_DIMMER_SWITCH_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_DIMMER_SWITCH_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_DIMMER_SWITCH_IN_CLUSTER_NUM, ZB_HA_DIMMER_SWITCH_OUT_CLUSTER_NUM); \ + \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + + +/*! + @brief Declare application's device context for Dimmer Switch device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ + +#define ZB_HA_DECLARE_DIMMER_SWITCH_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_DIMMER_SWITCH */ + +#endif /* ZB_HA_DIMMER_SWITCH_H */ diff --git a/zboss/include/ha/zb_ha_door_lock.h b/zboss/include/ha/zb_ha_door_lock.h new file mode 100644 index 0000000000..6a12ed8e31 --- /dev/null +++ b/zboss/include/ha/zb_ha_door_lock.h @@ -0,0 +1,222 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Door lock device definition +*/ + +#ifndef ZB_HA_DOOR_LOCK_H +#define ZB_HA_DOOR_LOCK_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_DOOR_LOCK || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_door_lock Door Lock + * @addtogroup ha_door_lock + * @ingroup ZB_HA_DEVICES + @{ + @details + Door Lock device has 5 clusters (see spec 7.4.11): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_DOOR_LOCK \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + Door Lock device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/door_lock/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/door_lock/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/door_lock/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Door Lock device samples can be found in /application/HA_samples/door_lock +*/ + +#define ZB_HA_DEVICE_VER_DOOR_LOCK 0 /*!< Door Lock device version */ + +/** @cond internal */ + +#define ZB_HA_DOOR_LOCK_IN_CLUSTER_NUM 5 /*!< @internal Door Lock IN clusters number */ +#define ZB_HA_DOOR_LOCK_OUT_CLUSTER_NUM 0 /*!< @internal Door Lock OUT clusters number */ + +/** @internal @brief Number of clusters for DoorLock HA device. */ +#define ZB_HA_DOOR_LOCK_CLUSTER_NUM \ + (ZB_HA_DOOR_LOCK_IN_CLUSTER_NUM + ZB_HA_DOOR_LOCK_OUT_CLUSTER_NUM) + + +/** @internal @brief Number of attribute for reporting on Door Lock device */ +#define ZB_HA_DOOR_LOCK_REPORT_ATTR_COUNT (ZB_ZCL_DOOR_LOCK_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for Door Lock device. + * @param cluster_list_name - cluster list variable name + * @param door_lock_attr_list - attribute list for On/off switch configuration cluster + * @param basic_attr_list - attribute list for Basic cluster + * @param identify_attr_list - attribute list for Identify cluster + * @param groups_attr_list - attribute list for Groups cluster + * @param scenes_attr_list - attribute list for Scenes cluster + */ +#define ZB_HA_DECLARE_DOOR_LOCK_CLUSTER_LIST( \ + cluster_list_name, \ + door_lock_attr_list, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_ARRAY_SIZE(door_lock_attr_list, zb_zcl_attr_t), \ + (door_lock_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for Door Lock device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters + @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + definitions, because these values are used to form simple descriptor type name +*/ +#define ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_DOOR_LOCK_DEVICE_ID, \ + ZB_HA_DEVICE_VER_DOOR_LOCK, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpointy for Door Lock device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_DOOR_LOCK_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_DOOR_LOCK_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_DOOR_LOCK_IN_CLUSTER_NUM, ZB_HA_DOOR_LOCK_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_DOOR_LOCK_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_DOOR_LOCK_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, \ + 0, NULL) + + +/** @brief Declares Door Lock device context. + * @param device_ctx - device context variable name. + * @param ep_name - endpoint variable name. + */ +#define ZB_HA_DECLARE_DOOR_LOCK_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/** @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_DOOR_LOCK */ + +#endif /* ZB_HA_DOOR_LOCK_H */ diff --git a/zboss/include/ha/zb_ha_door_lock_controller.h b/zboss/include/ha/zb_ha_door_lock_controller.h new file mode 100644 index 0000000000..744dffba27 --- /dev/null +++ b/zboss/include/ha/zb_ha_door_lock_controller.h @@ -0,0 +1,216 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Door lock controller device definition +*/ + +#ifndef ZB_HA_DOOR_LOCK_CONTROLLER_H +#define ZB_HA_DOOR_LOCK_CONTROLLER_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_DOOR_LOCK_CONTROLLER || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_door_lock_controller Door Lock Controller + * @ingroup ZB_HA_DEVICES + @{ + @details + Door Lock Controller device has 5 clusters (see spec 7.4.12): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_DOOR_LOCK \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + Door Lock Controller device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/door_lock_controller/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/door_lock_controller/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/door_lock_controller/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/door_lock_controller/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Door Lock Controller device samples can be found in /application/HA_samples/door_lock_controller +*/ + +#define ZB_HA_DEVICE_VER_DOOR_LOCK_CONTROLLER 0 /*!< Door Lock Controller device version */ + +/** @cond internals_doc */ + +#define ZB_HA_DOOR_LOCK_CONTROLLER_IN_CLUSTER_NUM 2 /*!< Door Lock Controller IN clusters number */ + +#define ZB_HA_DOOR_LOCK_CONTROLLER_OUT_CLUSTER_NUM 4 /*!< Door Lock Controller OUT clusters number */ + +#define ZB_HA_DOOR_LOCK_CONTROLLER_CLUSTER_NUM \ + (ZB_HA_DOOR_LOCK_CONTROLLER_IN_CLUSTER_NUM + ZB_HA_DOOR_LOCK_CONTROLLER_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Door Lock Controller device */ +#define ZB_HA_DOOR_LOCK_CONTROLLER_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/** @brief Declare cluster list for Door Lock Controller device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_DOOR_LOCK_CONTROLLER_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/** Declare simple descriptor for Door Lock Controller output device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters + @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + definitions, because these values are used to form simple descriptor type name +*/ +#define ZB_ZCL_DECLARE_DOOR_LOCK_CONTROLLER_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_DOOR_LOCK_CONTROLLER_DEVICE_ID, \ + ZB_HA_DEVICE_VER_DOOR_LOCK_CONTROLLER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpointy for Door Lock Controller device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_DOOR_LOCK_CONTROLLER_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_DOOR_LOCK_CONTROLLER_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_DOOR_LOCK_CONTROLLER_IN_CLUSTER_NUM, ZB_HA_DOOR_LOCK_CONTROLLER_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, 0, NULL) + +/** @brief Declare Door Lock Controller device context. + * @param device_ctx - device context variable name. + * @param ep_name - endpoint definition variable name. + */ +#define ZB_HA_DECLARE_DOOR_LOCK_CONTROLLER_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_DOOR_LOCK_CONTROLLER */ + +#endif /* ZB_HA_DOOR_LOCK_CONTROLLER_H */ diff --git a/zboss/include/ha/zb_ha_gp_dev.h b/zboss/include/ha/zb_ha_gp_dev.h new file mode 100644 index 0000000000..d1bfcfad66 --- /dev/null +++ b/zboss/include/ha/zb_ha_gp_dev.h @@ -0,0 +1,150 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Simple sensor device definition +*/ + +#ifndef ZB_HA_GP_DEV_H +#define ZB_HA_GP_DEV_H 1 + +#ifdef ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR + +#define ZB_HA_GP_DEV_DEVICE_ID 0x2020 + +#define ZB_HA_DEVICE_VER_GP_DEV 0 /*!< device version */ + +#define ZB_HA_GP_DEV_IN_CLUSTER_NUM 2 /*!< Simple Sensor IN (server) clusters number */ +#define ZB_HA_GP_DEV_OUT_CLUSTER_NUM 1 /*!< Simple Sensor OUT (client) clusters number */ + +#define ZB_HA_GP_DEV_CLUSTER_NUM (ZB_HA_GP_DEV_IN_CLUSTER_NUM + ZB_HA_GP_DEV_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Simple Sensor device */ +#define ZB_HA_GP_DEV_REPORT_ATTR_COUNT \ + (ZB_ZCL_BINARY_INPUT_REPORT_ATTR_COUNT) + +/*! + @brief Declare cluster list for Simple Sensor device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param binary_input_list - attribute list for Binary Input cluster + */ +#define ZB_HA_DECLARE_GP_DEV_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + binary_input_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_ARRAY_SIZE(binary_input_attr_list, zb_zcl_attr_t), \ + (binary_input_attr_list), \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! + @brief Declare simple descriptor for device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_GP_DEV_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_GP_DEV_DEVICE_ID, \ + ZB_HA_DEVICE_VER_GP_DEV, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_BINARY_INPUT \ + } \ + } + +/*! + @brief Declare endpoint for Simple Sensor device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_GP_DEV_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_GP_DEV_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_GP_DEV_IN_CLUSTER_NUM, ZB_HA_GP_DEV_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_GP_DEV_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_GP_DEV_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, 0, NULL) + + +#define ZB_HA_DECLARE_GP_DEV_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +#endif /* ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR */ + + +#endif /* ZB_HA_GP_DEV_H */ diff --git a/zboss/include/ha/zb_ha_ias_ancillary_control_equipment.h b/zboss/include/ha/zb_ha_ias_ancillary_control_equipment.h new file mode 100644 index 0000000000..2ccdce8468 --- /dev/null +++ b/zboss/include/ha/zb_ha_ias_ancillary_control_equipment.h @@ -0,0 +1,221 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Ancillary Control Equipment device definition +*/ + +#if ! defined ZB_HA_IAS_ANCILLARY_H +#define ZB_HA_IAS_ANCILLARY_H + +#if defined ZB_HA_DEFINE_DEVICE_IAS_ANCILLARY_CONTROL_EQUIPMENT || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_IAS_ANCILLARY IAS Ancillary Control Equipment + * @ingroup ZB_HA_DEVICES + * @{ + @details + IAS Ancillary Control Equipment has 5 clusters (see spec 7.8.2): \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_IAS_ZONE \n + - @ref ZB_ZCL_IAS_ACE \n + - @ref ZB_ZCL_IDENTIFY + + IAS Ancillary Control Equipment sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/common/zcl_ias_zone_attr_list.h IAS_ZONE_CLUSTER_COMMON + @snippet HA_samples/ias_ancillary_control_equipment/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/ias_ancillary_control_equipment/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/ias_ancillary_control_equipment/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/ias_ancillary_control_equipment/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of IAS Ancillary Control Equipment samples can be found in /application/HA_samples/ias_ancillary_control_equipment +*/ + +#define ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_VER 0 /*!< IAS ACE device version */ + +/** @cond internal */ + +/** Input clusters number. */ +#define ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_IN_CLUSTER_NUM 3 + +/** Output clusters number. */ +#define ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_OUT_CLUSTER_NUM 2 + +/*! Number of attribute for reporting on IAS Ancillary Control Equipment device */ +#define ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_REPORT_ATTR_COUNT \ + (ZB_ZCL_IAS_ZONE_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** + * @brief Declare cluster list for IAS Ancillary Control Equipment + * @param cluster_list_name [IN] - cluster list variable name. + * @param basic_attr_list [IN] - attribute list for Basic cluster. + * @param identify_attr_list [IN] - attribute list for Identify cluster. + * @param ias_zone_attr_list [IN] - attribute list for IAS Zone cluster + */ +#define ZB_HA_DECLARE_IAS_ANCILLARY_CONTROL_EQUIPMENT_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + ias_zone_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_ARRAY_SIZE(ias_zone_attr_list, zb_zcl_attr_t), \ + (ias_zone_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IAS_ACE, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ) \ + } + +/** + * @brief Declare simple descriptor for IAS Ancillary Control Equipment + * @param ep_name - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param in_clust_num [IN] - number of supported input clusters. + * @param out_clust_num [IN] - number of supported output clusters. + * @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + * definitions, because these values are used to form simple descriptor type name. + */ +#define ZB_HA_DECLARE_IAS_ANCILLARY_CONTROL_EQUIPMENT_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_ZLL_PROFILE_ID, \ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_ID, \ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_VER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** + * @brief Declare endpoint for IAS Ancillary Control Equipment + * @param ep_name [IN] - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param cluster_list [IN] - endpoint cluster list. + */ +#define ZB_HA_DECLARE_IAS_ANCILLARY_CONTROL_EQUIPMENT_EP(ep_name, ep_id, cluster_list) \ + ZB_HA_DECLARE_IAS_ANCILLARY_CONTROL_EQUIPMENT_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_IN_CLUSTER_NUM, \ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_IAS_ANCILLARY_CONTROL_EQUIPMENT_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL) + +/** + @brief Declare application's device context for Ansillary Control Equipment + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_IAS_ANCILLARY_CONTROL_EQUIPMENT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/** + * @} + */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* defined ZB_HA_DEFINE_DEVICE_IAS_ANCILLARY_CONTROL_EQUIPMENT || defined DOXYGEN */ + +#endif /* ! defined ZB_HA_IAS_ANCILLARY_H */ diff --git a/zboss/include/ha/zb_ha_ias_control_indicating_equipment.h b/zboss/include/ha/zb_ha_ias_control_indicating_equipment.h new file mode 100644 index 0000000000..5f555fdefb --- /dev/null +++ b/zboss/include/ha/zb_ha_ias_control_indicating_equipment.h @@ -0,0 +1,225 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Control and Indicating Equipment device definition +*/ + +#if ! defined ZB_HA_IAS_CONTR_INDICATION_H +#define ZB_HA_IAS_CONTR_INDICATION_H + +#if defined ZB_HA_DEFINE_DEVICE_IAS_CONTROL_INDICATING_EQUIPMENT || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_IAS_CONTR_INDICATION IAS Control and Indicating Equipment + * @ingroup ZB_HA_DEVICES + * @{ + @details + IAS Control and Indicating Equipment has 7 clusters (see spec 7.8.1): \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_IAS_ACE \n + - @ref ZB_ZCL_IAS_WD \n + - @ref ZB_ZCL_IAS_ZONE \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + IAS Control and Indicating Equipment sample + + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/common/zcl_ias_zone_attr_list.h IAS_ZONE_CLUSTER_COMMON + @snippet HA_samples/ias_control_indicating_equipment/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/ias_control_indicating_equipment/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/ias_control_indicating_equipment/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/ias_control_indicating_equipment/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of IAS Control and Indicating Equipment samples can be found in /application/HA_samples/ias_control_indicating_equipment +*/ + +#define ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_VER 0 /*!< IAS ACE device version */ + +/** @cond internals_doc */ + +/** Input clusters number. */ +#define ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_IN_CLUSTER_NUM 3 + +/** Output clusters number. */ +#define ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_OUT_CLUSTER_NUM 5 + +/** @endcond */ + +/** + * @brief Declare cluster list for IAS Control and Indicating Equipment + * @param cluster_list_name [IN] - cluster list variable name. + * @param basic_attr_list [IN] - attribute list for Basic cluster. + * @param identify_attr_list [IN] - attribute list for Identify cluster. + * @param ias_ace_attr_list [IN] - attribute list for IAS ACE cluster. + */ +#define ZB_HA_DECLARE_IAS_CONTROL_INDICATING_EQUIPMENT_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + ias_ace_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, \ + ZB_ZCL_ARRAY_SIZE(ias_ace_attr_list, zb_zcl_attr_t), \ + (ias_ace_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IAS_WD, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IAS_ZONE, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_SCENES, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_GROUPS, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ) \ + } + +/** + * @brief Declare simple descriptor for IAS Control and Indicating Equipment + * @param ep_name - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param in_clust_num [IN] - number of supported input clusters. + * @param out_clust_num [IN] - number of supported output clusters. + * @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + * definitions, because these values are used to form simple descriptor type name. + */ +#define ZB_HA_DECLARE_IAS_CONTROL_INDICATING_EQUIPMENT_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_ZLL_PROFILE_ID, \ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_ID, \ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_VER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, \ + ZB_ZCL_CLUSTER_ID_IAS_WD, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** + * @brief Declare endpoint for IAS Control and Indicating Equipment + * @param ep_name [IN] - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param cluster_list [IN] - endpoint cluster list. + */ +#define ZB_HA_DECLARE_IAS_CONTROL_INDICATING_EQUIPMENT_EP(ep_name, ep_id, cluster_list) \ + ZB_HA_DECLARE_IAS_CONTROL_INDICATING_EQUIPMENT_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_IN_CLUSTER_NUM, \ + ZB_HA_IAS_CONTROL_INDICATING_EQUIPMENT_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +/** + * @brief Declare application's device context for IAS Control Indicating Equipment + * @param device_ctx - device context variable + * @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_IAS_CONTROL_INDICATING_EQUIPMENT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/** + * @} + */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* defined ZB_HA_DEFINE_DEVICE_IAS_CONTROL_INDICATING_EQUIPMENT || defined DOXYGEN */ + +#endif /* ! defined ZB_HA_IAS_CONTR_INDICATION_H */ diff --git a/zboss/include/ha/zb_ha_ias_warning_device.h b/zboss/include/ha/zb_ha_ias_warning_device.h new file mode 100644 index 0000000000..02dc7a0f4d --- /dev/null +++ b/zboss/include/ha/zb_ha_ias_warning_device.h @@ -0,0 +1,230 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Warning Device +*/ + +#if ! defined ZB_HA_IAS_WARNING_H +#define ZB_HA_IAS_WARNING_H + +#if defined ZB_HA_DEFINE_DEVICE_IAS_WARNING_DEVICE || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_IAS_WARNING IAS Warning Device + * @ingroup ZB_HA_DEVICES + * @{ + @details + IAS Warning Device has 6 clusters (see spec 7.8.4): \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_IAS_WD \n + - @ref ZB_ZCL_IAS_ZONE \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS \n + + Sample use IAS Warning Device + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/common/zcl_ias_zone_attr_list.h IAS_ZONE_CLUSTER_COMMON + @snippet HA_samples/ias_warning_device/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/ias_warning_device/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/ias_warning_device/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/ias_warning_device/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + See application/HA_samples/ias_warning_device sample +*/ + +#define ZB_HA_IAS_WARNING_VER 0 /**< Device version */ + +#define ZB_HA_IAS_WARNING_IN_CLUSTER_NUM 6 /**< Input clusters number. */ +#define ZB_HA_IAS_WARNING_OUT_CLUSTER_NUM 0 /**< Output clusters number. */ + +/*! @internal Number of attribute for reporting on IAS Warning device */ +#define ZB_HA_IAS_WARNING_REPORT_ATTR_COUNT \ + (ZB_ZCL_IAS_ZONE_REPORT_ATTR_COUNT + ZB_ZCL_IAS_WD_REPORT_ATTR_COUNT) + +/** + * @brief Declare cluster list for IAS Warning device. + * @param cluster_list_name [IN] - cluster list variable name. + * @param basic_attr_list [IN] - attribute list for Basic cluster. + * @param identify_attr_list [IN] - attribute list for Identify cluster. + * @param ias_wd_attr_list [IN] - attribute list for IAS WD cluster. + * @param ias_zone_attr_list [IN] - attribute list for IAS Zone cluster. + * @param scenes_attr_list [IN] - attribute list for Scenes cluster. + * @param groups_attr_list [IN] - attribute list for Groups cluster. + */ +#define ZB_HA_DECLARE_IAS_WARNING_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + ias_wd_attr_list, \ + ias_zone_attr_list, \ + scenes_attr_list, \ + groups_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IAS_WD, \ + ZB_ZCL_ARRAY_SIZE(ias_wd_attr_list, zb_zcl_attr_t), \ + (ias_wd_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_ARRAY_SIZE(ias_zone_attr_list, zb_zcl_attr_t), \ + (ias_zone_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + } + +/** + * @brief Declare simple descriptor for IAS Warning device. + * @param ep_name - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param in_clust_num [IN] - number of supported input clusters. + * @param out_clust_num [IN] - number of supported output clusters. + * @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + * definitions, because these values are used to form simple descriptor type name. + */ +#define ZB_HA_DECLARE_IAS_WARNING_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) \ + simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_IAS_WARNING_DEVICE_ID, \ + ZB_HA_IAS_WARNING_VER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_IAS_WD, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + } \ + } + +/** + * @brief Declare endpoint for IAS Warning device. + * @param ep_name [IN] - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param cluster_list [IN] - endpoint cluster list. + */ +#define ZB_HA_DECLARE_IAS_WARNING_EP(ep_name, ep_id, cluster_list) \ + ZB_HA_DECLARE_IAS_WARNING_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_IAS_WARNING_IN_CLUSTER_NUM, \ + ZB_HA_IAS_WARNING_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_IAS_WARNING_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_IAS_WARNING_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL) + +#define ZB_HA_DECLARE_IAS_WARNING_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/** + * @} + */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* defined ZB_HA_DEFINE_DEVICE_IAS_WARNING_DEVICE || defined DOXYGEN */ + +#endif /* ! defined ZB_HA_IAS_WARNING_H */ diff --git a/zboss/include/ha/zb_ha_ias_zone.h b/zboss/include/ha/zb_ha_ias_zone.h new file mode 100644 index 0000000000..31aa918582 --- /dev/null +++ b/zboss/include/ha/zb_ha_ias_zone.h @@ -0,0 +1,233 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Ancillary Control Equipment device definition +*/ + +#if ! defined ZB_HA_IAS_ZONE_H +#define ZB_HA_IAS_ZONE_H + +#if defined ZB_HA_DEFINE_DEVICE_IAS_ZONE || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_IAS_ZONE IAS Zone + * @ingroup ZB_HA_DEVICES + * @{ + @details + IAS Zone has 6 clusters (see spec 7.8.3): \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_IAS_ZONE \n + - @ref ZB_ZCL_POLL_CONTROL \n + - @ref ZB_ZCL_POWER_CONFIG \n + - @ref ZB_ZCL_OTA_UPGRADE \n + + IAS Zone sample + + @par Example + Declaring clusters + @snippet ias_zone_sensor/src/izs_device.c COMMON_DECLARATION + Registering device list + @snippet ias_zone_sensor/src/izs_device.c REGISTER + Example of command handler + @snippet ias_zone_sensor/src/izs_device.c HANDLER + @par + + The complete set of IAS Zone samples can be found in /application/ias_zone_sensor +*/ + +/** HA IAS Zone device version */ +#define ZB_HA_IAS_ZONE_VER 0 + +/** @cond internals_doc */ +/** Input clusters number. */ +#define ZB_HA_IAS_ZONE_IN_CLUSTER_NUM 5 + +/** Output clusters number. */ +#define ZB_HA_IAS_ZONE_OUT_CLUSTER_NUM 1 + +/*! @internal Number of attribute for reporting on IAS Zone device */ +#define ZB_HA_IAS_ZONE_REPORT_ATTR_COUNT \ + (ZB_ZCL_IAS_ZONE_REPORT_ATTR_COUNT + ZB_ZCL_POWER_CONFIG_REPORT_ATTR_COUNT) + +/** @endcond */ +/** + * @brief Declare cluster list for IAS Zone + * @param cluster_list_name [IN] - cluster list variable name. + * @param basic_attr_list [IN] - attribute list for Basic cluster. + * @param identify_attr_list [IN] - attribute list for Identify cluster. + * @param ias_zone_attr_list [IN] - attribute list for IAS Zone cluster. + * @param poll_ctrl_attr_list [IN] - attribute list for Poll Control cluster. + * @param power_config_attr_list [IN] - attribute list for Power configuration cluster. + * @param ota_upgrade_attr_list [IN] - attribute list for Over The Air cluster. + */ +#define ZB_HA_DECLARE_IAS_ZONE_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + ias_zone_attr_list, \ + poll_ctrl_attr_list, \ + power_config_attr_list, \ + ota_upgrade_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_ARRAY_SIZE(ias_zone_attr_list, zb_zcl_attr_t), \ + (ias_zone_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(poll_ctrl_attr_list, zb_zcl_attr_t), \ + (poll_ctrl_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_POWER_CONFIG, \ + ZB_ZCL_ARRAY_SIZE(power_config_attr_list, zb_zcl_attr_t), \ + (power_config_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, \ + ZB_ZCL_ARRAY_SIZE(ota_upgrade_attr_list, zb_zcl_attr_t), \ + (ota_upgrade_attr_list), \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** + * @brief Declare simple descriptor for IAS Zone + * @param ep_name - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param in_clust_num [IN] - number of supported input clusters. + * @param out_clust_num [IN] - number of supported output clusters. + * @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + * definitions, because these values are used to form simple descriptor type name. + */ +#define ZB_HA_DECLARE_IAS_ZONE_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) \ + simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_IAS_ZONE_ID, \ + ZB_HA_IAS_ZONE_VER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, \ + ZB_ZCL_CLUSTER_ID_POWER_CONFIG, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE \ + } \ + } + +/** + * @brief Declare endpoint for IAS Ancillary Control Equipment + * @param ep_name [IN] - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param cluster_list [IN] - endpoint cluster list. + */ +#define ZB_HA_DECLARE_IAS_ZONE_EP(ep_name, ep_id, cluster_list) \ + ZB_HA_DECLARE_IAS_ZONE_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_IAS_ZONE_IN_CLUSTER_NUM, \ + ZB_HA_IAS_ZONE_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_IAS_ZONE_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_IAS_ZONE_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, \ + 0, NULL) + +/** + @brief Declare application's device context for IAS Zone device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_IAS_ZONE_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/** + * @} + */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* defined ZB_HA_DEFINE_DEVICE_IAS_ZONE_CONTROL_EQUIPMENT || defined DOXYGEN */ + +#endif /* ! defined ZB_HA_IAS_ZONE_H */ diff --git a/zboss/include/ha/zb_ha_level_control_switch.h b/zboss/include/ha/zb_ha_level_control_switch.h new file mode 100644 index 0000000000..5cd2df6b34 --- /dev/null +++ b/zboss/include/ha/zb_ha_level_control_switch.h @@ -0,0 +1,202 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Level control switch device definition +*/ + +#ifndef ZB_HA_LEVEL_CONTROL_SWITCH_H +#define ZB_HA_LEVEL_CONTROL_SWITCH_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_LEVEL_CONTROL_SWITCH || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_level_control_switch Level Control Switch + * @ingroup ZB_HA_DEVICES + @{ + Level Control Switch device has 4 clusters (see spec 7.4.8): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + + Sample use Level Control Switch device + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/level_control_switch/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/level_control_switch/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/level_control_switch/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/level_control_switch/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + See application/HA_samples/level_control_switch sample + */ + +#define ZB_HA_DEVICE_VER_LEVEL_CONTROL_SWITCH 0 /*!< Level Control Switch device version */ + +#define ZB_HA_LEVEL_CONTROL_SWITCH_IN_CLUSTER_NUM 2 /*!< @internal Level Control Switch IN + (server) clusters number */ +#define ZB_HA_LEVEL_CONTROL_SWITCH_OUT_CLUSTER_NUM 3 /*!< @internal Level Control Switch OUT + (client) clusters number */ + +#define ZB_HA_LEVEL_CONTROL_SWITCH_CLUSTER_NUM \ + (ZB_HA_LEVEL_CONTROL_SWITCH_IN_CLUSTER_NUM + ZB_HA_LEVEL_CONTROL_SWITCH_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Level Control Switch device */ +#define ZB_HA_LEVEL_CONTROL_SWITCH_REPORT_ATTR_COUNT 0 + +/** @brief Declare cluster list for Level Control Switch device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_LEVEL_CONTROL_SWITCH_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + +/** @brief Declare simple descriptor for Level control switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_LEVEL_CONTROL_SWITCH_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_LEVEL_CONTROL_SWITCH_DEVICE_ID, \ + ZB_HA_DEVICE_VER_LEVEL_CONTROL_SWITCH, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @brief Declare endpoint for Level Control Switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_LEVEL_CONTROL_SWITCH_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_LEVEL_CONTROL_SWITCH_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_LEVEL_CONTROL_SWITCH_IN_CLUSTER_NUM, ZB_HA_LEVEL_CONTROL_SWITCH_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + + +/*! + @brief Declare application's device context for Level Control Switch device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ + +#define ZB_HA_DECLARE_LEVEL_CONTROL_SWITCH_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_LEVEL_CONTROL_SWITCH */ + +#endif /* ZB_HA_LEVEL_CONTROL_SWITCH_H */ diff --git a/zboss/include/ha/zb_ha_level_controllable_output.h b/zboss/include/ha/zb_ha_level_controllable_output.h new file mode 100644 index 0000000000..d4521adffa --- /dev/null +++ b/zboss/include/ha/zb_ha_level_controllable_output.h @@ -0,0 +1,237 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Level controllable output for HA profile +*/ + +#ifndef ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_H +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_LEVEL_CONTROLLABLE_OUTPUT || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_level_controllable_output Level Controllable Output + * @ingroup ZB_HA_DEVICES + @{ + @details + Level Control device has 6 clusters (see spec 7.4.4): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + + Sample use Level Control device + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/level_controllable_output/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/level_controllable_output/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/level_controllable_output/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/level_controllable_output/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Level Control device samples can be found in /application/HA_samples/level_control_output +*/ + +/*!< Level Controllable Output device version */ +#define ZB_HA_DEVICE_VER_LEVEL_CONTROLLABLE_OUTPUT 0 + +/*!< Level Controllable Output IN (server) clusters number */ +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_IN_CLUSTER_NUM 6 + +/*!< Level Controllable Output OUT (client) clusters number */ +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_OUT_CLUSTER_NUM 0 + +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_CLUSTER_NUM \ + ( ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_IN_CLUSTER_NUM \ + + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_OUT_CLUSTER_NUM) + +/** @internal @brief Number of attribute for reporting on Level Controllable Output device */ +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_REPORT_ATTR_COUNT \ + (ZB_ZCL_LEVEL_CONTROL_REPORT_ATTR_COUNT + ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT) + +#define ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_CVC_ATTR_COUNT 1 + +/** @brief Declare cluster list for Level Controllable Output device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param groups_attr_list - attribute list for Groups cluster + @param on_off_attr_list - attribute list for On/Off cluster + @param level_control_attr_list - attribute list for Level Control cluster + */ +#define ZB_HA_DECLARE_LEVEL_CONTROLLABLE_OUTPUT_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + scenes_attr_list, \ + groups_attr_list, \ + on_off_attr_list, \ + level_control_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(level_control_attr_list, zb_zcl_attr_t), \ + (level_control_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + + +/** @internal @brief Declare simple descriptor for Level Controllable Output device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_LEVEL_CONTROLLABLE_OUTPUT_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_DEVICE_ID, \ + ZB_HA_DEVICE_VER_LEVEL_CONTROLLABLE_OUTPUT, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL \ + } \ + } + +/** @brief Declare endpoint for Level Controllable Output device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_LEVEL_CONTROLLABLE_OUTPUT_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_LEVEL_CONTROLLABLE_OUTPUT_SIMPLE_DESC(ep_name, \ + ep_id, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_IN_CLUSTER_NUM, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_REPORT_ATTR_COUNT); \ + ZBOSS_DEVICE_DECLARE_LEVEL_CONTROL_CTX(cvc_alarm_info## device_ctx_name, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_CVC_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, \ + ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_CVC_ATTR_COUNT, \ + cvc_alarm_info## device_ctx_name) + +/*! + @brief Declare application's device context for Level Control Switch device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ + +#define ZB_HA_DECLARE_LEVEL_CONTROLLABLE_OUTPUT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_LEVEL_CONTROLLABLE_OUTPUT */ + +#endif /* ZB_HA_LEVEL_CONTROLLABLE_OUTPUT_H */ diff --git a/zboss/include/ha/zb_ha_mains_power_outlet.h b/zboss/include/ha/zb_ha_mains_power_outlet.h new file mode 100644 index 0000000000..a4d8b1eb5e --- /dev/null +++ b/zboss/include/ha/zb_ha_mains_power_outlet.h @@ -0,0 +1,218 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Mains power outlet device definition +*/ + +#ifndef ZB_HA_MAINS_POWER_OUTLET_H +#define ZB_HA_MAINS_POWER_OUTLET_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_MAINS_POWER_OUTLET || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_mains_power_outlet Mains Power Outlet + * @ingroup ZB_HA_DEVICES + @{ + @details + Mains Power Outlet device has 5 clusters (see spec 7.4.10): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + Mains Power Outlet device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/mains_power_outlet/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/mains_power_outlet/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/mains_power_outlet/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/mains_power_outlet/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Mains Power Outlet device samples can be found in application/HA_samples/mains_power_outlet +*/ + +#define ZB_HA_DEVICE_VER_MAINS_POWER_OUTLET 0 /*!< Mains power outlet device version */ + +/** @cond internals_doc */ + +#define ZB_HA_MAINS_POWER_OUTLET_IN_CLUSTER_NUM 5 /*!< Mains power outlet IN (server) + clusters number */ +#define ZB_HA_MAINS_POWER_OUTLET_OUT_CLUSTER_NUM 0 /*!< Mains power outlet OUT (client) + clusters number */ + +#define ZB_HA_MAINS_POWER_OUTLET_CLUSTER_NUM \ + (ZB_HA_MAINS_POWER_OUTLET_IN_CLUSTER_NUM + ZB_HA_MAINS_POWER_OUTLET_OUT_CLUSTER_NUM) + +/** Number of attribute for reporting on Mains power outlet device */ +#define ZB_HA_MAINS_POWER_OUTLET_REPORT_ATTR_COUNT \ + (ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for Mains power outlet device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param on_off_attr_list - attribute list for On/Off cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param groups_attr_list - attribute list for Groups cluster + */ +#define ZB_HA_DECLARE_MAINS_POWER_OUTLET_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + on_off_attr_list, \ + scenes_attr_list, \ + groups_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internal_doc */ + +/** @brief Declare simple descriptor for Mains power outlet device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_MAINS_POWER_OUTLET_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_MAINS_POWER_OUTLET_DEVICE_ID, \ + ZB_HA_DEVICE_VER_MAINS_POWER_OUTLET, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for Mains power outlet device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_MAINS_POWER_OUTLET_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_MAINS_POWER_OUTLET_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_MAINS_POWER_OUTLET_IN_CLUSTER_NUM, ZB_HA_MAINS_POWER_OUTLET_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_MAINS_POWER_OUTLET_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_MAINS_POWER_OUTLET_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL) + +/** @brief Declare Mains Power Outlet device context. + @param device_ctx - device context variable name. + @param ep_name - andloint variable name. + */ +#define ZB_HA_DECLARE_MAINS_POWER_OUTLET_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_MAINS_POWER_OUTLET */ + +#endif /* ZB_HA_MAINS_POWER_OUTLET_H */ diff --git a/zboss/include/ha/zb_ha_on_off_output.h b/zboss/include/ha/zb_ha_on_off_output.h new file mode 100644 index 0000000000..f3c996eae1 --- /dev/null +++ b/zboss/include/ha/zb_ha_on_off_output.h @@ -0,0 +1,229 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: On/Off output device definition +*/ + +#ifndef ZB_HA_ON_OFF_OUTPUT_H +#define ZB_HA_ON_OFF_OUTPUT_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_on_off_output On/Off Output + * @addtogroup ha_on_off_output + * @ingroup ZB_HA_DEVICES + @{ + @details + On/Off Output device has 5 clusters (see spec 7.4.3): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + On/Off Output device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/on_off_output/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/on_off_output/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/on_off_output/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/on_off_output/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + + The complete set of On/Off Output device samples can be found in /application/HA_samples/on_off_output +*/ + +#define ZB_HA_DEVICE_VER_ON_OFF_OUTPUT 0 /*!< On/Off Output device version */ + +/** @cond internals_doc */ +#define ZB_HA_ON_OFF_OUTPUT_IN_CLUSTER_NUM 5 /*!< On/Off output IN cluster number */ +#define ZB_HA_ON_OFF_OUTPUT_OUT_CLUSTER_NUM 0 /*!< On/Off output OUT cluster number */ + +#define ZB_HA_ON_OFF_OUTPUT_CLUSTER_NUM \ + (ZB_HA_ON_OFF_OUTPUT_IN_CLUSTER_NUM + ZB_HA_ON_OFF_OUTPUT_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on On/Off output device */ +#define ZB_HA_ON_OFF_OUTPUT_REPORT_ATTR_COUNT \ + (ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for On/Off output device + @param cluster_list_name - cluster list variable name + @param on_off_attr_list - attribute list for On/Off cluster + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + */ +#define ZB_HA_DECLARE_ON_OFF_OUTPUT_CLUSTER_LIST( \ + cluster_list_name, \ + on_off_attr_list, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ + +/** @brief Declare simple descriptor for On/Off output device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters + @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + definitions, because these values are used to form simple descriptor type name +*/ +#define ZB_ZCL_DECLARE_ON_OFF_OUTPUT_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_ON_OFF_OUTPUT_DEVICE_ID, \ + ZB_HA_DEVICE_VER_ON_OFF_OUTPUT, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + + /** @endcond */ + +/** @brief Declare endpoint for On/off output device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_ON_OFF_OUTPUT_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_ON_OFF_OUTPUT_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_ON_OFF_OUTPUT_IN_CLUSTER_NUM, \ + ZB_HA_ON_OFF_OUTPUT_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_ON_OFF_OUTPUT_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_ON_OFF_OUTPUT_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, \ + 0, NULL) + +/** @brief Declare On/Off Output device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. + */ +#define ZB_HA_DECLARE_ON_OFF_OUTPUT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_ON_OFF_OUTPUT */ + +#endif /* ZB_HA_ON_OFF_OUTPUT_H */ diff --git a/zboss/include/ha/zb_ha_on_off_switch.h b/zboss/include/ha/zb_ha_on_off_switch.h new file mode 100644 index 0000000000..691aefd0ab --- /dev/null +++ b/zboss/include/ha/zb_ha_on_off_switch.h @@ -0,0 +1,235 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: On/off switch device definition +*/ +#ifndef ZB_HA_ON_OFF_SWITCH_H +#define ZB_HA_ON_OFF_SWITCH_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_ON_OFF_SWITCH || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_on_off_switch On/Off Switch + * @ingroup ZB_HA_DEVICES + @{ + @details + On/Off Switch device has 6 clusters (see spec 7.4.1): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_OOSC \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + On/Off Switch device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/on_off_switch/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/on_off_switch/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/on_off_switch/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/on_off_switch/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of On/Off samples can be found in /application/HA_samples/on_off_switch +*/ + +/** @cond internals_doc */ +#define ZB_HA_DEVICE_VER_ON_OFF_SWITCH 0 /*!< On/Off Switch device version */ + +#define ZB_HA_ON_OFF_SWITCH_IN_CLUSTER_NUM 3 /*!< On/Off switch IN clusters number */ +#define ZB_HA_ON_OFF_SWITCH_OUT_CLUSTER_NUM 4 /*!< On/Off switch OUT clusters number */ + +#define ZB_HA_ON_OFF_SWITCH_CLUSTER_NUM \ + (ZB_HA_ON_OFF_SWITCH_IN_CLUSTER_NUM + ZB_HA_ON_OFF_SWITCH_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on On/Off switch device */ +#define ZB_HA_ON_OFF_SWITCH_REPORT_ATTR_COUNT \ + (ZB_ZCL_ON_OFF_SWITCH_CONFIG_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for On/Off switch device + @param cluster_list_name - cluster list variable name + @param on_off_switch_config_attr_list - attribute list for On/off switch configuration cluster + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_ON_OFF_SWITCH_CLUSTER_LIST( \ + cluster_list_name, \ + on_off_switch_config_attr_list, \ + basic_attr_list, \ + identify_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG, \ + ZB_ZCL_ARRAY_SIZE(on_off_switch_config_attr_list, zb_zcl_attr_t), \ + (on_off_switch_config_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for On/Off switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters + @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + definitions, because these values are used to form simple descriptor type name +*/ +#define ZB_ZCL_DECLARE_ON_OFF_SWITCH_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_ON_OFF_SWITCH_DEVICE_ID, \ + ZB_HA_DEVICE_VER_ON_OFF_SWITCH, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for On/off Switch device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_ON_OFF_SWITCH_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_ON_OFF_SWITCH_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_ON_OFF_SWITCH_IN_CLUSTER_NUM, \ + ZB_HA_ON_OFF_SWITCH_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +/** @brief Declare On/Off Switch device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_ON_OFF_SWITCH_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_ON_OFF_SWITCH */ + +#endif /* ZB_HA_ON_OFF_SWITCH_H */ diff --git a/zboss/include/ha/zb_ha_range_extender.h b/zboss/include/ha/zb_ha_range_extender.h new file mode 100644 index 0000000000..e892dd2913 --- /dev/null +++ b/zboss/include/ha/zb_ha_range_extender.h @@ -0,0 +1,181 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Range extender defice definition +*/ + +#ifndef ZB_HA_RANGE_EXTENDER_H +#define ZB_HA_RANGE_EXTENDER_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_RANGE_EXTENDER || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_range_extender Range Extender + * @ingroup ZB_HA_DEVICES + @{ + @details + Range Entender device has 2 clusters (see spec 7.4.8): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC + + Range Extender device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/range_extender/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/range_extender/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/range_extender/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/range_extender/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Range Extended device samples can be found in /application/HA_samples/range_extender +*/ + +#define ZB_HA_DEVICE_VER_RANGE_EXTENDER 0 /*!< Range extender device version */ + +/** @cond internals_doc */ +#define ZB_HA_RANGE_EXTENDER_IN_CLUSTER_NUM 2 /*!< Range extender IN (server) clusters + number */ +#define ZB_HA_RANGE_EXTENDER_OUT_CLUSTER_NUM 0 /*!< Range extender OUT (client) clusters + number */ + +#define ZB_HA_RANGE_EXTENDER_CLUSTER_NUM \ + (ZB_HA_RANGE_EXTENDER_IN_CLUSTER_NUM + ZB_HA_RANGE_EXTENDER_OUT_CLUSTER_NUM) + +/** Number of attribute for reporting on Range extender device */ +#define ZB_HA_RANGE_EXTENDER_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/** @brief Declare cluster list for Range extender device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_RANGE_EXTENDER_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + +/** @cond internals_doc */ + +/** @brief Declare simple descriptor for Range extender device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_RANGE_EXTENDER_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_RANGE_EXTENDER_DEVICE_ID, \ + ZB_HA_DEVICE_VER_RANGE_EXTENDER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY \ + } \ + } + +/** @endcond internals_doc */ + +/** @brief Declare endpoint for Range extender device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_RANGE_EXTENDER_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_RANGE_EXTENDER_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_RANGE_EXTENDER_IN_CLUSTER_NUM, ZB_HA_RANGE_EXTENDER_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + + +/** @brief Declare Range Extender device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_RANGE_EXTENDER_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_RANGE_EXTENDER */ + +#endif /* ZB_HA_RANGE_EXTENDER_H */ diff --git a/zboss/include/ha/zb_ha_sas.h b/zboss/include/ha/zb_ha_sas.h new file mode 100644 index 0000000000..9e7dc33061 --- /dev/null +++ b/zboss/include/ha/zb_ha_sas.h @@ -0,0 +1,76 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA startup attribute sets definitions +*/ +#if ! defined ZB_HA_SAS_H +#define ZB_HA_SAS_H + +#include "zb_ha_config.h" + +#if defined ZB_ENABLE_HA_SAS + +#define ZB_HA_SAS_SHORT_ADDRESS ZB_NWK_BROADCAST_ALL_DEVICES +#define ZB_HA_SAS_EXT_PAN_ID {0, 0, 0, 0, 0, 0, 0, 0} +#define ZB_HA_SAS_PAN_ID ZB_BROADCAST_PAN_ID +#define ZB_HA_SAS_CHANNEL_MASK ZB_TRANSCEIVER_ALL_CHANNELS_MASK + +#define ZB_HA_SAS_TRUST_CENTER_ADDR 0 +#define ZB_HA_SAS_MASTER_KEY NULL +#define ZB_HA_SAS_NETWORK_KEY NULL +#define ZB_HA_SAS_DTC_LINK_KEY \ + "\x5a\x69\x67\x42\x65\x65\x41\x6C\x6C\x69\x61\x6E\x63\x65\x30\x39" + +#define ZB_HA_SAS_INSECURE_JOIN ZB_TRUE + +#define ZB_HA_SAS_SCAN_ATTEMPTS 3 + +/* 5.3.2 Join Parameters +TimeBetweenScans +(1 second) Determines the number of seconds between each unsuccessful scan +attempt + */ +#define ZB_HA_SAS_TIME_BTWN_SCANS 1000 + +zb_void_t zb_ha_process_sas(void); + +#endif /* defined ZB_ENABLE_HA_SAS */ + +#endif /* ! defined ZB_HA_SAS_H */ diff --git a/zboss/include/ha/zb_ha_scene_selector.h b/zboss/include/ha/zb_ha_scene_selector.h new file mode 100644 index 0000000000..7d0ddd2b7c --- /dev/null +++ b/zboss/include/ha/zb_ha_scene_selector.h @@ -0,0 +1,197 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Scene selector device definition +*/ + +#ifndef ZB_HA_SCENE_SELECTOR_H +#define ZB_HA_SCENE_SELECTOR_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_SCENE_SELECTOR || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_scene_selector Scene Selector + @ingroup ZB_HA_DEVICES + @{ + @details + Scene Selector device has 4 clusters (see spec 7.4.5): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + Scene Selector device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/scene_selector/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/scene_selector/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/scene_selector/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/scene_selector/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Scene Selector device samples can be found in /application/HA_samples/scene_selector +*/ + +#define ZB_HA_DEVICE_VER_SCENE_SELECTOR 0 /*!< Scene selector device version */ + +/** @cond internals_doc */ + +#define ZB_HA_SCENE_SELECTOR_IN_CLUSTER_NUM 2 /*!< Scene selector IN (server) clusters + number */ +#define ZB_HA_SCENE_SELECTOR_OUT_CLUSTER_NUM 2 /*!< Scene selector OUT (client) clusters + number */ + +#define ZB_HA_SCENE_SELECTOR_CLUSTER_NUM \ + (ZB_HA_SCENE_SELECTOR_IN_CLUSTER_NUM + ZB_HA_SCENE_SELECTOR_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Scene selector device */ +#define ZB_HA_SCENE_SELECTOR_REPORT_ATTR_COUNT 0 + +/** @endcond */ +/** @brief Declare cluster list for Scene selector device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_SCENE_SELECTOR_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for Scene selector device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_SCENE_SELECTOR_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_SCENE_SELECTOR_DEVICE_ID, \ + ZB_HA_DEVICE_VER_SCENE_SELECTOR, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for Scene selector device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_SCENE_SELECTOR_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_SCENE_SELECTOR_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_SCENE_SELECTOR_IN_CLUSTER_NUM, ZB_HA_SCENE_SELECTOR_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +/** @brief Declare Scene Selector device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. + */ +#define ZB_HA_DECLARE_SCENE_SELECTOR_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_ */ + +#endif /* ZB_HA_SCENE_SELECTOR_H */ diff --git a/zboss/include/ha/zb_ha_shade.h b/zboss/include/ha/zb_ha_shade.h new file mode 100644 index 0000000000..ff03fb192d --- /dev/null +++ b/zboss/include/ha/zb_ha_shade.h @@ -0,0 +1,254 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Shade device definition +*/ + +#if ! defined ZB_HA_SHADE_H +#define ZB_HA_SHADE_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_SHADE || defined DOXYGEN + +/******************* Specific definitions for Shade device **************************/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_SHADE Shade + * @ingroup ZB_HA_DEVICES + * @{ + @details + Shade device has 7 clusters: \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS \n + - @ref ZB_ZCL_SHADE_CONFIG \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/shade/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/shade/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/shade/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/shade/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + See Shade device sample in application/HA_samples/shade +*/ + +#define ZB_HA_DEVICE_VER_SHADE 0 /*!< Shade device version */ + +/*! @cond internals_doc */ +#define ZB_HA_SHADE_IN_CLUSTER_NUM 7 /*!< Shade IN (server) clusters number */ +#define ZB_HA_SHADE_OUT_CLUSTER_NUM 0 /*!< Shade OUT (client) clusters number */ + +#define ZB_HA_SHADE_CLUSTER_NUM \ + (ZB_HA_SHADE_IN_CLUSTER_NUM + ZB_HA_SHADE_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Shade device */ +#define ZB_HA_SHADE_REPORT_ATTR_COUNT \ + (ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT + ZB_ZCL_LEVEL_CONTROL_REPORT_ATTR_COUNT + ZB_ZCL_SHADE_CONFIG_REPORT_ATTR_COUNT) + +#define ZB_HA_SHADE_CVC_ATTR_COUNT 1 + +/** @endcond */ + +/*! + @brief Declare cluster list for Shade device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param shade_config_attr_list - attribute list for Shade Configuration cluster + @param on_off_attr_list - attribute list for On/Off cluster + @param level_control_attr_list - attribute list for Level Control cluster + */ +#define ZB_HA_DECLARE_SHADE_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list, \ + shade_config_attr_list, \ + on_off_attr_list, \ + level_control_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SHADE_CONFIG, \ + ZB_ZCL_ARRAY_SIZE(shade_config_attr_list, zb_zcl_attr_t), \ + (shade_config_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(level_control_attr_list, zb_zcl_attr_t), \ + (level_control_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! @cond internals_doc */ +/*! + @brief Declare simple descriptor for Shade device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_SHADE_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_SHADE_DEVICE_ID, \ + ZB_HA_DEVICE_VER_SHADE, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_SHADE_CONFIG, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL \ + } \ + } + +/*! @endcond */ + +/*! + @brief Declare endpoint for Shade device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ + +//TODO: Scenes needed? +#define ZB_HA_DECLARE_SHADE_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_SHADE_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_SHADE_IN_CLUSTER_NUM, \ + ZB_HA_SHADE_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_SHADE_REPORT_ATTR_COUNT); \ + ZBOSS_DEVICE_DECLARE_LEVEL_CONTROL_CTX(cvc_alarm_info## device_ctx_name, \ + ZB_HA_SHADE_CVC_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_SHADE_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, \ + ZB_HA_SHADE_CVC_ATTR_COUNT, cvc_alarm_info## device_ctx_name) + + +/** @brief Declare Shade device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_SHADE_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_SHADE */ + +#endif /* ! defined ZB_HA_SHADE_H */ diff --git a/zboss/include/ha/zb_ha_shade_controller.h b/zboss/include/ha/zb_ha_shade_controller.h new file mode 100644 index 0000000000..dadc7a2431 --- /dev/null +++ b/zboss/include/ha/zb_ha_shade_controller.h @@ -0,0 +1,219 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Shade controller device definition +*/ + +#ifndef ZB_HA_SHADE_CONTROLLER_H +#define ZB_HA_SHADE_CONTROLLER_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER || defined DOXYGEN + +/******************* Specific definitions for Shade controller device **************************/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER Shade Controller + * @ingroup ZB_HA_DEVICES + * @{ + @details + Shade Controller device has 4 clusters: \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_LEVEL_CONTROL + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/shade_controller/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/shade_controller/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/shade_controller/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/shade_controller/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + See Shade Controller sample in application/HA_samples/shade_controller + +*/ + +#define ZB_HA_DEVICE_VER_SHADE_CONTROLLER 0 /*!< Shade controller device version */ + +/*! @cond internals_doc */ +#define ZB_HA_SHADE_CONTROLLER_IN_CLUSTER_NUM 2 /*!< Shade controller IN (server) clusters number */ +#define ZB_HA_SHADE_CONTROLLER_OUT_CLUSTER_NUM 3 /*!< Shade controller OUT (client) clusters number */ + +#define ZB_HA_SHADE_CONTROLLER_CLUSTER_NUM (ZB_HA_SHADE_CONTROLLER_IN_CLUSTER_NUM + \ + ZB_HA_SHADE_CONTROLLER_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Shade controller device */ +#define ZB_HA_SHADE_CONTROLLER_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/*! + @brief Declare cluster list for Shade controller device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_SHADE_CONTROLLER_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/** @cond internals_doc */ +/*! + @brief Declare simple descriptor for Shade controller device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_SHADE_CONTROLLER_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_SHADE_DEVICE_ID, \ + ZB_HA_DEVICE_VER_SHADE, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @endcond */ + +/*! + @brief Declare endpoint for Shade controller device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ + +//TODO: remove scene? +//TODO: start here +#define ZB_HA_DECLARE_SHADE_CONTROLLER_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_SHADE_CONTROLLER_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_SHADE_CONTROLLER_IN_CLUSTER_NUM, \ + ZB_HA_SHADE_CONTROLLER_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + + +/** @brief Declare Shade Controller device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_SHADE_CONTROLLER_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_SHADE_CONTROLLER */ + +#endif /* ! defined ZB_HA_SHADE_CONTROLLER_H */ diff --git a/zboss/include/ha/zb_ha_simple_sensor.h b/zboss/include/ha/zb_ha_simple_sensor.h new file mode 100644 index 0000000000..78bcdbbea9 --- /dev/null +++ b/zboss/include/ha/zb_ha_simple_sensor.h @@ -0,0 +1,203 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Simple sensor device definition +*/ + +#ifndef ZB_HA_SIMPLE_SENSOR_H +#define ZB_HA_SIMPLE_SENSOR_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_simple_sensor Simple Sensor + * @ingroup ZB_HA_DEVICES + @{ + @details + Simple Sensor device has 3 clusters (see spec 7.4.13): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_BINARY_INPUT + + Simple Sensor device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/simple_sensor/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/simple_sensor/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/simple_sensor/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/simple_sensor/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Simple Sensor device samples can be found in /application/HA_samples/simple_sensor +*/ + + +/** @cond internals_doc */ +#define ZB_HA_DEVICE_VER_SIMPLE_SENSOR 0 /*!< "Device_name" device version */ + +#define ZB_HA_SIMPLE_SENSOR_IN_CLUSTER_NUM 3 /*!< Simple Sensor IN (server) clusters + number */ +#define ZB_HA_SIMPLE_SENSOR_OUT_CLUSTER_NUM 1 /*!< Simple Sensor OUT (client) clusters + number */ + +#define ZB_HA_SIMPLE_SENSOR_CLUSTER_NUM \ + (ZB_HA_SIMPLE_SENSOR_IN_CLUSTER_NUM + ZB_HA_SIMPLE_SENSOR_OUT_CLUSTER_NUM) + +/** @brief Number of attribute for reporting on Simple Sensor device */ +#define ZB_HA_SIMPLE_SENSOR_REPORT_ATTR_COUNT \ + (ZB_ZCL_BINARY_INPUT_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for Simple Sensor device. + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param binary_input_attr_list - attribute list for Binary Input cluster +*/ +#define ZB_HA_DECLARE_SIMPLE_SENSOR_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + binary_input_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_ARRAY_SIZE(binary_input_attr_list, zb_zcl_attr_t), \ + (binary_input_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for "Device_name" device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_SIMPLE_SENSOR_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_SIMPLE_SENSOR_DEVICE_ID, \ + ZB_HA_DEVICE_VER_SIMPLE_SENSOR, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @endcond internals_doc */ + +/** @brief Declare endpoint for Simple Sensor device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_SIMPLE_SENSOR_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_SIMPLE_SENSOR_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_SIMPLE_SENSOR_IN_CLUSTER_NUM, ZB_HA_SIMPLE_SENSOR_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_SIMPLE_SENSOR_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, 0, NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_SIMPLE_SENSOR_REPORT_ATTR_COUNT, \ + reporting_info## device_ctx_name, 0, NULL) + + +/** @brief Declare Simple Sensor device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_SIMPLE_SENSOR_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_SIMPLE_SENSOR */ + +#endif /* ZB_HA_SIMPLE_SENSOR_H */ diff --git a/zboss/include/ha/zb_ha_smart_plug.h b/zboss/include/ha/zb_ha_smart_plug.h new file mode 100644 index 0000000000..59a65155db --- /dev/null +++ b/zboss/include/ha/zb_ha_smart_plug.h @@ -0,0 +1,209 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA Smart Plug device definition +*/ + +#if ! defined ZB_HA_SMART_PLUG_H +#define ZB_HA_SMART_PLUG_H + +#if defined ZB_HA_DEFINE_DEVICE_SMART_PLUG || defined DOXYGEN + +/******************* Specific definitions for window covering device **************************/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_SMART_PLUG Smart Plug + * @ingroup ZB_HA_DEVICES + * @{ + @details + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_ON_OFF \n + - @ref ZB_ZCL_METERING \n + - @ref ZB_ZCL_ELECTRICAL_MEASUREMENT + +*/ + +#define ZB_HA_DEVICE_VER_SMART_PLUG 1 /*!< Smart Plug device version */ + +/*! @cond internals_doc */ +#define ZB_HA_SMART_PLUG_IN_CLUSTER_NUM 5 /*!< Smart Plug IN (server) clusters number */ +#define ZB_HA_SMART_PLUG_OUT_CLUSTER_NUM 1 /*!< Smart Plug OUT (client) clusters number */ + +#define ZB_HA_SMART_PLUG_CLUSTER_NUM (ZB_HA_SMART_PLUG_IN_CLUSTER_NUM + \ + ZB_HA_SMART_PLUG_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Smart Plug device */ +#define ZB_HA_SMART_PLUG_REPORT_ATTR_COUNT \ + (ZB_ZCL_METERING_REPORT_ATTR_COUNT \ + + ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT) + +/*! @endcond */ + +/*! + @brief Declare cluster list for Smart Plug device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param on_off_attr_list - attribute list for On/Off cluster + @param metering_attr_list - attribute list for Metering cluster + @param el_measurement_attr_list - attribute list for Electrical Measurement cluster + */ +#define ZB_HA_DECLARE_SMART_PLUG_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + on_off_attr_list, \ + metering_attr_list, \ + el_measurement_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_ARRAY_SIZE(on_off_attr_list, zb_zcl_attr_t), \ + (on_off_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_METERING, \ + ZB_ZCL_ARRAY_SIZE(metering_attr_list, zb_zcl_attr_t), \ + (metering_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, \ + ZB_ZCL_ARRAY_SIZE(el_measurement_attr_list, zb_zcl_attr_t), \ + (el_measurement_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! + @brief Declare simple descriptor for Smart Plug device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_SMART_PLUG_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_SMART_PLUG_DEVICE_ID, \ + ZB_HA_DEVICE_VER_SMART_PLUG, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_ON_OFF, \ + ZB_ZCL_CLUSTER_ID_METERING, \ + ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/*! + @brief Declare endpoint for Smart Plug device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_SMART_PLUG_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_SMART_PLUG_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_SMART_PLUG_IN_CLUSTER_NUM, ZB_HA_SMART_PLUG_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_SMART_PLUG_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_SMART_PLUG_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL) + + +/*! + @brief Declare application's device context for Smart Plug device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_SMART_PLUG_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + + +/* #define ZB_ZCL_ENABLE_DEFAULT_OTA_UPGRADE_PROCESSING */ +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_SMART_PLUG */ + +#endif /* ! defined ZB_HA_SMART_PLUG_H */ diff --git a/zboss/include/ha/zb_ha_temperature_sensor.h b/zboss/include/ha/zb_ha_temperature_sensor.h new file mode 100644 index 0000000000..394b27e535 --- /dev/null +++ b/zboss/include/ha/zb_ha_temperature_sensor.h @@ -0,0 +1,206 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Temperature sensor device definition +*/ + +#ifndef ZB_HA_TEMPERATURE_SENSOR_H +#define ZB_HA_TEMPERATURE_SENSOR_H 1 + +#if defined ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR || defined DOXYGEN + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_temperature_sensor Temperature Sensor + * @ingroup ZB_HA_DEVICES + @{ + @details + Temperature Sensor device has 3 clusters (see spec 7.7.3.1): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_TEMP_MEASUREMENT + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/temperature_sensor/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/temperature_sensor/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/temperature_sensor/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/temperature_sensor/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + See Temperature Sensor device sample in application/HA_samples/temperature_sensor + +*/ + +#define ZB_HA_DEVICE_VER_TEMPERATURE_SENSOR 0 /*!< Temperature sensor device version */ + +/** @cond internals_doc */ + +#define ZB_HA_TEMPERATURE_SENSOR_IN_CLUSTER_NUM 3 /*!< Temperature Sensor IN (server) clusters + number */ +#define ZB_HA_TEMPERATURE_SENSOR_OUT_CLUSTER_NUM 1 /*!< Temperature Sensor OUT (client) clusters + number */ + +#define ZB_HA_TEMPERATURE_SENSOR_CLUSTER_NUM \ + (ZB_HA_TEMPERATURE_SENSOR_IN_CLUSTER_NUM + ZB_HA_TEMPERATURE_SENSOR_OUT_CLUSTER_NUM) + +/** @brief Number of attribute for reporting on Temperature Sensor device */ +#define ZB_HA_TEMPERATURE_SENSOR_REPORT_ATTR_COUNT \ + (ZB_ZCL_TEMP_MEASUREMENT_REPORT_ATTR_COUNT) + +/** @endcond */ + +/** @brief Declare cluster list for Temperature Sensor device. + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param temp_measure_attr_list - attribute list for Temperature Measurement cluster +*/ +#define ZB_HA_DECLARE_TEMPERATURE_SENSOR_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + temp_measure_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, \ + ZB_ZCL_ARRAY_SIZE(temp_measure_attr_list, zb_zcl_attr_t), \ + (temp_measure_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/** @brief Declare simple descriptor for "Device_name" device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_TEMPERATURE_SENSOR_TEMPERATURE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_TEMPERATURE_SENSOR_DEVICE_ID, \ + ZB_HA_DEVICE_VER_TEMPERATURE_SENSOR, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** @endcond */ + +/** @brief Declare endpoint for Temperature Sensor device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_TEMPERATURE_SENSOR_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_TEMPERATURE_SENSOR_TEMPERATURE_DESC(ep_name, \ + ep_id, \ + ZB_HA_TEMPERATURE_SENSOR_IN_CLUSTER_NUM, \ + ZB_HA_TEMPERATURE_SENSOR_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_TEMPERATURE_SENSOR_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_TEMPERATURE_SENSOR_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, 0, NULL) + +/** @brief Declare Temperature Sensor device context. + @param device_ctx - device context variable name. + @param ep_name - endpoint variable name. +*/ +#define ZB_HA_DECLARE_TEMPERATURE_SENSOR_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_TEMPERATURE_SENSOR */ + +#endif /* ZB_HA_TEMPERATURE_SENSOR_H */ diff --git a/zboss/include/ha/zb_ha_test_device.h b/zboss/include/ha/zb_ha_test_device.h new file mode 100644 index 0000000000..69c93c6e39 --- /dev/null +++ b/zboss/include/ha/zb_ha_test_device.h @@ -0,0 +1,182 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA test device definition +*/ + +#if ! defined ZB_TEST_DEVICE_H +#define ZB_TEST_DEVICE_H + +#if defined ZB_HA_DEFINE_DEVICE_TEST_DEVICE || defined DOXYGEN + +/** @cond (DOXYGEN_HA_SECTION && internals_doc)*/ + +/** @addtogroup ha_api + * @{ + */ + +#define ZB_HA_TEST_DEVICE_VER 0 + + +/**< Control for test */ + +/**< Input clusters number. */ +#define ZB_HA_TEST_DEVICE_IN_CLUSTER_NUM 2 + +/**< Output clusters number. */ +#define ZB_HA_TEST_DEVICE_OUT_CLUSTER_NUM 5 + +/** + * @brief Declare cluster list for Test Device + * @param cluster_list_name [IN] - cluster list variable name. + * @param basic_attr_list [IN] - attribute list for Basic cluster. + * @param identify_attr_list [IN] - attribute list for Identify cluster. + * @param poll_control_attr_list [OUT] - attribute list for Poll Control cluster - client. +*/ +#define ZB_HA_DECLARE_TEST_DEVICE_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + poll_control_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IAS_WD, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_IAS_ZONE, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(poll_control_attr_list, zb_zcl_attr_t), \ + (poll_control_attr_list), \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC(ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, 0, NULL, ZB_ZCL_CLUSTER_CLIENT_ROLE, ZB_ZCL_MANUF_CODE_INVALID ) \ + } + +/** + * @brief Declare simple descriptor for Test Device + * @param ep_name - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param in_clust_num [IN] - number of supported input clusters. + * @param out_clust_num [IN] - number of supported output clusters. + * @note in_clust_num, out_clust_num should be defined by numeric constants, not variables or any + * definitions, because these values are used to form simple descriptor type name. + */ +#define ZB_HA_DECLARE_TEST_DEVICE_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_TEST_DEVICE_ID, \ + ZB_HA_TEST_DEVICE_VER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_IAS_WD, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, \ + ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/** + * @brief Declare endpoint for Test Device + * @param ep_name [IN] - endpoint variable name. + * @param ep_id [IN] - endpoint ID. + * @param cluster_list [IN] - endpoint cluster list. + */ +#define ZB_HA_DECLARE_TEST_DEVICE_EP(ep_name, ep_id, cluster_list) \ + ZB_HA_DECLARE_TEST_DEVICE_SIMPLE_DESC( \ + ep_name, \ + ep_id, \ + ZB_HA_TEST_DEVICE_IN_CLUSTER_NUM, \ + ZB_HA_TEST_DEVICE_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE( \ + cluster_list, \ + zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + +#define ZB_HA_DECLARE_TEST_DEVICE_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + + +#endif /* defined ZB_HA_DEFINE_DEVICE_TEST_DEVICE || defined DOXYGEN */ + +/** @} */ /* ha_api */ +/** @endcond */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ! defined ZB_TEST_DEVICE_H */ diff --git a/zboss/include/ha/zb_ha_thermostat.h b/zboss/include/ha/zb_ha_thermostat.h new file mode 100644 index 0000000000..7df0eed7ff --- /dev/null +++ b/zboss/include/ha/zb_ha_thermostat.h @@ -0,0 +1,275 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA Thermostat device definition +*/ + +#if ! defined ZB_HA_THERMOSTAT_H +#define ZB_HA_THERMOSTAT_H + +#if defined ZB_HA_DEFINE_DEVICE_THERMOSTAT || defined DOXYGEN + +/******************* Specific definitions for window covering device **************************/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ZB_HA_DEFINE_DEVICE_THERMOSTAT Thermostat + * @ingroup ZB_HA_DEVICES + * @{ + @details + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_THERMOSTAT \n + - @ref ZB_ZCL_FAN_CONTROL \n + - @ref ZB_ZCL_THERMOSTAT_UI_CONFIG + +*/ + +#define ZB_HA_DEVICE_VER_THERMOSTAT 1 /*!< Thermostat device version number */ + +/** @cond internals_doc */ + +#define ZB_HA_THERMOSTAT_IN_CLUSTER_NUM 5 +#define ZB_HA_THERMOSTAT_OUT_CLUSTER_NUM 0 + +#define ZB_HA_THERMOSTAT_CLUSTER_NUM (ZB_HA_THERMOSTAT_IN_CLUSTER_NUM + \ + ZB_HA_THERMOSTAT_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on Thermostat device */ +#define ZB_HA_THERMOSTAT_REPORT_ATTR_COUNT (ZB_ZCL_THERMOSTAT_REPORT_ATTR_COUNT \ + + ZB_ZCL_FAN_CONTROL_REPORT_ATTR_COUNT \ + + ZB_ZCL_THERMOSTAT_UI_CONFIG_REPORT_ATTR_COUNT) + +/** @endcond */ + +/*! + @brief Declare cluster list for Thermostat device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param thermostat_attr_list - attribute list for Thermostat cluster + @param fan_control_attr_list - attribute list for Fan Control cluster + @param thermostat_ui_config_attr_list - attribute list for Thermostat UI Config cluster + */ +#define ZB_HA_DECLARE_THERMOSTAT_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + thermostat_attr_list, \ + fan_control_attr_list, \ + thermostat_ui_config_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT, \ + ZB_ZCL_ARRAY_SIZE(thermostat_attr_list, zb_zcl_attr_t), \ + (thermostat_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_FAN_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(fan_control_attr_list, zb_zcl_attr_t), \ + (fan_control_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG, \ + ZB_ZCL_ARRAY_SIZE(thermostat_ui_config_attr_list, zb_zcl_attr_t), \ + (thermostat_ui_config_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/*! + @brief Declare cluster list for Thermostat device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param thermostat_attr_list - attribute list for Thermostat cluster + @param fan_control_attr_list - attribute list for Fan Control cluster + @param thermostat_ui_config_attr_list - attribute list for Thermostat UI Config cluster + */ +#define ZB_HA_DECLARE_THERMOSTAT_CLUSTER_LIST_EXT( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list, \ + thermostat_attr_list, \ + fan_control_attr_list, \ + thermostat_ui_config_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT, \ + ZB_ZCL_ARRAY_SIZE(thermostat_attr_list, zb_zcl_attr_t), \ + (thermostat_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_FAN_CONTROL, \ + ZB_ZCL_ARRAY_SIZE(fan_control_attr_list, zb_zcl_attr_t), \ + (fan_control_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG, \ + ZB_ZCL_ARRAY_SIZE(thermostat_ui_config_attr_list, zb_zcl_attr_t), \ + (thermostat_ui_config_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/** @cond internals_doc */ +/*! + @brief Declare simple descriptor for Thermostat device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_THERMOSTAT_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_THERMOSTAT_DEVICE_ID, \ + ZB_HA_DEVICE_VER_THERMOSTAT, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT, \ + ZB_ZCL_CLUSTER_ID_FAN_CONTROL, \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG, \ + } \ + } + +/** @endcond */ + +/*! + @brief Declare endpoint for Thermostat device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_THERMOSTAT_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_THERMOSTAT_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_THERMOSTAT_IN_CLUSTER_NUM, ZB_HA_THERMOSTAT_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_THERMOSTAT_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_THERMOSTAT_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, \ + 0, NULL) + + +/*! + @brief Declare application's device context for Thermostat device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_THERMOSTAT_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_THERMOSTAT */ + +#endif /* ! defined ZB_HA_THERMOSTAT_H */ diff --git a/zboss/include/ha/zb_ha_window_covering.h b/zboss/include/ha/zb_ha_window_covering.h new file mode 100644 index 0000000000..7ad5fbba1a --- /dev/null +++ b/zboss/include/ha/zb_ha_window_covering.h @@ -0,0 +1,219 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Window Covering device definition +*/ + +#if ! defined ZB_HA_WINDOW_COVERING_H +#define ZB_HA_WINDOW_COVERING_H + +#if defined ZB_HA_DEFINE_DEVICE_WINDOW_COVERING || defined DOXYGEN + +/******************* Specific definitions for window covering device **************************/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_window_covering Window Covering + * @ingroup ZB_HA_DEVICES + @{ + @details + Window Covering device has 5 clusters (see spec 7.6.3): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_WINDOW_COVERING \n + - @ref ZB_ZCL_SCENES \n + - @ref ZB_ZCL_GROUPS + + Window Covering device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/window_covering/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/window_covering/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/window_covering/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/window_covering/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Window Covering device samples can be found in /application/HA_samples/window_covering +*/ +#define ZB_HA_DEVICE_VER_WINDOW_COVERING 0 /*!< Window covering device version */ + +/** @cond internals_doc */ +#define ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM 5 /*!< Window covering IN (server) clusters number */ +#define ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM 0 /*!< Window covering OUT (client) clusters number */ + +#define ZB_HA_WINDOW_COVERING_CLUSTER_NUM (ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM + \ + ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on window covering device */ +#define ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT \ + (ZB_ZCL_WINDOW_COVERING_REPORT_ATTR_COUNT) + +/** @endcond */ + +/*! + @brief Declare cluster list for window covering device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + @param groups_attr_list - attribute list for Groups cluster + @param scenes_attr_list - attribute list for Scenes cluster + @param window_covering_attr_list - attribute list for Window covering cluster + */ +#define ZB_HA_DECLARE_WINDOW_COVERING_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list, \ + groups_attr_list, \ + scenes_attr_list, \ + window_covering_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + ZB_ZCL_ARRAY_SIZE(window_covering_attr_list, zb_zcl_attr_t), \ + (window_covering_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_ARRAY_SIZE(scenes_attr_list, zb_zcl_attr_t), \ + (scenes_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_GROUPS, \ + ZB_ZCL_ARRAY_SIZE(groups_attr_list, zb_zcl_attr_t), \ + (groups_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + + +/*! + @brief Declare simple descriptor for window covering device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC(ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_WINDOW_COVERING_DEVICE_ID, \ + ZB_HA_DEVICE_VER_WINDOW_COVERING, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + ZB_ZCL_CLUSTER_ID_GROUPS \ + } \ + } + +/*! + @brief Declare endpoint for window covering device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_WINDOW_COVERING_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_WINDOW_COVERING_SIMPLE_DESC(ep_name, ep_id, \ + ZB_HA_WINDOW_COVERING_IN_CLUSTER_NUM, ZB_HA_WINDOW_COVERING_OUT_CLUSTER_NUM); \ + ZBOSS_DEVICE_DECLARE_REPORTING_CTX(reporting_info## device_ctx_name, \ + ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + ZB_HA_WINDOW_COVERING_REPORT_ATTR_COUNT, reporting_info## device_ctx_name, \ + 0, NULL) /* No CVC ctx */ + + +/*! + @brief Declare application's device context for Window Covering device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_WINDOW_COVERING_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_WINDOW_COVERING */ + +#endif /* ! defined ZB_HA_WINDOW_COVERING_H */ diff --git a/zboss/include/ha/zb_ha_window_covering_controller.h b/zboss/include/ha/zb_ha_window_covering_controller.h new file mode 100644 index 0000000000..eca604b6b3 --- /dev/null +++ b/zboss/include/ha/zb_ha_window_covering_controller.h @@ -0,0 +1,210 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Window Covering Controller device definition +*/ + +#if ! defined ZB_HA_WINDOW_COVERING_CONTROLLER_H +#define ZB_HA_WINDOW_COVERING_CONTROLLER_H + +#if defined ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER || defined DOXYGEN + +/***** Specific definitions for window covering controller device *********/ + +/** @cond DOXYGEN_HA_SECTION */ + +/** + * @defgroup ha_window_covering_controller Window Covering Controller + * @ingroup ZB_HA_DEVICES + @{ + @details + Window Covering Controller device has 3 clusters (see spec 7.6.4): \n + - @ref ZB_ZCL_IDENTIFY \n + - @ref ZB_ZCL_BASIC \n + - @ref ZB_ZCL_WINDOW_COVERING + + Window Covering Controller device sample + + @par Example + + - Declaring clusters: + + @snippet HA_samples/common/zcl_basic_attr_list.h BASIC_CLUSTER_COMMON + @snippet HA_samples/window_covering_controller/sample_zc.c COMMON_DECLARATION + + - Registering device list: + + @snippet HA_samples/window_covering_controller/sample_zc.c REGISTER + + - Example of command handler: + + @snippet HA_samples/window_covering_controller/sample_zc.c COMMAND_HANDLER + @snippet HA_samples/window_covering_controller/sample_zc.c ZCL_COMMAND_HANDLER + + @par + + The complete set of Window Covering Controller device samples can be found in /application/HA_samples/window_covering_controller +*/ + +/*!< window covering controller device version */ +#define ZB_HA_DEVICE_VER_WINDOW_COVERING_CONTROLLER 0 + +/** @cond internals_doc */ +/*!< window covering controller IN (server) clusters number */ +#define ZB_HA_WINDOW_COVERING_CONTROLLER_IN_CLUSTER_NUM 2 + +/*!< window covering controller OUT (client) clusters number */ +#define ZB_HA_WINDOW_COVERING_CONTROLLER_OUT_CLUSTER_NUM 2 + +#define ZB_HA_WINDOW_COVERING_CONTROLLER_CLUSTER_NUM \ + (ZB_HA_WINDOW_COVERING_CONTROLLER_IN_CLUSTER_NUM \ + + ZB_HA_WINDOW_COVERING_CONTROLLER_OUT_CLUSTER_NUM) + +/*! Number of attribute for reporting on window covering controller device */ +#define ZB_HA_WINDOW_COVERING_CONTROLLER_REPORT_ATTR_COUNT 0 + +/** @endcond */ + +/*! + @brief Declare cluster list for window covering controller device + @param cluster_list_name - cluster list variable name + @param basic_attr_list - attribute list for Basic cluster + @param identify_attr_list - attribute list for Identify cluster + */ +#define ZB_HA_DECLARE_WINDOW_COVERING_CONTROLLER_CLUSTER_LIST( \ + cluster_list_name, \ + basic_attr_list, \ + identify_attr_list) \ +zb_zcl_cluster_desc_t cluster_list_name[] = \ +{ \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_ARRAY_SIZE(identify_attr_list, zb_zcl_attr_t), \ + (identify_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_ARRAY_SIZE(basic_attr_list, zb_zcl_attr_t), \ + (basic_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + 0, NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ +} + + +/*! + @brief Declare simple descriptor for window covering controller device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param in_clust_num - number of supported input clusters + @param out_clust_num - number of supported output clusters +*/ +#define ZB_ZCL_DECLARE_WINDOW_COVERING_CONTROLLER_SIMPLE_DESC( \ + ep_name, ep_id, in_clust_num, out_clust_num) \ + ZB_DECLARE_SIMPLE_DESC(in_clust_num, out_clust_num); \ + ZB_AF_SIMPLE_DESC_TYPE(in_clust_num, out_clust_num) simple_desc_##ep_name = \ + { \ + ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + ZB_HA_WINDOW_COVERING_CONTROLLER_DEVICE_ID, \ + ZB_HA_DEVICE_VER_WINDOW_COVERING_CONTROLLER, \ + 0, \ + in_clust_num, \ + out_clust_num, \ + { \ + ZB_ZCL_CLUSTER_ID_BASIC, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, \ + ZB_ZCL_CLUSTER_ID_IDENTIFY, \ + } \ + } + +/*! + @brief Declare endpoint for window covering controller device + @param ep_name - endpoint variable name + @param ep_id - endpoint ID + @param cluster_list - endpoint cluster list + */ +#define ZB_HA_DECLARE_WINDOW_COVERING_CONTROLLER_EP(ep_name, ep_id, cluster_list) \ + ZB_ZCL_DECLARE_WINDOW_COVERING_CONTROLLER_SIMPLE_DESC(ep_name, \ + ep_id, \ + ZB_HA_WINDOW_COVERING_CONTROLLER_IN_CLUSTER_NUM, \ + ZB_HA_WINDOW_COVERING_CONTROLLER_OUT_CLUSTER_NUM); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, ep_id, \ + ZB_AF_HA_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, /* No reporting ctx */ \ + 0, NULL) /* No CVC ctx */ + + +/*! + @brief Declare application's device context for Window Covering Controller device + @param device_ctx - device context variable + @param ep_name - endpoint variable name +*/ +#define ZB_HA_DECLARE_WINDOW_COVERING_CONTROLLER_CTX(device_ctx, ep_name) \ + ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx, ep_name) + +/*! @} */ + +/** @endcond */ /* DOXYGEN_HA_SECTION */ + +#endif /* ZB_HA_DEFINE_DEVICE_WINDOW_COVERING_CONTROLLER */ + +#endif /* ! defined ZB_HA_WINDOW_COVERING_CONTROLLER_H */ diff --git a/zboss/include/osif/libzboss_config.ed.h b/zboss/include/osif/libzboss_config.ed.h new file mode 100644 index 0000000000..c0479936a0 --- /dev/null +++ b/zboss/include/osif/libzboss_config.ed.h @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef LIBZBOSS_CONFIG_ED_H__ +#define LIBZBOSS_CONFIG_ED_H__ + +/** + * This is an autogenerated file. + * Please use Kconfig to change it. + */ + + +/** + * ZB_APS_SRC_BINDING_TABLE_SIZE + */ +/* #undef CONFIG_ZB_APS_SRC_BINDING_TABLE_SIZE */ + +/** + * ZB_NWK_BRR_TABLE_SIZE + */ +#define CONFIG_ZB_NWK_BRR_TABLE_SIZE 16 + +/** + * Source code - WWAH cluster + * + * Include Works With All Hubs cluster + */ +#define CONFIG_ZB_ZCL_SUPPORT_CLUSTER_WWAH y + +/** + * ZB_APS_GROUP_TABLE_SIZE + */ +#define CONFIG_ZB_APS_GROUP_TABLE_SIZE 8 + +/** + * Source code - Initialize and flush logger directly from ZBOSS kernel + */ +/* #undef CONFIG_ZB_ASYNC_TRACE_CONTROL */ + +/** + * Expected Zigbee application complexity - moderate + */ +/* #undef CONFIG_ZB_CONFIG_APPLICATION_MODERATE */ + +/** + * Source code - Check for Out Of Memory state + * + * If Zigbee packet buffer pool is in OOM state for a period, specified + * by ZB_OOM_THRESHOLD, then assertion is triggered. + */ +/* #undef CONFIG_ZB_CHECK_OOM_STATUS */ + +/** + * Source code - Enable test commands + * + * Enable reception of test commands on UART interface + * (enabled in ZBOSS test configs only) + */ +/* #undef CONFIG_ZB_NRF_TRACE_RX_ENABLE */ + +/** + * ZB_ZGP_SINK_TBL_SIZE + */ +#define CONFIG_ZB_ZGP_SINK_TBL_SIZE 24 + +/** + * Source code - Dynamic memory configuration + * + * Enable dynamic memory configuration feature that allows to change memory + * footprint if application uses ZBOSS binaries + */ +#define CONFIG_ZB_CONFIGURABLE_MEM y + +/** + * ZB_APS_ENDPOINTS_IN_GROUP_TABLE + */ +#define CONFIG_ZB_APS_ENDPOINTS_IN_GROUP_TABLE 8 + +/** + * Expected Zigbee traffic intensity - high + */ +#define CONFIG_ZB_CONFIG_HIGH_TRAFFIC y + +/** + * Source code - Distributed security + * + * Enable forming and joining Zigbee networks with distributed security + */ +#define CONFIG_ZB_DISTRIBUTED_SECURITY_ON y + +/** + * Source code - Install codes + * + * Enable commissioning with install codes + */ +#define CONFIG_ZB_SECURITY_INSTALLCODES y + +/** + * WWAH cluster - WWAHu client + * + * Include WWAHu cluster client implementation + */ +#define CONFIG_ZB_ZCL_ENABLE_WWAH_CLIENT y + +/** + * ZB_CONFIG_OVERALL_NETWORK_SIZE + */ +#define CONFIG_ZB_CONFIG_OVERALL_NETWORK_SIZE 128 + +/** + * Expected Zigbee application complexity - complex + */ +#define CONFIG_ZB_CONFIG_APPLICATION_COMPLEX y + +/** + * Expected Zigbee traffic intensity - light + */ +/* #undef CONFIG_ZB_CONFIG_LIGHT_TRAFFIC */ + +/** + * ZB_MAX_EP_NUMBER + * + * Maximum number of supported endpoints per device + */ +#define CONFIG_ZB_MAX_EP_NUMBER 6 + +/** + * WWAH cluster - WWAHu server + * + * Include WWAHu cluster server implementation + */ +#define CONFIG_ZB_ZCL_ENABLE_WWAH_SERVER y + +/** + * Expected Zigbee traffic intensity - moderate + */ +/* #undef CONFIG_ZB_CONFIG_MODERATE_TRAFFIC */ + +/** + * Source code - MAC filtering + * + * Enables filtering frames at MAC level, based on device's short or + * long address + */ +/* #undef CONFIG_ZB_LIMIT_VISIBILITY */ + +/** + * Source code - Enable Zigbee profile, used by verification framework + */ +/* #undef CONFIG_ZB_TEST_PROFILE */ + +/** + * Source code - NVRAM migration + * + * Include procedures to migrate legacy NVRAM structures + */ +#define CONFIG_ZB_NVRAM_ENABLE_VER_MIGRATION y + +/** + * ZB_ZDO_TRAN_TABLE_SIZE + */ +#define CONFIG_ZB_ZDO_TRAN_TABLE_SIZE 16 + +/** + * WWAHu server - Parent classification + * + * Enable parent classification + */ +#define CONFIG_ZB_PARENT_CLASSIFICATION y + +/** + * Source code - NWK security API + * + * Include API to disable NWK security + */ +#define CONFIG_ZB_LOW_SECURITY_MODE y + +/** + * Source code - Touchlink commissioning (experimental) + */ +/* #undef CONFIG_ZB_BDB_TOUCHLINK */ + +/** + * Max compiled-in log level for ZBOSS traces - Off + */ +/* #undef CONFIG_ZB_LOG_LEVEL_OFF */ + +/** + * Source code - Enable USB serial interface for ZBOSS CLI + */ +/* #undef CONFIG_ZB_HAVE_USERIAL */ + +/** + * Source code - Certification specific behavior + * + * Enable behaviors specific to golden devices used during certification + */ +/* #undef CONFIG_ZB_CERTIFICATION_HACKS */ + +/** + * Max compiled-in log level for ZBOSS traces - Debug + */ +/* #undef CONFIG_ZB_LOG_LEVEL_DBG */ + +/** + * Source code - Production configuration + * + * Enable production configuration + */ +#define CONFIG_ZB_PRODUCTION_CONFIG y + +/** + * ZB_BUF_Q_SIZE + * + * Size of queue for wait for free packet buffer + * + * Note: To prevent deadlocks ZB_BUF_Q_SIZE must be < ZB_IOBUF_POOL_SIZE/2 + */ +#define CONFIG_ZB_BUF_Q_SIZE 8 + +/** + * Source code - NWK requests with aliases + * + * Enables making NWK requests with aliases (see sec. 3.2.1.1.1) or + * R21 Zigbee PRO specification) + */ +/* #undef CONFIG_ZB_USEALIAS */ + +/** + * ZB_DEV_MANUFACTURER_TABLE_SIZE + * + * Size of table used for long addresses compression: 3 bytes of + * manufacturer id. + * + * ZBOSS implements long address compression: 3 bytes of manufacturer + * id are stored in the separate table; reference to manufacturer + * entry is stored in the long address giving 2 bytes economy. + * + * That is an absolute limit of number of manufacturers known to the device. + * + * Note: All that machinery will not work if instead of legal + * manufacturer ids (or illegal, but fixed ids) use random values. + */ +#define CONFIG_ZB_DEV_MANUFACTURER_TABLE_SIZE 32 + +/** + * Max compiled-in log level for ZBOSS traces - Info + */ +/* #undef CONFIG_ZB_LOG_LEVEL_INF */ + +/** + * ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT + */ +#define CONFIG_ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT 4000000 + +/** + * Source code - PAN ID blacklist + * + * Enable PAN ID blacklisting during rejoin + */ +#define CONFIG_ZB_NWK_BLACKLIST y + +/** + * Source code - APS user frames + * + * Include API to send raw APS frames + */ +#define CONFIG_ZB_APS_USER_PAYLOAD y + +/** + * Source code - Enable busy loop in GP implementation + * + * While communicating with Green Power device, ZBOSS will wait before issuing + * mcps-data.req in a busy loop instead of using MAC features + */ +/* #undef CONFIG_ZB_MAC_AUTO_DELAY_IN_MAC_GP_SEND */ + +/** + * Check for Out Of Memory state - Generate NWK status frame in OOM + * + * Send broadcast frame once OOM state is detected. + */ +/* #undef CONFIG_ZB_SEND_OOM_STATUS */ + +/** + * Max compiled-in log level for ZBOSS traces - Error + */ +/* #undef CONFIG_ZB_LOG_LEVEL_ERR */ + +/** + * Source code - Enable UART serial interface for ZBOSS CLI + */ +/* #undef CONFIG_ZB_HAVE_SERIAL */ + +/** + * Expected Zigbee application complexity - simple + */ +/* #undef CONFIG_ZB_CONFIG_APPLICATION_SIMPLE */ + +/** + * WWAHu server - Beacon survey + * + * Enable beacon survey + */ +#define CONFIG_ZB_BEACON_SURVEY y + +/** + * Source code - APS fragmentation + * + * Enable APS fragmentation inside ZBOSS + */ +#define CONFIG_ZB_APS_FRAGMENTATION y + +/** + * Max compiled-in log level for ZBOSS traces - Warning + */ +#define CONFIG_ZB_LOG_LEVEL_WRN y + +/** + * Source code - Disable TRACE_FILE_ID assert + * + * Disable sanity check for ZB_TRACE_FILE_ID macro definition in each file + */ +#define CONFIG_ZB_DONT_NEED_TRACE_FILE_ID y + +/** + * ZB_IOBUF_POOL_SIZE + */ +/* #undef CONFIG_ZB_IOBUF_POOL_SIZE */ + +/** + * ZB_PANID_TABLE_SIZE + * + * NWK: size of the long-short Pan ID translation table + * + * Must be <= (packet buffer size - sizeof(*discovery_confirm)) / + * sizeof(*network_descriptor) + * That value limits number of Pan IDs visible for device during active scan. + */ +#define CONFIG_ZB_PANID_TABLE_SIZE 28 + +/** + * Source code - Disable TRACE_FILE_ID assert + */ +#define CONFIG_ZB_TRACE_LOG_LEVEL 2 + +/** + * ZB_ZGP_PROXY_TBL_SIZE + */ +#define CONFIG_ZB_ZGP_PROXY_TBL_SIZE 5 + +/** + * Source code - Finding and Binding + * + * Enable finding and binding, as defined in BDB specification + */ +#define CONFIG_ZB_BDB_ENABLE_FINDING_BINDING y + +/** + * ZB_SCHEDULER_Q_SIZE + * + * Scheduler callbacks queue size + */ +/* #undef CONFIG_ZB_SCHEDULER_Q_SIZE */ + +/** + * ZB_TRACE_MASK + * + * Selectively enable Zigbee binary trace logs. + * The mask value should be a bitwise OR of values assigned to selected modules. + * + * Available modules are: + * + * - 0x4000 Zigbee Green Power + * - 0x0800 Application + * - 0x0200 Zigbee Light Link + * - 0x0100 Zigbee Cluster Library + * - 0x0080 Security + * - 0x0040 Zigbee Device Object + * - 0x0010 Application Support layer + * - 0x0008 Network layer + * - 0x0004 MAC layer + * - 0x0002 Memory management + * - 0x0001 Common + * + * For example, in order to enable traces related to OTA DFU, + * one should set this option to 0x4100. + * + * Note: For general debugging purposes, please use 0x0C48. + */ +#define CONFIG_ZB_TRACE_MASK 0x0000 + +/** + * WWAHu server - NWK retransmissions + * + * Enable retransmissions on NWK layer + */ +#define CONFIG_ZB_NWK_RETRY_COUNT y + +/** + * ZB_NWK_BLACKLIST_SIZE + */ +#define CONFIG_ZB_NWK_BLACKLIST_SIZE 16 + +/** + * ZB_APS_DST_BINDING_TABLE_SIZE + */ +/* #undef CONFIG_ZB_APS_DST_BINDING_TABLE_SIZE */ + +/** + * ZB_NWK_BTR_TABLE_SIZE + * + * See Zigbee Specification subclause 3.6.5 + */ +#define CONFIG_ZB_NWK_BTR_TABLE_SIZE 16 + +#endif /* LIBZBOSS_CONFIG_ED_H__ */ diff --git a/zboss/include/osif/libzboss_config.h b/zboss/include/osif/libzboss_config.h new file mode 100644 index 0000000000..20f4d4fa7e --- /dev/null +++ b/zboss/include/osif/libzboss_config.h @@ -0,0 +1,420 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef LIBZBOSS_CONFIG_H__ +#define LIBZBOSS_CONFIG_H__ + +/** + * This is an autogenerated file. + * Please use Kconfig to change it. + */ + + +/** + * ZB_APS_SRC_BINDING_TABLE_SIZE + */ +/* #undef CONFIG_ZB_APS_SRC_BINDING_TABLE_SIZE */ + +/** + * ZB_NWK_BRR_TABLE_SIZE + */ +#define CONFIG_ZB_NWK_BRR_TABLE_SIZE 16 + +/** + * Source code - WWAH cluster + * + * Include Works With All Hubs cluster + */ +#define CONFIG_ZB_ZCL_SUPPORT_CLUSTER_WWAH y + +/** + * ZB_APS_GROUP_TABLE_SIZE + */ +#define CONFIG_ZB_APS_GROUP_TABLE_SIZE 16 + +/** + * Source code - Initialize and flush logger directly from ZBOSS kernel + */ +/* #undef CONFIG_ZB_ASYNC_TRACE_CONTROL */ + +/** + * Expected Zigbee application complexity - moderate + */ +/* #undef CONFIG_ZB_CONFIG_APPLICATION_MODERATE */ + +/** + * Source code - Check for Out Of Memory state + * + * If Zigbee packet buffer pool is in OOM state for a period, specified + * by ZB_OOM_THRESHOLD, then assertion is triggered. + */ +/* #undef CONFIG_ZB_CHECK_OOM_STATUS */ + +/** + * Source code - Enable test commands + * + * Enable reception of test commands on UART interface + * (enabled in ZBOSS test configs only) + */ +/* #undef CONFIG_ZB_NRF_TRACE_RX_ENABLE */ + +/** + * ZB_ZGP_SINK_TBL_SIZE + */ +#define CONFIG_ZB_ZGP_SINK_TBL_SIZE 24 + +/** + * Source code - Dynamic memory configuration + * + * Enable dynamic memory configuration feature that allows to change memory + * footprint if application uses ZBOSS binaries + */ +#define CONFIG_ZB_CONFIGURABLE_MEM y + +/** + * ZB_APS_ENDPOINTS_IN_GROUP_TABLE + */ +#define CONFIG_ZB_APS_ENDPOINTS_IN_GROUP_TABLE 8 + +/** + * Expected Zigbee traffic intensity - high + */ +#define CONFIG_ZB_CONFIG_HIGH_TRAFFIC y + +/** + * Source code - Distributed security + * + * Enable forming and joining Zigbee networks with distributed security + */ +#define CONFIG_ZB_DISTRIBUTED_SECURITY_ON y + +/** + * Source code - Install codes + * + * Enable commissioning with install codes + */ +#define CONFIG_ZB_SECURITY_INSTALLCODES y + +/** + * WWAH cluster - WWAHu client + * + * Include WWAHu cluster client implementation + */ +#define CONFIG_ZB_ZCL_ENABLE_WWAH_CLIENT y + +/** + * ZB_CONFIG_OVERALL_NETWORK_SIZE + */ +#define CONFIG_ZB_CONFIG_OVERALL_NETWORK_SIZE 128 + +/** + * Expected Zigbee application complexity - complex + */ +#define CONFIG_ZB_CONFIG_APPLICATION_COMPLEX y + +/** + * Expected Zigbee traffic intensity - light + */ +/* #undef CONFIG_ZB_CONFIG_LIGHT_TRAFFIC */ + +/** + * ZB_MAX_EP_NUMBER + * + * Maximum number of supported endpoints per device + */ +#define CONFIG_ZB_MAX_EP_NUMBER 6 + +/** + * WWAH cluster - WWAHu server + * + * Include WWAHu cluster server implementation + */ +#define CONFIG_ZB_ZCL_ENABLE_WWAH_SERVER y + +/** + * Expected Zigbee traffic intensity - moderate + */ +/* #undef CONFIG_ZB_CONFIG_MODERATE_TRAFFIC */ + +/** + * Source code - MAC filtering + * + * Enables filtering frames at MAC level, based on device's short or + * long address + */ +/* #undef CONFIG_ZB_LIMIT_VISIBILITY */ + +/** + * Source code - Enable Zigbee profile, used by verification framework + */ +/* #undef CONFIG_ZB_TEST_PROFILE */ + +/** + * Source code - NVRAM migration + * + * Include procedures to migrate legacy NVRAM structures + */ +#define CONFIG_ZB_NVRAM_ENABLE_VER_MIGRATION y + +/** + * ZB_ZDO_TRAN_TABLE_SIZE + */ +#define CONFIG_ZB_ZDO_TRAN_TABLE_SIZE 16 + +/** + * WWAHu server - Parent classification + * + * Enable parent classification + */ +#define CONFIG_ZB_PARENT_CLASSIFICATION y + +/** + * Source code - NWK security API + * + * Include API to disable NWK security + */ +#define CONFIG_ZB_LOW_SECURITY_MODE y + +/** + * Source code - Touchlink commissioning (experimental) + */ +/* #undef CONFIG_ZB_BDB_TOUCHLINK */ + +/** + * Max compiled-in log level for ZBOSS traces - Off + */ +/* #undef CONFIG_ZB_LOG_LEVEL_OFF */ + +/** + * Source code - Enable USB serial interface for ZBOSS CLI + */ +/* #undef CONFIG_ZB_HAVE_USERIAL */ + +/** + * Source code - Certification specific behavior + * + * Enable behaviors specific to golden devices used during certification + */ +/* #undef CONFIG_ZB_CERTIFICATION_HACKS */ + +/** + * Max compiled-in log level for ZBOSS traces - Debug + */ +/* #undef CONFIG_ZB_LOG_LEVEL_DBG */ + +/** + * Source code - Production configuration + * + * Enable production configuration + */ +#define CONFIG_ZB_PRODUCTION_CONFIG y + +/** + * ZB_BUF_Q_SIZE + * + * Size of queue for wait for free packet buffer + * + * Note: To prevent deadlocks ZB_BUF_Q_SIZE must be < ZB_IOBUF_POOL_SIZE/2 + */ +#define CONFIG_ZB_BUF_Q_SIZE 8 + +/** + * Source code - NWK requests with aliases + * + * Enables making NWK requests with aliases (see sec. 3.2.1.1.1) or + * R21 Zigbee PRO specification) + */ +/* #undef CONFIG_ZB_USEALIAS */ + +/** + * ZB_DEV_MANUFACTURER_TABLE_SIZE + * + * Size of table used for long addresses compression: 3 bytes of + * manufacturer id. + * + * ZBOSS implements long address compression: 3 bytes of manufacturer + * id are stored in the separate table; reference to manufacturer + * entry is stored in the long address giving 2 bytes economy. + * + * That is an absolute limit of number of manufacturers known to the device. + * + * Note: All that machinery will not work if instead of legal + * manufacturer ids (or illegal, but fixed ids) use random values. + */ +#define CONFIG_ZB_DEV_MANUFACTURER_TABLE_SIZE 32 + +/** + * Max compiled-in log level for ZBOSS traces - Info + */ +/* #undef CONFIG_ZB_LOG_LEVEL_INF */ + +/** + * ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT + */ +#define CONFIG_ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT 4000000 + +/** + * Source code - PAN ID blacklist + * + * Enable PAN ID blacklisting during rejoin + */ +#define CONFIG_ZB_NWK_BLACKLIST y + +/** + * Source code - APS user frames + * + * Include API to send raw APS frames + */ +#define CONFIG_ZB_APS_USER_PAYLOAD y + +/** + * Source code - Enable busy loop in GP implementation + * + * While communicating with Green Power device, ZBOSS will wait before issuing + * mcps-data.req in a busy loop instead of using MAC features + */ +/* #undef CONFIG_ZB_MAC_AUTO_DELAY_IN_MAC_GP_SEND */ + +/** + * Check for Out Of Memory state - Generate NWK status frame in OOM + * + * Send broadcast frame once OOM state is detected. + */ +/* #undef CONFIG_ZB_SEND_OOM_STATUS */ + +/** + * Max compiled-in log level for ZBOSS traces - Error + */ +/* #undef CONFIG_ZB_LOG_LEVEL_ERR */ + +/** + * Source code - Enable UART serial interface for ZBOSS CLI + */ +/* #undef CONFIG_ZB_HAVE_SERIAL */ + +/** + * Expected Zigbee application complexity - simple + */ +/* #undef CONFIG_ZB_CONFIG_APPLICATION_SIMPLE */ + +/** + * WWAHu server - Beacon survey + * + * Enable beacon survey + */ +#define CONFIG_ZB_BEACON_SURVEY y + +/** + * Source code - APS fragmentation + * + * Enable APS fragmentation inside ZBOSS + */ +#define CONFIG_ZB_APS_FRAGMENTATION y + +/** + * Max compiled-in log level for ZBOSS traces - Warning + */ +#define CONFIG_ZB_LOG_LEVEL_WRN y + +/** + * Source code - Disable TRACE_FILE_ID assert + * + * Disable sanity check for ZB_TRACE_FILE_ID macro definition in each file + */ +#define CONFIG_ZB_DONT_NEED_TRACE_FILE_ID y + +/** + * ZB_IOBUF_POOL_SIZE + */ +/* #undef CONFIG_ZB_IOBUF_POOL_SIZE */ + +/** + * ZB_PANID_TABLE_SIZE + * + * NWK: size of the long-short Pan ID translation table + * + * Must be <= (packet buffer size - sizeof(*discovery_confirm)) / + * sizeof(*network_descriptor) + * That value limits number of Pan IDs visible for device during active scan. + */ +#define CONFIG_ZB_PANID_TABLE_SIZE 28 + +/** + * Source code - Disable TRACE_FILE_ID assert + */ +#define CONFIG_ZB_TRACE_LOG_LEVEL 2 + +/** + * ZB_ZGP_PROXY_TBL_SIZE + */ +#define CONFIG_ZB_ZGP_PROXY_TBL_SIZE 5 + +/** + * Source code - Finding and Binding + * + * Enable finding and binding, as defined in BDB specification + */ +#define CONFIG_ZB_BDB_ENABLE_FINDING_BINDING y + +/** + * ZB_SCHEDULER_Q_SIZE + * + * Scheduler callbacks queue size + */ +/* #undef CONFIG_ZB_SCHEDULER_Q_SIZE */ + +/** + * ZB_TRACE_MASK + * + * Selectively enable Zigbee binary trace logs. + * The mask value should be a bitwise OR of values assigned to selected modules. + * + * Available modules are: + * + * - 0x4000 Zigbee Green Power + * - 0x0800 Application + * - 0x0200 Zigbee Light Link + * - 0x0100 Zigbee Cluster Library + * - 0x0080 Security + * - 0x0040 Zigbee Device Object + * - 0x0010 Application Support layer + * - 0x0008 Network layer + * - 0x0004 MAC layer + * - 0x0002 Memory management + * - 0x0001 Common + * + * For example, in order to enable traces related to OTA DFU, + * one should set this option to 0x4100. + * + * Note: For general debugging purposes, please use 0x0C48. + */ +#define CONFIG_ZB_TRACE_MASK 0x0000 + +/** + * WWAHu server - NWK retransmissions + * + * Enable retransmissions on NWK layer + */ +#define CONFIG_ZB_NWK_RETRY_COUNT y + +/** + * ZB_NWK_BLACKLIST_SIZE + */ +#define CONFIG_ZB_NWK_BLACKLIST_SIZE 16 + +/** + * ZB_APS_DST_BINDING_TABLE_SIZE + */ +/* #undef CONFIG_ZB_APS_DST_BINDING_TABLE_SIZE */ + +/** + * ZB_NWK_BTR_TABLE_SIZE + * + * See Zigbee Specification subclause 3.6.5 + */ +#define CONFIG_ZB_NWK_BTR_TABLE_SIZE 16 + +#endif /* LIBZBOSS_CONFIG_H__ */ diff --git a/zboss/include/osif/mac_platform.h b/zboss/include/osif/mac_platform.h new file mode 100644 index 0000000000..86f0ed8278 --- /dev/null +++ b/zboss/include/osif/mac_platform.h @@ -0,0 +1,260 @@ +/* ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2018 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: MAC platform definitions for nRF SoC. +*/ + +#ifndef ZB_MAC_PLATFORM_H__ +#define ZB_MAC_PLATFORM_H__ + +#include "zb_macll.h" + + +#if defined(MAC_NO_DATA) && (MAC_NO_DATA != ZB_MACLL_NO_DATA) +#error Please align Error code values (ZB_MACLL_NO_DATA and MAC_NO_DATA) +#endif + +#define ZB_MAC_HARDWARE_PB_MATCHING +#define ZB_MAC_CONFIGURABLE_TX_POWER +#define ZB_MAC_MANUAL_DUPS +#define ZB_MAC_SINGLE_PACKET_IN_FIFO +//#define ZB_MAC_RX_QUEUE_CAP 5 + +#define ZB_MAC_PENDING_BIT_SOURCE_MATCHING +#define ZB_AUTO_ACK_TX +#define ZB_MAC_AUTO_ACK_RECV +#define ZB_MANUAL_ACK +#define ZB_MANUAL_ACK_TIMEOUT +#define MAC_ACK_PARSE_BY_INTR + +/* gpTxOffset should be calibrated for each HW/SW variant. + * The reason is that ZB_GPD_TX_OFFSET_US is used from ZGP stub during Green Power frame transmitting, + * and the actual TX time is not known at this level due to delays of MAC layer or transceiver. + */ +#define ZB_GPD_TX_OFFSET_US (ZB_MILLISECONDS_TO_USEC(ZB_GPD_RX_OFFSET_MS)) +//#define MAC_AUTO_DELAY_IN_MAC_GP_SEND +#define MAC_AUTO_GPDF_RETX + +#define MAC_TIMER_QUANT_US 4 + +#define ZB_TRANSCEIVER_START_CHANNEL_NUMBER 11 +#define ZB_TRANSCEIVER_MAX_CHANNEL_NUMBER 26 +#define ZB_TRANSCEIVER_ALL_CHANNELS_MASK 0x07FFF800 /* 0000.0111 1111.1111 1111.1000 0000.0000*/ + + +/* Type definition required by ZBOSS transceiver API */ +typedef struct zb_transceiver_ctx_s +{ + zb_uint_t tx_status; // Required and modified by zb_mac.c +} +zb_transceiver_ctx_t; + + + +/** + Tail size for mac packet +*/ +#define ZB_TAIL_SIZE_FOR_RECEIVED_MAC_FRAME (ZB_MAC_EXTRA_DATA_SIZE) /* 2 */ + +/** + Definitions for extra information size in RX fifo packet. Packet format: + 1 byte packet length + N bytes of RX fifo data + M bytes of extra information + (LQI, RSSI, at some platforms Frame timer, Superframe counter etc) +*/ +#define ZB_MAC_PACKET_LENGTH_SIZE ZB_MACLL_PACKET_LENGTH_SIZE +#define ZB_MAC_EXTRA_DATA_SIZE ZB_MACLL_EXTRA_DATA_SIZE /* rssi & lqi - see zb_macll_metadata_t */ + +#define ZB_TRANSCEIVER_INIT_RADIO() +#define ZB_TRANSCEIVER_DEINIT_RADIO() + +/* According to BZ#14383 and J#ZB-72 this workaround is not needed, if it is needed to put + * transceiver in idle it should be done automatically in the MAC logic. */ +#define ZB_MAC_TRANSCEIVER_GO_IDLE() /* not needed */ +#define ZB_MAC_TRANSCEIVER_RESTORE() /* not needed */ +#define ZB_TRANSCEIVER_RADIO_ON_OFF() zb_macll_get_radio_on_off() + +#define zb_mac_transport_init zb_macll_init +#define ZB_RADIO_INT_DISABLE() ZB_OSIF_GLOBAL_LOCK() +#define ZB_RADIO_INT_ENABLE() ZB_OSIF_GLOBAL_UNLOCK() +#define ZB_IS_TRANSPORT_BUSY() ZB_MAC_GET_TRANS_INT_FLAG() + +#define ZB_MAC_SET_TRANS_INT() zb_macll_set_trans_int() +#define ZB_MAC_CLEAR_TRANS_INT() zb_macll_clear_trans_int() +#define ZB_MAC_GET_TRANS_INT_FLAG() zb_macll_get_trans_int() + +#define ZB_MAC_SET_RX_INT_STATUS_BIT() zb_macll_set_rx_flag() +#define ZB_MAC_CLEAR_RX_INT_STATUS_BIT() zb_macll_clear_rx_flag() +#define ZB_MAC_GET_RX_INT_STATUS_BIT() zb_macll_get_rx_flag() + +#define ZB_MAC_SET_TX_INT_STATUS_BIT() zb_macll_set_tx_flag() +#define ZB_MAC_CLEAR_TX_INT_STATUS_BIT() (zb_macll_clear_tx_flag(), ZB_TRANS_SET_TX_STATUS(0)) +#define ZB_MAC_GET_TX_INT_STATUS_BIT() zb_macll_get_tx_flag() + +#define ZB_MAC_READ_INT_STATUS_REG() /* already done by int handler */ + +#define ZB_TRANS_SET_TX_STATUS(status) (TRANS_CTX().tx_status = (status)) +#define ZB_TRANS_CHECK_CHANNEL_BUSY_ERROR() (TRANS_CTX().tx_status == ZB_TRANS_CHANNEL_BUSY_ERROR) +#define ZB_TRANS_CHECK_TX_RETRY_COUNT_EXCEEDED_ERROR() 0 +#define ZB_TRANS_CHECK_NO_ACK() (TRANS_CTX().tx_status == ZB_TRANS_NO_ACK) + +#define ZB_TRANSCEIVER_SET_COORD_SHORT_ADDR(addr) +#define ZB_TRANSCEIVER_SET_COORD_EXT_ADDR(addr) + +#define ZB_TRANSCEIVER_SET_PAN_COORDINATOR(pan_coord) zb_macll_set_pan_coord((zb_bool_t)pan_coord) + + +#ifdef ZB_MAC_HARDWARE_PB_MATCHING + +/* MAC source matching logic implemented in radio-driver v1.6.0: + * 1) Add device address in the driver's pending table if there is no indirect data for it (clear pending bit); + * 2) Remove device address from he driver's pending table if there is an indirect data for it (set pending bit); +*/ + +#define ZB_TRANSCEIVER_SRC_MATCH_SHORT_SET_PENDING_BIT(short_addr, value) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)&(short_addr), (zb_bool_t)(value), ZB_FALSE) + +#define ZB_TRANSCEIVER_SRC_MATCH_ADD_SHORT_ADDR(index, short_addr) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)&(short_addr), ZB_FALSE, ZB_FALSE) + +#define ZB_TRANSCEIVER_SRC_MATCH_DELETE_SHORT_ADDR(index, short_addr) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)&(short_addr), ZB_TRUE, ZB_FALSE) + +#define ZB_TRANSCEIVER_SRC_MATCH_IEEE_SET_PENDING_BIT(ieee_addr, value) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)(ieee_addr), (zb_bool_t)(value), ZB_TRUE) + +#define ZB_TRANSCEIVER_SRC_MATCH_ADD_IEEE_ADDR(index, ieee_addr) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)(ieee_addr), ZB_FALSE, ZB_TRUE) + +#define ZB_TRANSCEIVER_SRC_MATCH_DELETE_IEEE_ADDR(index, ieee_addr) \ + zb_macll_src_match_set_pending_bit((zb_uint8_t *)(ieee_addr), ZB_TRUE, ZB_TRUE) + +#define ZB_TRANSCEIVER_SRC_MATCH_TBL_DROP() zb_macll_src_match_tbl_drop() + + +#else /* !ZB_MAC_HARDWARE_PB_MATCHING */ +#error Only one Pending Bit handling method is supported. + +#endif /* !ZB_MAC_HARDWARE_PB_MATCHING */ + + +#define ZB_TRANSCEIVER_SET_SHORT_ADDR(addr) zb_macll_set_short_addr(addr) +#define ZB_TRANSCEIVER_UPDATE_SHORT_ADDR() ZB_TRANSCEIVER_SET_SHORT_ADDR(MAC_PIB().mac_short_address) + +#define ZB_TRANSCEIVER_SET_PAN_ID(pan_id) zb_macll_set_pan_id(pan_id) +#define ZB_TRANSCEIVER_UPDATE_PAN_ID() ZB_TRANSCEIVER_SET_PAN_ID(MAC_PIB().mac_pan_id) + +#define ZB_TRANSCEIVER_SET_LONGMAC(long_mac) zb_macll_set_long_addr(long_mac) +#define ZB_TRANSCEIVER_UPDATE_LONGMAC() ZB_TRANSCEIVER_SET_LONGMAC((zb_uint8_t *)ZB_PIB_EXTENDED_ADDRESS()) + + +#define ZB_TRANS_SEND_FRAME(header_length, buf, wait_type) \ + { \ + ZB_DUMP_OUTGOING_DATA(buf); \ + (void)header_length; \ + zb_macll_send_packet((buf), (wait_type)); \ + } + +#define ZB_TRANS_REPEAT_SEND_FRAME(header_length, buf, wait_type) \ + (ZB_DUMP_OUTGOING_DATA(buf), \ + (void)header_length, zb_macll_resend_packet(wait_type, 0)) + +#define ZB_TRANS_GET_TX_TIMESTAMP() zb_macll_get_tx_timestamp() + +#ifdef MAC_RADIO_TX_WATCHDOG_ALARM +#error Not implemented feature +#define ZB_MAC_TX_ABORT() +#endif + + +#define ZB_TRANSCEIVER_SET_PROMISCUOUS(promiscuous_mode) + +#define ZB_TRANSCEIVER_SET_CHANNEL(page, channel_number) zb_macll_set_channel(channel_number) + +#define ZB_TRANSCEIVER_START_GET_RSSI(_scan_duration_bi) zb_macll_start_get_rssi(_scan_duration_bi); +#define ZB_TRANSCEIVER_GET_RSSI(rssi_value) zb_macll_get_rssi(rssi_value) +#define ZB_TRANSCEIVER_GET_ENERGY_LEVEL(ed_level) ZB_TRANSCEIVER_GET_RSSI(ed_level) + +#define ZB_TRANSCEIVER_SET_RX_ON_OFF(_rx_on) zb_macll_trans_set_rx_on_off(_rx_on) +#define ZB_TRANSCEIVER_GET_RX_ON_OFF() zb_macll_get_rx_on_off() + +#define ZB_TRANS_RECV_PACKET(buf) zb_macll_get_next_packet(buf) +#define ZB_MAC_TRANS_CLEAR_PENDING_BIT() +#define ZB_MAC_TRANS_SET_PENDING_BIT() + +/** + Get LQI value + @param packet - pointer to buffer +*/ +#define ZB_MAC_GET_LQI(packet) zb_macll_metadata_get_lqi(packet) + +/** + Set LQI value + @param packet - pointer to buffer + @param v - LQI value +*/ +#define ZB_MAC_SET_LQI(packet, v) zb_macll_metadata_set_lqi(packet, v) + +/** + Get RSSI value + @param packet - pointer to buffer +*/ +#define ZB_MAC_GET_RSSI(packet) zb_macll_metadata_get_power(packet) + +/** + Set RSSI value + @param packet - pointer to buffer + @param v - RSSI value +*/ +#define ZB_MAC_SET_RSSI(packet, v) zb_macll_metadata_set_power(packet, v) + + +/*PHY tests specific API. Implement for PHY tests only.*/ +#define ZB_TRANSCEIVER_PERFORM_CCA() (0) /*Perform single CCA attempt. Used in TP_154_PHY24_RECEIVER_07 test*/ +#define ZB_TRANS_TX_CARRIER_DATA(channel, timeout_bi) (0) /*Start continuous transmission. Used in TP_154_PHY24_TRANSMIT_02 test.*/ + +#define ZB_TRANSCEIVER_SET_TX_POWER(new_power) zb_macll_set_tx_power(new_power) +#define ZB_TRANSCEIVER_GET_TX_POWER(power) zb_macll_get_tx_power(power) + +/** + Cut transceiver-specific header (length byte) +*/ +#define ZB_TRANS_CUT_SPECIFIC_HEADER(zb_buffer) + + +#endif /* ZB_MAC_PLATFORM_H__ */ diff --git a/zboss/include/osif/zb_config_platform.h b/zboss/include/osif/zb_config_platform.h new file mode 100644 index 0000000000..b5185ce408 --- /dev/null +++ b/zboss/include/osif/zb_config_platform.h @@ -0,0 +1,95 @@ +/* ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2018 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Compiler and CPU specific configuration. +*/ + +#ifndef ZB_CONFIG_PLATFORM_H__ +#define ZB_CONFIG_PLATFORM_H__ + +#include /* memcpy */ +#include + + +#ifdef __IAR_SYSTEMS_ICC__ +#ifndef ZB_IAR +#define ZB_IAR +#endif +#endif + +/* The MAIN() macro is meant to be used only by applications and tests implemented within ZBOSS source code repository. */ +#define MAIN() int zboss_app_main(void) +#define FAKE_ARGV +#define ARGV_UNUSED +#define MAIN_RETURN(v) return (v) + +#ifdef KEIL +#define ZB_MEMCPY(dst, src, size) memcpy((void*)(dst), (void*)(src), (size)) +#define ZB_MEMSET(dst, val, size) memset((void*)(dst), (val), (size)) +#define ZB_MEMMOVE(dst, src, size) memmove((void*)(dst), (void*)(src), (size)) +#define ZB_MEMCMP(ptr1, ptr2, size) memcmp((void*)(ptr1), (void*)(ptr2), (size)) + +#else /* KEIL */ +#define ZB_MEMCPY memcpy +#define ZB_MEMSET memset +#define ZB_MEMMOVE memmove +#define ZB_MEMCMP memcmp +#endif /* KEIL */ + + +/* Enable default parameters, specific for nRF52 platform. */ +#define ZB_CONFIG_NRF52 +#define ZB_PLATFORM_NRF52 + +#define ZB_LITTLE_ENDIAN +#define ZB_NEED_ALIGN +#define ZB_VOLATILE +#define ZB_CALLBACK +#define ZB_SDCC_BANKED +#define ZB_KEIL_REENTRANT + +#define ZB_BZERO(s,l) ZB_MEMSET((char*)(s), 0, (l)) +#define ZB_BZERO2(s) ZB_BZERO(s, 2) +#define ZVUNUSED(v) (void)v + + +/* At ARM all types from 1 to 4 bytes are passed to vararg with casting to 4 bytes */ +typedef uint32_t zb_minimal_vararg_t; + +#endif /* ZB_CONFIG_PLATFORM_H__ */ diff --git a/zboss/include/osif/zb_macll.h b/zboss/include/osif/zb_macll.h new file mode 100644 index 0000000000..7733b52796 --- /dev/null +++ b/zboss/include/osif/zb_macll.h @@ -0,0 +1,96 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_MACLL_H__ +#define ZB_MACLL_H__ + +#include +#include "zb_transceiver.h" + +/** The number of metadata bytes, attached to each received frame, + * at the end of ZBOSS buffer. + */ +#define ZB_MACLL_EXTRA_DATA_SIZE sizeof(zb_macll_metadata_t) + +/** The number of bytes used to pass the frame length field, + * at the beginning of ZBOSS buffer. + */ +#define ZB_MACLL_PACKET_LENGTH_SIZE 1 + +/** + Get a reference to MAC LL specific metadata structure. + @param packet - pointer to buffer +*/ +#define ZB_MACLL_GET_METADATA(packet) ((zb_macll_metadata_t *)((zb_uint8_t*)zb_buf_end(packet) - ZB_MACLL_EXTRA_DATA_SIZE)) + +/** Status code indicating that the received Data frame + * was not acknowledged with a pending bit set (indirect poll). + */ +#define ZB_MACLL_NO_DATA 0xeb + + +/** Structure attached to each ZBOSS buffer used to pass additional metadata. */ +typedef struct +{ + uint8_t lqi; + int8_t power; +} ZB_PACKED_STRUCT zb_macll_metadata_t; + + +void zb_macll_init(void); + +void zb_macll_set_trans_int(void); +void zb_macll_clear_trans_int(void); +zb_bool_t zb_macll_get_trans_int(void); + +void zb_macll_set_rx_flag(void); +void zb_macll_clear_rx_flag(void); +zb_bool_t zb_macll_get_rx_flag(void); + +void zb_macll_set_tx_flag(void); +void zb_macll_clear_tx_flag(void); +zb_bool_t zb_macll_get_tx_flag(void); + +zb_uint8_t zb_macll_src_match_set_pending_bit(zb_uint8_t *addr, zb_bool_t value, zb_bool_t extended); +#define zb_macll_src_match_tbl_drop zb_trans_src_match_tbl_drop + +#define zb_macll_set_short_addr zb_trans_set_short_addr +#define zb_macll_set_long_addr zb_trans_set_long_addr +#define zb_macll_set_pan_id zb_trans_set_pan_id +#define zb_macll_set_pan_coord zb_trans_set_pan_coord + +#define zb_macll_get_radio_on_off zb_trans_is_active +#define zb_macll_set_tx_power zb_trans_set_tx_power +#define zb_macll_get_tx_power zb_trans_get_tx_power +#define zb_macll_set_channel zb_trans_set_channel +#define zb_macll_start_get_rssi zb_trans_start_get_rssi +#define zb_macll_get_rssi zb_trans_get_rssi + +void zb_macll_send_packet(zb_bufid_t buf, zb_uint8_t wait_type); +void zb_macll_resend_packet(zb_uint8_t wait_type, zb_time_t tx_at); +zb_time_t zb_macll_get_tx_timestamp(void); + +void zb_macll_transmitted_raw(zb_uint8_t * p_ack); +void zb_macll_transmit_failed(zb_uint8_t error); + +void zb_macll_trans_set_rx_on_off(int rx_on); +#define zb_macll_get_rx_on_off zb_trans_is_receiving +/**@brief Pass to MAC data packet already read by radio driver layer. + * + * @param buf - ZBOSS buffer - placeholder for incoming data. + * + * @retval[0] No packets available. + * @retval[1] New packet copied to the buf. + */ +#define zb_macll_get_next_packet zb_trans_get_next_packet + +int8_t zb_macll_metadata_get_power(zb_bufid_t bufid); +void zb_macll_metadata_set_power(zb_bufid_t bufid, int8_t power); +uint8_t zb_macll_metadata_get_lqi(zb_bufid_t bufid); +void zb_macll_metadata_set_lqi(zb_bufid_t bufid, uint8_t lqi); + + +#endif /* ZB_MACLL_H__ */ diff --git a/zboss/include/osif/zb_osif_platform.h b/zboss/include/osif/zb_osif_platform.h new file mode 100644 index 0000000000..5af73d5abd --- /dev/null +++ b/zboss/include/osif/zb_osif_platform.h @@ -0,0 +1,197 @@ +/* ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2018 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Header to combine osif dependent files with stack +*/ + +#ifndef ZB_OSIF_PLATFORM_H__ +#define ZB_OSIF_PLATFORM_H__ + +#include "zb_types.h" +#include "zb_ringbuffer.h" + + +#define ZB_INTERRUPT_SAFE_CALLBACKS +#define ZB_USE_NVRAM +#define ZB_NVRAM_RADIO_OFF_DURING_TRANSACTION + +/* trace */ +#define ZB_NRF_TRACE + +#ifdef ZB_TRACE_LEVEL +#define ZB_TRACE_OVER_USART +#define ZB_TRACE_TO_PORT +#define ZB_BINARY_TRACE +#define ZB_TRACE_FROM_INTR +#define ZB_TRAFFIC_DUMP_ON +#define ZB_TRAF_DUMP_V2 +#endif /* ZB_TRACE_LEVEL */ + +#if defined ZB_TRACE_OVER_USART && defined ZB_TRACE_LEVEL +#define ZB_SERIAL_FOR_TRACE +#endif /* ZB_TRACE_OVER_USART && ZB_TRACE_LEVEL */ + +#ifdef ZB_SERIAL_FOR_TRACE +void zb_osif_serial_flush(void); +#if defined(ZB_NRF_TRACE) && (defined CONFIG_ZB_ASYNC_TRACE_CONTROL || defined ZB_MULTI_TEST) +#define ZB_OSIF_SERIAL_FLUSH() zb_osif_serial_flush() +#else /* ZB_NRF_TRACE && (CONFIG_ZB_ASYNC_TRACE_CONTROL || defined ZB_MULTI_TEST) */ +#define ZB_OSIF_SERIAL_FLUSH() +#endif /* ZB_NRF_TRACE && (CONFIG_ZB_ASYNC_TRACE_CONTROL || defined ZB_MULTI_TEST) */ +#endif /* ZB_SERIAL_FOR_TRACE */ + + +#define ZB_SOFT_SECURITY +#define ZB_HW_ZB_AES128 + +#ifdef ZB_HW_ZB_AES128 +void zb_osif_aes128_hw_encrypt(zb_uint8_t *key, zb_uint8_t *msg, zb_uint8_t *c); +#define hw_aes128 zb_osif_aes128_hw_encrypt +#endif /* ZB_HW_ZB_AES128 */ + + +void zb_osif_init(void); +#define ZB_PLATFORM_INIT() zb_osif_init() + +void zb_osif_abort(void); +#define ZB_ABORT zb_osif_abort + +#define ZB_GO_IDLE() + + +void zb_osif_timer_init(void); +zb_uint32_t zb_osif_timer_get(void); + +void zb_osif_timer_stop(void); +#define ZB_STOP_HW_TIMER() zb_osif_timer_stop() + +void zb_osif_timer_start(void); +#define ZB_START_HW_TIMER() zb_osif_timer_start() + +zb_bool_t zb_osif_timer_is_on(void); +#define ZB_CHECK_TIMER_IS_ON() zb_osif_timer_is_on() + + +void zb_osif_enable_all_inter(void); +void zb_osif_disable_all_inter(void); + +#ifdef ZB_STACK_REGRESSION_TESTING_API + +#define ZB_ENABLE_ALL_INTER() \ + ZB_REGRESSION_TESTS_API().osif_interrupts_balance++; \ + zb_osif_enable_all_inter() +#define ZB_DISABLE_ALL_INTER() \ + ZB_REGRESSION_TESTS_API().osif_interrupts_balance--; \ + zb_osif_disable_all_inter() + +#else /* ZB_STACK_REGRESSION_TESTING_API */ + +#define ZB_ENABLE_ALL_INTER() zb_osif_enable_all_inter() +#define ZB_DISABLE_ALL_INTER() zb_osif_disable_all_inter() + +#endif /* ZB_STACK_REGRESSION_TESTING_API */ + +#define ZB_OSIF_GLOBAL_LOCK() ZB_DISABLE_ALL_INTER() +#define ZB_OSIF_GLOBAL_UNLOCK() ZB_ENABLE_ALL_INTER() + + +#ifdef ZB_USE_SLEEP +void zb_osif_sleep_init(void); +zb_uint32_t zb_osif_sleep(zb_uint32_t sleep_tmo); +zb_bool_t zb_osif_is_sleeping(void); +#endif /* ZB_USE_SLEEP */ + + + +#ifdef ZB_MACSPLIT_TRANSPORT_USERIAL +#define ZB_TRANSPORT_NONBLOCK_ITERATION() (zb_macsplit_transport_recv_bytes(),0) +#else /* ZB_MACSPLIT_TRANSPORT_USERIAL */ +#define ZB_TRANSPORT_NONBLOCK_ITERATION() 0 +#endif /* ZB_MACSPLIT_TRANSPORT_USERIAL */ + + +#ifdef CONFIG_ZB_HAVE_SERIAL +#define ZB_HAVE_SERIAL +#define ZB_HAVE_ASYNC_SERIAL +#endif /* CONFIG_ZB_HAVE_SERIAL */ + + +/** @addtogroup special_nordic_functions + * @{ + */ + +/** + * @brief Read IEEE long address from FICR registers. + * + * @param[out] ieee_eui64 Pointer to a long address structure to be filled. + */ +void zb_osif_get_ieee_eui64(zb_ieee_addr_t ieee_eui64); + +#ifdef CONFIG_RADIO_STATISTICS +typedef struct zb_osif_radio_stats_s +{ + zb_uint32_t rx_successful; /* Success: nrf_802154_received_timestamp_raw() calls count. */ + zb_uint32_t rx_err_none; /* Error Code: 0x00 */ + zb_uint32_t rx_err_invalid_frame; /* Error Code: 0x01 */ + zb_uint32_t rx_err_invalid_fcs; /* Error Code: 0x02 */ + zb_uint32_t rx_err_invalid_dest_addr; /* Error Code: 0x03 */ + zb_uint32_t rx_err_runtime; /* Error Code: 0x04 */ + zb_uint32_t rx_err_timeslot_ended; /* Error Code: 0x05 */ + zb_uint32_t rx_err_aborted; /* Error Code: 0x06 */ + + zb_uint32_t tx_successful; /* Success: nrf_802154_transmitted_raw() calls count. */ + zb_uint32_t tx_err_none; /* Error Code: 0x00 */ + zb_uint32_t tx_err_busy_channel; /* Error Code: 0x01 */ + zb_uint32_t tx_err_invalid_ack; /* Error Code: 0x02 */ + zb_uint32_t tx_err_no_mem; /* Error Code: 0x03 */ + zb_uint32_t tx_err_timeslot_ended; /* Error Code: 0x04 */ + zb_uint32_t tx_err_no_ack; /* Error Code: 0x05 */ + zb_uint32_t tx_err_aborted; /* Error Code: 0x06 */ + zb_uint32_t tx_err_timeslot_denied; /* Error Code: 0x07 */ + +} zb_osif_radio_stats_t; + +zb_osif_radio_stats_t *zb_osif_get_radio_stats(void); +#endif /* CONFIG_RADIO_STATISTICS */ + +/** + * @} + */ + +#endif /* ZB_OSIF_PLATFORM_H__ */ diff --git a/zboss/include/osif/zb_revision_r22.h b/zboss/include/osif/zb_revision_r22.h new file mode 100644 index 0000000000..3f9ac9b33c --- /dev/null +++ b/zboss/include/osif/zb_revision_r22.h @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + * + * This file implements mappings of Kconfig options enabling and configuring ZBOSS features. + */ + +/* ZBOSS platform for NCS build number. */ +#define ZBOSS_SDK_REVISION 1 diff --git a/zboss/include/osif/zb_transceiver.h b/zboss/include/osif/zb_transceiver.h new file mode 100644 index 0000000000..9aab8213ce --- /dev/null +++ b/zboss/include/osif/zb_transceiver.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +#ifndef ZB_TRANSCEIVER_H__ +#define ZB_TRANSCEIVER_H__ + +void zb_trans_hw_init(void); +void zb_trans_set_pan_id(zb_uint16_t pan_id); +void zb_trans_set_long_addr(zb_ieee_addr_t long_addr); +void zb_trans_set_short_addr(zb_uint16_t addr); +void zb_trans_start_get_rssi(zb_uint8_t scan_duration_bi); +void zb_trans_get_rssi(zb_uint8_t *rssi_value_p); +void zb_trans_set_channel(zb_uint8_t channel_number); +void zb_trans_set_tx_power(zb_int8_t power); +void zb_trans_get_tx_power(zb_int8_t *power); +void zb_trans_set_pan_coord(zb_bool_t pan_coord); +void zb_trans_set_auto_ack(zb_bool_t enabled); +void zb_trans_set_promiscuous_mode(zb_bool_t enabled); +void zb_trans_enter_receive(void); +void zb_trans_enter_sleep(void); +zb_bool_t zb_trans_is_receiving(void); +zb_bool_t zb_trans_is_active(void); +zb_bool_t zb_trans_transmit(zb_uint8_t wait_type, zb_time_t tx_at, zb_uint8_t *tx_buf, zb_uint8_t current_channel); +void zb_trans_buffer_free(zb_uint8_t *p_buf); +zb_bool_t zb_trans_set_pending_bit(zb_uint8_t *addr, zb_bool_t value, zb_bool_t extended); +void zb_trans_src_match_tbl_drop(void); +zb_time_t osif_sub_trans_timer(zb_time_t t2, zb_time_t t1); +zb_uint8_t zb_trans_get_next_packet(zb_bufid_t buf); + +#endif /* ZB_TRANSCEIVER_H__ */ diff --git a/zboss/include/osif/zb_vendor.h b/zboss/include/osif/zb_vendor.h new file mode 100644 index 0000000000..6c4fe8bd07 --- /dev/null +++ b/zboss/include/osif/zb_vendor.h @@ -0,0 +1,251 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + * + * This file implements mappings of Kconfig options enabling and configuring ZBOSS features. + */ + +#ifndef ZB_VENDOR_H__ +#define ZB_VENDOR_H__ + +/** + * Include additional configuration file, which usually contains the set of + * symbols defined by ZBOSS source code Kconfig, which can be found in NCS + * platform repository. + */ +#ifdef LIBZBOSS_CONFIG_FILE +#include LIBZBOSS_CONFIG_FILE +#endif + +#include "zb_config_platform.h" + + +#ifdef CONFIG_ZB_TRACE_LOG_LEVEL +#define ZB_TRACE_LEVEL CONFIG_ZB_TRACE_LOG_LEVEL +#endif + +#ifdef CONFIG_ZB_TRACE_MASK +#define ZB_TRACE_MASK CONFIG_ZB_TRACE_MASK +#endif + +#ifdef CONFIG_ZB_NVRAM_ENABLE_VER_MIGRATION +#define ZB_NVRAM_ENABLE_VER_MIGRATION +#else +#define ZB_NO_NVRAM_VER_MIGRATION +#endif + +#ifdef CONFIG_ZB_BDB_ENABLE_FINDING_BINDING +#define ZB_BDB_ENABLE_FINDING_BINDING +#endif + +#ifdef CONFIG_ZB_DISTRIBUTED_SECURITY_ON +#define ZB_DISTRIBUTED_SECURITY_ON +#endif + +#ifdef CONFIG_ZB_SECURITY_INSTALLCODES +#define ZB_SECURITY_INSTALLCODES +#endif + +#ifdef CONFIG_ZB_PRODUCTION_CONFIG +#define ZB_PRODUCTION_CONFIG +#endif + +#ifdef CONFIG_ZB_APS_USER_PAYLOAD +#define ZB_APS_USER_PAYLOAD +#endif + +#ifdef CONFIG_ZB_LOW_SECURITY_MODE +#define ZB_LOW_SECURITY_MODE +#endif + +#ifdef CONFIG_ZB_APS_FRAGMENTATION +#define APS_FRAGMENTATION +#endif + +#ifdef CONFIG_ZB_NWK_BLACKLIST +#define ZB_NWK_BLACKLIST + +#ifdef CONFIG_ZB_NWK_BLACKLIST_SIZE +#define ZB_NWK_BLACKLIST_SIZE CONFIG_ZB_NWK_BLACKLIST_SIZE +#endif + +#endif /* CONFIG_ZB_NWK_BLACKLIST */ + +#ifdef CONFIG_ZB_ZCL_SUPPORT_CLUSTER_WWAH +#define ZB_R22_MULTIMAC +#define ZB_ZCL_SUPPORT_CLUSTER_WWAH + +#ifdef CONFIG_ZB_ZCL_ENABLE_WWAH_CLIENT +#define ZB_ZCL_ENABLE_WWAH_CLIENT +#endif + +#ifdef CONFIG_ZB_ZCL_ENABLE_WWAH_SERVER +#define ZB_ZCL_ENABLE_WWAH_SERVER + +#ifdef CONFIG_ZB_NWK_RETRY_COUNT +#define ZB_NWK_RETRY_COUNT +#endif + +#ifdef CONFIG_ZB_BEACON_SURVEY +#define ZB_BEACON_SURVEY +#endif + +#ifdef CONFIG_ZB_PARENT_CLASSIFICATION +#define ZB_PARENT_CLASSIFICATION +#endif + +#elif defined(CONFIG_ZB_NWK_RETRY_COUNT) || defined(CONFIG_ZB_BEACON_SURVEY) || defined(CONFIG_ZB_PARENT_CLASSIFICATION) +#error ZBOSS configuration mismatch: You have to enable WWAHu cluster server implementation to use additional WWAHu features. + +#endif /* ZB_ZCL_ENABLE_WWAH_SERVER */ + +#endif /* CONFIG_ZB_ZCL_SUPPORT_CLUSTER_WWAH */ + +#ifdef CONFIG_ZB_CHECK_OOM_STATUS +#define ZB_CHECK_OOM_STATUS +#endif + +#ifdef CONFIG_ZB_SEND_OOM_STATUS +#define ZB_SEND_OOM_STATUS +#endif + +#ifdef CONFIG_ZB_PROMISCUOUS_MODE +#define ZB_PROMISCUOUS_MODE +#endif + +#ifdef CONFIG_ZB_CERTIFICATION_HACKS +#define ZB_CERTIFICATION_HACKS +#endif + +#ifdef CONFIG_ZB_TEST_PROFILE +#define ZB_TEST_PROFILE +#endif + +#ifdef CONFIG_ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT +#define ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT CONFIG_ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT +#endif + +#ifdef CONFIG_ZB_DONT_NEED_TRACE_FILE_ID +#define ZB_DONT_NEED_TRACE_FILE_ID +#endif + +#ifdef CONFIG_ZB_MAC_AUTO_DELAY_IN_MAC_GP_SEND +#define MAC_AUTO_DELAY_IN_MAC_GP_SEND +#endif + +#ifdef CONFIG_ZB_USEALIAS +#define ZB_USEALIAS +#endif + +#ifdef CONFIG_ZB_LIMIT_VISIBILITY +#define ZB_LIMIT_VISIBILITY +#endif + +#ifdef CONFIG_ZB_BDB_TOUCHLINK +#define ZB_ENABLE_INTER_PAN_EXCHANGE +#define ZB_ENABLE_ZLL +#define ZB_BDB_TOUCHLINK +#endif + +#ifdef CONFIG_ZB_CONFIGURABLE_MEM +#define ZB_CONFIGURABLE_MEM +#endif + +/* Default memory storage configuration, used while dynamic memory configuration features is enabled. */ +#ifdef ZB_CONFIG_DEFAULT_KERNEL_DEFINITION + +/* Select memory configuration according to the implemented Zigbee role. */ +#ifndef ZB_ED_ROLE +#define ZB_CONFIG_ROLE_ZC +#else +#define ZB_CONFIG_ROLE_ZED +#endif + +#ifdef CONFIG_ZB_CONFIG_OVERALL_NETWORK_SIZE +#define ZB_CONFIG_OVERALL_NETWORK_SIZE CONFIG_ZB_CONFIG_OVERALL_NETWORK_SIZE +#endif + +#ifdef CONFIG_ZB_CONFIG_HIGH_TRAFFIC +#define ZB_CONFIG_HIGH_TRAFFIC +#endif + +#ifdef CONFIG_ZB_CONFIG_MODERATE_TRAFFIC +#define ZB_CONFIG_MODERATE_TRAFFIC +#endif + +#ifdef CONFIG_ZB_CONFIG_LIGHT_TRAFFIC +#define ZB_CONFIG_LIGHT_TRAFFIC +#endif + +#ifdef CONFIG_ZB_CONFIG_APPLICATION_COMPLEX +#define ZB_CONFIG_APPLICATION_COMPLEX +#endif + +#ifdef CONFIG_ZB_CONFIG_APPLICATION_MODERATE +#define ZB_CONFIG_APPLICATION_MODERATE +#endif + +#ifdef CONFIG_ZB_CONFIG_APPLICATION_SIMPLE +#define ZB_CONFIG_APPLICATION_SIMPLE +#endif + +#endif /* ZB_CONFIG_DEFAULT_KERNEL_DEFINITION */ + +/* Compile-time parameters, affecting memory usage in all configurations. */ +#define ZB_PANID_TABLE_SIZE CONFIG_ZB_PANID_TABLE_SIZE +#define ZB_DEV_MANUFACTORER_TABLE_SIZE CONFIG_ZB_DEV_MANUFACTURER_TABLE_SIZE +#define ZB_BUF_Q_SIZE CONFIG_ZB_BUF_Q_SIZE +#define ZDO_TRAN_TABLE_SIZE CONFIG_ZB_ZDO_TRAN_TABLE_SIZE +#define ZB_APS_ENDPOINTS_IN_GROUP_TABLE CONFIG_ZB_APS_ENDPOINTS_IN_GROUP_TABLE +#define ZB_NWK_BTR_TABLE_SIZE CONFIG_ZB_NWK_BTR_TABLE_SIZE +#define ZB_NWK_BRR_TABLE_SIZE CONFIG_ZB_NWK_BRR_TABLE_SIZE +#define ZB_MAX_EP_NUMBER CONFIG_ZB_MAX_EP_NUMBER +#define ZB_APS_GROUP_TABLE_SIZE CONFIG_ZB_APS_GROUP_TABLE_SIZE +#define ZB_ZGP_SINK_TBL_SIZE CONFIG_ZB_ZGP_SINK_TBL_SIZE +#define ZB_ZGP_PROXY_TBL_SIZE CONFIG_ZB_ZGP_PROXY_TBL_SIZE + +#ifdef CONFIG_ZB_APS_SRC_BINDING_TABLE_SIZE +#define ZB_APS_SRC_BINDING_TABLE_SIZE CONFIG_ZB_APS_SRC_BINDING_TABLE_SIZE +#endif + +#ifdef CONFIG_ZB_APS_DST_BINDING_TABLE_SIZE +#define ZB_APS_DST_BINDING_TABLE_SIZE CONFIG_ZB_APS_DST_BINDING_TABLE_SIZE +#endif + +#ifdef CONFIG_ZB_IOBUF_POOL_SIZE +#define ZB_IOBUF_POOL_SIZE CONFIG_ZB_IOBUF_POOL_SIZE +#endif + +#ifdef CONFIG_ZB_SCHEDULER_Q_SIZE +#define ZB_SCHEDULER_Q_SIZE CONFIG_ZB_SCHEDULER_Q_SIZE +#endif + +#ifndef ZB_CONFIGURABLE_MEM +#define ZB_CHILD_HASH_TABLE_SIZE (((ZB_IEEE_ADDR_TABLE_SIZE + ZB_IEEE_ADDR_TABLE_SIZE / 3) + 31) / 32 * 32) +#endif /* ZB_CONFIGURABLE_MEM */ + + +/* ZBOSS stack options non-configurable via Kconfig. */ + +/* Include Zigbee BDB implementation (always defined, except macsplit). */ +#define ZB_BDB_MODE + +/* Include Zigbee HA clusters implementation (always defined, except macsplit). */ +#define ZB_ENABLE_HA + +/* Include all HA device definitions. For a better granularity, please take a look at the list in zb_ha_device_config.h file (always defined, except macsplit). */ +#define ZB_ALL_DEVICE_SUPPORT + +/* Include rejoin backoff procedure (always included, except macsplit). */ +#define ZB_REJOIN_BACKOFF + +/* Enable ZGP profile (always defined, except macsplit). */ +#define ZB_ENABLE_ZGP + +/* Enable sleepy behaviour on all devices. The sleep signal will allow other, lower-priority task to take over. */ +#ifndef ZB_USE_SLEEP +#define ZB_USE_SLEEP +#endif + +#endif /* ZB_VENDOR_H__ */ diff --git a/zboss/include/se/zb_se_keep_alive.h b/zboss/include/se/zb_se_keep_alive.h new file mode 100644 index 0000000000..36976678f3 --- /dev/null +++ b/zboss/include/se/zb_se_keep_alive.h @@ -0,0 +1,162 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Definitions of SE's Keep-Alive cluster (SE spec, Annex A.3) +*/ + +#ifndef ZB_SE_KEEP_ALIVE_H +#define ZB_SE_KEEP_ALIVE_H 1 + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_SE_SECTION */ + +/** @addtogroup ZB_ZCL_KEEP_ALIVE + * @{ + * @details + * This cluster supports the commands and attributes directed to the network Trust Center in + * order to determine whether communication with the Trust Center is still available. + * + */ + +/* Cluster ZB_ZCL_CLUSTER_ID_KEEP_ALIVE */ + +/*! @name Keep-Alive cluster attributes + @{ +*/ + +/*! @brief Keep-Alive cluster attribute identifiers + @see SE spec, subclause A.3.2 +*/ +enum zb_zcl_keep_alive_attr_e +{ + /*! @brief TC Keep-Alive Base attribute */ + ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID = 0, + /*! @brief TC Keep-Alive Jitter attribute */ + ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID = 1 +}; + +/** @brief Default value for TC Keep-Alive Base attribute */ +#define ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_DEFAULT_VALUE 0x0a +/** @brief Default value for TC Keep-Alive Jitter attribute */ +#define ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_DEFAULT_VALUE 0x012c + +/*! @} */ /* Keep-Alive cluster attributes */ + +/*! @name Keep-Alive cluster commands + @{ +*/ +/*! @} */ /* Keep-Alive cluster commands */ + +/*! @cond internals_doc + @internal @name Keep-Alive cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/** @internal @brief Declare attribute list for Keep-Alive cluster + @param attr_list - attribute list name + @param base - pointer to variable to store TC Keep-Alive Base attribute value + @param jitter - pointer to variable to store TC Keep-Alive Jitter attribute value +*/ +#define ZB_ZCL_DECLARE_KEEP_ALIVE_ATTR_LIST_FULL(attr_list, base, jitter) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID, (base)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID, (jitter)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @internal Number of attributes mandatory for reporting in Keep-Alive cluster */ +#define ZB_ZCL_KEEP_ALIVE_REPORT_ATTR_COUNT 0 + +/*! @} + @endcond */ /* Keep-Alive cluster internals */ + + +/** + * @brief Keep-Alive cluster attributes + */ +typedef struct zb_zcl_keep_alive_attrs_s +{ + + /** @copydoc ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID + * @see ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_BASE_ID + */ + zb_uint8_t base; + + /** @copydoc ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID + * @see ZB_ZCL_ATTR_KEEP_ALIVE_TC_KEEP_ALIVE_JITTER_ID + */ + zb_uint16_t jitter; +} zb_zcl_keep_alive_attrs_t; + + +/** @brief Declare attribute list for Keep-Alive cluster cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - pointer to @ref zb_zcl_keep_alive_attrs_s structure + */ +#define ZB_ZCL_DECLARE_KEEP_ALIVE_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_KEEP_ALIVE_ATTR_LIST_FULL(attr_list, &attrs.base, &attrs.jitter ) + + +/*! @} */ /* SE Keep-Alive cluster definitions */ + +/** @endcond */ /* DOXYGEN_SE_SECTION */ + +#define ZB_ZCL_CLUSTER_ID_KEEP_ALIVE_SERVER_ROLE_INIT (zb_zcl_cluster_init_t)NULL +#define ZB_ZCL_CLUSTER_ID_KEEP_ALIVE_CLIENT_ROLE_INIT (zb_zcl_cluster_init_t)NULL + +#endif /* ZB_SE_KEEP_ALIVE_H */ diff --git a/zboss/include/zb_address.h b/zboss/include/zb_address.h new file mode 100644 index 0000000000..9bdaad516f --- /dev/null +++ b/zboss/include/zb_address.h @@ -0,0 +1,612 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Zigbee address management +*/ + +#ifndef ZB_ADDRESS_H +#define ZB_ADDRESS_H 1 + +/*! \addtogroup ZB_NWK_ADDR */ +/*! @{ */ + + +/*! @cond internals_doc */ + +#define ZB_UNKNOWN_SHORT_ADDR (zb_uint16_t)(-1) + +/** + Compressed IEEE address. One byte device manufacturer - reference to + \see zb_dev_manufacturer_t array. +*/ +typedef ZB_PACKED_PRE struct zb_ieee_addr_compressed_s +{ + zb_uint8_t dev_manufacturer; /*!< Index from dev manufacturer array */ + zb_uint8_t device_id[5]; /*!< Device id */ +} +ZB_PACKED_STRUCT +zb_ieee_addr_compressed_t; + +/*! @endcond */ + + +/** + Pan ID reference + + Should be used inside protocol tables instead of 64-bit Pan ID +*/ +typedef zb_uint8_t zb_address_pan_id_ref_t; + + +/** + IEEE address reference + + Should be used inside protocol tables instead of 64/16-bit IEEE. +*/ +typedef zb_uint8_t zb_address_ieee_ref_t; + +/*! @cond internals_doc */ + +/** + 64-bit / 16-bit address map +*/ +typedef ZB_PACKED_PRE struct zb_address_map_s +{ + zb_ieee_addr_compressed_t ieee_addr; /*!< Compressed IEEE address */ + zb_uint16_t addr; /*!< 16-bit device address */ + zb_address_ieee_ref_t redirect_ref; /*!< Reference to redirected or regular record */ + + zb_bitfield_t used:1; /*!< if 0, this entry is free (never used) */ + zb_bitfield_t has_address_conflict:1; /*!< Set to 1 if device discovers address conflict + * Cleared when conflict is resolved: + * - Device that discovers conflict sending Network Status + * - or another Network Status with identical payload was received */ + zb_bitfield_t padding:3; /*!< Explicit padding bits */ + zb_bitfield_t clock:1; /*!< clock value for the clock usage algorithm */ + zb_bitfield_t redirect_type:2; /*!< redirect type @ref zb_addr_redirect_type_e */ + zb_bitfield_t lock_cnt:7; /*!< lock counter. not locked if 0 */ + zb_bitfield_t pending_for_delete:1; /*!< record is pending for deletetion */ +} ZB_PACKED_STRUCT zb_address_map_t; + + +/** + \par work with compresed addresses + */ + +/* + * AS: Fixed wrong division 64-bit extended address into + * manufacturer specific and device unique parts. +*/ +#define ZB_ADDRESS_DECOMPRESS(address, copressed_address) \ +do \ +{ \ + if (ZB_ADDRESS_COMPRESED_IS_UNKNOWN(copressed_address)) \ + { \ + ZB_64BIT_ADDR_UNKNOWN(address); \ + } \ + else \ + { \ + ZB_MEMCPY(&((address)[5]), \ + &(ZG->addr.dev_manufacturer[(copressed_address).dev_manufacturer].device_manufacturer[0]), \ + (sizeof((address)[0]) * 3)); \ + ZB_MEMCPY(&((address)[0]), &((copressed_address).device_id[0]), (sizeof((address)[0]) * 5)); \ + \ + } \ +} \ +while (0) + +/* +#define ZB_ADDRESS_COMPRESSED_CMP(one, two) ( \ + (one).dev_manufacturer == (two).dev_manufacturer \ + && (one).device_id[0] == (two).device_id[0] \ + && (one).device_id[1] == (two).device_id[1] \ + && (one).device_id[2] == (two).device_id[2] \ + && (one).device_id[3] == (two).device_id[3] \ + && (one).device_id[4] == (two).device_id[4] ) +*/ +zb_bool_t zb_address_compressed_cmp(zb_ieee_addr_compressed_t *one, zb_ieee_addr_compressed_t *two); +#define ZB_ADDRESS_COMPRESSED_CMP(one, two) zb_address_compressed_cmp(&one, &two) + +#define ZB_ADDRESS_COMPRESSED_COPY(dest, src) \ + ZB_MEMCPY(&(dest).dev_manufacturer, &(src).dev_manufacturer, sizeof(zb_ieee_addr_compressed_t)) + + /* g_zero_addr is declared as ZB_CONST which allows IAR to place it in CODE memory. + Compiled this by IAR 7.60 for 8051. + This placement changes pointer type making it unusable + Is this cast needed here? + */ +#define ZB_ADDRESS_COMPRESED_IS_ZERO(dest) \ + (!ZB_MEMCMP(&(dest).dev_manufacturer, (void const *)g_zero_addr, sizeof(zb_ieee_addr_compressed_t))) + +#define ZB_ADDRESS_COMPRESED_IS_UNKNOWN(dest) \ + (!ZB_MEMCMP(&(dest).dev_manufacturer, (void const *)g_unknown_ieee_addr, sizeof(zb_ieee_addr_compressed_t))) + +#define ZB_ADDRESS_COMPRESS_UNKNOWN(dest) \ + (ZB_MEMCPY(&(dest).dev_manufacturer, (void const *)g_unknown_ieee_addr, sizeof(zb_ieee_addr_compressed_t))) + +/** + Add Pan ID to address storage and return reference. + + @param short_pan_id - 16-bit Pan ID identifier + @param pan_id - 64-bit Pan ID identifier + @param ref - (output) reference to Pan ID. + + @return RET_OK - when success, error code otherwise. + + @b Example +@code + zb_address_pan_id_ref_t panid_ref; + zb_ret_t ret; + + ret = zb_address_set_pan_id(mhr.src_pan_id, beacon_payload->extended_panid, &panid_ref); + if (ret == RET_ALREADY_EXISTS) + { + ret = RET_OK; + } +@endcode + + See nwk_addr sample + */ +zb_ret_t zb_address_set_pan_id(zb_uint16_t short_pan_id, zb_ext_pan_id_t pan_id, zb_address_pan_id_ref_t *ref); + + +/** + Get extended Pan ID with reference. + + @param pan_id_ref - reference to Pan ID + @param pan_id - (output) Pan ID. + + @return nothing + + @b Example +@code + zb_uint8_t i; + ZB_BUF_INITIAL_ALLOC((zb_bufid_t )ZB_BUF_FROM_REF(param), + sizeof(*discovery_confirm) + sizeof(*network_descriptor) * ZB_PANID_TABLE_SIZE, + discovery_confirm); + zb_nlme_network_descriptor_t *network_descriptor = (zb_nlme_network_descriptor_t *)(discovery_confirm + 1); + for (i = 0 ; i < ZG->nwk.neighbor.ext_neighbor_used ; ++i) + { + zb_address_get_pan_id(ZG->nwk.neighbor.ext_neighbor[i].panid_ref, network_descriptor[j].extended_pan_id); + network_descriptor[j].logical_channel = ZG->nwk.neighbor.ext_neighbor[i].logical_channel; + ... + n_nwk_dsc++; + } + discovery_confirm->network_count = n_nwk_dsc; + discovery_confirm->status = (zb_mac_status_t)((zb_bufid_t )ZB_BUF_FROM_REF(param))->u.hdr.status; + ZB_SCHEDULE_CALLBACK(zb_nlme_network_discovery_confirm, param); +@endcode + + See nwk_addr sample + */ +void zb_address_get_pan_id(zb_address_pan_id_ref_t pan_id_ref, zb_ext_pan_id_t pan_id); + +/** + Clears Pan ID table except own pan_id. + + @param pan_id - (our) Pan ID. + + @return nothing + + See zdo_startup_copmlete_int code + */ +void zb_address_clear_pan_id_table(zb_ext_pan_id_t pan_id); + +/** + Clears whole Pan ID table + + @return nothing + + See zdo_startup_copmlete_int code + */ +void zb_address_reset_pan_id_table(void); + +/*! @endcond */ + +/** + Get Pan ID reference with extended Pan ID. + + @param pan_id - Pan ID + @param ref - (output) reference to Pan ID + + @return RET_OK - when success, error code otherwise. + + @b Example +@code + zb_address_pan_id_ref_t my_panid_ref; + if ( zb_address_get_pan_id_ref(ZB_NIB_EXT_PAN_ID(), &my_panid_ref) != RET_OK ) + { + TRACE_MSG(TRACE_NWK1, "Pan ID " TRACE_FORMAT_64 " not in Pan ID arr - ?", (FMT__A, + TRACE_ARG_64(ZB_NIB_EXT_PAN_ID()))); + } +@endcode + */ +zb_ret_t zb_address_get_pan_id_ref(zb_ext_pan_id_t pan_id, zb_address_pan_id_ref_t *ref); + +/** + Get short Pan ID with reference. + + @param pan_id_ref - reference to Pan ID + @param pan_id_p - (output) Pan ID. + + + @b Example +@code + zb_uint16_t nt_panid; + zb_address_get_short_pan_id(ZG->nwk.neighbor.ext_neighbor[i].panid_ref, &nt_panid); + if (nt_panid == pan_id) + { + TRACE_MSG(TRACE_NWK1, "pan_id %d is on ch %hd", (FMT__D_H, pan_id, channel)); + unique_pan_id = 0; + } +@endcode + */ +void zb_address_get_short_pan_id(zb_address_pan_id_ref_t pan_id_ref, zb_uint16_t *pan_id_p); + + +/** + Compare Pan ID in the source form with Pan ID reference. + + @param pan_id_ref - Pan ID ref + @param pan_id - PAn ID (64-bit) + + @return ZB_TRUE if addresses are equal, ZB_FALSE otherwhise + + @b Example +@code + for (i = 0 ; i < ZG->nwk.neighbor.ext_neighbor_used ; ++i) + { + for (j = 0 ; j < n_nwk_dsc && + !zb_address_cmp_pan_id_by_ref(ZG->nwk.neighbor.ext_neighbor[i].panid_ref, network_descriptor[j].extended_pan_id) ; + ++j) + { + ... + } + } +@endcode + */ +zb_bool_t zb_address_cmp_pan_id_by_ref(zb_address_pan_id_ref_t pan_id_ref, zb_ext_pan_id_t pan_id); + +/** + Update long/short address pair. Create the pair if not exist. Optionally, lock. + Reaction on device annonce etc. Long and short addresses are present. Must + syncronize the address translation table with this inforormation. + + @note Never call zb_address_update() with empty (zero) ieee_address or empty + (-1) short_address. + + @param ieee_address - long address + @param short_address - short address + @param lock - if TRUE, lock address entry + @param ref_p - (out) address reference + + @return RET_OK or error code + + @b Example +@code + zb_address_ieee_ref_t addr_ref; + zb_uint16_t nwk_addr; + zb_zdo_nwk_addr_resp_head_t *resp = (zb_zdo_nwk_addr_resp_head_t*)zb_buf_begin(buf); + if (resp->status == ZB_ZDP_STATUS_SUCCESS) + { + ZB_LETOH64(ieee_addr, resp->ieee_addr); + ZB_LETOH16(&nwk_addr, &resp->nwk_addr); + zb_address_update(ieee_addr, nwk_addr, ZB_TRUE, &addr_ref); + } +@endcode + + See nwk_addr sample + */ +zb_ret_t zb_address_update(zb_ieee_addr_t ieee_address, zb_uint16_t short_address, zb_bool_t lock, zb_address_ieee_ref_t *ref_p); + + +/** + Get address with address reference. + + Get existing IEEE (long) and short addresses with address reference. Update address alive + time if it not locked. + + @param ieee_address - (out) long address + @param short_address_p - (out) short address + @param ref - address reference + + @b Example +@code + zb_address_ieee_ref_t addr_ref; + zb_nlme_join_indication_t *resp = ZB_BUF_GET_PARAM((zb_bufid_t )ZB_BUF_FROM_REF(param), zb_nlme_join_indication_t); + zb_address_by_ref(resp->extended_address, &resp->network_address, addr_ref); +@endcode + + See nwk_addr sample + */ +void zb_address_by_ref(zb_ieee_addr_t ieee_address, zb_uint16_t *short_address_p, zb_address_ieee_ref_t ref); + +/** + Get IEEE address with address reference. + + Get existing IEEE address(long address) with address reference. Update address alive time if it not locked. + + @param ieee_address - (out) long address + @param ref - address reference + + @b Example +@code +void func(zb_neighbor_tbl_ent_t *nbt) +{ + zb_ieee_addr_t ieee_addr; + zb_address_ieee_by_ref(ieee_addr, nbt->addr_ref); + ... +} +@endcode + + See tp_pro_bv-32 sample + */ +void zb_address_ieee_by_ref(zb_ieee_addr_t ieee_address, zb_address_ieee_ref_t ref); + + +/** + Get short address by address reference. + + Get existing short address with address reference. Update address alive time if it not locked. + + @param short_address_p - (out) short address + @param ref - address reference + + @b Example +@code + zb_neighbor_tbl_ent_t *nbt; + if(zb_nwk_neighbor_with_address_conflict(&nbt)==RET_OK) + { + zb_uint16_t addr; + zb_address_short_by_ref(&addr, nbt->addr_ref); + func(addr); + } +@endcode + + See tp_pro_bv-32 sample + */ +void zb_address_short_by_ref(zb_uint16_t *short_address_p, zb_address_ieee_ref_t ref); + +/** + Get address ref by long address, optionaly create if not exist, optionally lock. + Update address alive time if not locked. + @param ieee - IEEE device address + @param create - if TRUE, create address entry if it does not exist + @param lock - if TRUE, lock address entry + @param ref_p - (out) address reference + + @note: never call zb_address_by_ieee() with empty (zero) ieee_address + + @return RET_OK or error code + + @b Example +@code + void test_get_short_addr(zb_uint8_t param) + { + zb_address_ieee_ref_t ref_p; + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + + if (zb_address_by_ieee(g_ieee_addr_r2, ZB_TRUE, ZB_FALSE, &ref_p) == RET_OK) + { + ... + } + } +@endcode + + See nwk_addr sample + */ +zb_ret_t zb_address_by_ieee(zb_ieee_addr_t ieee, zb_bool_t create, zb_bool_t lock, zb_address_ieee_ref_t *ref_p); + + +/** + Get short address by IEEE address (long). + + @param ieee_address - long address + + @return short address if ok, -1 otherwhise. + + @par Example + @snippet thermostat/thermostat_zc/thermostat_zc.c default_short_addr + @snippet thermostat/thermostat_zc/thermostat_zc.c address_short_by_ieee + @par + + See thermostat sample + */ +zb_uint16_t zb_address_short_by_ieee(zb_ieee_addr_t ieee_address); + + +/** + Get IEEE address (long) with short address. + + @param short_addr - short address + @param ieee_address - (out)long address + + @return RET_OK or RET_NOT_FOUND + + @b Example + @snippet light_sample/light_coordinator/light_zc.c address_ieee_by_short + + See light_sample + */ +zb_ret_t zb_address_ieee_by_short(zb_uint16_t short_addr, zb_ieee_addr_t ieee_address); + + +/** + Get address reference with long address. Create the reference if it does not exist. + Optionally, lock the address. Update address alive time if not locked. + @param short_address - 16bit device address + @param create - if TRUE, create address entry if it does not exist + @param lock - if TRUE, lock address entry + @param ref_p - (out) address reference + + @note Never call zb_address_by_short() with empty (-1) short_address + + @return RET_OK or error code + + @b Example + @snippet simple_gw/simple_gw.c address_by_short + + See simple_gw sample + */ +zb_ret_t zb_address_by_short(zb_uint16_t short_address, zb_bool_t create, zb_bool_t lock, zb_address_ieee_ref_t *ref_p); + + +/*! @cond internals_doc */ +/** + Get address ref by index from short_sorted table. + @param index - index address short_sorted table + @param ref_p - (out) address reference + + @return RET_OK or error code + + @b Example +@code + zb_address_ieee_ref_t ref_p; + if( ZG->nwk.neighbor.base_neighbor_used > 0 && + zb_address_by_sorted_table_index(ZG->nwk.neighbor.send_link_status_index, &ref_p)==RET_OK + ) + { + ... + } +@endcode + */ +zb_ret_t zb_address_by_sorted_table_index(zb_ushort_t index, zb_address_ieee_ref_t *ref_p); +/*! @endcond */ + +/** + + Increase address lock counter, when it used in some table. + Address must be already locked. + + @param ref - IEEE/network address pair reference + + @return RET_OK or RET_ERROR + */ +zb_ret_t zb_address_lock(zb_address_ieee_ref_t ref); + + +/** + + Unlock address counter. Decrease lock counter. + + @param ref - IEEE/network address pair reference + + @return RET_OK or RET_ERROR + */ +zb_ret_t zb_address_unlock(zb_address_ieee_ref_t ref); + +/** + Delete address. + + @return RET_OK or RET_ERROR + + @param ref - IEEE/network address pair reference + */ +zb_ret_t zb_address_delete(zb_address_ieee_ref_t ref); + + +/*! @cond internals_doc */ + +/** + Deinitialize Zigbee address management + + Function doesn't return values + */ +void zb_address_deinit(void); + + +/** + Compress long address: store manufacturer address part elsewhere + + This routine packs 8 bytes address to 6 bytes + + @param address - uncompressed address + @param compressed_address - (out) compressed address + + @b Example +@code + void func(zb_address_pan_id_ref_t panid_ref, zb_ieee_addr_t long_addr, zb_ext_neighbor_tbl_ent_t **enbt) + { + zb_ieee_addr_compressed_t compressed_addr; + zb_ieee_addr_compress(long_addr, &compressed_addr); + + for (i = 0 ; i < ZG->nwk.neighbor.ext_neighbor_used ; ++i) + { + if (ZG->nwk.neighbor.ext_neighbor[i].panid_ref == panid_ref + && ZB_ADDRESS_COMPRESSED_CMP(ZG->nwk.neighbor.ext_neighbor[i].long_addr, compressed_addr)) + { + *enbt = &ZG->nwk.neighbor.ext_neighbor[i]; + } + } + } +@endcode + */ +void zb_ieee_addr_compress(zb_ieee_addr_t address, zb_ieee_addr_compressed_t *compressed_address); + + +/** + Decompress compressed long address. + + This routine unpacks 6 bytes address to 8 bytes + + @param address - (out) uncompressed address + @param compressed_address - compressed address + + @b Example +@code + zb_ieee_addr_t long_address; + if (ZG->nwk.neighbor.ext_neighbor[i].short_addr != (zb_uint16_t)~0) + { + if (!ZB_ADDRESS_COMPRESED_IS_UNKNOWN(ZG->nwk.neighbor.ext_neighbor[i].long_addr)) + { + zb_ieee_addr_decompress(long_address, &ZG->nwk.neighbor.ext_neighbor[i].long_addr); + zb_address_update(long_address, ZG->nwk.neighbor.ext_neighbor[i].short_addr, ZB_FALSE, &addr_ref); + } + } +@endcode + */ +void zb_ieee_addr_decompress(zb_ieee_addr_t address, zb_ieee_addr_compressed_t *compressed_address); + +/*! @endcond */ + +/*! @} */ + + +#endif /* ZB_ADDRESS_H */ diff --git a/zboss/include/zb_channel_page.h b/zboss/include/zb_channel_page.h new file mode 100644 index 0000000000..22d955de0f --- /dev/null +++ b/zboss/include/zb_channel_page.h @@ -0,0 +1,491 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Channel page header file. All channel-related stuff. +*/ +#ifndef ZB_CHANNEL_PAGE_H +#define ZB_CHANNEL_PAGE_H 1 + +#include "zb_types.h" +#include "zb_errors.h" + +/*! \addtogroup channel_page */ +/*! @{ */ + +#define ZB_CHANNEL_PAGE_PAGE_BITMASK 0xF8000000u +#define ZB_CHANNEL_PAGE_MASK_BITMASK 0x07FFFFFFu + +/** + * Represents the fields of the Channel Page structure (binary encoded channel + * page and channels mask). + */ +typedef zb_uint32_t zb_channel_page_t; + +/** + * Channel list structure (ZBOSS internal) + */ +typedef zb_channel_page_t zb_channel_list_t[ZB_CHANNEL_PAGES_NUM]; + +/* Private API */ +#define ZB_CHANNEL_LIST_PAGE0_IDX 0 +#define ZB_CHANNEL_LIST_PAGE28_IDX 1 +#define ZB_CHANNEL_LIST_PAGE29_IDX 2 +#define ZB_CHANNEL_LIST_PAGE30_IDX 3 +#define ZB_CHANNEL_LIST_PAGE31_IDX 4 + +#define ZB_PAGE0_2_4_GHZ_CHANNEL_FROM 11 +#define ZB_PAGE0_2_4_GHZ_CHANNEL_TO 26 + +#define ZB_PAGE28_SUB_GHZ_CHANNEL_FROM 0 +#define ZB_PAGE28_SUB_GHZ_CHANNEL_TO 26 + +#define ZB_PAGE29_SUB_GHZ_CHANNEL_FROM 27 +#define ZB_PAGE29_SUB_GHZ_CHANNEL_TO 34 + +#define ZB_PAGE30_SUB_GHZ_CHANNEL_FROM 35 +#define ZB_PAGE30_SUB_GHZ_CHANNEL_TO 61 + +#define ZB_PAGE31_SUB_GHZ_CHANNEL_FROM 0 +#define ZB_PAGE31_SUB_GHZ_CHANNEL_TO 26 + +#define ZB_CHANNEL_PAGE_TO_IDX(channel_page) ((channel_page > 0) ? (channel_page - 27) : 0) +#define ZB_CHANNEL_PAGE_FROM_IDX(channel_page_idx) ((channel_page_idx > 0) ? (channel_page_idx + 27) : 0) + +#ifdef ZB_PAGES_REMAP_TO_2_4GHZ +/** + The following remap stuff allows to remap Sub GHz pages/channel to 2.4GHz. + This is used to test Sub GHz without getting out from the town to desert + island due to wide range of Sub GHz. + + Remap is based on using of channels range of 2.4GHz to imitate working with + Sub GHz. The main idea is to devide channels range of 2.4GHz, where each + channels area corresponds to particular channel page. We have 5 channel + pages, so the range of channel numbers of 2.4GHz is devided into 5 areas: + + * 0-2 - PAGE0 + * 3-5 - PAGE28 + * 6-8 - PAGE29 + * 9-11 - PAGE30 + * 12-14 - PAGE31 + + So whole range of used channel numbers starts from 0 and ends with 14 + (15 channels of 2.4GHz are used). + + The following formula is used to remap channel number into 2.4GHz channel number. + * remap_channel_number = (channel_number % 3) + page_shift + */ + +#define ZB_PAGES_REMAP_PAGE_CHANNELS_NUM 3 + +#define ZB_PAGES_REMAP_PAGE0_SHIFT 0 +#define ZB_PAGES_REMAP_PAGE28_SHIFT (ZB_PAGES_REMAP_PAGE0_SHIFT + ZB_PAGES_REMAP_PAGE_CHANNELS_NUM) +#define ZB_PAGES_REMAP_PAGE29_SHIFT (ZB_PAGES_REMAP_PAGE28_SHIFT + ZB_PAGES_REMAP_PAGE_CHANNELS_NUM) +#define ZB_PAGES_REMAP_PAGE30_SHIFT (ZB_PAGES_REMAP_PAGE29_SHIFT + ZB_PAGES_REMAP_PAGE_CHANNELS_NUM) +#define ZB_PAGES_REMAP_PAGE31_SHIFT (ZB_PAGES_REMAP_PAGE30_SHIFT + ZB_PAGES_REMAP_PAGE_CHANNELS_NUM) + +#define ZB_PAGES_REMAP_CHANNEL_PAGE ZB_CHANNEL_PAGE0_2_4_GHZ +#define ZB_PAGES_REMAP_CHANNEL_NUMBER(page, channel_number) (((channel_number % ZB_PAGES_REMAP_PAGE_CHANNELS_NUM)) + ZB_PAGE0_2_4_GHZ_START_CHANNEL_NUMBER + \ + (page == ZB_CHANNEL_PAGE28_SUB_GHZ ? ZB_PAGES_REMAP_PAGE28_SHIFT : \ + (page == ZB_CHANNEL_PAGE29_SUB_GHZ ? ZB_PAGES_REMAP_PAGE29_SHIFT : \ + (page == ZB_CHANNEL_PAGE30_SUB_GHZ ? ZB_PAGES_REMAP_PAGE30_SHIFT : \ + (page == ZB_CHANNEL_PAGE31_SUB_GHZ ? ZB_PAGES_REMAP_PAGE31_SHIFT : \ + ZB_PAGES_REMAP_PAGE0_SHIFT))))) + +/** + Remaps logical channel into correspondong logical channel in 2.4GHz range. + + @param channel_page - original channel page + @param logical_channel - original logical channel in scope of original channel page + @param remap_logical_channel [out] - remapped logical channel in scope of 2.4GHz + + @return remapped channel if success + 0xff in case of error +*/ +zb_uint8_t zb_pages_remap_logical_channel(zb_uint8_t channel_page, + zb_uint8_t logical_channel); + +#define ZB_PAGES_REMAP_LOGICAL_CHANNEL(page, lchannel_number) zb_pages_remap_logical_channel(page, lchannel_number) + +#else + +#define ZB_PAGES_REMAP_LOGICAL_CHANNEL(page, lchannel_number) (lchannel_number) + +#endif + +/** + * Gets channel page field from Channel page structure + * + * @param channel_page - binary encoded channel page and channels mask + */ +#define ZB_CHANNEL_PAGE_GET_PAGE(channel_page) (((channel_page) & ZB_CHANNEL_PAGE_PAGE_BITMASK) >> 27) + +/** + * Gets channels mask field from Channel page structure + * + * @param channel_page - binary encoded channel page and channels mask + */ +#define ZB_CHANNEL_PAGE_GET_MASK(channel_page) ((channel_page) & ZB_CHANNEL_PAGE_MASK_BITMASK) + +/** + * Sets channel page field for Channel page structure + * + * @param channel_page - binary encoded channel page and channels mask + * @param page - channel page to set + */ +#define ZB_CHANNEL_PAGE_SET_PAGE(channel_page, page) (channel_page) = ((channel_page) & ZB_CHANNEL_PAGE_MASK_BITMASK) | (((zb_uint32_t)(page)) << 27) + +/** + * Sets channels mask field for Channel page structure + * + * @param channel_page - binary encoded channel page and channels mask + * @param mask - channels mask to set + */ +#define ZB_CHANNEL_PAGE_SET_MASK(channel_page, mask) (channel_page) = ((channel_page) & ZB_CHANNEL_PAGE_PAGE_BITMASK) | ((mask) & ZB_CHANNEL_PAGE_MASK_BITMASK) + +/* Numbers [28, 29, 30, 31] have common first three bits + * + * 28 = 0b11100 + * 29 = 0b11101 + * 30 = 0b11110 + * 31 = 0b11111 + * + * So, can only compare with 0b11100 mask = 0x1C = 28 (dec) + */ +#define ZB_LOGICAL_PAGE_SUB_GHZ_PAGE_MASK ZB_CHANNEL_PAGE28_SUB_GHZ + +#define ZB_LOGICAL_PAGE_IS_SUB_GHZ_EU_FSK(logical_page) \ + ((logical_page) & ZB_LOGICAL_PAGE_SUB_GHZ_PAGE_MASK) + +#define ZB_LOGICAL_PAGE_IS_2_4GHZ(logical_page) \ + ((logical_page) == ZB_CHANNEL_PAGE0_2_4_GHZ) + +#define ZB_CHANNEL_PAGE_IS_SUB_GHZ_EU_FSK(channel_page) \ + (ZB_LOGICAL_PAGE_IS_SUB_GHZ_EU_FSK(ZB_CHANNEL_PAGE_GET_PAGE(channel_page))) + +#define ZB_CHANNEL_PAGE_IS_2_4GHZ(channel_page) \ + (ZB_LOGICAL_PAGE_IS_2_4GHZ(ZB_CHANNEL_PAGE_GET_PAGE(channel_page))) + +#define ZB_CHANNEL_PAGE_IS_MASK_EMPTY(channel_page) \ + (ZB_CHANNEL_PAGE_GET_MASK(channel_page) == 0) + +/** + * @brief Copies source channel page list to the destination. Destination list + * must be allocated. + * + * @note Number of elements in both lists must be equal to ZB_CHANNEL_PAGES_NUM. + * + * @param dst - destination channel page list + * @param src - source channel page list + */ +void zb_channel_page_list_copy(zb_channel_list_t dst, + zb_channel_list_t src); + +/** + * @brief Sets channels mask for specified element of channel page list. + * + * @param list - channel page list + * @param idx - index of the list element + * @param mask - channels mask to set + */ +void zb_channel_page_list_set_mask(zb_channel_list_t list, + zb_uint8_t idx, + zb_uint32_t mask); + +/** + * @brief Gets channels mask of specified element of channel page list. + * + * @param list - channel page list + * @param idx - index of the list element + * + * @return Channels mask. + */ +zb_uint32_t zb_channel_page_list_get_mask(zb_channel_list_t list, + zb_uint8_t idx); + +/** + * @brief Sets channel page for specified element of channel page list. + * + * @param list - channel page list + * @param idx - index of the list element + * @param page - channel page to set + */ +void zb_channel_page_list_set_page(zb_channel_list_t list, + zb_uint8_t idx, + zb_uint8_t page); + +/** + * @brief Gets channel page of specified element of channel page list. + * + * @param list - channel page list + * @param idx - index of the list element + * + * @return Channel page. + */ +zb_uint8_t zb_channel_page_list_get_page(zb_channel_list_t list, + zb_uint8_t idx); + + +/** + * @brief Gets channel page index in channel lists. + * + * @param page - channel page + * @param idx [out] - index of the channel page in channel lists + * + * @return RET_OK or RET_NOT_FOUND. + */ +zb_ret_t zb_channel_page_list_get_page_idx(zb_uint8_t page, zb_uint8_t *idx); + + +/** + * @brief Gets page number by channel page index. + * + * @param idx - index of the channel page in channel lists + * @param page[out] - channel page + * + * @return RET_OK or RET_NOT_FOUND. + */ +zb_ret_t zb_channel_page_get_page_by_idx(zb_uint8_t idx, zb_uint8_t *page); + +/** + * @brief Sets channels mask for the list element of channel page list that + * corresponds to 2.4GHz. + * + * @param list - channel page list + * @param mask - channels mask to set + */ +void zb_channel_page_list_set_2_4GHz_mask(zb_channel_list_t list, + zb_uint32_t mask); + +/** + * @brief Gets channels mask of the list element of channel page list that + * corresponds to 2.4GHz. + * + * @param list - channel page list + * + * @return 2.4GHz channels mask. + */ +zb_uint32_t zb_channel_page_list_get_2_4GHz_mask(zb_channel_list_t list); + +/** + * @brief Sets channels mask for specified element of the AIB channel page list. + * + * @param idx - index of the list element + * @param mask - channels mask to set + */ +void zb_aib_channel_page_list_set_mask(zb_uint8_t idx, + zb_uint32_t mask); + +/** + * @brief Gets channels mask of specified element of the AIB channel page list. + * + * @param idx - index of the list element + * + * @return Channels mask. + */ +zb_uint32_t zb_aib_channel_page_list_get_mask(zb_uint8_t idx); + +/** + * @brief Sets channel page for specified element of the AIB channel page list. + * + * @param idx - index of the list element + * @param page - channel page to set + */ +void zb_aib_channel_page_list_set_page(zb_uint8_t idx, + zb_uint8_t page); + +/** + * @brief Gets channels page of specified element of the AIB channel page list. + * + * @param idx - index of the list element + * + * @return Channel page. + */ +zb_uint8_t zb_aib_channel_page_list_get_page(zb_uint8_t idx); + +/** + * @brief Sets channels mask for the list element of the AIB channel page list that + * corresponds to 2.4GHz. + * + * @param mask - channels mask to set + */ +void zb_aib_channel_page_list_set_2_4GHz_mask(zb_uint32_t mask); + +/** + * @brief Gets channels mask of the list element of the AIB channel page list that + * corresponds to 2.4GHz. + * + * @return 2.4GHz channels mask. + */ +zb_uint32_t zb_aib_channel_page_list_get_2_4GHz_mask(void); + +/** + * @brief Gets the first channel number for specified channel page. + * + * @note The channel number is returned in inner representation as channels bits + * stored in channel mask internally, it may differ from real channel numbers + * specified by spec. + * + * @param page - channel page + * @param channel_number [out] - channel number + * + * @return RET_OK or RET_NOT_FOUND. + */ +zb_ret_t zb_channel_page_get_start_channel_number(zb_uint8_t page, zb_uint8_t *channel_number); + +/** + * @brief Gets the last channel number for specified channel page. + * + * @note The channel number is returned in inner representation as channels bits + * stored in channel mask internally, it may differ from real channel numbers + * specified by spec. + * + * @param page - channel page + * @param channel_number [out] - channel number + * + * @return RET_OK or RET_NOT_FOUND. + */ +zb_ret_t zb_channel_page_get_max_channel_number(zb_uint8_t page, zb_uint8_t *channel_number); + +/** + * @brief Converts logical channel to channel number within channel mask for + * specified channel page. For example: + * - page [in] = 30 + * - logical channel [in] = 36 + * - channel number [out] = 1 + * + * @param page [in] - channel page + * @param logical_channel [in] - logical channel (e.g. simply channel) + * @param channel_number [out] - channel number within channel mask (inner representation) + * + * @return RET_OK - success, + * RET_NOT_FOUND - unknown channel page, + * RET_INVALID_PARAMETER - unacceptable logical channel for specified channel page. + */ +zb_ret_t zb_channel_page_channel_logical_to_number(zb_uint8_t page, + zb_uint8_t logical_channel, + zb_uint8_t *channel_number); + +/** + * @brief Converts channel number within channel mask to logical channel for + * specified channel page. For example: + * - page [in] = 30 + * - channel number [in] = 1 + * - logical channel [out] = 36 + * + * @param page - channel page + * @param channel_number - channel number within channel mask (inner representation) + * @param logical_channel [out] - logical channel (e.g. simply channel) + * + * @return RET_OK - success, + * RET_NOT_FOUND - unknown channel page, + * RET_INVALID_PARAMETER - unacceptable logical channel for specified channel page. + */ +zb_ret_t zb_channel_page_channel_number_to_logical(zb_uint8_t page, + zb_uint8_t channel_number, + zb_uint8_t *logical_channel); + +/** + * @brief Sets bit in channel mask corresponding to specified channel number. + * + * @param list - channel list + * @param idx - index of channel page which channel mask will be modified + * @param channel_number - channel number within channel mask (inner representation) + * + * @return RET_OK - success, + * RET_INVALID_PARAMETER - unacceptable channel number for specified channel page. + */ +zb_ret_t zb_channel_page_list_set_channel(zb_channel_list_t list, + zb_uint8_t idx, + zb_uint8_t channel_number); + +/** + * @brief Sets bit in channel mask corresponding to specified channel number. + * + * @param list - channel list + * @param page - logicl page number + * @param channel_number - logical channel number + * + * @return RET_OK - success, + * RET_INVALID_PARAMETER - unacceptable channel number for specified channel page. + */ +zb_ret_t zb_channel_page_list_set_logical_channel(zb_channel_list_t list, + zb_uint8_t page, + zb_uint8_t channel_number); + + + +/** + * @brief Unsets bit in channel mask corresponding to specified channel number. + * + * @param list - channel list + * @param idx - index of channel page which channel mask will be modified + * @param channel_number - channel number within channel mask (inner representation) + * + * @return RET_OK - success, + * RET_INVALID_PARAMETER - unacceptable channel number for specified channel page. + */ +zb_ret_t zb_channel_page_list_unset_channel(zb_channel_list_t list, + zb_uint8_t idx, + zb_uint8_t channel_number); + +zb_uint8_t zb_channel_page_list_get_channels_num(zb_channel_list_t list, + zb_uint8_t idx); + + +#ifdef ZB_MAC_CONFIGURABLE_TX_POWER +/** + * @brief Get offsets for MAC TX power stored in the production config for + * specified channel and page + * + * @param page - logicl page number + * @param channel_number - logical channel number + * @param array_idx [out] - pointer to store array id. The value -1 is an invalid value. + * @param array_ofs [out] - pointer to store array offset. The value -1 is an invalid value. + * + */ +void zb_channel_get_tx_power_offset(zb_uint8_t page, zb_uint8_t channel, + zb_uint8_t *array_idx, zb_uint8_t *array_ofs); + +#endif /* ZB_MAC_CONFIGURABLE_TX_POWER */ + + +/*! @} */ + +#endif /* ZB_CHANNEL_PAGE_H */ diff --git a/zboss/include/zb_config.h b/zboss/include/zb_config.h new file mode 100644 index 0000000000..17dbe7f6b6 --- /dev/null +++ b/zboss/include/zb_config.h @@ -0,0 +1,1700 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Configuration file: configuration- and platform-specific definitions, +constants etc. +*/ + +#ifndef ZB_CONFIG_H +#define ZB_CONFIG_H 1 + +/** + Load vendor specific configurations +*/ + +/* \defgroup buildconfig Build Configurations + @{ */ +#include "zb_vendor.h" +/** + Load common ZBOSS definitions +*/ +#include "zb_config_common.h" + +/* + * ZC/ZR - GPPB role library (default) (implementation of Basic Proxy is mandatory for ZigBee 3.0 ZR) + * ZC/ZR - GPCB role library (Options file shall use ZB_ENABLE_ZGP_COMBO define) + * ZC/ZR - GP Commissioning Tool (Options file shall use ZGP_COMMISSIONING_TOOL define) + * ZED - Target role library (default) (Options file shall use ZB_ENABLE_ZGP_TARGET define) + * ZED - Target+ role library (Options file shall use ZB_ENABLE_ZGP_TARGET_PLUS define) + * + * To enable advanced features (not covered by the curent version of GP specification) please + * define ZB_ENABLE_ZGP_ADVANCED, so in this case the GPPB/GPCB/GPCT basic libs will be re-compiled + * to GPP/GPC/GPCT advanced libs + * + * GP infrastructure devices: + * + * A.3.2.1 GP Target device ability: + * - ability to receive any GP frame in tunneled mode + * + * A.3.2.2 GP Target+ device ability: + * - ability to receive any GP frame both in direct mode and in tunneled mode + * + * A.3.2.3 GP Proxy device ability: + * - ability to receive any GP frame in direct mode when the proxy is in the radio range of the + * GPD + * - ability to send to the registered sink devices a GP Notification command with the received + * GP frame + * - ability to maintain a Proxy Table at commissioning time to register sink devices which are + * asking for GP frame forwarding service + * - ability to update the Proxy Table based on the observed GP traffic in order to enable GP + * device mobility in the network + * - ability to drop scheduled tunneling of GP frame, based on received GP commands related to + * the same GP frame + * + * A.3.2.4 GP Combo device + * - ability to receive any GP frame both in direct mode and in tunneled mode + * + * For migration old sink dataset use ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET define + */ + +#ifdef ZB_ZGPD_ROLE +#define ZB_ENABLE_ZGP_DIRECT +#define ZB_ENABLE_ZGP_SECUR +#define APP_ONLY_NVRAM +#elif defined ZB_ENABLE_ZGP && !defined ZB_ENABLE_ZGP_TARGET && defined ZB_ED_ROLE +#undef ZB_ENABLE_ZGP +#endif + + +#if defined ZB_ENABLE_ZGP && !defined ZB_ZGPD_ROLE + +/* +#define ZB_ENABLE_ZGP_ADVANCED +*/ + +#define ZB_ENABLE_ZGP_CLUSTER +#define ZB_ENABLE_ZGP_SECUR +#define ZB_USEALIAS + +#ifndef ZB_ED_ROLE +/* ZED can only be implemented as GP Target/Target+ */ +#define ZB_ENABLE_ZGP_PROXY +#endif + +#ifndef ZB_ENABLE_ZGP_TARGET +#define ZB_ENABLE_ZGP_DIRECT +#define ZB_ENABLE_ZGP_TX_QUEUE +#endif + +/** Maximum payload lenght in translation table entry */ +#ifndef ZB_ZGP_TRANSL_CMD_PLD_MAX_SIZE +#define ZB_ZGP_TRANSL_CMD_PLD_MAX_SIZE 3 +#endif + +#if (defined ZB_ENABLE_ZGP_COMBO || defined ZB_ENABLE_ZGP_TARGET || defined ZB_ENABLE_ZGP_TARGET_PLUS || defined ZGP_COMMISSIONING_TOOL) +#define ZB_ENABLE_ZGP_SINK + +/** Max number of command identifiers in one + * functionality matching table entry */ +#define ZB_ZGP_MATCH_TBL_MAX_CMDS_FOR_MATCH 5 + +/** Max number of cluster identifiers in one + * functionality matching table entry */ +#define ZB_ZGP_TBL_MAX_CLUSTERS 5 +#endif + +#ifndef ZB_ENABLE_ZGP_SINK +#undef ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET +#endif + +/** Sink table size */ +#ifndef ZB_ZGP_SINK_TBL_SIZE +#define ZB_ZGP_SINK_TBL_SIZE 32 +#endif /* ZB_ZGP_SINK_TBL_SIZE */ + + + +/* Obsolete define to support old sink table migration + * Looks like for correct migration needs to upgrade old system to zgp_dataset_info_ver_6_0_s using + * the same ZB_ZGP_SINK_TBL_SIZE number */ +/* Anyway we don't need do migration for translaion table so let's keep this define as is. */ +#define ZB_ZGP_TRANSL_TBL_SIZE 4*ZB_ZGP_SINK_TBL_SIZE + +/* 5.1.2.3.2 test specification - The default value for DUT-GPP being a Basic Combo pr a Basic Proxy + * is "ZigBeeAlliance09", i.e. {0x5A 0x69 0x67 0x42 0x65 0x65 0x41 0x6C 0x6C 0x69 0x61 0x6E + * 0x63 0x65 0x30 0x39}. */ +#define ZB_ZGP_DEFAULT_LINK_KEY "ZigBeeAlliance09" + +/* 5.1.2.3.2 test specification - The default value for DUT-GPP being a Basic Proxy or Basic Combo + * is 0b000. */ +#define ZB_ZGP_DEFAULT_SHARED_SECURITY_KEY_TYPE ZB_ZGP_SEC_KEY_TYPE_NO_KEY + +/* A.3.3.2.5 The default value is 180 seconds. */ +#ifndef ZB_ZGP_DEFAULT_COMMISSIONING_WINDOW +#define ZB_ZGP_DEFAULT_COMMISSIONING_WINDOW 180 +#endif + +/* in bytes */ +#define ZB_ZGP_MIN_PROXY_TABLE_ENTRY_SIZE 7 + +#ifndef ZB_ZGP_PROXY_COMMISSIONING_DEFAULT_COMMUNICATION_MODE +#define ZB_ZGP_PROXY_COMMISSIONING_DEFAULT_COMMUNICATION_MODE ZGP_PROXY_COMM_MODE_UNICAST +#endif + +#define ZB_ZGP_DEFAULT_COMMISSIONING_EXIT_MODE ZGP_COMMISSIONING_EXIT_MODE_ON_GP_PROXY_COMMISSIONING_MODE_EXIT + +#define ZB_ZGP_DEFAULT_SEC_LEVEL_PROTECTION_WITH_GP_LINK_KEY 0 +#define ZB_ZGP_DEFAULT_SEC_LEVEL_INVOLVE_TC 0 +#define ZB_ZGP_MAX_TEMP_MASTER_COUNT 0x03 +#define ZB_ZGP_DMAX_FOR_ACCUMULATE_TEMP_MASTER_INFO 100 +#define ZB_ZGP_MIN_SINK_TABLE_ENTRY_SIZE 8 +#ifndef MAX_ZGP_CLUSTER_GPDF_PAYLOAD_SIZE +#define MAX_ZGP_CLUSTER_GPDF_PAYLOAD_SIZE 65 /* (64 for APP_000 + 1 byte header size) */ +#endif +#define ZB_GP_DMIN_U_MS 5 +#define ZB_GP_DMIN_D_MS 32 + +#ifndef ZB_ZGP_DEFAULT_COMMUNICATION_MODE +#define ZB_ZGP_DEFAULT_COMMUNICATION_MODE ZGP_COMMUNICATION_MODE_LIGHTWEIGHT_UNICAST +#endif + +#define ZB_ZGP_DEFAULT_SECURITY_LEVEL ZB_ZGP_SEC_LEVEL_NO_SECURITY + +#ifdef ZB_ENABLE_ZGP_PROXY +#ifndef ZB_ZGP_PROXY_TBL_SIZE +#define ZB_ZGP_PROXY_TBL_SIZE 16 +#endif /* ZB_ZGP_PROXY_TBL_SIZE */ +#endif /* ZB_ENABLE_ZGP_PROXY */ + +#endif /* !ZB_ZGPD_ROLE */ + + +#ifdef ZB_ZCL_SUPPORT_CLUSTER_WWAH +#define ZB_ENABLE_NWK_RETRANSMIT +/* #ifdef ZB_ENABLE_SE */ +/* #pragma error SE inconsistent with WWAH. Disable ZB_ENABLE_SE */ +/* #endif */ +#endif /* ZB_ZCL_SUPPORT_CLUSTER_WWAH */ + +#ifdef ZB_SUBGHZ_MODE +#define ZB_R22_MULTIMAC +#define ZB_MAC_DUTY_CYCLE_MONITORING +#define ZB_SUB_GHZ_LBT +#define ZB_FILTER_OUT_CLUSTERS +#define ZB_MAC_POWER_CONTROL +#endif + + +/** + # of frames in GPFS (repeated frames with same mac seq #) + + For debug purposes set it to 1 +*/ + +#ifndef ZB_ZGP_TX_QUEUE_SIZE +#define ZB_ZGP_TX_QUEUE_SIZE 10 +#endif + +#ifdef ZB_ZGP_IMMED_TX +/** Number of zb_zgp_tx_pinfo_t in zb_zgp_tx_packet_info_q_t. */ +#define ZB_ZGP_TX_PACKET_INFO_COUNT ZB_ZGP_TX_QUEUE_SIZE + (ZB_IOBUF_POOL_SIZE / 4) +/** Value with which immed_tx_frame_counter is incremented upon a reboot. */ +#define ZB_GP_IMMED_TX_FRAME_COUNTER_UPDATE_INTERVAL 1000 +#define ZGP_INCLUDE_DST_LONG_ADDR +#else +#define ZB_ZGP_TX_PACKET_INFO_COUNT ZB_ZGP_TX_QUEUE_SIZE +#endif /* ZB_ZGP_IMMED_TX */ +/** Maximum payload lenght in outgoing ZGP frames */ +#ifndef ZB_ZGP_TX_CMD_PLD_MAX_SIZE +#define ZB_ZGP_TX_CMD_PLD_MAX_SIZE 64 /* Maximum payload size of APP_0000 packet */ +#endif + +#define ZB_ZGP_LED_COMMISSIONING_PARAMS ZB_LED_ARG_CREATE(0, ZB_LED_BLINK_HALF_SEC) + +/* some preconditions and dependencies */ +#ifdef ZB_BDB_TOUCHLINK +#define ZB_ENABLE_ZLL +#define ZB_ENABLE_INTER_PAN_EXCHANGE +#endif + +/* + Features to be specified in vendor config: + + - ZB_ENABLE_HA + - ZB_ENABLE_ZLL + - ENABLE_ZGP_TARGET_PLUS + + HA specific: + -ZB_ALL_DEVICE_SUPPORT + +*/ + +/* BDB uses HA clusters */ +#if defined ZB_BDB_MODE && !defined ZB_ENABLE_HA +#define ZB_ENABLE_HA +#endif + +/** + Size of table used for long addresses compression: 3 bytes of manufacturer id. + + ZBOSS implements long address compression: 3 bytes of manufacturer + id are stored in the separate table; reference to manufacturer + entry is stored in the long address giving 2 bytes economy. + + That is an absolute limit of # of manufactorers known to the device. + + @note All that machinery will not work if instead of legal + maufacturer ids (or illegal, but fixed ids) use random values. + */ +#ifndef ZB_DEV_MANUFACTORER_TABLE_SIZE +#define ZB_DEV_MANUFACTORER_TABLE_SIZE 32 +#endif + +/* There were configuration options for different platfoirms. + Since in ZOI we are separating stack and platform making not all platforms visible, + include here current platform-specific stuff. + + Now every platform has its own platform/include/zb_config_platform.h where we moved stuff like +#if (defined ZB_CONFIG_LINUX_NSNG || defined ZB_CONFIG_SGW_NSNG) +#define ZB_NSNG +#define ZB_DSR_MAC +... + + +Ideally should rework the whole zb_config.h to suit better for that new concept. + + */ +#include "zb_config_platform.h" + +#ifndef ZB_ZGPD_GPFS_SIZE +#define ZB_ZGPD_GPFS_SIZE 4 +#endif + + + +/* #define ZB_TRANSCEIVER_ALL_CHANNELS_MASK (0xffff << 11) */ /* 0000.0111 1111.1111 1111.1000 0000.0000*/ +/* C51 doesn't like long shifts, it just cut last two bytes. (11-26) */ +/* TODO: Remove old subgig definitions */ +#define ZB_TRANSCEIVER_ALL_CHANNELS_MASK 0x07FFF800 /* 0000.0111 1111.1111 1111.1000 0000.0000*/ + +#define MAC_DEVICE_TABLE_SIZE 4 + +#if defined ZB_ENABLE_INTER_PAN_EXCHANGE && ! defined ZB_MAC_EXT_DATA_REQ +#define ZB_MAC_EXT_DATA_REQ +#endif /* defined ZB_ENABLE_INTER_PAN_EXCHANGE && ! defined ZB_MAC_EXT_DATA_REQ */ + + + + + +/* MAC transport in Linux, line nsng, uart/macsplit etc */ + +/***********************************************************************/ +/****************************General stack options**********************/ +/***********************************************************************/ + +#define ZB_VERSION "0.2.0.1" + +/*! \addtogroup ZB_CONFIG */ +/*! @{ */ + +/** Network Selection Stack Profile Id*/ +#define STACK_NETWORK_SELECT 0x00 +/** 2007 Stack Profile Id*/ +#define STACK_2007 0x01 +/** Pro Stack Profile Id */ +#define STACK_PRO 0x02 + +/** + This define switches PRO version on or off. +*/ +#define ZB_PRO_STACK + +/** + If defined, 2007 stack profile is implemented +*/ +//#define ZB_STACK_PROFILE_2007 + +/** + * If defined, NVRAM is used + * Create *.nvram file + * + * To be used near always to prevent flash damage (flash can do ~1000 rewrites only) + * + * For certification test need comment. + * Else change Assignment to Rejoin for second and last runs + * + */ +//#define NVRAM_NOT_AVAILABLE + +#ifndef NVRAM_NOT_AVAILABLE +#define ZB_USE_NVRAM +#endif + + +/** + Use 32-bit timer +*/ +#define ZB_TIMER_32 + +#ifndef ZB_CB_QUANT +#define ZB_CB_QUANT 1 +#endif /* !ZB_CB_QUANT */ + +/*! \addtogroup ZB_CONFIG */ +/*! @{ */ + +/* MMDEVQ: what to do??? */ +/** + Zigbee channel selection. + Default value of ZB_AIB().aps_channel_mask + Channels to be used for discovery and join. + If a single channel is selected, there is no need to perform energy scan. + + @note ZLL, HA, ZLL tests can redefine this mask with the means of other constants. +*/ + +/* ZB_DEFAULT_APS_CHANNEL_MASK can be redefined in zb_vendor.h */ +#ifndef ZB_DEFAULT_APS_CHANNEL_MASK +//#define ZB_DEFAULT_APS_CHANNEL_MASK ((1l<<11)) +/* Change that place if you want to set channel for internal tests */ +//#define ZB_DEFAULT_APS_CHANNEL_MASK ((1l<<11)) +/* #define ZB_DEFAULT_APS_CHANNEL_MASK ((1l<<16)) */ +#define ZB_DEFAULT_APS_CHANNEL_MASK (ZB_TRANSCEIVER_ALL_CHANNELS_MASK) +#endif /* ZB_DEFAULT_APS_CHANNEL_MASK */ +/** @} */ /* ZB_CONFIG */ + + +//** +// If defined, do not compile some features, even Mandatory, to fit into 64k ROM at 2410/64k device in Keil debug build. +//*/ +//#define ZB_LIMITED_FEATURES + +/* PRO stack specific details */ +/** + NWK: If defined, use stochastic address assignment (Zigbee PRO). +*/ +#define ZB_NWK_STOCHASTIC_ADDRESS_ASSIGN + +/*! Source routing path lenght, also called nwkMaxSourceRoute */ +#define ZB_NWK_MAX_PATH_LENGTH 5 +/*! Source route table capacity */ +/* 10/21/2019 EE CR:MINOR Isn't it too many? Can we handle situation when source route table is not big enough? */ +#define ZB_NWK_MAX_SRC_ROUTES ZB_NEIGHBOR_TABLE_SIZE +/* 10/21/2019 EE CR:MINOR Better indicate in const name that this is time in secunds by adding _S suffix */ +/*! Expiration time of the source route table (300 sec) */ +#define ZB_NWK_SRC_ROUTE_TABLE_EXPIRY 60 + + + + +/****************************Zigbee Roles*******************************/ + +/* +# Device roles per build. + +We usually have ZC and ZR combined. +We can have ZR which can be switched to ZED (via reset to factory defaults), or ZR which is "just ZR". +It could be useful to have ZC-only and ZR-only libraries. +ZED rx-on-when-idle can be configurable at runtime or at compile time. + +To better divide ZC an ZR define functionality groups: + +- routing & parent srv (zc & zr) - ZB_ROUTER_ROLE (name is not perfect, but keep it to minimizze code change) +- centralized TC - ZB_COORDINATOR_ROLE (name is not perfect, but keep it to minimizze code change) +- joiner client functionality (zr & zed) - ZB_JOIN_CLIENT +- formation functionality - ZB_FORMATION == ZB_COORDINATOR_ROLE || ZB_ROUTER_ROLE && ZB_DISTRIBUTED_SECURITY_ON. Also in request key etc +- distributed-only ZR build (do not link router's update device etc) - ZB_DISTRIBUTED_ONLY +- distributed security - ZB_ROUTER_ROLE & ZB_DISTRIBUTED_SECURITY_ON + - ZR (link if enabled?) +- router security (upd dev send etc) ZB_ROUTER_SECURITY == ZB_ROUTER_ROLE && !ZB_COORDINATOR_ROLE && !ZB_DISTRIBUTED_ONLY +- By default + +- panid conflict resolution (TBD) + - ZC part - always, or if enabled + - ZR part - if enabled + +- address conflict resolution (TBD) + - in ZR role + - in ZC role (recheck: is it so?) + +- ZED functionality (either ZED or ZR) - ZB_ED_FUNC. Can be present in ED-only or ZR build. + +ZB_ED_ROLE == ZB_ED_FUNC && !ZB_ROUTER_ROLE && !ZB_COORDINATOR_ROLE + +ZB_ED_FUNC is polling and ED aging. + +ZB_ROUTER_ROLE, ZB_COORDINATOR_ROLE, ZB_ED_ROLE defines exists for the very beginning. Let's keep it in the code where it is appropriate. + +In general, define ZB_COORDINATOR_ROLE to compile ZC-only build, ZB_ROUTER_ROLE to compile ZR+ZED build, ZB_ED_ROLE to compile ZED-onlyt build. + */ + +#if !defined ZB_ED_ROLE && !defined ZB_ZGPD_ROLE && !defined ZB_COORDINATOR_ROLE && !defined ZB_ROUTER_ROLE +/** + If no any role defined, let it be max possible roles set: ZC + ZR switcheable to ZED at runtime +*/ +#define ZB_COORDINATOR_ROLE +#define ZB_ROUTER_ROLE +#ifndef ZB_ROUTER_NO_ED +/*! Define Zigbee end device functionality */ +#define ZB_ED_FUNC +#endif +#endif + +#if defined ZB_ED_ROLE || defined ZB_ROUTER_ROLE +/*! Define joiner client functionality */ +#define ZB_JOIN_CLIENT +#endif + +#if defined ZB_COORDINATOR_ROLE && !defined ZB_ROUTER_ROLE +/** + If only ZB_COORDINATOR_ROLE is defined, only ZC role is compiled. +*/ +#define ZB_ROUTER_ROLE +#define ZB_COORDINATOR_ONLY +#endif /*defined ZB_COORDINATOR_ROLE && !defined ZB_ROUTER_ROLE*/ + +#if defined ZB_ROUTER_ROLE && !defined ZB_COORDINATOR_ONLY && !defined ZB_ROUTER_NO_ED + +/* By default ZR can be switched to ZED at runtime. */ +/*! ZB enddevice functionality */ +#define ZB_ED_FUNC +#endif + +#ifdef ZB_ROUTER_NO_ED +#define ZB_LITE_NO_JOIN_ZR_AS_ZED +#endif + +/* +Related defined +ZB_LITE_ROUTER_ONLY_ROLE +ZB_LITE_NO_JOIN_ZR_AS_ZED +ZB_ED_RX_OFF_WHEN_IDLE + */ + +#if defined ZB_COORDINATOR_ROLE || (defined ZB_ROUTER_ROLE && defined ZB_DISTRIBUTED_SECURITY_ON) + +/*! Formation is supported by ZC or ZR in Distributed mode */ +#define ZB_FORMATION +#endif + +#if defined ZB_ROUTER_ROLE && !defined ZB_COORDINATOR_ONLY && !defined ZB_DISTRIBUTED_ONLY +/*! Defines router security */ +#define ZB_ROUTER_SECURITY +#endif + +#if defined ZB_ED_ROLE && (defined ZB_ROUTER_ROLE || defined ZB_COORDINATOR_ROLE) +#error Conflicting defines: ZB_ED_ROLE excludes ZB_ROUTER_ROLE/ZB_COORDINATOR_ROLE +#endif + +#ifdef ZB_ED_ROLE +/* ED funtionality is implemented by ZED-only build or ZR switcheable to ZED */ +#define ZB_ED_FUNC +#endif +/** @addtogroup ZB_CONFIG */ +/** @{ */ +/** + * NWK: size of the neighbor table + * + * @note This is a default value of the define. This value can be changed by user. + */ +#ifndef ZB_NEIGHBOR_TABLE_SIZE + +#if defined ZB_COORDINATOR_ROLE +#define ZB_NEIGHBOR_TABLE_SIZE 32 + +#elif defined ZB_ROUTER_ROLE +#define ZB_NEIGHBOR_TABLE_SIZE 32 + +#elif defined ZB_ED_ROLE +#define ZB_NEIGHBOR_TABLE_SIZE 32 + +#elif defined ZB_ZGPD_ROLE +/* zcl_common.zgpd.o won't be built without any ZB_NEIGHBOR_TABLE_SIZE definition. */ +#define ZB_NEIGHBOR_TABLE_SIZE 1 + +#else +#error No any role defined +#endif /* roles */ + +#endif /* ZB_NEIGHBOR_TABLE_SIZE */ + +/** + * Scheduler callbacks queue size. Usually not need to change it. + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#ifndef ZB_SCHEDULER_Q_SIZE +#ifdef ZB_ED_ROLE +#define ZB_SCHEDULER_Q_SIZE 16 +#else +/* @note: If set ZB_SCHEDULER_Q_SIZE > 32 is set, change alarms bitmask in the scheduler */ +#define ZB_SCHEDULER_Q_SIZE 32 +#endif +#endif /*ZB_SCHEDULER_Q_SIZE*/ +/** @} */ /* ZB_CONFIG */ +#if defined ZB_ED_ROLE +/** + End device idle time-out +*/ +#define ZB_TIME_ED_IDLE ZB_MILLISECONDS_TO_BEACON_INTERVAL(7500) +#endif + + +#if defined ZB_ROUTER_ROLE +/** + NWK: If defined, enable routing functionality +*/ +#define ZB_NWK_ROUTING + +/** + Number of secure materials to store +*/ +#define N_SECUR_MATERIAL 3 + + +#ifndef ZB_NWK_STOCHASTIC_ADDRESS_ASSIGN +/** + If not defined, implement tree routing +*/ +#define ZB_NWK_TREE_ROUTING +#endif /*ZB_NWK_STOCHASTIC_ADDRESS_ASSIGN*/ + +/** + NWK: if defined, implement mesh routing +*/ +#define ZB_NWK_MESH_ROUTING + +#else + +#define N_SECUR_MATERIAL 1 + +#endif /* coordinator or router */ + + +/****************************APS layer options**************************/ +/** @addtogroup ZB_CONFIG */ +/** @{ */ +#ifndef ZB_MAX_EP_NUMBER +/* max supported EP number, increase if needed */ +/** Maximum number of supported enpoints per device */ +#define ZB_MAX_EP_NUMBER 5 +#endif +/* APS binding */ + +#ifndef ZB_MEMORY_COMPACT + +#ifndef ZB_APS_SRC_BINDING_TABLE_SIZE +/** + * APS: SRC binding table size + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#define ZB_APS_SRC_BINDING_TABLE_SIZE 32 +#endif + + +#ifndef ZB_APS_DST_BINDING_TABLE_SIZE +/** + * APS: DST binding table size + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#define ZB_APS_DST_BINDING_TABLE_SIZE 32 +#endif + + +#ifndef ZB_APS_GROUP_TABLE_SIZE +/** + APS: man number of groups in the system +*/ +#define ZB_APS_GROUP_TABLE_SIZE 16 +#endif + + +#ifndef ZB_APS_ENDPOINTS_IN_GROUP_TABLE +/** + APS: max number of endpoints per group table entry +*/ +#define ZB_APS_ENDPOINTS_IN_GROUP_TABLE 8 +#endif + +/** + APS: size of queue to be used to pass + incoming group addresses packets up +*/ +#define ZB_APS_GROUP_UP_Q_SIZE 8 + +#else /* ZB_MEMORY_COMPACT */ + +#ifndef ZB_APS_SRC_BINDING_TABLE_SIZE +#define ZB_APS_SRC_BINDING_TABLE_SIZE 8 +#endif + + +#ifndef ZB_APS_DST_BINDING_TABLE_SIZE +/** + APS: DST binding table size +*/ +#define ZB_APS_DST_BINDING_TABLE_SIZE 8 +#endif + + +#ifndef ZB_APS_GROUP_TABLE_SIZE +/** + APS: man number of groups in the system +*/ +#define ZB_APS_GROUP_TABLE_SIZE 4 +#endif + + +#ifndef ZB_APS_ENDPOINTS_IN_GROUP_TABLE +/** + APS: max number of endpoints per group table entry +*/ +#define ZB_APS_ENDPOINTS_IN_GROUP_TABLE 4 +#endif + +/** + APS: size of queue to be used to pass + incoming group addresses packets up +*/ +#define ZB_APS_GROUP_UP_Q_SIZE 4 + +#endif /* ZB_MEMORY_COMPACT */ + + +#ifndef ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE +/** + * APS: maximum number of tables with key-pair information + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#ifdef ZB_ED_ROLE +#define ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE 5 +#else +/* [EE] 05/25/2016 CR:MINOR Set it to some big value - say, 128. This is total # + * of devices in the network, not neighbor table size */ +#define ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE ZB_NEIGHBOR_TABLE_SIZE +#endif +#endif + +/** + If the joining device does not receive any of + the keys within apsSecurityTimeOutPeriod, of receiving the NLME-JOIN. + confirm primitive, it shall reset + + apsSecurityTimeOutPeriod value is not defined by specification and should be defined in stack + profile. For ZB_PRO_STACK this value equal to 1.7 seconds on 2.4 GHz. + + See Zigbee specification revision 22 subclause 4.4.11 +*/ +#define ZB_APS_SECURITY_TIME_OUT_PERIOD ZB_MILLISECONDS_TO_BEACON_INTERVAL(1700) + +/** + APS: Get APS ACK wait time for the device depending on its receiver on when idle +*/ +/* WARNING: Generally, it is not according to spec. There are some nwk and APS routines that should + * correllate to this interval, for these we will use ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY. */ +#ifndef ZB_ED_RX_OFF_WHEN_IDLE +#define ZB_N_APS_ACK_WAIT_DURATION(_rx_on_when_idle) \ + ((_rx_on_when_idle) ? \ + ZB_N_APS_ACK_WAIT_DURATION_FROM_NON_SLEEPY : ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY) +#else +#define ZB_N_APS_ACK_WAIT_DURATION(_rx_on_when_idle) \ + (ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY) +#endif + +/****************************NWK layer options**************************/ + +/* + If defined, NWK and upper layers can access PIB directly. + + Usually, can be defined when using our MAC. + Undef it to separate MAC and upper layers IB spaces for debug purposes. + + #define ZB_DIRECT_PIB_ACCESS + +*/ +/** + * NWK: size of the long-short address translation table + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#ifndef ZB_MEMORY_COMPACT +#define ZB_IEEE_ADDR_TABLE_SIZE 101 +#else +#define ZB_IEEE_ADDR_TABLE_SIZE 32 +#endif + +#ifndef ZB_PANID_TABLE_SIZE +/** + NWK: size of the long-short Pan ID translation table + + Must be <= (packet buffer size - sizeof(*discovery_confirm)) / sizeof(*network_descriptor) + + That value limits number of Pan IDs visible for device during active scan. +*/ +#define ZB_PANID_TABLE_SIZE 16 +#endif +/** @cond internals_doc */ +/** + If defined, add jitter to broadcast transmits etc. + + @note It adds zb_random() and breaks some tests that are supposed to know + next generated address by setting random generator start. +*/ +#define ZB_NWK_USE_SEND_JITTER +/**@endcond*//*internals_doc*/ +/* Some defaults for ZDO startup */ + +#ifndef ZB_TRACE_LEVEL +/** + NWK: default energy/active scan duration +*/ +#define ZB_DEFAULT_SCAN_DURATION 3 + + +#else /* ZB_TRACE_LEVEL */ + +#define ZB_DEFAULT_SCAN_DURATION 5 + + +#endif /*ZB_TRACE_LEVEL*/ + + +#if ZB_ZDO_NWK_SCAN_ATTEMPTS == 1 +/** + Integer value representing the + * number of scan attempts to make + * before the NWK layer decides + * which Zigbee coordinator or + * router to associate with + */ + +#define ZB_NWK_ONE_SCAN_ATTEMPT +#endif /*ZB_ZDO_NWK_SCAN_ATTEMPTS == 1*/ + + +/** + Number of pending Mgmt_Leave requests allowed +*/ +#ifndef ZB_MEMORY_COMPACT +#define ZB_ZDO_PENDING_LEAVE_SIZE 4 +#else +#define ZB_ZDO_PENDING_LEAVE_SIZE 2 +#endif /*ZB_MEMORY_COMPACT*/ +/** @cond internals_doc */ +#ifndef ZB_COORDINATOR_ONLY +/* Enables PAN blacklisting. Note: it was under ifdef + * ZB_COORDINATOR_ROLE. But ZBOSS usually built with ZR & ZC, so + * blacklist is useful for ZR. */ +/** Enables PAN blacklisting */ +#define ZB_NWK_BLACKLIST +#ifndef ZB_NWK_BLACKLIST_SIZE +/** Size of PAN IDs blacklist */ +#define ZB_NWK_BLACKLIST_SIZE 16 +#endif +#endif + +/** + * NWK Mesh route: routing table size + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#ifndef ZB_MEMORY_COMPACT +#define ZB_NWK_ROUTING_TABLE_SIZE ZB_NEIGHBOR_TABLE_SIZE +#else +#define ZB_NWK_ROUTING_TABLE_SIZE 5 +#endif +/** @endcond */ /* internals_doc */ +/** @cond DOXYGEN_MULTIMAC_SECTION */ +#ifndef ZB_NWK_MAC_IFACE_TBL_SIZE +/* For now we use only 1 MAC interface (maybe, working in 2.4 os sub-gig) */ +/** + NWK MultiMAC content +*/ +#define ZB_NWK_MAC_IFACE_TBL_SIZE 1 +#endif /* ZB_NWK_MAC_IFACE_TBL_SIZE */ +/** @endcond */ /* DOXYGEN_MULTIMAC_SECTION */ +/** + Size of channel list structure +*/ +#define ZB_CHANNEL_PAGES_NUM 1 +/** @cond DOXYGEN_SE_SECTION */ +/** Maximum channel pages number according to the Zigbee revision 22 specification */ +#define ZB_CHANNEL_PAGES_MAX_NUM 5 +/** @endcond */ +/*! @cond internals_doc */ +/** +The minimum value of the +backoff exponent (BE) in the +CSMA-CA algorithm. See +7.5.1.4 for a detailed +explanation of the backoff +exponent. + */ +#define ZB_MAC_MIN_BE 3 + + /** +The maximum value of the +backoff exponent, BE, in the +CSMA-CA algorithm. See +7.5.1.4 for a detailed +explanation of the backoff +exponent. + */ +#define ZB_MAC_MAX_BE 5 +/*! @endcond */ /*internals_doc*/ +#ifdef ZB_MAC_POLL_INDICATION_CALLS_REDUCED +#ifndef ZB_MAC_POLL_INDICATION_CALL_MAX_TIMEOUT +/** + Default maximum value of Poll Indication calls timeout (in sec) + */ +#define ZB_MAC_POLL_INDICATION_CALL_MAX_TIMEOUT 3600 +#endif +#endif /* ZB_MAC_POLL_INDICATION_CALLS_REDUCED */ +/** @cond internals_doc */ +#ifndef ZB_NWK_NEIGHBOUR_PATH_COST_RSSI_BASED +/** + Neighbour path cost calculation method. + By default, calculate neighbour path cost from LQI value as described in ZB + spec(section 3.6.3.1). But for sime special cases (e.g. LCGW) we need to calculate path cost + from RSSI value. + */ +#define ZB_NWK_NEIGHBOUR_PATH_COST_LQI_BASED +#endif /* ZB_NWK_NEIGHBOUR_PATH_COST_RSSI_BASED */ +/** @endcond */ /* internals_doc */ +/***********************************************************************/ +/***************************ZBOSS FEATURES SECTION**********************/ +/***********************************************************************/ + +/***************************STACK FEATURES**********************/ +/** @cond internals_doc *//* Current stack profile */ +#define ZB_STACK_PROFILE STACK_PRO + +/** + Protocol version selection: see table 1.1(pro-specification) +*/ +#if ZB_STACK_PROFILE == STACK_PRO || ZB_STACK_PROFILE == STACK_2007 +#define ZB_PROTOCOL_VERSION 0x02 +#else +#define ZB_PROTOCOL_VERSION 0x01 +#endif +/** @endcond */ /* internals_doc ZB_STACK_PROFILE */ + + +#ifndef ZB_BUF_Q_SIZE +/* @note To prevent deadlocks ZB_BUF_Q_SIZE must be < ZB_IOBUF_POOL_SIZE/2 */ +/** + Size of queue for wait for free packet buffer +*/ +#define ZB_BUF_Q_SIZE 8 +#endif /*ZB_BUF_Q_SIZE*/ + +/** + Size, in bytes, of the packet buffer + + @internal Be sure keep it multiple of 4 to exclude alignment problems at ARM +*/ +#ifndef ZB_IO_BUF_SIZE +#define ZB_IO_BUF_SIZE 148 +#endif /* ZB_IO_BUF_SIZE */ + +/** + Buffer tail portion alignment - 4. + + Note: not sizeof(zb_size_t) because at 64-bit buld it is 8 which we don't want. + */ +#define ZB_BUF_ALLOC_ALIGN 4 + + +/** + Number of fragmented packets which ZBOSS can receive in parallel + */ +#define ZB_APS_MAX_IN_FRAGMENT_TRANSMISSIONS 3 + +/** + * Number of packet buffers. More buffers - more memory. Less buffers - risk to be blocked due to buffer absence. + * + * @note This is a default value of the define. This value can be changed by user. +*/ +#ifndef ZB_IOBUF_POOL_SIZE +#if defined ZB_MEMORY_COMPACT && defined ZB_ED_ROLE +#define ZB_IOBUF_POOL_SIZE 20 +#else +#define ZB_IOBUF_POOL_SIZE 26 +#endif +#endif +/** @cond internals_doc */ +/* + If enabled, real int24 and uint48 types will work. Else, int24 and uint48 is mapped to + int32 and uint32. + See include/zb_uint48.h. +*/ +/** Enable support for int24 and uint48 data types */ +#define ZB_UINT24_48_SUPPORT +/** @endcond */ /* internals_doc */ +/** Should expire in this number of attemptes if failure*/ +#define ZB_NWK_ROUTING_FAILURE_ATTEMTS_NUM 1 + +/** Calculate routing expiry step interval based on timer initiation value and number of attempts*/ +#define ZB_NWK_ROUTING_FAILURE_EXPIRY_STEP (ZB_NWK_ROUTING_TABLE_EXPIRY / ZB_NWK_ROUTING_FAILURE_ATTEMTS_NUM) + +/** + Number of times device failes to send packet to the parent before rejoin +*/ +#define ZB_ZDO_PARENT_LINK_FAILURE_CNT 12 +/** @cond internals_doc */ +//#define ZB_ZDO_CHECK_FAILS_NWK_UPDATE_NOTIFY_LIMIT 4 +#define ZB_ZDO_CHECK_FAILS_CLEAR_TIMEOUT (30 * ZB_TIME_ONE_SECOND) +/** @endcond */ /* internals_doc */ + +/** @cond internals_doc */ +#define ZB_PREDEFINED_ROUTER_ADDR 0x3344 +#define ZB_PREDEFINED_ED_ADDR 0x3344 +/** @endcond */ /* internals_doc */ + +#ifdef ZB_LIMIT_VISIBILITY +/** + Maximum number of addresses in the visibility limit arrays +*/ +#define ZB_N_VIZIBLE_ADDRESSES 6 +#endif + +#if defined ZB_LITTLE_ENDIAN && defined ZB_BIG_ENDIAN +#error Enable only 1 profile support: ZB_LITTLE_ENDIAN or ZB_BIG_ENDIAN +#endif /* defined ZB_LITTLE_ENDIAN && defined ZB_BIG_ENDIAN */ + +/** @cond internals_doc */ +/* DA: network status with OUT_OF_MEMORY custom value */ +#if !defined ZB_CHECK_OOM_STATUS && !defined xZB_CHECK_OOM_STATUS && !defined ZB_MACSPLIT_DEVICE && !defined ZB_LITE_NO_OOM_DETECTION +/** Enable check whether the ZBOSS stack is out of memory */ +#define ZB_CHECK_OOM_STATUS +#endif +//#define ZB_SEND_OOM_STATUS + +#ifdef ZB_CHECK_OOM_STATUS +/** If bufpool is in out of memory state for a period, specified by ZB_OOM_THRESHOLD, + * then assertion is triggered. */ +#define ZB_OOM_THRESHOLD (120 * ZB_TIME_ONE_SECOND) +#ifdef ZB_SEND_OOM_STATUS +#define ZB_SEND_OOM_DELAY (5 * ZB_TIME_ONE_SECOND) +#endif /* ZB_SEND_OOM_STATUS */ +#endif /* ZB_CHECK_OOM_STATUS */ +/** @endcond */ /* internals_doc */ +/** @cond DOXYGEN_JOINING_LIST_SECTION */ +#define ZB_JOINING_LIST_Q_SIZE 5 +#define ZB_JOINING_LIST_RESP_ITEMS_LIMIT 9 +#define ZB_JOINING_LIST_DELAY_STEP ZB_TIME_ONE_SECOND +/* default value for mibIeeeExpiryInterval, in minutes */ +#define ZB_JOINING_LIST_DEFAULT_EXPIRY_INTERVAL 5 +/** @endcond */ /* DOXYGEN_JOINING_LIST_SECTION */ +/***************************HA and ZLL FEATURES**********************/ +/** @cond internals_doc */ +#if defined ZB_ENABLE_HA || defined ZB_ENABLE_ZLL +#define ZB_ENABLE_ZCL +#endif /* defined ZB_ENABLE_HA || ZB_ENABLE_ZLL */ +/** @endcond */ /* internals_doc */ +/* Enable only 1 profile support: ZLL or HA */ +/** @cond DOXYGEN_ZLL_SECTION */ +#if defined ZB_ENABLE_ZLL || defined DOXYGEN +/** @brief Controls inter-PAN exchange feature */ +#define ZB_ENABLE_INTER_PAN_EXCHANGE +/* only ZLL uses AES128 decoding */ +#define ZB_NEED_AES128_DEC +#define ZB_ZLL_ENABLE_COMMISSIONING_CLIENT +#define ZB_ZLL_ENABLE_COMMISSIONING_SERVER +#ifdef ZB_ZLL_ENABLE_COMMISSIONING_CLIENT +/* Client device should be address assignment capable */ +#define ZB_ZLL_ADDR_ASSIGN_CAPABLE +#endif +#define ZB_ZLL_PRIMARY_CHANNELS {11, 15, 20, 25} +#endif /* defined ZB_ENABLE_ZLL || defined DOXYGEN */ +/** @endcond */ /* DOXYGEN_ZLL_SECTION */ + +/*************************Serial and UDP trace**********************/ +#ifndef ZB_PLATFORM_LINUX /* Uncomment for binary logs! */ +#if defined ZB_SERIAL_FOR_TRACE || defined ZB_TRACE_OVER_JTAG || defined ZB_NET_TRACE +/* binary trace: optimize traffic size. need special win_com_dump */ +#define ZB_BINARY_TRACE +/* #define ZB_TRAFFIC_DUMP_ON */ +/* #define ZB_TRAF_DUMP_V2 */ +#endif /*ZB_SERIAL_FOR_TRACE || defined ZB_TRACE_OVER_JTAG || defined ZB_NET_TRACE*/ +#endif /*ZB_PLATFORM_LINUX*/ + + +#ifdef ZB_PLATFORM_LINUX + +/* nsng run in the single thread */ +#define ZB_THREADS +#ifndef ZB_INIT_HAS_ARGS +#define ZB_INIT_HAS_ARGS +#endif +#ifndef ZB_HAVE_FILE +#define ZB_HAVE_FILE +#endif +#ifndef ZB_TRACE_TO_FILE +#define ZB_TRACE_TO_FILE +#endif +#ifndef ZB_TMP_FILE_PATH_PREFIX +#define ZB_TMP_FILE_PATH_PREFIX "" +#endif +#ifndef ZB_BINARY_FILE_PATH_PREFIX +#define ZB_BINARY_FILE_PATH_PREFIX "" +#endif +#ifndef ZB_USERDATA_FILE_PATH_PREFIX +#define ZB_USERDATA_FILE_PATH_PREFIX "" +#endif +/* # define ZB_BINARY_TRACE */ +/* # define ZB_NET_TRACE */ +/* # define ZB_TRAFFIC_DUMP_ON */ +#endif + +/** @cond internals_doc */ +#ifndef ZB_MEMTRACE_BUF_SIZE +#define ZB_MEMTRACE_BUF_SIZE 4080 +#endif + +/* Tune trace portion to fit HTTPS body into single Ethernet frame. Align to 3 + * because base64 packs 3 bytes into 4 chars. */ +#ifndef ZB_NET_TRACE_PORTION +#define ZB_NET_TRACE_PORTION 1020 +#endif + + +/** + If defined, transport calls traffic dump by itself, generic MAC not need to do it +*/ +//#define ZB_TRANSPORT_OWN_TRAFFIC_DUMP_ON + +//#define ZB_DUMP_TRAF + +/** + Name for trace off switch file + + If file of this name exists in the current directory, swicth off both trace + and traffic dump. +*/ +#define ZB_TRACE_SWITCH_OFF_FILE_NAME "trace_off" +/** @endcond */ /* internals_doc */ + +/************************Hardware watchdog******************/ + + +#ifndef ZB_WATCHDOG_SCHED_QUANT +/** + *Check watchdods once per 20 sec. + *The hardware watchdog timer is set to 30 seconds, + *it should be initiated even if there is no job for it +*/ +#define ZB_WATCHDOG_SCHED_QUANT (20 * ZB_TIME_ONE_SECOND) +#endif + + + +/* membuffers debug: */ +/* extra buffers trace and debug */ +/* WARNING: Disabled by default. It costs too many ROM size! */ +#if ZB_TRACE_LEVEL && ZB_TRACE_MASK +/* #define ZB_DEBUG_BUFFERS */ +#endif + +/* Assert when already freed memory buffer is accessed. Useful for debugging */ +#ifdef ZB_DEBUG_BUFFERS +#define ZB_BUF_SHIELD +/* extended membuffers debug*/ +#ifdef ZB_DEBUG_BUFFERS_EXT +#define ZB_DEBUG_BUFFERS_EXT_USAGES_COUNT 1 +#endif +#endif /*ZB_DEBUG_BUFFERS*/ + + +/************************Special modes for testing*******************/ + +#ifdef DEBUG +#if !defined ZB_LIMITED_FEATURES && !defined ZB_TEST_PROFILE && !defined xZB_TEST_PROFILE +#ifdef ZB_CERTIFICATION_HACKS +/** + * This define turns on/off test profile + */ +#define ZB_TEST_PROFILE +#endif +#endif /*ZB_LIMITED_FEATURES*/ +#endif /*DEBUG*/ + + +/* Testing mode for some pro certification tests */ +/** @cond internals_doc */ + +#define ZB_PRO_TESTING_MODE +#ifdef ZB_PRO_TESTING_MODE + +/* See: certification test TP_PRO_BV-11 */ +#ifdef ZB_CERTIFICATION_HACKS +#if !defined ZB_LIMIT_VISIBILITY && !defined ZB_MEMORY_COMPACT +#define ZB_LIMIT_VISIBILITY +#endif /*!defined ZB_LIMIT_VISIBILITY && !defined ZB_MEMORY_COMPACT*/ +#endif /* ZB_CERTIFICATION_HACKS */ + +#if defined ZB_ROUTER_ROLE +/* See: certification test 13.66_Commissioning_the_short_address */ +#define ZB_PRO_ADDRESS_ASSIGNMENT_CB +#endif /*defined ZB_COORDINATOR_ROLE || defined ZB_ROUTER_ROLE*/ + +/* Compatibility tests (with Ember Zigbee platform ISA3)*/ + +/* Ember + ZBOSS stack with ZLL Profile*/ + +/* Ember + ZBOSS Core Pro stack */ +//#define ZB_EMBER_TESTS + +/* Send messages with empty payload without APS-security */ +#define ZB_SEND_EMPTY_DATA_WITHOUT_APS_ENCRYPTION + +#endif /* ZB_PRO_TESTING_MODE */ + +/** @endcond */ /* internals_doc */ +//* Definitions for 802.15.4 certification hacks */ + +//#define MAC_CERT_TEST_HACKS + +//* +// This define turns on/off channel error mode (set errors while data sending) +//*/ +//#define ZB_CHANNEL_ERROR_TEST + +//#define TP_PRO_BV_31 + +//#define TP_PRO_BV_38 + + + + +/* Certification defines */ + +#if 0 +/** + Disabling of processing of bind_req and end_device_bind_req for certification purposes +*/ +#define ZB_DISABLE_BIND_REQ +#endif + + +#if 0 +/** + Disabling of processing of end device bind requests +*/ +#define ZB_DISABLE_ED_BIND_REQ +#endif + +/*PRO STACK COMPATIBILITY, it is better to turn it on only when needed */ +/* #AT disable compatible mode with 2007 stack version */ +#if 0 +#define ZB_PRO_COMPATIBLE +#endif + +/** + Default value for mac frame version subfield +*/ +#define MAC_FRAME_VERSION MAC_FRAME_IEEE_802_15_4_2003 +/** @cond internals_doc */ +/** + Block sleepy end devices (devices with rx-on-when-idle == false) from receiving broadcasts (drop it at MAC level) +*/ +#define ZB_BLOCK_BROADCASTS_SLEEPY_ED +/** @endcond */ /* internals_doc */ +/* MAC */ +/* TODO: add MAC properties here */ +/** @cond DOXYGEN_JOINING_LIST_SECTION */ +#ifndef MAC_JOINING_LIST_SIZE_LIMIT +#define MAC_JOINING_LIST_SIZE_LIMIT 16 +#endif +/** @endcond */ /* DOXYGEN_JOINING_LIST_SECTION */ + +/***** GREEN POWER *****/ + +#ifdef ZB_ZGPD_ROLE +#define ZB_MAC_ONLY_STACK +#undef ZB_CHECK_OOM_STATUS +#undef APS_FRAME_SECURITY +#undef ZB_ENABLE_ZCL +#undef ZB_ENABLE_ZLL +#undef ZB_ENABLE_HA +#undef ZB_USE_NVRAM +/* Temporarily disabled for ZGPD MAC library build. */ +/* #undef ZB_DIRECT_MODE_WITH_ZGPD */ +#define ZB_ENABLE_ZGPD_ATTR_REPORTING +/* + * The OperationalChannel sub-field can take the following values: 0b0000: channel 11, + * 0b0001: channel 12, , 0b1111: channel 26. + * 26-11+1 = 12. Let's use 3 series of 4 channels each. + * @note that channelsdiapason must be multiple of series. + */ +#define ZB_ZGPD_CH_SERIES 3 + +#define ZB_GPD_COMMISSIONING_RETRY_INTERVAL ZB_MILLISECONDS_TO_BEACON_INTERVAL(500) +#endif /* ZB_ZGPD_ROLE */ + +#ifdef ZB_ENABLE_ZGP_DIRECT +/* Old GP GPD sensors (until May, 2014) use + * 5 ms offset. New sensors use 20 ms offset.*/ +//#define ZB_GPD_RX_OFFSET_MS 5 +#define ZB_GPD_RX_OFFSET_MS 20 + +/* Old platforms require gpTxOffset calibration. It put into zb_config_platform.h. At new DSR platforms DSR MAC has a call "tx at specified time" so GP TX delay calibrating is not required. */ +#ifndef ZB_GPD_TX_OFFSET_US +#define ZB_GPD_TX_OFFSET_US \ + (ZB_MILLISECONDS_TO_USEC(ZB_GPD_RX_OFFSET_MS)) +#endif + +/** + gpdMinRxWindow + The gpdMinRxWindow is minimal duration of the reception window of an Rx-capable GPD. + It has the value of 0.576 ms that corresponds to the Channel Configuration GPDF of 18B. + GPD vendors shall implement reception window duration that corresponds to the actual GPD frame + size to be received by this GPD, which may never be shorter than + gpdMinRxWindow. + + A.1.6.3.2 gpdMinRxWindow +*/ +#define ZB_GPD_MIN_RX_WINDOW_MS 50 +#endif /* ZB_ENABLE_ZGP_DIRECT */ +/** @} */ /* ZB_CONFIG */ +/************************NVRAM SUPPORT*******************/ + +#if defined ZB_USE_NVRAM +/** + Storing NWK security counter in NVRAM +*/ +#define ZB_STORE_COUNTERS +/** + Interval in which counter is stored +*/ +#define ZB_LAZY_COUNTER_INTERVAL 0x400 +#endif /*ZB_USE_NVRAM*/ + +/** + Migration datasets when page overflow in NVRAM +*/ +#define ZB_NVRAM_DATASET_MIGRATION + +/** Save address map in the NVRAM */ +#define ZB_STORE_ADDR_MAP + +/** Save neighbor table in the NVRAM */ +#define ZB_STORE_NEIGHBOR_TBL + + + +#ifndef ZB_LITE_NO_NVRAM_DATASET_VERSIONING +#define ZB_NVRAM_DATASET_OWN_VERSIONING +#endif + +/* Check for old GP definitions and produce a error */ +#if defined ENABLE_ZGP_TARGET_PLUS || defined ZB_ENABLE_ZGP_EP || defined ZB_DIRECT_MODE_WITH_ZGPD +#error Old ZGP define detected! +#endif + +/* ZBOSS Lite defines */ + +/** Do not allow ZR to join as ZED by default. */ +#define ZB_LITE_NO_JOIN_ZR_AS_ZED + +/* Since R21 NWK multicast should be turned off by default */ +#define ZB_LITE_NO_NWK_MULTICAST + +/* + If defined maximum possible features cut + */ + +#ifdef ZB_ZBOSS_LITE_MAX +#ifndef ZB_LITE_NO_SOURCE_ROUTING +/** + Disable source routing + */ +#define ZB_LITE_NO_SOURCE_ROUTING +#endif + +#ifndef ZB_LITE_NO_NLME_ROUTE_DISCOVERY +/** + Disable route discovery API (but keep implicit route discovery) + */ +#define ZB_LITE_NO_NLME_ROUTE_DISCOVERY +#endif + +#ifndef ZB_NO_NWK_MULTICAST +/** + Disable NWK multicast. Use APS grops and NWK broadcast instead. + */ +#define ZB_NO_NWK_MULTICAST +#endif + +#ifndef ZB_LITE_NO_PANID_CONFLICT_DETECTION +/** + Disable Pan ID conflict detection + */ +#define ZB_LITE_NO_PANID_CONFLICT_DETECTION +#endif + +#ifndef ZB_LITE_NO_PANID_CONFLICT_RECEIVING +/** + Disable Pan ID conflict command receiving + */ +#define ZB_LITE_NO_PANID_CONFLICT_RECEIVING +#endif + + +#ifdef ZB_LITE_NO_LINK_COST +/** + Disable nwk link cost based on lqi + + See 3.6.3.1 Routing Cost + */ +///not sure this is good idea #define ZB_LITE_NO_LINK_COST +#endif + +#ifndef ZB_LITE_NO_JOIN_ZR_AS_ZED +/** + Do not attempt to join ZR as ZED if join as ZR failed. + Do not join as ZED if joinint net is prior PRO. + */ +#define ZB_LITE_NO_JOIN_ZR_AS_ZED +#endif + +#ifndef ZB_LITE_NO_ORPHAN_SCAN +//#define ZB_LITE_NO_ORPHAN_SCAN +#endif + + +#ifndef ZB_LITE_NO_APS_DATA_ENCRYPTION +/** + Do not encrypt data at APS level + */ +#define ZB_LITE_NO_APS_DATA_ENCRYPTION +#endif + +#ifndef ZB_LITE_NO_STORE_APS_COUNTERS +/** + Do not store APS security frame counters in nvram + */ +#define ZB_LITE_NO_STORE_APS_COUNTERS +#endif + +/** + Do not check for APS security counters inconsistence at unsecure + */ +#ifndef ZB_NO_CHECK_INCOMING_SECURE_APS_FRAME_COUNTERS +#define ZB_NO_CHECK_INCOMING_SECURE_APS_FRAME_COUNTERS +#endif + +#ifdef ZB_DISTRIBUTED_SECURITY_ON +#undef ZB_DISTRIBUTED_SECURITY_ON +#endif + +#ifdef ZB_SECURITY_INSTALLCODES +#undef ZB_SECURITY_INSTALLCODES +#endif + +#ifdef ZB_CERTIFICATION_HACKS +#undef ZB_CERTIFICATION_HACKS +#endif + + +#ifndef ZB_LITE_NO_UNICAST_SWITCH_KEY +/** + Do not send switch key unicast + */ +#define ZB_LITE_NO_UNICAST_SWITCH_KEY +#endif + + +#ifndef ZB_LITE_NO_GLOBAL_VS_UNIQUE_KEYS +/** + Treate all APS keys as Unique. +(Unique vs Global is brain-damaging flag to define encryption/non wncryption at +APS of some APS commands, like Update Device. It introduced in r20 probably for +compatibility with some mammoth shit */ +//#define ZB_LITE_NO_GLOBAL_VS_UNIQUE_KEYS +#endif + + +#ifndef ZB_LITE_NO_TRUST_CENTER_REQUIRE_KEY_EXCHANGE +/** + Never require unique keys exchange on join + */ +#define ZB_LITE_NO_TRUST_CENTER_REQUIRE_KEY_EXCHANGE +#endif + +#ifndef ZB_LITE_NO_ZDO_SYSTEM_SERVER_DISCOVERY +/** + Exclude ZDO Syetrm Server Discovery + */ +#define ZB_LITE_NO_ZDO_SYSTEM_SERVER_DISCOVERY +#endif + +#ifndef ZB_LITE_NO_ZDO_MGMT_RTG +#define ZB_LITE_NO_ZDO_MGMT_RTG +#endif + +#ifndef ZB_LITE_NO_FULL_FUNCLIONAL_MGMT_NWK_UPDATE +#define ZB_LITE_NO_FULL_FUNCLIONAL_MGMT_NWK_UPDATE +#endif + +/** + Do not try to inject LEAVE on data request from ZED which we already timed out. + + That define removes stupid r21 feature which requires from us to always set + pending bit in any our real devices (just because we are a) not so fast to check + _absence_ of device in the neighbor table and replay with MAC ACK and b) want + to use auto-ack feature of radio which support it - like TI devices). + */ +#ifndef ZB_LITE_NO_LEAVE_INJECTION +#define ZB_LITE_NO_LEAVE_INJECTION +#endif +#ifdef ZB_LITE_NO_LEAVE_INJECTION +#ifdef ZB_MAC_STICKY_PENDING_BIT +#undef ZB_MAC_STICKY_PENDING_BIT +#endif +#endif + +#ifndef ZB_LITE_NO_CONFIGURABLE_LINK_STATUS +#define ZB_LITE_NO_CONFIGURABLE_LINK_STATUS +#endif + +#ifdef ZB_COORDINATOR_ONLY +#ifdef ZB_DISTRIBUTED_SECURITY_ON +#undef ZB_DISTRIBUTED_SECURITY_ON +#endif +#endif + +#ifndef ZB_LITE_NO_INDIRECT_MGMT_LEAVE +/** + Disable mgmt leave with requires sendint leave to third device. + */ +#define ZB_LITE_NO_INDIRECT_MGMT_LEAVE +/* Need to store only one entry - about leave myself */ +#ifdef ZB_ZDO_PENDING_LEAVE_SIZE +#undef ZB_ZDO_PENDING_LEAVE_SIZE +#define ZB_ZDO_PENDING_LEAVE_SIZE 1 +#endif +#endif + +#ifndef ZB_LITE_APS_DONT_TX_PACKET_TO_MYSELF +/** + Don't pass from APS up packet which is sent to myself - either directly or + via group. + */ +#define ZB_LITE_APS_DONT_TX_PACKET_TO_MYSELF +#endif + + +#ifndef ZB_LITE_BDB_ONLY_COMMISSIONING +/** + Allow only BDB commissioning and disallow old ZBOSS start sequence + */ +#define ZB_LITE_BDB_ONLY_COMMISSIONING +#endif +#if defined ZB_LITE_BDB_ONLY_COMMISSIONING && !defined ZB_BDB_MODE +#define ZB_BDB_MODE +#endif + + +#ifndef ZB_LITE_LIMIT_PIB_ACCESS +/** + Limit access to PIB to values really used by the stack + */ +#define ZB_LITE_LIMIT_PIB_ACCESS +#endif + +#ifndef ZB_LITE_ALWAYS_SECURE +/** + No ability to switch off security + */ +#define ZB_LITE_ALWAYS_SECURE +#endif + +#ifndef ZB_LITE_DONT_STORE_RSSI +/** + Do not store rssi in the neigbor + */ +//#define ZB_LITE_DONT_STORE_RSSI +//#define ZB_LITE_DONT_STORE_RSSI +#endif + +/** + Disable end device bind + */ +#ifndef ZB_LITE_NO_END_DEVICE_BIND +#define ZB_LITE_NO_END_DEVICE_BIND +#endif + +#ifdef ZB_TEST_PROFILE +#undef ZB_TEST_PROFILE +#endif + +#endif /* ZB_ZBOSS_LITE_MAX */ + + +#ifdef ZB_COORDINATOR_ONLY +#undef ZB_DISTRIBUTED_SECURITY_ON +#endif + +#if defined ZB_TRAFFIC_DUMP_OFF && defined ZB_TRAFFIC_DUMP_ON +#undef ZB_TRAFFIC_DUMP_ON +#endif + + +#ifndef ZB_NO_NWK_MULTICAST +/** + Disable NWK multicast. Deprecated in R21. + Use APS grops and NWK broadcast instead. + */ +#define ZB_NO_NWK_MULTICAST +#endif + + +#ifdef ZB_CONFIGURABLE_MEM + +/* + Huge feature if configuring RAM usage without ZBOSS library recompiling. + Instead of normal static declarations use pointers. + At init time set pointers to be used instead of static arrays used normally. + Keep possibility to compile in a normal way; also keep code mergeable. + Undefine here array size constants and define it to be variables. See zb_g_context.h for details. +*/ +#ifdef ZB_IOBUF_POOL_SIZE +#undef ZB_IOBUF_POOL_SIZE +#endif +#ifdef ZB_SCHEDULER_Q_SIZE +#undef ZB_SCHEDULER_Q_SIZE +#endif +#ifdef ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE +#undef ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE +#endif +#ifdef ZB_IEEE_ADDR_TABLE_SIZE +#undef ZB_IEEE_ADDR_TABLE_SIZE +#endif +#ifdef ZB_NEIGHBOR_TABLE_SIZE +#undef ZB_NEIGHBOR_TABLE_SIZE +#endif +#ifdef ZB_NWK_ROUTING_TABLE_SIZE +#undef ZB_NWK_ROUTING_TABLE_SIZE +#endif +#ifdef ZB_APS_DUPS_TABLE_SIZE +#undef ZB_APS_DUPS_TABLE_SIZE +#endif +#ifdef ZB_APS_SRC_BINDING_TABLE_SIZE +#undef ZB_APS_SRC_BINDING_TABLE_SIZE +#endif +#ifdef ZB_APS_DST_BINDING_TABLE_SIZE +#undef ZB_APS_DST_BINDING_TABLE_SIZE +#endif +#ifdef ZB_APS_BIND_TRANS_TABLE_SIZE +#undef ZB_APS_BIND_TRANS_TABLE_SIZE +#endif +#ifdef ZB_SINGLE_TRANS_INDEX_SIZE +#undef ZB_SINGLE_TRANS_INDEX_SIZE +#endif +/* 10/21/2019 EE CR:MINOR There was #undef ZB_SCHEDULER_Q_SIZE_PROTECTED_STACK_POOL. Was its removal intended? */ +#ifdef ZB_NWK_MAX_SRC_ROUTES +#undef ZB_NWK_MAX_SRC_ROUTES +#endif + +#endif /* ZB_CONFIGURABLE_MEMORY */ + +/* pending bit source matching intended for ZB_ROUTER_ROLE only */ +#ifndef ZB_ROUTER_ROLE +#ifdef ZB_MAC_PENDING_BIT_SOURCE_MATCHING +#undef ZB_MAC_PENDING_BIT_SOURCE_MATCHING +#endif +#ifdef ZB_MAC_SOFTWARE_PB_MATCHING +#undef ZB_MAC_SOFTWARE_PB_MATCHING +#endif +#endif + +#ifndef ZB_NO_SYSTEST_SUPPORT +/* That is legacy for some tests. Not used any more */ +#define ZB_NO_SYSTEST_SUPPORT +#endif + +#ifdef ZB_COORDINATOR_ONLY +/* ZLL/Touchlink can be only ZR and ZED */ +#ifdef ZB_BDB_TOUCHLINK +#undef ZB_BDB_TOUCHLINK +#endif +#ifdef ZB_ENABLE_INTER_PAN_EXCHANGE +#undef ZB_ENABLE_INTER_PAN_EXCHANGE +#endif +#ifdef ZB_REJOIN_BACKOFF +#undef ZB_REJOIN_BACKOFF +#endif +#ifdef ZB_DISTRIBUTED_SECURITY_ON +#undef ZB_DISTRIBUTED_SECURITY_ON +#endif +#endif + +#ifdef ZB_ED_ROLE +#define ZB_USE_SLEEP +#endif + +/*! \addtogroup ZB_CONFIG */ +/*! @{ */ +/** Maximum buffer index. Buffer indexing starts from one. */ +#define ZB_N_BUF_IDS (ZB_IOBUF_POOL_SIZE + 1) + +#ifdef ZB_PRODUCTION_CONFIG +#define ZB_PRODUCTION_CONFIG_MAX_SIZE 128 + +typedef enum zb_production_config_version_e +{ + ZB_PRODUCTION_CONFIG_VERSION_1_0 = 0x01, + ZB_PRODUCTION_CONFIG_VERSION_2_0 = 0x02, +} zb_production_config_version_t; + +#define ZB_PRODUCTION_CONFIG_CURRENT_VERSION ZB_PRODUCTION_CONFIG_VERSION_2_0 +#endif /*ZB_PRODUCTION_CONFIG*/ +/*! @} */ + +#if defined USE_ZB_WATCHDOG || defined ZB_MACSPLIT_DEVICE +#define ZB_NEVER_STOP_TIMER +#endif + +#endif /* ZB_CONFIG_H */ diff --git a/zboss/include/zb_config_common.h b/zboss/include/zb_config_common.h new file mode 100644 index 0000000000..5225525fa2 --- /dev/null +++ b/zboss/include/zb_config_common.h @@ -0,0 +1,1628 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Common constants and definitions, mainly related to ZigBee protocol. +*/ +#ifndef ZB_CONFIG_COMMON_H +#define ZB_CONFIG_COMMON_H 1 + +/* +Note: that file included form the very beginning of zb_config.h +Do not put there ifdefs depending on defines made in the middle of zb_config.h! + */ + +/*! \addtogroup ZB_CONFIG */ +/*! @{ */ +/**@cond internals_doc*/ +/* To compile MAC only build; + TODO: Fix it. there should probably be another way to build without security +*/ +/** @endcond *//* internals_doc */ +/****************************Sequrity options**************************/ + +/****************************Sequtity keys***************************/ + +/* Always security on (both NWK and APS). Remove all special security configs */ + +/* +4.6.3.2.2.1 Standard Security Mode + +A default global trust center link key must be supported by the device if no other +link key is specified by the application at the time of joining. This default link key +shall have a value of 5A 69 67 42 65 65 41 6C 6C 69 61 6E 63 65 30 39 +(ZigbeeAlliance09).44 + */ +/*! Define a default global trust center link key */ +#define ZB_STANDARD_TC_KEY {0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 }; + + +/** + In ZLL specification this is ZLL Certification pre-installed link key - see + 8.7.2 Transfer ring the network key dur ing classical Zigbee commissioning. + + + The distributed security global link key is used to join a distributed security + network. This link key is provided to a company as a result of a successful + certification of a product. For testing, this key SHALL have this default value. + + + See Base Device Behaviour Specification subclause 6.3.2 Distributed security global link key + */ +#define ZB_DISTRIBUTED_GLOBAL_KEY {0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf}; + +/** @cond touchlink */ + +/** +6.3.4 Touchlink preconfigured link key + +The touchlink preconfigured link key is used to join a network via +touchlink. This link key is provided to a company as a result of a +successful certification of a product. For testing, this key SHALL have the +value of: + +In ZLL specification this is 8.7.5.1.2 Certification key (key index 15) + +In BDB 8.7.1.2 Key index and encrypted network key fields. +"This value SHALL be set to 0x04 during certification testing or 0x0f at all +other times." +In ZLL Table 67 Key encryption algorithms: 4 is Master key, 0xf is Certification +key. They use same algorithm. + + */ +#define ZB_TOUCHLINK_PRECONFIGURED_KEY {0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf}; + +/** @endcond */ /* touchlink */ + +/* BDB does not mention using of Development ZLL key, so skip it. */ +/** @cond internals_doc */ +/** + SECUR: if defined, implement Standard security + + @note High Security is obsolete and will never be implemented. +*/ +#define ZB_STANDARD_SECURITY + +/** + SECUR: If defined, generate random keys at Trust Center at start of pre-configured jey is not set. +*/ +#define ZB_TC_GENERATES_KEYS + +/* (currently - always)*/ +/** + SECUR: If defined, trust Center is at ZC +*/ +#define ZB_TC_AT_ZC +/** @endcond */ /* internals_doc */ +/** + SECUR: CCM key size. Hard-coded +*/ +#define ZB_CCM_KEY_SIZE 16 + +/* NLS5 - All devices shall maintain at least 2 NWK keys with the frame + counters consistent with the security mode of the network (Standard or High).*/ +/*! Define number of network keys with the frame counter */ +#define ZB_SECUR_N_SECUR_MATERIAL 3 + + +/* parameters for security level 5 - the only security level supported */ +/** + SECUR: security level. Now fixed to be 5 +*/ +#define ZB_SECURITY_LEVEL 5 +/** @cond internals_doc */ +/*! + CCM L parameter for security level 5. +*/ +#define ZB_CCM_L 2 + +/*! + CCM nonce length. +*/ +#define ZB_CCM_NONCE_LEN (15 - ZB_CCM_L) + +/*! + CCM M parameter for security level 5 +*/ +#define ZB_CCM_M 4 + +/*! + Value of nwk packets counter which trigger nwk key switch +*/ +#define ZB_SECUR_NWK_COUNTER_LIMIT (((zb_uint32_t)~0) - 128) + +//#define ZB_DEFAULT_SECURE_ALL_FRAMES 0 +/*! + Default value for nib.secure_all_frames +*/ +#define ZB_DEFAULT_SECURE_ALL_FRAMES 1 + +/*! + Include long address into APS security header + */ +#define ZB_APS_SECUR_APS_USE_EXT_NONCE + +/*! + This macro defines total number of NWK frame unsecure attempts before NWK decides that + frame can not be processed. Made as Workaround. + If frame was not unsecured, cut 1 byte of buffer end and try to unsecure frame again. + */ +//#define ZB_NWK_SECUR_UNSECURE_FRAME_ATTEMPTS 4 + + +/****************************APS layer options**************************/ + + + +/* APS */ + +/* + APS: dup check timeout. + + APS dup checks resolution is 1 sec, so dup timeout is 21 sec. This + interval guaranties total APS retransmission interval (1 original + 2 retransmits). +*/ +/*! Dup check timeout */ +#define ZB_APS_DUP_INITIAL_CLOCK 21 +/*! Sets APS dup chekcks time out. By default it is 21 sec. This +* interval guaranties total APS retransmission interval (1 original + 2 retransmits). +*/ +#define ZB_APS_DUP_CHECK_TIMEOUT ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000) + +#ifndef ZB_APS_DUPS_TABLE_SIZE +/** + * APS dups table size. + * + * @note This is a default value of the define. This value can be changed by user. + */ +#define ZB_APS_DUPS_TABLE_SIZE 32 +#endif + +/** @endcond *//* internals_doc */ +/*! + Maximum MAC packet waiting time to expire + */ + #define ZB_MAC_INDIRECT_POLL_EXPIRE_TMO ZB_MILLISECONDS_TO_BEACON_INTERVAL(7680) + + + +/** + APS retransmissions + */ + +/* + APS: max number of packets waiting for APS ACK + + Derive it from the pool size. Keep some free buffers in the pool, remember some + buffers are reserved at start (I see 4 out buffers resetved). +*/ +#ifndef ZB_CONFIGURABLE_MEM +/** + * APS: maximum number of packets waiting for APS ACK + * + * @note This is a default value of the define. This value can be changed by user. + */ + #define ZB_N_APS_RETRANS_ENTRIES ((ZB_IOBUF_POOL_SIZE / 3) > 0 ? (ZB_IOBUF_POOL_SIZE / 3) : (ZB_IOBUF_POOL_SIZE / 2)) +#endif + +/** + * APS maximum of apscMaxFrameRetries times + * + * See Zigbee specification revision 22 section 2.2.7.1 APS Constants +*/ + #define ZB_N_APS_MAX_FRAME_RETRIES 3 + + +/*! + APS: APS ACK wait time from Sleepy devices. After this timeout resend APS packet + see Zigbee specification revision 22 section 2.2.7.1 APS Constants +*/ + #define ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY (10*ZB_TIME_ONE_SECOND) +/** @cond internals_doc */ +/*! + APS: The base amount of delay before each broadcast parent announce is sent. + */ +#define ZB_APS_PARENT_ANNOUNCE_BASE_TIMER (10 * ZB_TIME_ONE_SECOND) + +/*! +The max amount of jitter that is added to the apsParentAnnounceBaseTimer before each broadcast parent announce is sent. +*/ +#define ZB_APS_PARENT_ANNOUNCE_JITTER_MAX (10 * ZB_TIME_ONE_SECOND) +/** @endcond */ /*internals_doc*/ + +/** + * APS: APS ACK wait time from Non Sleepy devices. After this timeout resend APS packet + * + * See Zigbee specification revision 22 section 2.2.7.1 APS Constants +*/ + /* Some devices send APS_ACK to AF and ZDO commands after sending appropriate response or + * DefaultResponse. For example, ZCL On/Off command can be done within 5-7 seconds, + * so 2 seconds for wail duration is insufficiently. */ + #define ZB_N_APS_ACK_WAIT_DURATION_FROM_NON_SLEEPY (3*ZB_TIME_ONE_SECOND) + +/** + APS: maximum number of tables with information from a binding table to be sent to the devices +*/ + #define ZB_N_APS_BINDTRANS_ARR_MAX_SIZE 5 + +/** + * APS: maximum number of elements in array with index from dst array in bind table +*/ + #define ZB_N_APS_BINDTRANS_DST_INDEX_ARR_MAX_SIZE ZB_APS_DST_BINDING_TABLE_SIZE + +/** @cond internals_doc */ +/* Origin of this tweak is R21 version of core stack */ +/* Also it is a kind of "everybody knows" issue */ +/** + Disable APS acknowledgement request bit in APS commands. +*/ +#define ZB_APS_DISABLE_ACK_IN_COMMANDS +/** @endcond *//*internals_doc*/ + +/* EE: wrong place for that constant in zb_aps.h (this is not public APS API!) and wrong + * calculation! + * BTW that constant used at 1 place only. + * ZB_ZDO_MAX_PAYLOAD_SIZE in zb_zdo.h is hard-coded! + * And, zb_zdo.h is also bad place for it. + * + * Let's count supposing no APS security. + * MAC header - 10 with fcf (suppose Pan ID compression) + * NWK header - 24 unicast, but 16 broadcast + * NWK ZB security header + MIC - cf 1 + fcnt 4 + ext src 8 + key seq 1 mic 4 = 18 + * APS hdr 8b + * Totally for broadcast - 127 - (11+16+18+8) = 74 + * For unicast 74-8 = 66 + +Fixed that size for the certification test TP/R21/BV-24. +We actually fit 5 parent annce records into 127 bytes only for broadcast tx, +with Pan ID compression. + +At the worst case our NWK can skip long address at tx: 8 bytes of reserve. + + */ +/**@cond internals_doc*/ +/*! Maximum broadcast APS payload size */ +#define ZB_APS_MAX_BROADCAST_PAYLOAD_SIZE 74 +/** + Maximum broadcast APS payload size supposing NWK encryption only, no long + address in NWK header. That means definitely the largest possible size. + */ +#define ZB_APS_MAX_MAX_BROADCAST_PAYLOAD_SIZE (74 + 8) + +/** + MAC hdr: + 3 (hdr, seq num) + 2 * 3 (short dst and src; dst panid) + NWK hdr: + 4 + 2*2 (dst, src short) + 8*2 (dst, src long) + NWK security: 18 + APS hdr: 8 (max, without ext header and security) + MAC footer: 2 + + Total: 69 bytes + So we can send: 127-69 = 58 bytes +*/ +#define ZB_APS_GUARANTEED_PAYLOAD_SIZE_WO_SECURITY 58 + +/** + Maximum number of bytes that is additionally occupied by APS security (in case of extended nonce) +*/ +#define ZB_APS_MAX_APS_SECURITY_SIZE 17 + +/** + Maximal frame size + */ +#define MAX_PHY_FRM_SIZE 127 + +/* ZB packet length must not exceed 127 bytes + * + * Old calculation by Maxim: + * + * MAC header (total: 11 bytes) + * - FCF: 2 bytes + * - Sequence number: 1 bytes + * - PAN: 2 bytes + * - Destination address: 2 bytes + * - Source address: 2 bytes + * + * NWK header (total: 24 bytes) + * - FCF: 2 bytes + * - Destination short address: 2 bytes + * - Source short address: 2 bytes + * - Radius: 1 byte + * - Sequence number: 1 byte + * - Destination long address: 8 bytes + * - Source long address: 8 bytes + * + * ZB security header (total: 31 bytes) + * + * APS header (total: 8 bytes) + * - FCF: 1 byte + * - Destination endpoint: 1 byte + * - Cluster id: 2 bytes + * - Profile id: 2 bytes + * - Source endpoint: 1 byte + * - Counter: 1 byte + * + * APS payload (total: variable length) + * + * MAC footer (total: 2 bytes) + * - FCS: 2 bytes + * + * Total length w/o APS payload: 127-(11+24+31+8+2)= 51 bytes, + * consequently APS payload max size is 51 bytes. + */ +/* + * MAC (short source, short destination): MAX_MAC_OVERHEAD_SHORT_ADDRS bytes + * NWK (broadcast, no destination IEEE): 16 bytes header + 18 bytes security + * Total length: 127-(11+16+18) = 82 bytes */ + /* nwk hdr include source IEEE address */ + +/*! Maximum broadcast NWK header size */ +#define ZB_NWK_MAX_BROADCAST_HDR_SIZE 16 +/*! Maximum security NWK header size */ +#define ZB_NWK_MAX_SECURITY_HDR_SIZE 18 +/*! Maximum broadcast NWK payload size */ +#define ZB_NWK_MAX_BROADCAST_PAYLOAD_SIZE (MAX_PHY_FRM_SIZE - (MAX_MAC_OVERHEAD_SHORT_ADDRS + \ + ZB_NWK_MAX_BROADCAST_HDR_SIZE + ZB_NWK_MAX_SECURITY_HDR_SIZE)) +/** @endcond */ /* internals_doc */ +/*! + * Maximum unicast APS payload size, if no APS encryption is provided + */ +#define ZB_APS_MAX_PAYLOAD_SIZE (ZB_APS_MAX_BROADCAST_PAYLOAD_SIZE - 8) +/** @cond internals_doc */ +/*! Maximum ZDO payload size */ +#define ZB_ZDO_MAX_PAYLOAD_SIZE (ZB_APS_MAX_PAYLOAD_SIZE-1) +/*! The size of the MAC header used by the Zigbee NWK layer. */ +#define ZB_NWKC_MAC_FRAME_OVERHEAD 0xB +/*! The minimum number of octets added by the NWK layer to an NSDU. */ +#define ZB_NWKC_MIN_HEADER_OVERHEAD 0x8 + +/*! + * The number of network layer retries on unicast messages that are attempted before + * reporting the result to the higher layer. It must be at least 3. + * Value: 3 + */ +#define ZB_NWKC_UNICAST_RETRIES 3 + +/*! + * The delay between network layer retries. + * Value: 50 ms + */ +#define ZB_NWKC_UNICAST_RETRY_DELAY ZB_MILLISECONDS_TO_BEACON_INTERVAL(50) + +/* max nsdulength = aMaxPHYFrameSize -(nwkcMACFrameOverhead + nwkcMinHeaderOverhead) (D.4 aMaxMACFrameSize) */ +/*! Maximum NSDU(Network Service Data Unit) length */ +#define ZB_NSDU_MAX_LEN (MAX_PHY_FRM_SIZE - (ZB_NWKC_MAC_FRAME_OVERHEAD + ZB_NWKC_MIN_HEADER_OVERHEAD)) +/*! The minimum number of octets added by the APS sub-layer to an ASDU. */ +#define ZB_APSC_MIN_HEADER_OVERHEAD 0x0C +/* max asdu length 256*(NsduLength - apscMinHeaderOverhead); currently fragmentation + * is not supported */ +/*! Maximum ASDU(APS service data unit) length*/ +#define ZB_ASDU_MAX_LEN (ZB_NSDU_MAX_LEN - ZB_APSC_MIN_HEADER_OVERHEAD) + +/* 06/20/2017 EE CR:MAJOR can't always count extra header bytes when calculating max packet length. It is not optimal, and we even may not pass tests checking for max payload length */ +/* NK: Agree, but this define is called MAX_LEN, and includes maximum possible data. Better to + * calculate maximum payload length dynamically (based on fragmentation, destination addr, + * security mode etc). + * Anyway, there are not too many cases where we use ZB_APS_HEADER_MAX_LEN or + * ZB_APS_PAYLOAD_MAX_LEN. + * EE: Can't we assert in zb_zdo_nwk_upd_notify()? You can define 2 constamts: fragmented and not. + */ + +/* 2 stands for fc + aps counter( Packet either has dest and src endpoints (1+1 byte) if not group +* addressing or Group address elsewhere - so 2 anyway) +* + 2(cluster id, profile id)* +* + 4(fragmentation and Extended header are NOT included +* TODO: handle fragmentation and Extended header.*) +* + 1(Security control field) +* + 4(Frame Counter) +* + 4(Message Integrity Code) +* + 0 +*/ + +/*! Maximum length of APS header */ +#define ZB_APS_HEADER_MAX_LEN (17) + +/*! Maximum length of an APS payload.*/ +#define ZB_APS_PAYLOAD_MAX_LEN ZB_ASDU_MAX_LEN - ZB_APS_HEADER_MAX_LEN + +/* 01/24/2018 EE CR:MINOR Better move it out of zb_config.common.h */ +/* Value 3 in this define comes for fragmentation and ext header */ +/*Take into account that ZB_ASDU_MAX_LEN counts minimum overhead, but it is sometimes +* impossible to send pkt with these conditions; add 10 more bytes for nwk security etc +*/ +/*! + * Length of an APS payload fragment + * @param short_addr - address of the buffer containing APS fragment + */ +#define ZB_APS_FRAG_PAYLOAD_LEN(short_addr) ((zb_aps_get_max_buffer_size(short_addr)>40+ZB_APS_HEADER_MAX_LEN)?\ + (zb_aps_get_max_buffer_size(short_addr) - ZB_APS_HEADER_MAX_LEN \ + - 3 \ + - 37 ):21) +/*! + * Maximum number of APS fragments + * See Zigbee specification revision 22 section 2.2.8.4.5 Fragmented Transmissions + */ +#define ZB_APS_MAX_FRAGMENT_NUM 8 + +/*! +* Maximum number of fragments which can be +* transmitted/received during one APS frame window. +* +* See Zigbee specification revision 22 section 2.2.8.4.5 Fragmented Transmissions +*/ +#define ZB_APS_MAX_FRAGMENT_NUM_IN_WINDOW 8 +/** @endcond *//* internals_doc */ +/** Maximum buffer size for APS fragmentation. Bigger buffer will not be created for APS fragmentation */ +#define APS_IN_FRAG_MAX_BUF_SIZE 1500 + + +/****************************NWK layer options**************************/ +/** @cond internals_doc */ +/*! + Define maximum number of children per node. + + This value should be defined in stack profile. + + See Zigbee specification revision 22 subclause 3.5.2 +*/ +#define ZB_NWK_MAX_CHILDREN 4 + +/*! + Define maximum number of routers per node. + + This value should be defined in stack profile. + + See Zigbee specification revision 22 subclause 3.5.2. +*/ +#define ZB_NWK_MAX_ROUTERS 4 + +/** + Define maximum network depth for a tree routing +*/ +#define ZB_NWK_TREE_ROUTING_DEPTH 5 + +/** + Define maimum network depth in stochastic addressing mode (NLF90) +*/ +#define ZB_NWK_STOCH_DEPTH 15 + + +/*! + NWK Mesh route stuff: route discovery table size +*/ +#ifndef ZB_NWK_ROUTE_DISCOVERY_TABLE_SIZE +#define ZB_NWK_ROUTE_DISCOVERY_TABLE_SIZE 5 +#endif + +/* nwkcRouteDiscoveryTime == 0x2710 ms == 10 sec. Expiry function called once + * per second */ +/*! Time period for calling route discovery expiry function */ +#define ZB_NWK_ROUTE_DISCOVERY_EXPIRY 10 +/*! Length of the route discovery function */ +#define ZB_NWK_EXPIRY_ROUTE_DISCOVERY (ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY / ZB_NWK_ROUTE_DISCOVERY_EXPIRY) + +/*#define ZB_NWK_RREQ_TABLE_SIZE 5*/ + +/*! +* The number of times the first broadcast +* transmission of a route request command +* frame is retried. +* +* Correspond to nwkcInitialRREQRetries in Zigbee Specification revision 22 subclause 3.5.1 NWK +* Constants +* +* The value is defined by specification. +*/ +#define ZB_NWK_INITIAL_RREQ_RETRIES 3 +/*! + * The number of times the broadcast + * transmission of a route request command + * frame is retried on relay by an intermediate + * Zigbee router or Zigbee coordinator. + * + * Correspond to nwkcRREQRetries in Zigbee Specification revision 22 subclause 3.5.1 NWK Constants + * The value defined by specification. + */ +#define ZB_NWK_RREQ_RETRIES 2 + +#ifndef ZB_NWK_PENDING_TABLE_SIZE +/*! Pending table size */ +#define ZB_NWK_PENDING_TABLE_SIZE 5 +#endif + +/*! Pending entry expiry during route request */ +#define ZB_NWK_PENDING_ENTRY_EXPIRY 2 +/*! Network static path cost */ +#define ZB_NWK_STATIC_PATH_COST 7 + +/*! +* Delay to wait before sending packet after receiving route replay. +* +* Used only if ZB_CERT_HACKS().delay_pending_tx_on_rresp is 1. +* Useful for test TP_PRO_BV-04. +* Normally ZBOSS sends NWK immediately after receiving any route. +*/ +#define ZB_NWK_SEND_AFTER_RRESP_RECV_DELAY_MS 1000 + + +#ifndef ZB_NWK_BTR_TABLE_SIZE +/*! +* Broadcast transaction record table size +* See Zigbee Specification subclause 3.6.5 +*/ +#define ZB_NWK_BTR_TABLE_SIZE 16 +#endif + +#ifndef ZB_NWK_BRR_TABLE_SIZE +/*! Broadcast Retransmission table size */ +#define ZB_NWK_BRR_TABLE_SIZE 8 +#endif + +/* 01/15/2019 EE CR:MINOR Can't it be better to keep ZB_NWK_MAX_BROADCAST_JITTER_INTERVAL define but internally define it using octets? + In such case you minimize code modifications. same for all similar cases. Why movve "octets" to the upper layer? */ +/* nwkcMaxBroadcastJitter */ +/* 01/15/2019 EE CR:MINOR Add reference to the specification: here and in similar cases */ +#define ZB_NWKC_MAX_BROADCAST_JITTER_OCTETS 0x7d0 + +/* nwkcMinRREQJitter */ +#define ZB_NWKC_MIN_RREQ_JITTER_OCTETS 0x3f + +/* nwkcMaxRREQJitter */ +#define ZB_NWKC_MAX_RREQ_JITTER_OCTETS 0xfa0 + +/* nwkcRREQRetryInterval */ +#define ZB_NWKC_RREQ_RETRY_INTERVAL 0x1f02 + +/*! Expiration time of pending period */ +#define ZB_NWK_EXPIRY_PENDING (ZB_N_APS_ACK_WAIT_DURATION_FROM_SLEEPY / 2) /* 5 seconds */ + +/* 9 seconds */ +/* According to 2013 PICS, it should be 9 sec. + According to spec, it should be converted from broadcastDeliveryTime */ +/** See Zigbee specification revision 22 section 3.5.2 NWK Information Base + * nwkBroadcastDeliveryTime */ +#define ZB_NWK_EXPIRY_BROADCAST 9 + +/* Check if it is really should be so long. According to r21 spec, 3.6.3.2 - it is out of + * the scope of this spec. */ +/* Should correspond to ( 5 * minutes = 300 seconds / ZB_NWK_EXPIRY_PENDING ) */ +/*! Expiration time of the network routing table */ +#define ZB_NWK_ROUTING_TABLE_EXPIRY 60 + +/*! + * The maximum number of retries allowed after a broadcast transmission failure. + * + * See PICS NDF4. +*/ +#define ZB_NWK_MAX_BROADCAST_RETRIES 0x02 + +/*! + * The maximum time duration in milliseconds allowed for the parent and all + * child devices to retransmit a broadcast message. + * + * See PICS NDF4. + */ +#define ZB_NWK_PASSIVE_ACK_TIMEOUT_OCTETS 0x3D09 + +/*! + NWK Broadcast delivery time See 3.5.2.1 +nwkBroadcastDeliveryTime = 2*nwkMaxDepth* ((0.05+(nwkcMaxBroadcastJitter/2))+ nwkPassiveAckTimeout*nwkBroadcastRetries/1000 +nwkcMaxBroadcastJitter and nwkPassiveAckTimeout are measured in OctetDurations (!). + +In PICS NDF4 for PRO: + +nwkBroadcastDeliveryTime = 0x44AA2 Octet +durations (9 seconds on +2.4 GHz) +nwkPassiveAckTimeout = +0x3D09 Octet +Durations9 (500 ms on +2.4 GHz) maximum +nwkMaxBroadcastRetries += 2 + */ +#define ZB_NWK_BROADCAST_DELIVERY_TIME_OCTETS 0x44AA2 +/** @endcond *//* internals_doc */ + +/*! + * The time in seconds between link status command frames. + * + * Correspond to nwkLinkStatusPeriod in Zigbee Specification revision 22 subclause 3.5.1 NWK Constants + * The value defined by specification. + */ +#define ZB_NWK_LINK_STATUS_PERIOD 0xf + +/*! + * The number of missed link status command frames before + * resetting the link costs to zero. + * + * Correspond to nwkRouterAgeLimit in Zigbee Specification revision 22 subclause 3.5.1 NWK Constants + * The value defined by specification. +*/ +#define ZB_NWK_ROUTER_AGE_LIMIT 3 +/** @cond internals_doc */ +/*! + Maximum number of rejoin requests in progress +*/ +#define ZB_NWK_REJOIN_REQUEST_TABLE_SIZE 1 +/** @endcond */ /* internals_doc */ +/*! Rejoin timeout length */ +#define ZB_NWK_REJOIN_TIMEOUT (ZB_TIME_ONE_SECOND * 5) + +/*! +* The rejoining sleeping end-device shall not poll before the response timeout (500ms), such that +* the parent has enough time to process the rejoin request and put a response frame in its indirect +* queue (same as for association response). Depending on the implementation, once a rejoining device +* has performed an active scan and selected a new parent router, it sends a rejoin request (and at +* that time considers this router to be its new parent, otherwise it cannot accept the rejoin +* response), and polls for a response 500ms later. + */ +#define ZB_NWK_REJOIN_FIRST_POLL_DELAY (ZB_TIME_ONE_SECOND / 2) + +/*! Number of poll attempts during rejoin */ +#define ZB_NWK_REJOIN_POLL_ATTEMPTS 3 +//#define ZB_NWK_REJOIN_POLL_ATTEMPTS 6 //TEST +/** @cond internals_doc */ +/*! + * Acceptable energy level on channel + */ +#define ZB_NWK_CHANNEL_ACCEPT_LEVEL 0x60 + +/** + Devices which sends broadcast packets with rssi lower than this value will not be added + to the neighbor table. + */ +#ifndef ZB_NWK_NEIGHBOR_RSSI_FILTER +#define ZB_NWK_NEIGHBOR_RSSI_FILTER (-80) +#endif + +#ifndef ZB_DEFAULT_PERMIT_JOINING_DURATION +/*! + Default duration to permit joining. Set to infinite by default. +*/ +#define ZB_DEFAULT_PERMIT_JOINING_DURATION 0xff +#endif +/** @endcond *//* internals_doc */ + +/*! + * Default value of nib.max_children - max number of children which can join to this device + * + * See Zigbee Specification revision 22 section 3.5.2 NWK Information Base +*/ +#define ZB_DEFAULT_MAX_CHILDREN 32 +/**@cond internals_doc */ +/* Old feature from pre-3.0 (HA) era */ +/* If there was an error in NWK security processing of incoming packet from parent, + * then device tries to rejoin. This define disables this behaviour */ + +/* By default device is rejoined if network key switch failed */ +/* #define ZB_DISABLE_REJOIN_AFTER_KEY_SWITCH_FAIL */ + +/*! +* The default value of zb_tc_rejoin flag. Allows ZED to rejoin using Trust Center +* rejoin procedure +*/ +#define ZB_TC_REJOIN_ENABLE + + /*! + Define policy of ignoring assoc. permit and corresponding flags during rejoin + */ +#define ZB_REJOIN_IGNORES_FLAGS + +/*! +Workaroud for secure rejoin +*/ +#define xZB_NO_KEY_AFTER_REJOIN + +//#define ZB_MULTILEAVE_HACK + + /*! If the macro is defined, the device leaves the network according to application callback*/ +#define ZB_LEAVE_USE_APP_CALLBACK +/** @endcond *//* internals_doc */ +/**@cond DOXYGEN_MULTIMAC_SECTION */ +/*! +* The rate, in seconds, of how often a Link Power Delta request is generated. +* In bands where this is optional, it should be set to 0, disabling the +* function. The default value should be 16. + */ +#define ZB_NWK_LINK_POWER_DELTA_TRANSMIT_RATE 16 + +/*! A Link Power Delta request rate jitter */ +#define ZB_NWK_LINK_POWER_DELTA_TRANSMIT_RATE_JITTER 10 /* 10 seconds */ +/** @endcond *//* DOXYGEN_MULTIMAC_SECTION */ +/********************ZDO layer options*********************************/ +/**@cond internals_doc*/ + /*! + ZDO Indirect poll timer + */ +#define ZB_ZDO_INDIRECT_POLL_TIMER (5*ZB_TIME_ONE_SECOND) /* ZB_TIME_ONE_SECOND*10 */ + +/*! + ZDO Max parent threshold retry + */ +#define ZB_ZDO_MAX_PARENT_THRESHOLD_RETRY 10 + +/*! + Min scan duration for mgmt_nwk_update_req +*/ +#define ZB_ZDO_MIN_SCAN_DURATION 0 +/*! + Max scan duration for mgmt_nwk_update_req +*/ +#define ZB_ZDO_MAX_SCAN_DURATION 5 +/*! + Max scan count for mgmt_nwk_update_freq +*/ +#define ZB_ZDO_MAX_SCAN_COUNT_PARAM 1 +/*! + * Special value of the ScanDuration for Mgmt_NWK_Update_req for channel change. + * + * See Zigpee Specification revision 22 Table 2.88, field ScanDuration. + */ +#define ZB_ZDO_NEW_ACTIVE_CHANNEL 0xFE +/*! + * Special value of the ScanDuration for Mgmt_NWK_Update_req for channel mask change. + * + * See Zigpee Specification revision 22 Table 2.88, field ScanDuration. +*/ +#define ZB_ZDO_NEW_CHANNEL_MASK 0xFF + + +/** + * @todo{OLD_DESCRIPTION} Old (2015) and strange define + * A countdown timer (in minutes) indicating the time to the next + * permitted frequency agility channel change + */ +#define ZB_ZDO_APS_CHANEL_TIMER (1 * 60) + +/*! + 1 minute timer to measure large timeouts +*/ +#define ZB_ZDO_1_MIN_TIMEOUT (ZB_TIME_ONE_SECOND * 60) + +/* Default values: see HA spec 9.6.4.2 Attribute Settings and Battery Life Considerations */ +/** @endcond *//* intrenals_doc */ +/*! + Default fast poll timeout + */ +#define ZB_PIM_DEFAULT_FAST_POLL_TIMEOUT (ZB_TIME_ONE_SECOND * 10) + +/*! + Default fast poll interval + */ +#define ZB_PIM_DEFAULT_FAST_POLL_INTERVAL ZB_QUARTERECONDS_TO_BEACON_INTERVAL(2) + + +/*! + Default long poll interval + */ +#define ZB_PIM_DEFAULT_LONG_POLL_INTERVAL (ZB_TIME_ONE_SECOND * 5) + +/*! + Default turbo poll interval + */ +#define ZB_PIM_DEFAULT_TURBO_POLL_INTERVAL ZB_MILLISECONDS_TO_BEACON_INTERVAL(100) + +/*! + Minimal possible turbo poll interval + */ +#define ZB_PIM_DEFAULT_MIN_TURBO_POLL_INTERVAL ZB_MILLISECONDS_TO_BEACON_INTERVAL(100) +//#define ZB_PIM_DEFAULT_MIN_TURBO_POLL_INTERVAL ZB_MILLISECONDS_TO_BEACON_INTERVAL(60) + +/*! + Maximal possible turbo poll interval + */ +#define ZB_PIM_DEFAULT_MAX_TURBO_POLL_INTERVAL ZB_MILLISECONDS_TO_BEACON_INTERVAL(3000) + +/*! + Timeout for turbo poll + */ +#define ZB_PIM_TURBO_POLL_PACKETS_TIMEOUT (ZB_TIME_ONE_SECOND * 15) + +/*! + Timeout for turbo poll + */ +#define ZB_PIM_TURBO_POLL_LEAVE_TIMEOUT (ZB_TIME_ONE_SECOND / 3) +/**@cond internals_doc*/ +/*! + Timeout for poll buffer allocation retry + */ +#define ZB_PIM_POLL_ALLOC_TIMEOUT ZB_MILLISECONDS_TO_BEACON_INTERVAL(500) +/** @endcond *//* internals_doc */ +/*! + Integer value representing the + time duration (in milliseconds) +*/ +#define ZB_ZDO_NWK_TIME_BTWN_SCANS 30 +/**@cond internals_doc*/ +/*! + Timeout value in seconds + employed in End Device + Binding */ +#define ZB_ZDO_ENDDEV_BIND_TIMEOUT 60 + + +#ifndef ZDO_TRAN_TABLE_SIZE +/*! + Transactions table size +*/ +#define ZDO_TRAN_TABLE_SIZE 16 +#endif + +/*! Number of packets with "no ack" status before removing unreachable device from nbt. */ +#define ZB_ZDO_NEIGHBOR_FAILURE_PKT_THRESHOLD 5 +/* 60 seconds */ +/*! Timeout before removing unreachable device from nbt. */ +#define ZB_ZDO_NEIGHBOR_UNREACHABLE_TIMEOUT 60 + +/*! Checking channel timeout*/ +#define ZB_ZDO_CHECK_CHANNEL_TIMEOUT (24 * 60 * 60 * ZB_TIME_ONE_SECOND) +/** @endcond *//* internals_doc */ +/* Berore r22 this value could be only 1, because scan attempts routine work + * wrong. Rewritten/fixed in r22. */ +/*! +* Integer value representing the number of scan attempts to make before the NWK layer decides +* which ZigBee coordinator or router to associate with. +* +* See Zigbee Specification revision 22 section 2.5.51 Configuration Attribute Definitions +* +* Table 2-154 of Zigbee Specification reviaion 22 : Config_NWK_Scan_Attempts default value is 5. +*/ +#define ZB_ZDO_NWK_SCAN_ATTEMPTS 5 +/** @cond internals_doc */ +/*! Delay for sending the end device request command. */ +#define ZB_ZDO_SEND_ED_TIMEOUT_REQ_DELAY ZB_MILLISECONDS_TO_BEACON_INTERVAL(100) +/** @endcond *//*internals_doc*/ +/**********************************************************************/ +/************************** MAC SECTION********************************/ +/**********************************************************************/ +/*! @cond internals_doc */ +/* +IEEE 802.15.4g p.7 + +Table 0 - MR-FSK symbol duration used for MAC and PHY timing parameters +Frequency band (MHz) MR-FSK symbol duration used for MAC + and PHY timing parameters (us) +-------------------------------------------------------------------------- +169.400-169.475 (Europe) 208+1/3 +450-470 (US FCC Part 22/90) 104+1/6 +470-510 (China) 20 +779-787 (China) 20 +863-870 (Europe) 20 +896-901 (US FCC Part 90) 100 +901-902 (US FCC Part 24) 100 +902-928 (US ISM) 20 +917-923.5 (Korea) 20 +928-960 (US FCC Part 22/24/90/101) 100 +920-928 (Japan) 20 +950-958 (Japan) 20 +1427-1518 (US FCC Part 90)/(Canada 100 + SRSP 301.4) +2400-2483.5 (Worldwide) 20 +*/ + +#if defined(ZB_SUB_GHZ_EU1) || defined(ZB_SUB_GHZ_EU2) || defined(ZB_SUB_GHZ_EU3) +#define ZB_SYMBOL_DURATION_USEC 20 +#elif defined(ZB_SUB_GHZ_US) +#define ZB_SYMBOL_DURATION_USEC 20 +#elif defined ZB_SUB_GHZ_JP +#define ZB_SYMBOL_DURATION_USEC 20 +#elif defined ZB_SUB_GHZ_CN +#else + +/*! + * @brief Symbol duration + * @see 6.5.3.2 Symbol rate + * The 2450 MHz PHY symbol rate shall be 62. + * 5 ksymbol/s 40 ppm. + */ +#define ZB_SYMBOL_DURATION_USEC 16 /* 1 symbol = 16e-6 sec (mac spec 6.5.3.2 Symbol rate) */ +#endif + +/*! + * @brief Symbol duration for O-QPSK (2.4 GHz) + * @see 12.3 section of 802.15.4-2015 + */ +#define ZB_O_QPSK_2_4_GHZ_SYMBOL_DURATION_USEC 16 +#define ZB_O_QPSK_2_4_GHZ_PHY_SYMBOLS_PER_OCTET 2 + +#define ZB_2_4_GHZ_OCTET_DURATION_USEC (ZB_O_QPSK_2_4_GHZ_SYMBOL_DURATION_USEC * ZB_O_QPSK_2_4_GHZ_PHY_SYMBOLS_PER_OCTET) + +/*! + * @brief Symbol duration for European FSK Sub-GHz + * @see D.11.2 MAC Support for Listen Before Talk (LBT) + */ +#define ZB_EU_FSK_SYMBOL_DURATION_USEC 10 + +#define ZB_EU_FSK_PHY_SYMBOLS_PER_OCTET 8 + +/*! + * @brief Synchronization header for European FSK Sub-GHz + * @see D.10.1.1.1 SHR for European Sub-GHz FSK + * synchronization header: 8 bytes preamble + 2 bytes SFD + */ +#define ZB_MAC_EU_FSK_SHR_LEN_BYTES 10 +#define ZB_MAC_EU_FSK_SHR_LEN_SYMBOLS \ + (ZB_MAC_EU_FSK_SHR_LEN_BYTES * ZB_EU_FSK_PHY_SYMBOLS_PER_OCTET) + +/*! + * @brief PHY header for European FSK Sub-GHz + * @see D.10.1.1.2 PHR for European Sub-GHz FSK + * PHY header: 2 bytes + */ +#define ZB_MAC_EU_FSK_PHR_LEN_BYTES 2 +#define ZB_MAC_EU_FSK_PHR_LEN_SYMBOLS \ + (ZB_MAC_EU_FSK_PHR_LEN_BYTES * ZB_EU_FSK_PHY_SYMBOLS_PER_OCTET) + +/*! + \par Time measurement unit is beacon interval. + It is both internal representation and value used in API. + It is still possible to convert it to/from msec. + aBaseSuperframeDuration = aBaseSlotDuration * aNumSuperframeSlots + aBaseSlotDuration = 60 + aNumSuperframeSlots = 16 +*/ +#define ZB_ABASE_SUPERFRAME_DURATION 960 + + +/*! +RX-to-TX or TX-to-RX maximum turnaround time +(in symbol periods) (see 6.9.1 and 6.9.2) + */ +#define ZB_MAC_A_TURNAROUND_TIME_SYM 12 + + +/* @note: All packet tx timings are for 2.4 GHz radio. */ + +/* + +6.3.1 Preamble field, octets +Table 19Preamble field length + +24002483.5 MHz O-QPSK 4 octets 8 symbols + */ +/*! Preamble field length */ +#define ZB_MAC_PREAMBLE_LEN 4 + + +/* + PHY hdr len, octets + + +6.3 PPDU format +This subclause specifies the + */ +/*! PHY header length */ +#define ZB_MAC_PHR_LEN 1 + + +/* + +The SFD is a field indicating the end of the SHR and the start of the packet data. + + +6.3.2 SFD field + */ +/*! Start of length delimiter field lenght */ +#define ZB_MAC_SFD_LEN 1 + + + +/** + MAC frame preamble length, octets. + +Each PPDU consists of the following basic components: + + A synchronization header (SHR), which allows a receiving device to synchronize and lock onto the +bit stream + + A PHY header (PHR), which contains frame length information + + A variable length payload, which carries the MAC sublayer frame + +See IEEE Standard for Low-Rate Wireless Networks, section 5.7.3 Frame structure. + */ +/* MAC frame preamble length, octets. */ +#define ZB_MAC_FRAME_PPDU_HDR_LEN (ZB_MAC_PREAMBLE_LEN + ZB_MAC_SFD_LEN + ZB_MAC_PHR_LEN) + + + /* See D.10.1.1 PPDU Format for European Sub-GHz FSK */ + /*! MAC SUB GHZ peamble length */ +#define ZB_MAC_SUBG_PEAMBLE_LEN 8 +/*! MAC SUB GHZ start of frame delimiter length*/ +#define ZB_MAC_SUBG_SFD_LEN 2 +/*! MAC SUB GHZ PHY header length */ +#define ZB_MAC_SUBG_PHR_LEN 2 +/*! MAC SUB GHZ PHY protocol data unit frame header length */ +#define ZB_MAC_SUBG_FRAME_PPDU_HDR_LEN (ZB_MAC_SUBG_PEAMBLE_LEN + ZB_MAC_SUBG_SFD_LEN + ZB_MAC_SUBG_PHR_LEN) +/*! MAC SUB GHZ PHY protocol data unit frame footer length */ +#define ZB_MAC_SUBG_FRAME_PPDU_FOOTER_LEN 2 +/*! MAC SUB GHZ symbol duration in microseconds */ +#define ZB_MAC_SUBG_SYMBOL_DURATION_USEC 10 +/*! MAC SUB GHZ transition octet to symbol */ +#define ZB_MAC_SUBG_OCTET_TO_SYMBOL(octets) ((octets) * 8) +/* aRxTxTurnAround - see Table D-23 LBT MAC Sublayer Constants - Implementation */ +/*! +* Time for radio to switch between receive and transmit +* +* See Table D-23 LBT MAC Sublayer Constants - Implementation +*/ +#define ZB_MAC_SUBG_TURNAROUND_TIME_SYM 100 + +/* + Define how many symbols used to transmit given number of octets + +6.5.2.2 Bit-to-symbol mapping +All binary data contained in the PPDU shall be encoded using the modulation and spreading functions +shown in Figure 18. This subclause describes how binary information is mapped into data symbols. +The 4 LSBs (b0, b1, b2, b3) of each octet shall map into one data symbol, and the 4 MSBs (b4, b5, b6, b7) of +each octet shall map into the next data symbol. Each octet of the PPDU is processed through the modulation +and spreading functions (see Figure 18) sequentially, beginning with the Preamble field and ending with the +last octet of the PSDU. + */ +/*! Define how many symbols used to transmit given number of octets */ +#define ZB_MAC_OCTET_TO_SYMBOL(octets) ((octets) * 2) + +/*! +The maximum number of +backoffs the CSMA-CA +algorithm will attempt before +declaring a channel access +failure. + */ +#define ZB_MAC_MAX_CSMA_BACKOFFS 4 + +/*! +The number of symbols forming the basic time period +used by the CSMA-CA algorithm. + +See 7.4.1 MAC constants +*/ +#define ZB_MAC_A_UNIT_BACKOFF_PERIOD 20 + +/*! +6.9.9 Clear channel assessment (CCA) +The CCA detection time shall be equal to 8 symbol periods. + */ +/*! Clear channel assessment period */ +#define ZB_MAC_CCA_PERIOD 8 + +/*! Number of times performed in slotted CSMA-CA by CCA */ +#define ZB_MAC_NUM_CCA 2 +/*! Total transmission attempts */ +#define ZB_TX_TOTAL_THRESHOLD 20 +/* TODO: check it */ +/*! Endpoint busy state value */ +#define ZB_CHANNEL_BUSY_ED_VALUE 0x60 +/* TODO: check it */ +/*! Endpoint free state value */ +#define ZB_CHANNEL_FREE_ED_VALUE 0x60 +/* use it as divider, 25% */ +/*! Percentage of failures. Use it as divider to get 25 % */ +#define ZB_FAILS_PERCENTAGE 4 +/*! MAC queue size */ +#define ZB_MAC_QUEUE_SIZE 5 + +/* +The maximum time, in +multiples of +aBaseSuperframeDuration, a +device shall wait for a +response command frame to +be available following a +request command frame. +*/ +/*! + Maximum time to wait for a response command frame, range 2-64 + Default is 32, 64 set for better compatibility +*/ +#define ZB_MAC_RESPONSE_WAIT_TIME 32 + +/*! Make all MAC PIB attributes configurable */ +#define ZB_CONFIGURABLE_MAC_PIB + +/* Zigbee IEEE 802.15.4 Test Spec (ZibBee Doc. 14-0332-01), TP/154/MAC/DATA-04 test: + macMaxFrameTotalWaitTime for 2.4 GHz 802.15.4-2003 Zigbee/PRO/RF4CE device is + 1220 symbols (or 20 msec) - minimal WaitTime to pass the test. + + Previous value was 500 msec, looks like it is too big. Big WaitTime values bring additional + battery drain for ED devices. + + The value should be at least 1 beacon interval higher than in specs: + ZBOSS timer resolution is 1 beacon interval, so there is a chance that 2 BI may correspond to + 16 ms of real time -- too low (especially for nsng). + */ +/*! +* Maximum time to wait for indirect data. +* +* See IEEE Standard for Low-Rate Wireless Networks 2006, section 7.4.2 MAC PIB attributes. +* +* @note Make sure the time value is not too big. +*/ +#define ZB_MAX_FRAME_TOTAL_WAIT_TIME_2_4_GHZ (ZB_MILLISECONDS_TO_BEACON_INTERVAL(40) + 1) +/*! +* Maximum time to wait for indirect data for SUB GHZ. +* +* IEEE Standard for Low-Rate Wireless Networks 2006, section 7.4.2 MAC PIB attributes. +* +* @note Make sure the time value is not too big. +*/ +#define ZB_MAX_FRAME_TOTAL_WAIT_TIME_SUB_GHZ (ZB_MILLISECONDS_TO_BEACON_INTERVAL(48) + 1) + + +/*! +* The maximum number of retries allowed after a transmission failure 0-7 +*/ +#define ZB_MAC_MAX_FRAME_RETRIES 3 + + +/* (currently - all platforms)*/ +/*! +* Sets MAC address at start +*/ +#define ZB_SET_MAC_ADDRESS + +#ifndef ZB_SEND_BEACON_IMMEDIATELY +/*! +* Replay to the beacon request after a jitter (meaningful for DSR MAC only). + */ +#define ZB_SEND_BEACON_AFTER_RANDOM_DELAY +#endif /* ZB_SEND_BEACON_IMMEDIATELY */ + +/*! +* External MAC + */ +#define ZB_MAC_EXT_DATA_REQ + +/* Was 3, seems like it is too small when there are >7-10 beacons. + Also it seems like we need some bottom line for this - it should not be 1 etc. */ +/*! MAC beacon request timeout length (high bound of the random value) */ +#ifndef ZB_MAC_HANDLE_BEACON_REQ_HI_TMO +/*! Default MAC beacon request timeout length */ +#define ZB_MAC_HANDLE_BEACON_REQ_HI_TMO_DEFAULT 8 +/*! Extended MAC beacon request timeout length */ +#define ZB_MAC_HANDLE_BEACON_REQ_HI_TMO_EXTENDED 20 + +#ifdef ZB_CERTIFICATION_HACKS +/* Choose exact value depending on cert hack flags */ +/*! Default MAC beacon request timeout length depending on certification hack flags */ +#define ZB_MAC_HANDLE_BEACON_REQ_HI_TMO (ZB_CERT_HACKS().extended_beacon_send_jitter ? ZB_MAC_HANDLE_BEACON_REQ_HI_TMO_EXTENDED : ZB_MAC_HANDLE_BEACON_REQ_HI_TMO_DEFAULT) +#else +/* Otherwise use the default value*/ +/*! Default MAC beacon request timeout length */ +#define ZB_MAC_HANDLE_BEACON_REQ_HI_TMO ZB_MAC_HANDLE_BEACON_REQ_HI_TMO_DEFAULT +#endif + +#endif /* ZB_MAC_HANDLE_BEACON_REQ_HI_TMO */ + +/*! MAC beacon request timeout length (low bound of the random value) */ +#ifndef ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO +/*! Default MAC beacon request timeout length */ +#define ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO_DEFAULT 1 +/*! Extended MAC beacon request timeout length */ +#define ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO_EXTENDED 12 + +#ifdef ZB_STACK_REGRESSION_TESTING_API +/** Choose exact value depending on regression tests flags */ +#define ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO (ZB_REGRESSION_TESTS_API().extended_beacon_send_delay ? ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO_EXTENDED : ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO_DEFAULT) +#else +/** Otherwise use the default value */ +#define ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO_DEFAULT +#endif + +#endif /* ZB_MAC_HANDLE_BEACON_REQ_LOW_TMO */ +/*! @endcond */ /* internals_doc */ +/** @cond DOXYGEN_MULTIMAC_SECTION */ +/*! +* European Sub-GHz FSK reverence sensitivity level, in dBm +* D.10.2.2.1.2. Sensitivity Requirement, +* Reference document 05-3474-22 Zigbee Specification R22 +* + */ +#define ZB_EU_FSK_REFERENCE_SENSITIVITY -99 + + +/* IMPORTANT!!! + * As mentioned in section D.11.2 MAC Support for Listen Before Talk + * of Zigbee Specification R22, document 05-3474-22, page 543 + * + * Quote: "The UK have adopted the same values for ALL channel pages as defined + * for pages 28 & 29. Other regions may use different values for pages 30 & 31 + * which as yet have not been defined or verified." + * + */ +/* aLBTTxMinOff */ +/* 100 ms */ +/*! The minimum permitted off time between a device's own transmissions. */ +#define ZB_MAC_LBT_TX_MIN_OFF_SYMBOLS 10000 +/*! The minimum permitted off time between a device's own transmissions in microseconds. */ +#define ZB_MAC_LBT_TX_MIN_OFF_USEC (ZB_MAC_LBT_TX_MIN_OFF_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! The minimum permitted off time between a device's own transmissions in ms.*/ +#define ZB_MAC_LBT_TX_MIN_OFF_MS (ZB_MAC_LBT_TX_MIN_OFF_USEC / 1000) + +/* aLBTTxMaxPKT */ +/* 1 second */ +/*! The maximum permitted off time between a device's own transmissions. */ +#define ZB_MAC_LBT_TX_MAX_PKT_SYMBOLS 100000 +/*! The maximum permitted off time between a device's own transmissions in microseconds. */ +#define ZB_MAC_LBT_TX_MAX_PKT_USEC (ZB_MAC_LBT_TX_MAX_PKT_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! The maximum permitted off time between a device's own transmissions in ms.*/ +#define ZB_MAC_LBT_TX_MAX_PKT_MS (ZB_MAC_LBT_TX_MAX_PKT_USEC / 1000) + +/* aLBTMinFree */ +/* 5 ms */ +/*! The minimum duration a channel should be free */ +#define ZB_MAC_LBT_MIN_FREE_SYMBOLS 500 +/*! The minimum duration a channel should be free in microseconds*/ +#define ZB_MAC_LBT_MIN_FREE_USEC (ZB_MAC_LBT_MIN_FREE_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! The minimum duration a channel should be free in ms*/ +#define ZB_MAC_LBT_MIN_FREE_MS (ZB_MAC_LBT_MIN_FREE_USEC / 1000) + +/* aLBTMaxRandom */ +/* 5 ms */ +/*! The maximum period of the backoff */ +#define ZB_MAC_LBT_MAX_RANDOM_SYMBOLS 500 +/*! The maximum period of the backoff in microseconds */ +#define ZB_MAC_LBT_MAX_RANDOM_USEC (ZB_MAC_LBT_MAX_RANDOM_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! The maximum period of the backoff in ms */ +#define ZB_MAC_LBT_MAX_RANDOM_MS (ZB_MAC_LBT_MAX_RANDOM_USEC / 1000) + +/* aLBTMinRandom */ +/* 0 ms */ +/*! The minimum period of the backoff */ +#define ZB_MAC_LBT_MIN_RANDOM_SYMBOLS 0 +/*! The minimum period of the backoff in microseconds */ +#define ZB_MAC_LBT_MIN_RANDOM_USEC 0 +/*! The minimum period of the backoff in ms */ +#define ZB_MAC_LBT_MIN_RANDOM_MS 0 + +/* aLBTGranularity */ +/* 500 us */ +/*! The granularity in the random backoff */ +#define ZB_MAC_LBT_GRANULARITY_SYMBOLS 50 +/*! The granularity in the random backoff in microseconds */ +#define ZB_MAC_LBT_GRANULARITY_USEC (ZB_MAC_LBT_GRANULARITY_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) + +/* aLBTThresholdLevelLp */ +/*! +* The level (in dBm) at which the receiver determines whether there +* is activity in a low power channel (+14 dBm Tx). +*/ +#define ZB_MAC_LBT_THRESHOLD_LEVEL_LP (-87) + +/* aLBTThresholdLevelHp */ +/*! +* The level (in dBm) at which the receiver determines whether +* there is activity in a high power channel (+27 dBm Tx). +*/ +#define ZB_MAC_LBT_THRESHOLD_LEVEL_HP (-91) + +/* aLBTMaxTxRetries */ +/*! The maximum number of retries allowed while looking for a clear channel. + * + * See Zigbee Specification revision 22 Table D-23 LBT MAC Sublayer Constants - Implementation. +*/ +#define ZB_MAC_LBT_MAX_TX_RETRIES 3 + +/* aLBTAckWindowStart */ +/* 450 us */ +/*! +* The minimum pause before acknowledging a received packet. +* This is to allow a transmitting device to change from +* transmit to receive mode. Starting an ACK before this time +* may result in the transmitter missing the ACK. +*/ +#define ZB_MAC_LBT_ACK_WINDOW_START_SYMBOLS 45 +/*! +* The minimum pause before acknowledging a received packet in microseconds. +* This is to allow a transmitting device to change from +* transmit to receive mode. Starting an ACK before this time +* may result in the transmitter missing the ACK. +*/ +#define ZB_MAC_LBT_ACK_WINDOW_START_USEC \ + (ZB_MAC_LBT_ACK_WINDOW_START_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) + +/* aLBTAckWindow */ +/* 1ms */ +/*! +* The maximum wait time before acknowledging a received +* packet (includes @ref ZB_MAC_LBT_ACK_WINDOW_START_SYMBOLS). +* This time MUST be shorter than @ref ZB_MAC_LBT_MIN_FREE_SYMBOLS otherwise other +* devices could interpret the quiet as an opportunity to transmit. +*/ +#define ZB_MAC_LBT_ACK_WINDOW_SYMBOLS 100 +/*! +* The maximum wait time in microseconds before acknowledging a received +* packet (includes @ref ZB_MAC_LBT_ACK_WINDOW_START_SYMBOLS). +* This time MUST be shorter than @ref ZB_MAC_LBT_MIN_FREE_SYMBOLS otherwise other +* devices could interpret the quiet as an opportunity to transmit. +*/ +#define ZB_MAC_LBT_ACK_WINDOW_USEC (ZB_MAC_LBT_ACK_WINDOW_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! +* The maximum wait time in ms before acknowledging a received +* packet (includes @ref ZB_MAC_LBT_ACK_WINDOW_START_SYMBOLS). +* This time MUST be shorter than @ref ZB_MAC_LBT_MIN_FREE_SYMBOLS otherwise other +* devices could interpret the quiet as an opportunity to transmit. +*/ +#define ZB_MAC_LBT_ACK_WINDOW_MS (ZB_MAC_LBT_ACK_WINDOW_USEC / 1000) +/*aTxRxTurnAround */ +/*! +* Time for radio to switch between transmit and receive +*/ +#define ZB_MAC_LBT_TX_RX_SWITCH_TIME_SYMBOLS 45 +/* aLBTTimeout */ +/* 6 ms */ +/*! +* Time before aborting LBT if it cannot find a free slot. +* This value should be set to at least +* [@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_TX_RETRIES * (@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_RANDOM_SYMBOLS) + @ref ZB_MAC_LBT_TX_RX_SWITCH_TIME_SYMBOLS )] +* to ensure that all re-tries can occur. +*/ +#define ZB_MAC_LBT_TIMEOUT_SYMBOLS 6000 +/*! +* Time before aborting LBT if it cannot find a free slot in microseconds. +* This value should be set to at least +* [@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_TX_RETRIES * (@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_RANDOM_SYMBOLS) + @ref ZB_MAC_LBT_TX_RX_SWITCH_TIME_SYMBOLS )] +* to ensure that all re-tries can occur. +*/ +#define ZB_MAC_LBT_TIMEOUT_USEC (ZB_MAC_LBT_TIMEOUT_SYMBOLS * ZB_EU_FSK_SYMBOL_DURATION_USEC) +/*! +* Time before aborting LBT if it cannot find a free slot in ms. +* This value should be set to at least +* [@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_TX_RETRIES * (@ref ZB_MAC_LBT_MIN_FREE_SYMBOLS + @ref ZB_MAC_LBT_MAX_RANDOM_SYMBOLS) + @ref ZB_MAC_LBT_TX_RX_SWITCH_TIME_SYMBOLS )] +* to ensure that all re-tries can occur. +*/ +#define ZB_MAC_LBT_TIMEOUT_MS (ZB_MAC_LBT_TIMEOUT_USEC / 1000) +/*! LBT acknowledgement length for SUB GHZ */ +#define ZB_MAC_LBT_SUB_GHZ_ACK_LEN_SYMBOLS (ZB_MAC_ACK_LEN_BYTES * ZB_EU_FSK_PHY_SYMBOLS_PER_OCTET) + +/* Tuned to fit to 2 beacon intervals */ +/*! LBT transmition wait period in ms */ +#define ZB_MAC_LBT_TX_WAIT_QUANT_MS 33 + +/* aDUTYCYCLEMeasurementPeriod */ +/*! The period over which the duty cycle is calculated. */ +#define ZB_MAC_DUTY_CYCLE_MEASUREMENT_PERIOD_SYMBOLS 360000000 +/*! The period over which the duty cycle is calculated in seconds */ +#define ZB_MAC_DUTY_CYCLE_MEASUREMENT_PERIOD_SEC \ + (ZB_MAC_DUTY_CYCLE_MEASUREMENT_PERIOD_SYMBOLS / 1000000 * ZB_EU_FSK_SYMBOL_DURATION_USEC) + +/* aDUTYCYCLERampUp */ +#ifndef ZB_MAC_DUTY_CYCLE_RAMP_UP_SYMBOLS +/*! Time transmitter is transmitting carrier prior to start of data */ +#define ZB_MAC_DUTY_CYCLE_RAMP_UP_SYMBOLS 0 +#endif /* ZB_MAC_DUTY_CYCLE_RAMP_UP_SYMBOLS */ + +/* aDUTYCYCLERampDown */ +#ifndef ZB_MAC_DUTY_CYCLE_RAMP_DOWN_SYMBOLS +/*! Time transmitter is transmitting carrier after end of data */ +#define ZB_MAC_DUTY_CYCLE_RAMP_DOWN_SYMBOLS 0 +#endif /* ZB_MAC_DUTY_CYCLE_RAMP_DOWN_SYMBOLS */ + +/*! MAC duty cycle of limited threshold length */ +#define ZB_MAC_DUTY_CYCLE_LIMITED_THRESHOLD_SYMBOLS 5400000 +/*! MAC duty cycle of critical threshold length */ +#define ZB_MAC_DUTY_CYCLE_CRITICAL_THRESHOLD_SYMBOLS 7500000 + +/*! Length of regulated MAC duty cycle pages 29 and 29 */ +#define ZB_MAC_DUTY_CYCLE_REGULATED_SYMBOLS_PAGES_28_29 10000000 +/*! Length of regulated MAC duty cycle pages 30 and 31 */ +#define ZB_MAC_DUTY_CYCLE_REGULATED_SYMBOLS_PAGES_30_31 9000000 + +/* aDUTYCYCLEBuckets */ +/*! Number of buckets used for duty cycle monitoring */ +#define ZB_MAC_DUTY_CYCLE_BUCKETS 13 + +/*! +* Duty cycle monitoring period + */ +#define ZB_MAC_DUTY_CYCLE_TIME_PERIOD_SEC \ + (ZB_MAC_DUTY_CYCLE_MEASUREMENT_PERIOD_SEC / (ZB_MAC_DUTY_CYCLE_BUCKETS - 1)) + +/*! +* MAC power control information table size +* +* See reference document 05-3474-22 section D.9.2 Zigbee Specification R22 + */ +#define ZB_MAC_POWER_CONTROL_INFO_TABLE_SIZE 10 +/*! MAC power control expiration time out */ +#define ZB_MAC_POWER_CONTROL_EXPIRATION_TIMEOUT (10 * ZB_TIME_ONE_SECOND) +/*! +* Optimal signal level for Eu FSK should be +20dB above the reference sensitivity @ref ZB_EU_FSK_REFERENCE_SENSITIVITY +* +* See reference document 05-3474-22 section D.9.2.4.2. Zigbee Specification R22 + */ +#define ZB_MAC_POWER_CONTOL_OPT_SIGNAL_LEVEL (ZB_EU_FSK_REFERENCE_SENSITIVITY + 20) + + +#ifndef ZB_MAC_DEFAULT_TX_POWER_SUB_GHZ +/*! Default MAC transmition power for SUB GHZ */ +#define ZB_MAC_DEFAULT_TX_POWER_SUB_GHZ +14 +#endif +/** @endcond */ /* DOXYGEN_MULTIMAC_SECTION */ +/** @cond internals_doc */ +#ifndef ZB_MAC_DEFAULT_TX_POWER_24_GHZ +/*! Default MAC transmition power for 2.4 GHZ */ +#define ZB_MAC_DEFAULT_TX_POWER_24_GHZ +20 +#endif +/*! MAC diagnostic filter size */ +#define ZB_MAC_DIAGNOSTICS_FILTER_SIZE 4 +/*! MAC diagnostic time period in minutes */ +#define ZB_MAC_DIAGNOSTICS_TIME_PERIOD_MIN 10 +/*! MAC diagnostic time period in seconds */ +#define ZB_MAC_DIAGNOSTICS_TIME_PERIOD_SEC \ + (ZB_MAC_DIAGNOSTICS_TIME_PERIOD_MIN * 60 * ZB_TIME_ONE_SECOND) + +#ifndef ZB_MAC_ASSOCIATION_DATA_REQUEST_COUNT +/*! Count of MAC data association */ +#define ZB_MAC_ASSOCIATION_DATA_REQUEST_COUNT 1 +#endif +/* Base Device */ + +/** +* See about bdbTrustCenterNodeJoinTimeout in Base Device Specification subclause 5.3.16. +* +* The bdbTrustCenterNodeJoinTimeout attribute specifies a timeout in seconds +* for the Trust Center to remove the Trust Center link key of the newly joined +* node that did not successfully establish a new link key. This attribute +* is used by Zigbee coordinator nodes. + */ +/*! Timeout in seconds for the Trust Center to remove the Trust Center link key of the newly joined + node that did not successfully establish a new link key. This attribute + is used by Zigbee coordinator nodes.*/ +#define ZB_DEFAULT_BDB_TRUST_CENTER_NODE_JOIN_TIMEOUT ZB_MILLISECONDS_TO_BEACON_INTERVAL(0xf * 1000) +/*! Timeout in seconds for the Trust Center to exchange link keys with the newly joined node */ +#define ZB_BDBC_TCLINK_KEY_EXCHANGE_TIMEOUT ZB_MILLISECONDS_TO_BEACON_INTERVAL(5000) +/*! Minimum commisioning period */ +#define ZB_BDBC_MIN_COMMISSIONING_TIME_S 180 +/*! Number of Trust Center link attempts to exchange link keys with the newly joined node. */ +#define ZB_DEFAULT_BDB_TCLINK_KEY_EXCHANGE_ATTEMPTS_MAX 3 +/** @endcond *//*internals_doc*/ +/*! Specification version of the specification */ +#define ZB_STACK_SPEC_VERSION 22 + + +/*! @cond touchlink */ +/* Table 2 Constants used by nodes supporting touchlink */ +#define ZB_BDBC_TL_INTER_PANTRANS_ID_LIFETIME ZB_MILLISECONDS_TO_BEACON_INTERVAL(8000) +#define ZB_BDBC_TL_MIN_STARTUP_DELAY_TIME ZB_MILLISECONDS_TO_BEACON_INTERVAL(2000) +/* used for a non-extended touchlink scan */ +#define ZB_BDBC_TL_PRIMARY_CHANNEL_SET 0x02108800 +#define ZB_BDBC_TL_RX_WINDOW_DURATION ZB_MILLISECONDS_TO_BEACON_INTERVAL(5000) +#define ZB_BDBC_TL_SCAN_TIME_BASE_DURATION ZB_MILLISECONDS_TO_BEACON_INTERVAL(250) +/* used for an extended touchlink scan after the bdbcTLPrimaryChannelSet + * channels have been scanned. */ +#define ZB_BDBC_TL_SECONDARY_CHANNEL_SET (0x07fff800 ^ ZB_BDBC_TL_PRIMARY_CHANNEL_SET) +/*! @endcond */ /* touchlink */ + + +/* Green Power */ + +/** @cond DOXYGEN_ZGP_SECTION */ +/*! + * zgpDuplicateTimeout value + * + * The time the EPP of the ZGPS and ZGPP keeps the information on the received + * GPDF with random sequence number, in order to filter out duplicates. + * + * The default value of 2 seconds can be modified by the application profile + * + * @see ZGP spec, A.3.6.1.2.1 */ +#define ZB_ZGP_DUPLICATE_TIMEOUT (1 * ZB_TIME_ONE_SECOND) + +/* + The OperationalChannel sub-field can take the following values: 0b0000: channel 11, 0b0001: channel + 12, , 0b1111: channel 26. +*/ +/*! First Zigbee green power device channel value */ +#define ZB_ZGPD_FIRST_CH 11 +/*! Last Zigbee green power device channel value */ +#define ZB_ZGPD_LAST_CH 26 + +/* ZGP spec, A.3.9.1: + * If no Channel Request is received on channel TransmitChannel for 5sec, + * the TempMaster removes the Channel Configuration GPDF from its + * gpTxQueue and returns to the operational channel in commissioning mode + */ +/*! Timeout of Zigbee Green Power Device channel transition request */ +#define ZB_ZGP_CHANNEL_REQ_ON_TX_CH_TIMEOUT (5 * ZB_TIME_ONE_SECOND) + +/*! + * If commissioning on the last stage, then it determines time to wait + * until commissioning is complete. If commissioning is not completed + * during this time, then commissioning cancel procedure is started. + */ +/*! +* Timeout before completing commissioning if +* the last stage is successful or, +* otherwise, start the cancel procedure. +*/ +#define ZB_ZGP_TIMEOUT_BEFORE_FORCE_CANCEL (3 * ZB_TIME_ONE_SECOND) + +/*! Unspecified Zigbee Green Power device manufacturer Id */ +#define ZB_ZGPD_MANUF_ID_UNSPEC 0xFFFF +/*! Default Zigbee Green Power device manufacturer Id */ +#define ZB_ZGPD_DEF_MANUFACTURER_ID 0x10d0 +/*! Maximum number of lightweight unicast address per Green Power device. */ +#define ZB_ZGP_MAX_LW_UNICAST_ADDR_PER_GPD 2 +/*! Maximum number of SINK groups per Green Power device */ +#define ZB_ZGP_MAX_SINK_GROUP_PER_GPD 2 +/*! Maximum number of paired endpoints*/ +#define ZB_ZGP_MAX_PAIRED_ENDPOINTS 2 +/*! Maximum number of paired Green Power devices commands */ +#define ZB_ZGP_MAX_PAIRED_CONF_GPD_COMMANDS 2 +/*! Maximum number of paired configuration clusters */ +#define ZB_ZGP_MAX_PAIRED_CONF_CLUSTERS 2 +/** @endcond */ /* DOXYGEN_ZGP_SECTION */ +/*! @} */ + +/* ****************** Smart Energy parameters ******************* */ +/* 5.3.8 APS Fragmentation Parameters + For the Smart Energy Profile the default value shall be set to 128 bytes. */ +#define ZB_ASDU_MAX_FRAG_LEN (ZB_IO_BUF_SIZE - sizeof(zb_apsde_data_indication_t) - ZB_APS_HEADER_MAX_LEN - 3) +#define ZB_APS_MAX_WINDOW_SIZE 1 +#define ZB_APS_INTERFRAME_DELAY 50 /* milliseconds */ + + +#define ZB_SE_STEADY_STATE_CLUSTER_MATCH_DESC_TIME (ZB_TIME_ONE_SECOND * 20) +#define ZB_SE_STEADY_STATE_MAX_FAILURE_CNT 3 + +#define ZB_SE_PARTNER_LK_SETUP_TIMEOUT (ZB_TIME_ONE_SECOND * 30) + +#define ZB_SE_HI_FREQ_MSG_TIMEOUT (ZB_TIME_ONE_SECOND * 30) +#define ZB_SE_HI_FREQ_MSG_N_SLOTS 4 + +/*! @cond internals_doc */ +/* No need to set manufacturer code in node descriptor directly. + * zb_set_node_descriptor should select the right one depending on defined platform and/or radio + * For other codes see docs-05-3874-26-0csg-database-of-manufacturer-codes-for-use-in-the-node-descriptor.pdf */ +#define ZB_MANUFACTURER_CODE_DSR 0x1234 +/* That is not a joke, our manufacturer code is really 1234! */ +/*! @endcond */ /* internals_doc */ + +#define ZB_DEFAULT_MANUFACTURER_CODE ZB_MANUFACTURER_CODE_DSR + +#ifndef ZB_MULTITEST_HW_INIT_WAIT_ITERATIONS +#define ZB_MULTITEST_HW_INIT_WAIT_ITERATIONS 0 +#endif + +#ifndef ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT +#define ZB_MULTITEST_CONSOLE_SLEEP_TIMEOUT 4000000 +#endif + + +#endif /* ZB_CONFIG_COMMON_H */ diff --git a/zboss/include/zb_debug.h b/zboss/include/zb_debug.h new file mode 100644 index 0000000000..859c570efd --- /dev/null +++ b/zboss/include/zb_debug.h @@ -0,0 +1,261 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Tests and debug macros +*/ +#ifndef ZB_DEBUG_H +#define ZB_DEBUG_H 1 + +/*! \addtogroup ZB_ASSERT_DYNAMIC */ +/*! @{ */ + +/** + Trace current location, abort current program execution, with core dump if possible. + + @param caller_file - source file name + @param caller_line - line in the source + */ +void zb_abort(char *caller_file, int caller_line); + +#if defined DEBUG || defined USE_ASSERT + + +#ifndef ZB_BINARY_TRACE +/** @cond internals_doc */ +/** + Assert: print diagnostic and force core dump + + @param file_name - source file name + @param line_number - line in the source +*/ +void zb_assert(zb_char_t *file_name, zb_int_t line_number); +/** @endcond */ +/** + Check for expression in runtime and call zb_assert() if it is false. + + Compiled to nothing if USE_ASSERT is not defined. + + @param expr expression to check +*/ +#define ZB_ASSERT(expr) {if(!(expr)) zb_assert(__FILE__, __LINE__);} +/** @cond internals_doc */ +#define ZB_INLINE_ASSERT_SIMPLE(expr) ((expr) ? 1 : (zb_assert(__FILE__, __LINE__), 1)) +/** @endcond */ + +#else /* !ZB_BINARY_TRACE */ +/** + Assert: print diagnostic and force core dump + + @param file_id - source file id + @param line_number - line in the source +*/ +void zb_assert(zb_uint16_t file_id, zb_int_t line_number); +/** + Check for expression in runtime and call zb_assert() if it is false. + + Compiled to nothing if USE_ASSERT is not defined. + + @param expr expression to check +*/ +#define ZB_ASSERT(expr) {if(!(expr)) zb_assert(ZB_TRACE_FILE_ID, __LINE__);} +/** @cond internals_doc */ +#define ZB_INLINE_ASSERT_SIMPLE(expr) ((expr) ? 1 : (zb_assert(ZB_TRACE_FILE_ID, __LINE__), 1)) +/** @endcond */ + +#endif /* !ZB_BINARY_TRACE */ + +/** @cond internals_doc */ +void lwip_zb_assert(zb_uint16_t file_id, zb_int_t line_number); +/** @endcond */ + +/** + Assert which can be used inside an expression. + + @param expr - expression to check. + @return always 1 (true) + */ +#define ZB_INLINE_ASSERT(expr) ZB_INLINE_ASSERT_SIMPLE((expr)), + +#else /* release */ + +#ifndef KEIL +#define ZB_ASSERT(expr) ((void)(expr)) +#else +#define ZB_ASSERT(expr) ((void)(expr)) +#endif + +#define ZB_INLINE_ASSERT_SIMPLE(expr) -1 +#define ZB_INLINE_ASSERT(expr) + +#endif + +/*! @} */ + +/** \addtogroup ZB_ASSERT_STATIC */ +/** @{ */ + +/** @cond internals_doc */ +/* Tricks to force preprocessor to substitute __LINE__ in macros */ +#define ZB_ASSERT_CAT_(a, b) a##_##b +#define ZB_ASSERT_CAT(a, b) ZB_ASSERT_CAT_(a, b) +/** @endcond */ + +/** + Check condition at compile time in the code (not declaration block) + + @param expr - expression to check. + */ +#if defined SDCC || defined KEIL +#define ZB_ASSERT_COMPILE_TIME(expr) +#else +#define ZB_ASSERT_COMPILE_TIME(expr) ((void)(zb_int_t (*)[(expr) ? 1 : -1])0) +#endif +/** + Check condition at compile time in the code (not declaration block), return 0 + To be used inside an expressions. + + @param expr - expression to check. + */ +#define ZB_ASSERT_COMPILE_TIME_EXPR(expr) ((zb_int_t)((zb_int_t (*)[(expr) ? 1 : -1])0)) + +/** + Check condition at compile time in the declaration block + + @param expr - expression to check. + */ +#if (defined __GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define ZB_ASSERT_COMPILE_DECL(expr) __extension__ _Static_assert(expr, "Assert at line __LINE__") +#elif defined(__COUNTER__) +#define ZB_ASSERT_COMPILE_DECL(expr) typedef zb_int_t ZB_ASSERT_CAT(assert, ZB_ASSERT_CAT(__LINE__, __COUNTER__))[(expr) ? 1 : -1] +#else +#define ZB_ASSERT_COMPILE_DECL(expr) +#endif + + +/** + Ensures, that size of type `type' is not greater than `limit'. If it is not, + compilation is aborted. + + @param type - type name + @param limit - size limit + */ +#define ZB_ASSERT_TYPE_SIZE_NOT_GREATER(type, limit) ZB_ASSERT_COMPILE_DECL(sizeof(type) <= (limit)) + +/** + Ensures, that size of type `type' is not less than `limit'. If it is not, + compilation is aborted. + + @param type - type name + @param limit - size limit + */ +#define ZB_ASSERT_TYPE_SIZE_NOT_LESS(type, limit) ZB_ASSERT_COMPILE_DECL(sizeof(type) >= (limit)) + +/** + Ensures, that size of type `type' is equal to the `limit'. If it is not, + compilation is aborted. + + @param type - type name + @param limit - size limit + */ +#define ZB_ASSERT_TYPE_SIZE_EQ(type, limit) ZB_ASSERT_COMPILE_DECL(sizeof(type) == (limit)) + +/*! @} */ + +#ifdef ZB_ARRAYS_CHECK +/** + Address all array elements. Use this macro to test that array really inited + by valgring in Linux + */ +#define ZB_CHK_ARR(arr, len) \ + do \ + { \ + zb_ushort_t _ii; \ + zb_ushort_t n = 0; \ + for (_ii = 0 ; _ii < (len) ; ++_ii) \ + { \ + if ((arr)[_ii] < 2) \ + { \ + n++; \ + } \ + else \ + { \ + n--; \ + } \ + } \ + } \ +while (0) + +#else +#define ZB_CHK_ARR(arr, len) +#endif /* ZB_ARRAYS_CHECK */ + + +#define ZB_P3_ON() +#define ZB_P3_OFF() +#define ZB_P4_ON() +#define ZB_P4_OFF() + +/** + Dump array of byte + + @param buf - array of byte + @param len - size of array + */ +void dump_traf(zb_uint8_t *buf, zb_ushort_t len); + +#ifdef DEBUG +void dump_usb_traf(zb_uint8_t *buf, zb_ushort_t len); +#else +#define dump_usb_traf(buf, len) +#endif + +#if (defined ZB_MAC_TESTING_MODE || defined ZB_DUMP_TRAF) && defined DEBUG +#define DUMP_TRAF(cmt, buf, len, total) TRACE_MSG(TRACE_SECUR3, #cmt, (FMT__0)); dump_traf(buf, len) +#else +#define DUMP_TRAF(comment, buf, len, total) +#endif + +#ifdef DEBUG +void dump_hex_data(zb_uint_t trace_mask, zb_uint8_t trace_level, zb_uint8_t *buf, zb_ushort_t len); +#else +#define dump_hex_data(trace_mask, trace_level, buf, len) +#endif /* DEBUG */ + +#endif /* ZB_DEBUG_H */ diff --git a/zboss/include/zb_errors.h b/zboss/include/zb_errors.h new file mode 100644 index 0000000000..f787af33eb --- /dev/null +++ b/zboss/include/zb_errors.h @@ -0,0 +1,149 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Error codes +*/ + +#ifndef ZB_ERRORS_H +#define ZB_ERRORS_H + +/** + * @addtogroup base_types + * @{ + */ +/** @brief Return type for ZB functions returning execution status. @see enum zb_ret_e. */ +typedef zb_int_t zb_ret_t; +/** @} */ + +/*! @cond internals_doc */ + +/* categories */ + +#define ERROR_CATEGORY_INTERVAL 256 + +enum zb_error_category_e +{ + ERROR_CATEGORY_GENERIC, + ERROR_CATEGORY_SYSTEM, + ERROR_CATEGORY_MAC, + ERROR_CATEGORY_NWK, + ERROR_CATEGORY_APS, + ERROR_CATEGORY_ZDO, + ERROR_CATEGORY_CBKE, +}; + +/* Let's always return 0 for RET_OK - in any category. */ +#define ERROR_CODE(category, code) ((zb_ret_t)((code) != 0 ? -(((category) * ERROR_CATEGORY_INTERVAL) + (code)) : 0)) +#define GENERIC_ERROR_CODE(code) ERROR_CODE(ERROR_CATEGORY_GENERIC, code) +#define SYSTEM_ERROR_CODE(code) ERROR_CODE(ERROR_CATEGORY_SYSTEM, code) + +#define ERROR_GET_CATEGORY(err) (((-(zb_int_t)(err))) / ERROR_CATEGORY_INTERVAL) +#define ERROR_GET_CODE(err) ((-(zb_int_t)(err)) % ERROR_CATEGORY_INTERVAL) + +/** @endcond */ /* internals_doc */ + +/** + * @addtogroup error_codes + * @{ + */ + +/** + * @brief Error codes for non-void stack functions. + * In general, function can return OK, BLOCKED or some error. Errors are negative. + * + * Error can be "generic" or some additional error code. + */ +enum zb_ret_e +{ + /* Most common return types: ok, generic error, BLOCKED, thread exit indication. */ + RET_OK = 0, + RET_ERROR = ERROR_CODE(ERROR_CATEGORY_GENERIC, 1), /* -1 indeed */ + RET_BLOCKED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 2), + RET_EXIT = ERROR_CODE(ERROR_CATEGORY_GENERIC, 3), + RET_BUSY = ERROR_CODE(ERROR_CATEGORY_GENERIC, 4), + RET_EOF = ERROR_CODE(ERROR_CATEGORY_GENERIC, 5), + RET_OUT_OF_RANGE = ERROR_CODE(ERROR_CATEGORY_GENERIC, 6), + RET_EMPTY = ERROR_CODE(ERROR_CATEGORY_GENERIC, 7), + RET_CANCELLED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 8), + + + RET_INVALID_PARAMETER_1 = ERROR_CODE(ERROR_CATEGORY_GENERIC, 10), + RET_INVALID_PARAMETER_2 = ERROR_CODE(ERROR_CATEGORY_GENERIC, 11), + RET_INVALID_PARAMETER_3 = ERROR_CODE(ERROR_CATEGORY_GENERIC, 12), + RET_INVALID_PARAMETER_4 = ERROR_CODE(ERROR_CATEGORY_GENERIC, 13), + RET_INVALID_PARAMETER_6 = ERROR_CODE(ERROR_CATEGORY_GENERIC, 15), + RET_PENDING = ERROR_CODE(ERROR_CATEGORY_GENERIC, 21), + RET_NO_MEMORY = ERROR_CODE(ERROR_CATEGORY_GENERIC, 22), + RET_INVALID_PARAMETER = ERROR_CODE(ERROR_CATEGORY_GENERIC, 23), + RET_OPERATION_FAILED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 24), + RET_BUFFER_TOO_SMALL = ERROR_CODE(ERROR_CATEGORY_GENERIC, 25), + RET_END_OF_LIST = ERROR_CODE(ERROR_CATEGORY_GENERIC, 26), + RET_ALREADY_EXISTS = ERROR_CODE(ERROR_CATEGORY_GENERIC, 27), + RET_NOT_FOUND = ERROR_CODE(ERROR_CATEGORY_GENERIC, 28), + RET_OVERFLOW = ERROR_CODE(ERROR_CATEGORY_GENERIC, 29), + RET_TIMEOUT = ERROR_CODE(ERROR_CATEGORY_GENERIC, 30), + RET_NOT_IMPLEMENTED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 31), + RET_NO_RESOURCES = ERROR_CODE(ERROR_CATEGORY_GENERIC, 32), + RET_UNINITIALIZED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 33), + RET_INVALID_STATE = ERROR_CODE(ERROR_CATEGORY_GENERIC, 35), + RET_CONNECTION_FAILED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 37), + RET_CONNECTION_LOST = ERROR_CODE(ERROR_CATEGORY_GENERIC, 38), + RET_UNAUTHORIZED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 40), + RET_CONFLICT = ERROR_CODE(ERROR_CATEGORY_GENERIC, 41), + RET_INVALID_FORMAT = ERROR_CODE(ERROR_CATEGORY_GENERIC, 42), + RET_NO_MATCH = ERROR_CODE(ERROR_CATEGORY_GENERIC, 43), + RET_PROTOCOL_ERROR = ERROR_CODE(ERROR_CATEGORY_GENERIC, 44), + RET_VERSION = ERROR_CODE(ERROR_CATEGORY_GENERIC, 45), + RET_FILE_NOT_FOUND = ERROR_CODE(ERROR_CATEGORY_GENERIC, 48), + RET_CONVERSION_ERROR = ERROR_CODE(ERROR_CATEGORY_GENERIC, 50), + RET_FILE_CORRUPTED = ERROR_CODE(ERROR_CATEGORY_GENERIC, 56), + RET_PAGE_NOT_FOUND = ERROR_CODE(ERROR_CATEGORY_GENERIC, 57), + RET_ILLEGAL_REQUEST = ERROR_CODE(ERROR_CATEGORY_GENERIC, 62), + RET_INVALID_GROUP = ERROR_CODE(ERROR_CATEGORY_GENERIC, 64), + RET_TABLE_FULL = ERROR_CODE(ERROR_CATEGORY_GENERIC, 65), + RET_IGNORE = ERROR_CODE(ERROR_CATEGORY_GENERIC, 69), + RET_AGAIN = ERROR_CODE(ERROR_CATEGORY_GENERIC, 70), + RET_DEVICE_NOT_FOUND = ERROR_CODE(ERROR_CATEGORY_GENERIC, 71), + RET_OBSOLETE = ERROR_CODE(ERROR_CATEGORY_GENERIC, 72), +}; + +/** @} */ /* Error codes */ + +#endif /* ZB_ERRORS_H */ diff --git a/zboss/include/zb_ha.h b/zboss/include/zb_ha.h new file mode 100644 index 0000000000..6e25ad10e7 --- /dev/null +++ b/zboss/include/zb_ha.h @@ -0,0 +1,82 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: HA global definitions +*/ + +#ifndef ZB_HA_H +#define ZB_HA_H + +#include "ha/zb_ha_config.h" +#include "ha/zb_ha_sas.h" + +#include "ha/zb_ha_door_lock.h" +#include "ha/zb_ha_door_lock_controller.h" +#include "ha/zb_ha_on_off_output.h" +#include "ha/zb_ha_on_off_switch.h" +#include "ha/zb_ha_simple_sensor.h" +#include "ha/zb_ha_combined_interface.h" +#include "ha/zb_ha_scene_selector.h" +#include "ha/zb_ha_configuration_tool.h" +#include "ha/zb_ha_mains_power_outlet.h" +#include "ha/zb_ha_range_extender.h" +#include "ha/zb_ha_level_control_switch.h" +#include "ha/zb_ha_level_controllable_output.h" +#include "ha/zb_ha_window_covering.h" +#include "ha/zb_ha_window_covering_controller.h" +#include "ha/zb_ha_shade.h" +#include "ha/zb_ha_shade_controller.h" + +#include "ha/zb_ha_temperature_sensor.h" + +#include "ha/zb_ha_ias_control_indicating_equipment.h" +#include "ha/zb_ha_ias_ancillary_control_equipment.h" +#include "ha/zb_ha_ias_zone.h" +#include "ha/zb_ha_ias_warning_device.h" + +#include "ha/zb_ha_custom_attr.h" +#include "ha/zb_ha_dimmable_light.h" +#include "ha/zb_ha_dimmer_switch.h" +#include "ha/zb_ha_smart_plug.h" +#include "ha/zb_ha_thermostat.h" + +#include "ha/zb_ha_test_device.h" + +#endif /* ZB_HA_H */ diff --git a/zboss/include/zb_led_button.h b/zboss/include/zb_led_button.h new file mode 100644 index 0000000000..82c567c024 --- /dev/null +++ b/zboss/include/zb_led_button.h @@ -0,0 +1,215 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Common definitions for leds and buttons functionality +*/ + +#ifndef ZB_LED_H +#define ZB_LED_H 1 + +#include "zb_vendor.h" +#include "zboss_api_core.h" + +/*! @addtogroup leds_buttons */ +/*! @{ */ + +/** + * @name LED + * @{ + */ + +/** + * Prepare LEDs for usage + */ +void zb_led_init(void); + +/** + * Stop blinking on given LED + * + * See ZB_LED_ARG_CREATE() for contructing led_arg + */ +void zb_led_blink_off(zb_uint8_t led_arg); + +/** + * Start blinking on given LED + * + * See ZB_LED_ARG_CREATE() for constructing led_arg + */ +void zb_led_blink_on(zb_uint8_t led_arg); + +/** + * Quant size for intervals passed to ZBOSS LED functions. + * + * See ZB_LED_ARG_CREATE() + */ +#define ZB_LED_PERIOD_MULTIPLIER ZB_MILLISECONDS_TO_BEACON_INTERVAL(250) + +/** + * Conveniency constants to be used with ZB_LED_ARG_CREATE() macro + */ +typedef enum zb_led_blink_frequency_e +{ + ZB_LED_BLINK_QUATER_SEC = 1, /*!< Blink four times per second */ + ZB_LED_BLINK_HALF_SEC = 2, /*!< Blink twice per second */ + ZB_LED_BLINK_PER_SEC = 4, /*!< Blink every second */ + ZB_LED_BLINK_PER_2SEC = 8, /*!< Blink every two seconds */ +} zb_led_blink_frequency_t; + +/** @cond internals_doc */ + +/** + * @brief get period argument value (in beacon intervals) from led_arg. + * To be used in ZBOSS led functions + */ +#define ZB_LED_ARG_PERIOD(led_arg) (((led_arg) >> 4) * ZB_LED_PERIOD_MULTIPLIER) + +/** + * @brief get LED number from led_arg + * To be used in ZBOSS led functions + */ +#define ZB_LED_ARG_NUMBER(led_arg) ((led_arg) & 0xf) + +/** @endcond */ + +/** + * @brief Construct argument to pass to LEd functions line zb_led_blink_on() + * @param num - number of LED for which command is meant + * @param period - interval between LED state changes. + * see @ref ZB_LED_PERIOD_MULTIPLIER for quant size. + * @note period should not exceed value of 16 + */ +#define ZB_LED_ARG_CREATE(num, period) ((num) | (period << 4)) + +/** @} */ + +/** + * @name Buttons + * @{ + */ + +/** + * @brief Set state of given button to on + * + * @param butt_no - number of button being pressed + */ +void zb_button_on_cb(zb_uint8_t butt_no); + +/** + * @brief Set state of given button to off and invoke button handler. + * + * Handler to invoke is chosed by botton and duration of button press. + * See @ref zb_button_register_handler() for how to setup button handlers + * + * @param butt_no - number of button being released + */ +void zb_button_off_cb(zb_uint8_t butt_no); + +/** + * @brief Register handler to be called on button release + * + * Several handlers can be set for one button (see ZB_BUTT_N_CBS for maximum number of callbacks) + * Each handler is associated with handler press duration, and only one will be called, + * it depends on how long button was pressed which one. + * + * @param butt_no - number of button with which handler is associated + * @param pressed_sec_pow2 - duration with which handler is associated. + * calculated as given power of 2 (in sec): 1-2-4-8... sec + * @param cb - pointer to handler functions + */ +void zb_button_register_handler(zb_uint8_t butt_no, zb_uint8_t pressed_sec_pow2, zb_callback_t cb); + + +/** @cond internals_doc */ +void zb_osif_led_button_init(void); +/** @endcond */ + +/** + * @brief Set state of given LED to "On" + */ +void zb_osif_led_on(zb_uint8_t led_no); + +/** + * @brief Set state of given LED to "Off" + */ +void zb_osif_led_off(zb_uint8_t led_no); + +/** @cond internals_doc */ +zb_bool_t zb_setup_buttons_cb(zb_callback_t cb); +void zb_osif_button_cb(zb_uint8_t arg); +int zb_osif_button_state(zb_uint8_t arg); +/** @endcond */ + +/** + * Number of handler that can be associated with a button. + * + * Each of those handlers corresponds to its own press duration + */ +#define ZB_BUTT_N_CBS 5 + +#ifndef ZB_N_BUTTONS + +/** + * Number of button utilized by application + */ +#define ZB_N_BUTTONS 1 + +#endif + +/** @cond internals_doc */ +typedef struct zb_button_ctl_s +{ + zb_uint8_t is_on; + zb_time_t on_time; + zb_callback_t handlers[ZB_BUTT_N_CBS]; +} zb_button_ctl_t; + + +typedef struct zb_buttons_global_s +{ + zb_button_ctl_t buttons[ZB_N_BUTTONS]; +} zb_buttons_global_t; + +/** @endcond */ + +/*! @} */ + +/*! @} */ + +#endif /* ZB_LED_H */ diff --git a/zboss/include/zb_list_macros.h b/zboss/include/zb_list_macros.h new file mode 100644 index 0000000000..90c722a97d --- /dev/null +++ b/zboss/include/zb_list_macros.h @@ -0,0 +1,519 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Very simple lists operations (macroses). +*/ +#ifndef LIST_H +#define LIST_H 1 + +/*! @cond internals_doc */ +/** + @addtogroup ZB_BASE + @{ +*/ + + +/** + \par Double linked list + + Usage sample: + - declare some structure, include list field into it: + struct xxx { + ... + ZB_LIST_FIELD(struct xxx *, next1); + }; + - declare list head in some other place: + struct xxx * list_head; + + - insert into the list + ZB_LIST_INSERT_HEAD(list_head, next1, ent) + ZB_LIST_INSERT_TAIL(list_head, next1, ent) + ZB_LIST_INSERT_AFTER(list_head, next1, old_ent, new_ent) + + - iterate (for loop): + ZB_LIST_ITERATE(list_head, next1, ent) + { + do something with ent + } + + - iterate back (for loop) + ZB_LIST_ITERATE_BACK(list_head, next1, ent) + { + do something with ent + } + + - iterate (manual) + struct xxx *ent = ZB_LIST_GET_HEAD(list_head, next1) + while (ent) + { + ... + ent = ZB_LIST_NEXT(ent, next1); + } + + - iterate back (manual) + struct xxx *ent = ZB_LIST_GET_TAIL(list_head, next1) + while (ent) + { + ... + ent = ZB_LIST_PREV_FOR_ITER(ent, next1); + } + + - remove + ZB_LIST_REMOVE_HEAD(list_head, next1) + ZB_LIST_REMOVE_TAIL(list_head, next1) + ZB_LIST_REMOVE(list_head, next1, ent) + + - check that item is already in list + ZB_LIST_ITEM_IN_LIST(ent, next1) + */ + + +/** + * List control fields declaratuion. To be put into the structure + * definition. + * + * _prev field has special meaning for the list head: this is pointer + * to the list tail. + */ +#define ZB_LIST_FIELD(type, name) type name ## _next; type name ## _prev + +#if defined DEBUG && defined __GNUC__ +#define ZB_LIST_CHECK_ENT(list, name, ent) do { \ + { \ + typeof(ent) tmp; \ + ZB_LIST_ITERATE(list, name, tmp) \ + { \ + ZB_ASSERT(tmp != ent); \ + } \ + } \ +} while(0) +#else +#define ZB_LIST_CHECK_ENT(list, name, ent) do{}while(0) +#endif + +/* Macro for debugging adding duplicates to the list */ +#define ZB_LIST_CHECK_ENT1(list, name, ent, type) do{ \ + type * tmp; \ + ZB_LIST_ITERATE(list, name, tmp) \ + { \ + ZB_ASSERT(tmp != ent); \ + } \ +}while(0) + +#define ZB_LIST_SIZE(type) (2 * sizeof(type)) + +#define ZB_LIST_DEFINE(type, list) type list +#define ZB_LIST_ARRAY_DEFINE(type, list, n) type list[n] +#define ZB_LIST_INIT(list) (list) = NULL + + +#define ZB_LIST_IS_EMPTY(list) ((list) == NULL) +#define ZB_LIST_IS_NOT_EMPTY(list) ((list) != NULL) +#define ZB_LIST_NEXT(ent, name) (ent)->name ## _next +#define ZB_LIST_PREV_RAW(ent, name) (ent)->name ## _prev +#define ZB_LIST_ZERO(ent, name) (ent)->name ## _prev = (ent)->name ## _next = 0 + +/** + * Like ZB_LIST_PREV(), but check for going over list head + */ +#define ZB_LIST_PREV(ent, name) ((((ent)->name ## _prev)->name ## _next) ? (ent)->name ## _prev : 0) +#define ZB_LIST_GET_HEAD(list, name) (list) +#define ZB_LIST_GET_TAIL(list, name) ((list) ? (list)->name ## _prev : 0) +#define ZB_LIST_ITEM_IN_LIST(t, name) (((t)->name ## _prev) != NULL) + + +/* + * Remove from the list head, and store it in ent + */ +#define ZB_LIST_CUT_HEAD(list, name, ent) do \ +{ \ + ent = list; \ + if ((list)) \ + { \ + if (((list)->name ## _next)) \ + { \ + ((list)->name ## _next)->name ## _prev = (list)->name ## _prev; \ + } \ + (list)->name ## _prev = 0; \ + (list) = (list)->name ## _next; \ + } \ +} while (0) + + + +/* + * Insert to the list head + */ +#define ZB_LIST_INSERT_HEAD(list, name, ent) do \ +{ \ + ZB_LIST_CHECK_ENT(list, name, ent); \ + (ent)->name ## _next = (list); \ + if ((list)) \ + { \ + (ent)->name ## _prev = (list)->name ## _prev; \ + (list)->name ## _prev = (ent); \ + } \ + else \ + { \ + (ent)->name ## _prev = (ent); \ + } \ + (list) = (ent); \ +} while(0) + + +/* + * Insert to the list tail + */ +#define ZB_LIST_INSERT_TAIL(list, name, ent) do \ +{ \ + ZB_LIST_CHECK_ENT(list, name, ent); \ + (ent)->name ## _next = 0; \ + if ((list)) \ + { \ + (ent)->name ## _prev = (list)->name ## _prev; \ + ((list)->name ## _prev)->name ## _next = (ent); \ + (list)->name ## _prev = (ent); \ + } \ + else \ + { \ + (ent)->name ## _prev = (ent); \ + (list) = (ent); \ + } \ +} while (0) + + +/* + * Insert after existend entry + */ +#define ZB_LIST_INSERT_AFTER(list, name, ent, new_ent) do \ +{ \ + ZB_LIST_CHECK_ENT(list, name, new_ent); \ + if ((ent)) \ + { \ + if ((ent) == ZB_LIST_GET_TAIL(list, name)) \ + { \ + ZB_LIST_INSERT_TAIL(list, name, new_ent); \ + } \ + else \ + { \ + (new_ent)->name ## _next = (ent)->name ## _next; \ + (new_ent)->name ## _prev = (ent); \ + ((ent)->name ## _next)->name ## _prev = (new_ent); \ + (ent)->name ## _next = (new_ent); \ + } \ + } \ +} while(0) + + +/* + * Remove from the list head + */ +#define ZB_LIST_REMOVE_HEAD(list, name) do \ +{ \ + if ((list)) \ + { \ + if (((list)->name ## _next)) \ + { \ + ((list)->name ## _next)->name ## _prev = (list)->name ## _prev; \ + } \ + (list)->name ## _prev = 0; \ + (list) = (list)->name ## _next; \ + } \ +} while (0) + +/* + * Remove from the list tail + */ +#define ZB_LIST_REMOVE_TAIL(list, name) do \ +{ \ + if ((list)) \ + { \ + if ((list)->name ## _prev == (list)) /* made an empty list */ \ + { \ + (list)->name ## _prev = 0; \ + (list) = 0; \ + } \ + else \ + { \ + (((list)->name ## _prev)->name ## _prev)->name ## _next = 0; \ + /* This is a bit tricky: we need to assign list->prev and set \ + * tail->prev to 0, but we can't use temporary variable because \ + * we have no type here. Use _next as temporary variable. */ \ + ((list)->name ## _prev)->name ## _next = ((list)->name ## _prev)->name ## _prev; \ + ((list)->name ## _prev)->name ## _prev = 0; \ + (list)->name ## _prev = ((list)->name ## _prev)->name ## _next; \ + } \ + } \ +} while (0) + +#define ZB_LIST_ITERATE(list, name, ent) \ +for ((ent) = (list) ; (ent) != 0 ; (ent) = (ent)->name ## _next) + +#define ZB_LIST_ITERATE_BACK(list, name, ent) \ +for ((ent) = (list) ? (list)->name ## _prev : 0 ; (ent) ; (ent) = (((ent)->name ## _prev)->name ## _next) ? (ent)->name ## _prev : 0) + +#define ZB_LIST_NULL_INIT 0,0 + +#define ZB_LIST_REMOVE(list, name, ent) \ +do \ +{ \ + if ((ent)->name ## _prev != 0) \ + { \ + if ((ent)->name ## _next) /* this is not a tail */ \ + { \ + ((ent)->name ## _next)->name ## _prev = (ent)->name ## _prev; \ + } \ + else /* this is a tail */ \ + { \ + (list)->name ## _prev = (ent)->name ## _prev; \ + } \ + if ((ent) == (list)) /* this is a head */ \ + { \ + (list) = (ent)->name ## _next; \ + } \ + else /* this is not a head */ \ + { \ + ((ent)->name ## _prev)->name ## _next = (ent)->name ## _next; \ + } \ + (ent)->name ## _prev = 0; \ + } \ +} \ +while (0) + +/** + \par Single-linked list (stack and FIFO). + + Use same name ## _next field of the double linked list, so can coexist with it. + */ + +/** + Define single-linked list head/tail pointer + + @param type - type of the pointer to the list element + @param list - list head/tail name prefix + + @b Example: +@code + ZB_SL_LIST_DEFINE (struct work_file_page0_s *, f); +@endcode + */ +#define ZB_SL_LIST_DEFINE(type, list) type list ## _head; type list ## _tail + +#define ZB_SL_LIST_INIT(list) list ## _head = list ## _tail = 0 + + +/** + Define field in the single-linked list element + + @param type - type of the pointer to the list element + @param name - list name (to be able to put element to more then one list) + + @b Example: +@code + ZB_SL_LIST_FIELD (struct work_file_page0_s *, f); +@endcode + */ +#define ZB_SL_LIST_FIELD(type, name) type name ## _next + +/** + Insert into single-linked list head + + @param list - list header pointer (sample: some_ptr->some_list) + @param name - list name + @param ent - element for insert + */ +#define ZB_SL_LIST_INSERT_HEAD(list, name, ent) \ +do \ +{ \ + (ent)->name ## _next = (list ## _head); \ + if (!(list ## _head)) \ + { \ + (list ## _tail) = (ent); \ + } \ + (list ## _head) = (ent); \ +} \ +while (0) + + +#define ZB_SL_LIST_INSERT_TAIL(list, name, ent) \ +do \ +{ \ + (ent)->name ## _next = 0; \ + if (list ## _tail) \ + { \ + (list ## _tail)->name ## _next = (ent); \ + list ## _tail = (ent); \ + } \ + else \ + { \ + (list ## _head) = (ent); \ + (list ## _tail) = (ent); \ + } \ +} \ +while (0) + + + +#define ZB_SL_LIST_REMOVE_HEAD(list, name) \ +do \ +{ \ + if ((list ## _head)) \ + { \ + (list ## _head) = (list ## _head)->name ## _next; \ + if (!(list ## _head)) \ + { \ + (list ## _tail) = 0; \ + } \ + } \ +} \ +while (0) + +#define ZB_SL_LIST_CUT_HEAD(list, name, ent) \ +do \ +{ \ + if ((list ## _head)) \ + { \ + ent = (list ## _head); \ + (list ## _head) = (list ## _head)->name ## _next; \ + if (!(list ## _head)) \ + { \ + (list ## _tail) = 0; \ + } \ + } \ + else \ + { \ + (ent) = 0; \ + } \ +} \ +while (0) + +#define ZB_SL_LIST_REMOVE(type, list, name, ent) \ +do \ +{ \ + type p; \ + type prev = 0; \ + for (p = (list ## _head) ; p ; prev = p, p = p->name ## _next) \ + { \ + if (p == (ent)) \ + { \ + if (prev) \ + { \ + prev->name ## _next = p->name ## _next; \ + if ((list ## _tail) == ent) \ + { \ + (list ## _tail) = prev; \ + } \ + } \ + else \ + { \ + (list ## _head) = p->name ## _next; \ + } \ + if (!(list ## _head)) \ + { \ + (list ## _tail) = 0; \ + } \ + break; \ + } \ + } \ +} \ +while (0) + + +#define ZB_SL_LIST_ITERATE(list, name, ent) for ((ent) = (list ## _head) ; (ent) ; (ent) = (ent)->name ## _next) + +#define ZB_SL_LIST_NEXT(ent, name) ((ent)->name ## _next) + +#define ZB_SL_LIST_GET_HEAD(list) (list ## _head) + + +/* FIFO compatible with double-linked list macros */ + +#define ZB_FIFO_DEFINE ZB_SL_LIST_DEFINE +#define ZB_FIFO_FIELD ZB_SL_LIST_FIELD +#define ZB_FIFO_INIT ZB_SL_LIST_INIT +#define ZB_FIFO_PUT ZB_SL_LIST_INSERT_TAIL +#define ZB_FIFO_PUT_TAIL ZB_SL_LIST_INSERT_HEAD +#define ZB_FIFO_GET ZB_SL_LIST_CUT_HEAD +#define ZB_FIFO_PEEK ZB_SL_LIST_GET_HEAD +#define ZB_FIFO_REMOVE ZB_SL_LIST_REMOVE_HEAD +#define ZB_FIFO_ITERATE_FROM_TAIL ZB_SL_LIST_ITERATE + + +/* Stack compatible with double-linked list macros */ + +#define ZB_STK_DEFINE(type, list) type list ## _head + +#define ZB_STK_INIT(list) list ## _head = 0 + +#define ZB_STK_FIELD ZB_SL_LIST_FIELD + +#define ZB_STK_FIELD_INIT(field) field ## _next = 0 + +#define ZB_STK_PUSH(list, name, ent) \ +do \ +{ \ + (ent)->name ## _next = (list ## _head); \ + (list ## _head) = (ent); \ +} \ +while (0) + +#define ZB_STK_POP(list, name, ent) \ +do \ +{ \ + if ((list ## _head)) \ + { \ + (ent) = (list ## _head); \ + (list ## _head) = (list ## _head)->name ## _next; \ + } \ + else \ + { \ + (ent) = 0; \ + } \ +} \ +while (0) + +#define ZB_STK_PEEK ZB_SL_LIST_GET_HEAD +#define ZB_STK_ITERATE ZB_SL_LIST_ITERATE +#define ZB_STK_NEXT ZB_SL_LIST_NEXT + +/*! @} */ +/*! @endcond */ + +#endif /* LIST_H */ diff --git a/zboss/include/zb_mem_config_common.h b/zboss/include/zb_mem_config_common.h new file mode 100644 index 0000000000..670e338ced --- /dev/null +++ b/zboss/include/zb_mem_config_common.h @@ -0,0 +1,331 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Common rules for ZBOSS application-sude memory configuring + +That file is to be included from zb_mem_config_xxxx.h after basic +selectors defined. + +Do not include that file directly into the application source! +*/ +#ifndef ZB_MEM_CONFIG_COMMON_H +#define ZB_MEM_CONFIG_COMMON_H 1 + +/* + That file is useful only for ZBOSS buld with memory configurable by the user without ZBOSS lib recompile. + */ +#ifdef ZB_CONFIGURABLE_MEM + +#ifdef ZB_ED_ROLE +/* If ZBOSS library is compiled for ZED only, force ZED config role. */ +#ifndef ZB_CONFIG_ROLE_ZED +#define ZB_CONFIG_ROLE_ZED +#endif +#ifdef ZB_CONFIG_ROLE_ZC +#undef ZB_CONFIG_ROLE_ZC +#endif +#ifdef ZB_CONFIG_ROLE_ZR +#undef ZB_CONFIG_ROLE_ZR +#endif +#endif + +/* + Rules of deriving parameters from generic settings. + +## device role ZC/ZR/ZED +### Parameters depending on it: +ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE: set 4 for ZR / OVERALL_NETWORK_SIZE for ZC + +## Overall Zigbee network size: +OVERALL_NETWORK_SIZE 16 to 200 + +### Parameters depending on it: +- ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE: set = OVERALL_NETWORK_SIZE +- ZB_IEEE_ADDR_TABLE_SIZE - set = OVERALL_NETWORK_SIZE + reserve for redirected entries +- ZB_NEIGHBOR_TABLE_SIZE - set = ZB_IEEE_ADDR_TABLE_SIZE + +## Total network traffic +HIGH_TRAFFIC / MODERATE_TRAFFIC / LIGHT_TRAFFIC + +### Parameters depending on it: +- ZB_IOBUF_POOL_SIZE: 18 LITE / 32 MODERATE / 48 HIGH +- ZB_NWK_ROUTING_TABLE_SIZE ZB_NEIGHBOR_TABLE_SIZE if MODERATE or HIGH, 8 if LITE +- ZB_MAC_PENDING_QUEUE_SIZE (ZB_IOBUF_POOL_SIZE / 4) +- ZB_APS_BIND_TRANS_TABLE_SIZE function of ZB_IOBUF_POOL_SIZE + +## Complexity of application relationships +APPLICATION_SIMPLE / APPLICATION_MODERATE / APPLICATION_COMPLEX + +### Parameters depending on it: +- ZB_IOBUF_POOL_SIZE: same constants as for net traffic; use bigger one if have a choice +- ZB_N_APS_RETRANS_ENTRIES: derived from ZB_IOBUF_POOL_SIZE +- ZB_APS_DUPS_TABLE_SIZE: 8 SIMPLE / 16 MODERATE / 32 COMPLEX +- ZB_SCHEDULER_Q_SIZE 20 SIMPLE / 32 MODERATE / 48 COMPLEX + */ + +/* + Total network size: set at upperl level, just a verification here. + */ +#ifndef ZB_CONFIG_OVERALL_NETWORK_SIZE +#error Define ZB_CONFIG_OVERALL_NETWORK_SIZE! +#elif ZB_CONFIG_OVERALL_NETWORK_SIZE < 2 || ZB_CONFIG_OVERALL_NETWORK_SIZE > 200 +#error ZB_CONFIG_OVERALL_NETWORK_SIZE must be between 2 and 200! +#else +/* Derive constands from the network size */ + +#endif /* ZB_CONFIG_OVERALL_NETWORK_SIZE */ + + /* Reserve in address translation table for aliases: 1/4, at least + * 4. Table size must be < 255, so let's limit net size to 200 */ +#define ZB_IEEE_ADDR_TABLE_SIZE_RESERVE(n) ((n + 15)/16 * 4) + +/* + Device role +*/ +#ifdef ZB_CONFIG_ROLE_ZC + +#if defined ZB_CONFIG_ROLE_ZR || defined ZB_CONFIG_ROLE_ZED +#error Only one ZB_CONFIG_ROLE_xxx can be defined! +#endif + +/* ZC need to store one TCLK per device in the overall network */ +#define ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE ZB_CONFIG_OVERALL_NETWORK_SIZE +/* Address table for entire network + reserve */ +#define ZB_CONFIG_IEEE_ADDR_TABLE_SIZE (ZB_CONFIG_OVERALL_NETWORK_SIZE + ZB_IEEE_ADDR_TABLE_SIZE_RESERVE(ZB_CONFIG_OVERALL_NETWORK_SIZE)) +/* Let's have enough space to have the entire network in neighbors - Star topology */ +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE ZB_CONFIG_OVERALL_NETWORK_SIZE +#define ZB_CONFIG_NWK_MAX_SOURCE_ROUTES ZB_CONFIG_OVERALL_NETWORK_SIZE + +#elif defined ZB_CONFIG_ROLE_ZR + +#if defined ZB_CONFIG_ROLE_ZC || defined ZB_CONFIG_ROLE_ZED +#error Only one ZB_CONFIG_ROLE_xxx can be defined! +#endif + +/* Only own keys need to be stored */ +#define ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE 4 +/* The same as ZC: let's be able to work in Star. */ +#define ZB_CONFIG_IEEE_ADDR_TABLE_SIZE (ZB_CONFIG_OVERALL_NETWORK_SIZE + ZB_IEEE_ADDR_TABLE_SIZE_RESERVE(ZB_CONFIG_OVERALL_NETWORK_SIZE)) +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE ZB_CONFIG_OVERALL_NETWORK_SIZE +/* 10/21/2019 EE CR:MINOR Why we ever need that constant for ZR? Only ZC is a concentrator. */ +#define ZB_CONFIG_NWK_MAX_SOURCE_ROUTES ZB_CONFIG_OVERALL_NETWORK_SIZE + +#elif defined ZB_CONFIG_ROLE_ZED + +#if defined ZB_CONFIG_ROLE_ZC || defined ZB_CONFIG_ROLE_ZR +#error Only one ZB_CONFIG_ROLE_xxx can be defined! +#endif + +/* 2 is needed to perform BDB TCLK, 1 more is needed to request new TCLK */ +#define ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE 4 +/* Set it here big enough; may decrease it later */ +#define ZB_CONFIG_IEEE_ADDR_TABLE_SIZE ZB_CONFIG_OVERALL_NETWORK_SIZE + +/* ZED needs neighbor table at join time only. More devices and nets around - biger nbt required. Let's use some euristics. */ +#if ZB_CONFIG_OVERALL_NETWORK_SIZE < 8 +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE 8 +#elif ZB_CONFIG_OVERALL_NETWORK_SIZE < 32 +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE 16 +#else +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE 32 +#endif + +#else + +#error Define exactly one ZB_CONFIG_ROLE_xxx! + +#endif /* ZB_CONFIG_ROLE_ZC */ + + +/* + Total network traffic (including NWK routing) + */ +#ifdef ZB_CONFIG_HIGH_TRAFFIC + +#if defined ZB_CONFIG_MODERATE_TRAFFIC || defined ZB_CONFIG_LIGHT_TRAFFIC +#error Only one ZB_CONFIG_xxx_TRAFFIC can be defined! +#endif + +/* More NWK traffic we route or send/recv from our app - more packet buffers required. */ +#define ZB_CONFIG_IOBUF_POOL_SIZE 48 +#define ZB_CONFIG_NWK_ROUTING_TABLE_SIZE ZB_CONFIG_NEIGHBOR_TABLE_SIZE +#define ZB_CONFIG_MAC_PENDING_QUEUE_SIZE (ZB_CONFIG_IOBUF_POOL_SIZE / 4) +#define ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE ((ZB_CONFIG_IOBUF_POOL_SIZE + 15)/16 * 4) /* 1/4, at least 4 */ +#define ZB_CONFIG_SINGLE_TRANS_INDEX_SIZE ((ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE + 7) / 8) +#define ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE 32 +#define ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE 32 + +#elif defined ZB_CONFIG_MODERATE_TRAFFIC + +#if defined ZB_CONFIG_HIGH_TRAFFIC || defined ZB_CONFIG_LIGHT_TRAFFIC +#error Only one ZB_CONFIG_xxx_TRAFFIC can be defined! +#endif + +#define ZB_CONFIG_IOBUF_POOL_SIZE 32 +#define ZB_CONFIG_NWK_ROUTING_TABLE_SIZE ZB_CONFIG_NEIGHBOR_TABLE_SIZE +#define ZB_CONFIG_MAC_PENDING_QUEUE_SIZE (ZB_CONFIG_IOBUF_POOL_SIZE / 4) +#define ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE ((ZB_CONFIG_IOBUF_POOL_SIZE + 15)/16 * 4) /* 1/4, at least 4 */ +#define ZB_CONFIG_SINGLE_TRANS_INDEX_SIZE ((ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE + 7) / 8) +#define ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE 24 +#define ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE 24 + +#elif defined ZB_CONFIG_LIGHT_TRAFFIC + +#if defined ZB_CONFIG_HIGH_TRAFFIC || defined ZB_CONFIG_MODERATE_TRAFFIC +#error Only one ZB_CONFIG_xxx_TRAFFIC can be defined! +#endif + +#define ZB_CONFIG_IOBUF_POOL_SIZE 20 +#define ZB_CONFIG_NWK_ROUTING_TABLE_SIZE 8 +#define ZB_CONFIG_MAC_PENDING_QUEUE_SIZE (ZB_CONFIG_IOBUF_POOL_SIZE / 4) +#define ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE ((ZB_CONFIG_IOBUF_POOL_SIZE + 15)/16 * 4) /* 1/4, at least 4 */ +#define ZB_CONFIG_SINGLE_TRANS_INDEX_SIZE ((ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE + 7) / 8) +#define ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE 16 +#define ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE 16 + +#else + +#error Define exactly one ZB_CONFIG_xxx_TRAFFIC! + +#endif /* ZB_CONFIG_HIGH_TRAFFIC */ + +/* check that 5 bits of src_table_index is enough */ +ZB_ASSERT_COMPILE_DECL(ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE <= (1<<5)); + +/* + Complexity of the application interconnection to other Zigbee devices. + */ +#ifdef ZB_CONFIG_APPLICATION_COMPLEX + +#if defined ZB_CONFIG_APPLICATION_MODERATE || defined ZB_CONFIG_APPLICATION_SIMPLE +#error Only one ZB_CONFIG_APPLICATION_xxx can be defined! +#endif + +#define ZB_CONFIG_SCHEDULER_Q_SIZE 48 + +/* Increase pool and neighbor table sizes of complex application is supposed. */ + +#if ZB_CONFIG_IOBUF_POOL_SIZE < 32 +#undef ZB_CONFIG_IOBUF_POOL_SIZE +#define ZB_CONFIG_IOBUF_POOL_SIZE 32 +#endif + +#if ZB_CONFIG_NEIGHBOR_TABLE_SIZE < 16 +#undef ZB_CONFIG_NEIGHBOR_TABLE_SIZE +#define ZB_CONFIG_NEIGHBOR_TABLE_SIZE 16 +#endif + +#define ZB_CONFIG_APS_DUPS_TABLE_SIZE 32 +#define ZB_CONFIG_N_APS_RETRANS_ENTRIES ((ZB_CONFIG_IOBUF_POOL_SIZE + 8)/9 * 3) /* 1/3, at least 3 */ + +#elif defined ZB_CONFIG_APPLICATION_MODERATE + +#if defined ZB_CONFIG_APPLICATION_COMPLEX || defined ZB_CONFIG_APPLICATION_SIMPLE +#error Only one ZB_CONFIG_APPLICATION_xxx can be defined! +#endif + +#ifdef ZB_CONFIG_HIGH_TRAFFIC +#define ZB_CONFIG_SCHEDULER_Q_SIZE 48 +#else +#define ZB_CONFIG_SCHEDULER_Q_SIZE 32 +#endif + +#if ZB_CONFIG_IOBUF_POOL_SIZE < 24 +#undef ZB_CONFIG_IOBUF_POOL_SIZE +#define ZB_CONFIG_IOBUF_POOL_SIZE 24 +#endif + +#define ZB_CONFIG_APS_DUPS_TABLE_SIZE 16 +#define ZB_CONFIG_N_APS_RETRANS_ENTRIES ((ZB_CONFIG_IOBUF_POOL_SIZE + 8)/9 * 3) /* 1/3, at least 3 */ + +#elif defined ZB_CONFIG_APPLICATION_SIMPLE + +#if defined ZB_CONFIG_APPLICATION_MODERATE || defined ZB_CONFIG_APPLICATION_COMPLEX +#error Only one ZB_CONFIG_APPLICATION_xxx can be defined! +#endif + +#define ZB_CONFIG_SCHEDULER_Q_SIZE 20 + +#define ZB_CONFIG_APS_DUPS_TABLE_SIZE 8 +#define ZB_CONFIG_N_APS_RETRANS_ENTRIES 6 + +#else + +#error Define exactly one ZB_CONFIG_APPLICATION_xxx! + +#endif /* ZB_CONFIG_APPLICATION_COMPLEX */ + +#ifdef ZB_CONFIG_SCHEDULER_Q_SIZE +/** + The purpose of the define. Ret code handling implementation on the application side + (via ZB_SCHEDULE_USER_APP_ALARM and ZB_SCHEDULE_USER_APP_CALLBACK) implies that we have some part + of the callback and alarm queues which can not be used from the user app and always should be reserved + for stack schedule purposes. So, let's define this part as 12 (for both immediate callbacks and alarms) + for all configurations. + */ +#define ZB_CONFIG_SCHEDULER_Q_SIZE_PROTECTED_STACK_POOL 12 +#if (ZB_CONFIG_SCHEDULER_Q_SIZE - ZB_CONFIG_SCHEDULER_Q_SIZE_PROTECTED_STACK_POOL) < 6 +#error The size of application scheduler queue is very small! Please, change ZB_CONFIG_SCHEDULER_Q_SIZE_PROTECTED_STACK_POOL, ZB_CONFIG_SCHEDULER_Q_SIZE to set it at least 6 +#endif +#endif + +#ifdef ZB_CONFIG_ROLE_ZED +/* That parameters will not be used in ZED, but just in case - let + * compiler fail if routing parameter used by mistake. */ +#undef ZB_CONFIG_NWK_ROUTING_TABLE_SIZE +#undef ZB_CONFIG_MAC_PENDING_QUEUE_SIZE +#define ZB_CONFIG_NWK_ROUTING_TABLE_SIZE 0 +#define ZB_CONFIG_MAC_PENDING_QUEUE_SIZE 0 +#endif + +#ifdef ZB_MAC_SOFTWARE_PB_MATCHING +/* Child heighbor hash table size equals to size of addr table + 33% aligned to 32 */ +#define ZB_CONFIG_CHILD_HASH_TABLE_SIZE (((ZB_CONFIG_IEEE_ADDR_TABLE_SIZE + ZB_CONFIG_IEEE_ADDR_TABLE_SIZE / 3) + 31) / 32 * 32) + +/* Pending bitmap size. Each bit corresponds to "child_hash_table" */ +#define ZB_CONFIG_PENDING_BITMAP_SIZE ((ZB_CONFIG_CHILD_HASH_TABLE_SIZE + 31) / 32) +#endif + +/* This value must not be changed. Initialization is based on the ZB_CONFIG_IOBUF_POOL_SIZE value. */ +#define ZB_CONFIG_BUF_POOL_BITMAP_SIZE ((ZB_CONFIG_IOBUF_POOL_SIZE + 7) / 8) + +#endif /* ZB_CONFIGURABLE_MEM */ + +#endif /* ZB_MEM_CONFIG_COMMON_H */ diff --git a/zboss/include/zb_mem_config_context.h b/zboss/include/zb_mem_config_context.h new file mode 100644 index 0000000000..ee782b45e4 --- /dev/null +++ b/zboss/include/zb_mem_config_context.h @@ -0,0 +1,317 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Contexts for ZBOSS configurable memory +*/ +#ifndef ZB_MEM_CONFIG_CONTEXT_H +#define ZB_MEM_CONFIG_CONTEXT_H 1 + + +/*! @internal */ +/*! @{ */ + +/** + @defgroup configurable_mem_internals + @{ + @details + Design of configurable ZBOSS internal memory provides an ability to + configure some storage parameters at application link time without + recompiling ZBOSS libraries. + If application does not configure storage parameters, default values will be used. + + ZBOSS uses static memory allocation technic. + + Initially (before introducing configurable memory) ZBOSS uses static arrays inside data structures and defines for arraps syzes. + Defines are fixed at ZBOSS compile time. @see zb_buf_pool_t.pool as an example. + + To be able to configure memory at compile time, ZBOSS changes static buffers to pointers (@see zb_buf_pool_t.pool again). + Size constants are redefined to variables (@see gc_pool_size). + So ZBOSS code mostly not changed and can be compiled with or without configurable memory feature. + + This header file defines variables for buffers and variables for buffer sizes. + That file can be included strictly once from the kernel (zb_init.c) or + from the user's application (indirectly, from file zb_mem_config_xxx.h). + When included form the kernel, ZB_CONFIG_DEFAULT_KERNEL_DEFINITION is defined, so all symbols are defined as weak. + As a result, if application does not included any memory configuration includes, + default buffers and its sizes (weak) are used. + If application includes one of zb_mem_config_xxx.h, it owerwrites weak symbols for buffers and its sizes. + + Pointers assignment (like @ref zb_buf_pool_t.pool) and arrays syzes + initialization are done at ZBOSS start time from @ref zb_init_configurable_mem(). + + Default storage settings are defined in zb_vendor.h file. + @note Changing zb_vendor.h is meaningful only if you re-compile ZBOSS library. + Do not change it when you compile the application. + + See also @ref configurable_mem. + @} +*/ + +#if defined ZB_CONFIGURABLE_MEM || defined DOXYGEN + +/* + some data structures use 7 bits to address a buffer, so can have up to 127 buffers. + Actually it is big enough because more than 48 are rarely used.. + */ +#if ZB_CONFIG_IOBUF_POOL_SIZE > 127 +#error ZB_CONFIG_IOBUF_POOL_SIZE must be <= 127 +#endif + +/**@brief Maximum buffer index. + * This macro is just an abbreviation for a corresponding macro in ZBOSS sources and its value must not be changed. + */ +#define ZB_CONFIG_N_BUF_IDS (ZB_CONFIG_IOBUF_POOL_SIZE + 1) + +/** + @par + Define default configuration in the kernel lib as a weak symbol + */ +#if defined ZB_CONFIG_DEFAULT_KERNEL_DEFINITION || defined DOXYGEN + +/** + Kernel's default buffers. Define weak global variables. +*/ +#define ZB_CONFIG_POST ZB_WEAK +#define ZB_CONFIG_PRE ZB_WEAK_PRE ZB_ALIGNED_PRE +#define ZB_CONFIG_USE_DEFAULTS 1 + +#else + +/* User's app. Just define global variables. */ +#define ZB_CONFIG_POST +#define ZB_CONFIG_PRE ZB_ALIGNED_PRE +#define ZB_CONFIG_USE_DEFAULTS 0 + +#endif + + +/** + If user did not owerwrite default memory configuration, that variable value is 1, else 0. + + Currently used in trace only, but, maybe, implement user API for it if customer require it? + */ +ZB_CONFIG_PRE zb_uint_t gc_use_defaults ZB_CONFIG_POST = ZB_CONFIG_USE_DEFAULTS; + +/* Can't put all that variables into the struct because its sizes will + * be different for in-kernel default case and in the application + * which overwritten some sizes. So declare variables one by one. */ + +/* If we are here from the user's app, here are buffers + definition. Application must be here only once. + + If we are here from the kernel, it can be either default buffers + definition or variables declaration (including variables storing + sizes). + */ + + +/** +Buffer pool: +ZB_IOBUF_POOL_SIZE and derivatives. + +Arrays directly defined by ZB_IOBUF_POOL_SIZE: + +zb_zdo_globals.h +nwk_addr_req_pending_tsns +nwk_addr_req_pending_mask + +zb_bufpool_globals.h + +zb_buf_pool_t.pool +zb_buf_pool_t.bufs_busy_bitmap +zb_buf_pool_t.buf_in_use + */ +ZB_CONFIG_PRE zb_buf_ent_t gc_iobuf_pool[ZB_CONFIG_IOBUF_POOL_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_bufs_busy_bitmap[ZB_CONFIG_BUF_POOL_BITMAP_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_buf_pool_bitmap_size ZB_CONFIG_POST = ZB_CONFIG_BUF_POOL_BITMAP_SIZE; +#ifdef ZB_BUF_SHIELD +ZB_CONFIG_PRE zb_uint8_t gc_iobuf_buf_in_use[(ZB_CONFIG_IOBUF_POOL_SIZE + 7)/8] ZB_CONFIG_POST = { 0 }; +#endif + +/** +Input packets queue + +zb_nwk_globals.h + +zb_nwk_handle_t.input_q +*/ +ZB_RING_BUFFER_DECLARE(zb_nwk_in_q_buf, zb_uint8_t, (ZB_CONFIG_IOBUF_POOL_SIZE/2)); +ZB_CONFIG_PRE zb_nwk_in_q_buf_t gc_nwk_in_q ZB_CONFIG_POST = { 0 }; + +/** +TSNs pending for address request complete. + +zb_zdo_globals.h +nwk_addr_req_pending_tsns +nwk_addr_req_pending_mask +*/ +ZB_CONFIG_PRE zb_uint8_t gc_nwk_addr_req_pending_tsns[ZB_CONFIG_N_BUF_IDS] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_nwk_addr_req_pending_mask[(ZB_CONFIG_N_BUF_IDS + 7) / 8] ZB_CONFIG_POST = { 0 }; + +/** +Node Desc feature: mask of pending pkt for every buffer + +zb_zdo_globals.h +node_desc_req_pending_mask +*/ +ZB_CONFIG_PRE zb_uint8_t gc_node_desc_req_pending_mask[(ZB_CONFIG_N_BUF_IDS + 7) / 8] ZB_CONFIG_POST = { 0 }; + +/** +MAC pending TX queue (FFDs). + +zb_mac_globals.h +ZB_MAC_PENDING_QUEUE_SIZE (ZB_IOBUF_POOL_SIZE / 4) + + */ +#ifdef ZB_ROUTER_ROLE +ZB_CONFIG_PRE zb_mac_pending_data_t gc_mac_pending_data_queue[ZB_CONFIG_MAC_PENDING_QUEUE_SIZE] ZB_CONFIG_POST = { 0 }; +#endif + +#ifdef ZB_MAC_SOFTWARE_PB_MATCHING +ZB_CONFIG_PRE zb_uint_t gc_child_hash_table_size ZB_CONFIG_POST = ZB_CONFIG_CHILD_HASH_TABLE_SIZE; + +ZB_CONFIG_PRE zb_uint16_t gc_child_hash_table[ZB_CONFIG_CHILD_HASH_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint32_t gc_pending_bitmap[ZB_CONFIG_PENDING_BITMAP_SIZE] ZB_CONFIG_POST = { 0 }; + +#ifdef ZB_MAC_POLL_INDICATION_CALLS_REDUCED +ZB_CONFIG_PRE zb_time_t gc_poll_timestamp_table[ZB_CONFIG_CHILD_HASH_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint16_t gc_poll_timeout_table[ZB_CONFIG_CHILD_HASH_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +#endif /* ZB_MAC_POLL_INDICATION_CALLS_REDUCED */ + +#endif /* ZB_MAC_SOFTWARE_PB_MATCHING */ + +/** + APS bound transmission buffers + + zb_aps_globals.h + + zb_aps_bind_dst_table_t.trans_index + */ + +ZB_CONFIG_PRE zb_uint8_t gc_trans_table_size ZB_CONFIG_POST = ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE; +ZB_CONFIG_PRE zb_uint8_t gc_single_trans_index_size ZB_CONFIG_POST = ZB_CONFIG_SINGLE_TRANS_INDEX_SIZE; +ZB_CONFIG_PRE zb_uint8_t gc_trans_index_buf[ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE][ZB_CONFIG_SINGLE_TRANS_INDEX_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_trans_table[ZB_CONFIG_APS_BIND_TRANS_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; + +/** + APS bind tables + + zb_aps_globals.h + + ZG->aps.binding.zb_aps_bind_src_table_t + ZG->aps.binding.zb_aps_bind_dst_table_t + */ +ZB_CONFIG_PRE zb_uint8_t gc_aps_bind_src_table_size ZB_CONFIG_POST = ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE; +ZB_CONFIG_PRE zb_uint8_t gc_aps_bind_dst_table_size ZB_CONFIG_POST = ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE; +ZB_CONFIG_PRE zb_aps_bind_src_table_t gc_aps_bind_src_table[ZB_CONFIG_APS_SRC_BINDING_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_aps_bind_dst_table_t gc_aps_bind_dst_table[ZB_CONFIG_APS_DST_BINDING_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; + +/** + APS retransmission buffer + + zb_aps_globals.h + zb_aps_retrans_t.hash + */ + +ZB_CONFIG_PRE zb_aps_retrans_ent_t gc_aps_retrans[ZB_CONFIG_N_APS_RETRANS_ENTRIES] ZB_CONFIG_POST = { 0 }; + +/* + Declarations of variables defining parameters sizes. + */ + +ZB_CONFIG_PRE zb_uint_t gc_pool_size ZB_CONFIG_POST = ZB_CONFIG_IOBUF_POOL_SIZE; +ZB_CONFIG_PRE zb_uint_t gc_mac_pending_queue_size ZB_CONFIG_POST = ZB_CONFIG_MAC_PENDING_QUEUE_SIZE; +ZB_CONFIG_PRE zb_uint_t gc_n_aps_retrans_entries ZB_CONFIG_POST = ZB_CONFIG_N_APS_RETRANS_ENTRIES; + + +/* ZB_CONFIG_SCHEDULER_Q_SIZE */ +ZB_RING_BUFFER_DECLARE(zb_cb_q_buf, zb_cb_q_ent_t, ZB_CONFIG_SCHEDULER_Q_SIZE); +ZB_CONFIG_PRE zb_cb_q_buf_t gc_cb_q ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_tm_q_ent_t gc_tm_buf[ZB_CONFIG_SCHEDULER_Q_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint32_t gc_cb_flag_bm[(ZB_CONFIG_SCHEDULER_Q_SIZE + 31)/32] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_sched_q_size ZB_CONFIG_POST = ZB_CONFIG_SCHEDULER_Q_SIZE; +ZB_CONFIG_PRE zb_uint_t gc_sched_stack_unprotected_q_size ZB_CONFIG_POST = ZB_CONFIG_SCHEDULER_Q_SIZE_PROTECTED_STACK_POOL; + + +/* ZB_N_APS_KEY_PAIR_ARR_MAX_SIZE */ +#if defined ZB_COORDINATOR_ROLE && defined ZB_SECURITY_INSTALLCODES +ZB_CONFIG_PRE zb_aps_installcode_storage_t gc_installcodes_table[ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE] ZB_CONFIG_POST = { 0 }; +#endif +ZB_CONFIG_PRE zb_aps_device_key_pair_array_t gc_key_pair_set[ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_n_aps_key_pair ZB_CONFIG_POST = ZB_CONFIG_N_APS_KEY_PAIR_ARR_MAX_SIZE; + + +/* ZB_IEEE_ADDR_TABLE_SIZE */ +ZB_CONFIG_PRE zb_address_map_t gc_addr_map[ZB_CONFIG_IEEE_ADDR_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_short_sorted[ZB_CONFIG_IEEE_ADDR_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_addr_to_neighbor[ZB_CONFIG_IEEE_ADDR_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_addr_table_size ZB_CONFIG_POST = ZB_CONFIG_IEEE_ADDR_TABLE_SIZE; + +/* ZB_NEIGHBOR_TABLE_SIZE */ +#ifdef ZB_ROUTER_ROLE +ZB_CONFIG_PRE zb_uint8_t gc_passive_ack[ZB_NWK_BRR_TABLE_SIZE][((ZB_CONFIG_NEIGHBOR_TABLE_SIZE + 7) / 8)] ZB_CONFIG_POST = { 0 }; +#endif + + +ZB_CONFIG_PRE zb_neighbor_tbl_ent_t gc_neighbor[ZB_CONFIG_NEIGHBOR_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_neighbor_table_size ZB_CONFIG_POST = ZB_CONFIG_NEIGHBOR_TABLE_SIZE; + +/* ZB_NWK_ROUTING_TABLE_SIZE */ +#ifdef ZB_ROUTER_ROLE +ZB_CONFIG_PRE zb_nwk_routing_t gc_routing_table[ZB_CONFIG_NWK_ROUTING_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_routing_table_size ZB_CONFIG_POST = ZB_CONFIG_NWK_ROUTING_TABLE_SIZE; +/* ZB_NWK_SOURCE_ROUTING_TABLE_SIZE */ +#if defined ZB_PRO_STACK && !defined ZB_LITE_NO_SOURCE_ROUTING +/* 10/21/2019 EE CR:MAJOR ZC only! Not ZB_ROUTER_ROLE but ZB_COORDINATOR_ROLE */ +ZB_CONFIG_PRE zb_nwk_rrec_t gc_src_routing_table[ZB_CONFIG_NWK_MAX_SOURCE_ROUTES] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint8_t gc_nwk_max_source_routes ZB_CONFIG_POST = ZB_CONFIG_NWK_MAX_SOURCE_ROUTES; +#endif +#endif + +/* ZB_APS_DUPS_TABLE_SIZE */ +ZB_CONFIG_PRE zb_aps_dup_tbl_ent_t gc_dups_table[ZB_CONFIG_APS_DUPS_TABLE_SIZE] ZB_CONFIG_POST = { 0 }; +ZB_CONFIG_PRE zb_uint_t gc_aps_dups_table_size ZB_CONFIG_POST = ZB_CONFIG_APS_DUPS_TABLE_SIZE; + +#endif /* ZB_CONFIGURABLE_MEM */ + +/*! @} */ +/*! @} */ + +#endif /* ZB_MEM_CONFIG_CONTEXT_H */ diff --git a/zboss/include/zb_mem_config_max.h b/zboss/include/zb_mem_config_max.h new file mode 100644 index 0000000000..cbd0b2f06c --- /dev/null +++ b/zboss/include/zb_mem_config_max.h @@ -0,0 +1,106 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: The biggest pissible configuration: ZC, big net, high load, high complexity +*/ +#ifndef ZB_MEM_CONFIG_MAXIMUM_H +#define ZB_MEM_CONFIG_MAXIMUM_H 1 + +/** + @addtogroup configurable_mem + @{ +*/ +/** + Configure memory sizes for ZC device role + */ +#define ZB_CONFIG_ROLE_ZC + +#ifdef DOXYGEN +/** + Configure memory sizes for ZED device role + */ +#define ZB_CONFIG_ROLE_ZED +/** + Configure memory sizes for ZR device role + */ +#define ZB_CONFIG_ROLE_ZR +#endif + +/*#define ZB_CONFIG_ROLE_ZR*/ +/*#define ZB_CONFIG_ROLE_ZED*/ +/** + Max total number of devices in Zigbee network. + + From 2 to 200. + */ +#define ZB_CONFIG_OVERALL_NETWORK_SIZE 200 +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 16*/ +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 32*/ + +/** + High routing and application traffic from/to that device. + */ +#define ZB_CONFIG_HIGH_TRAFFIC +/*#define ZB_CONFIG_MODERATE_TRAFFIC*/ +/*#define ZB_CONFIG_LIGHT_TRAFFIC*/ + +/** + Complex user's application at that device: complex relations to other devices. + */ +#define ZB_CONFIG_APPLICATION_COMPLEX +/*#define ZB_CONFIG_APPLICATION_MODERATE*/ +/*#define ZB_CONFIG_APPLICATION_SIMPLE*/ + +/** + @} +*/ + +/* Now common logic derives numerical parameters from the defined configuration. */ +#include "zb_mem_config_common.h" + +/* Now if you REALLY know what you do, you can study zb_mem_config_common.h and redefine some configuration parameters, like: +#undef ZB_CONFIG_SCHEDULER_Q_SIZE +#define ZB_CONFIG_SCHEDULER_Q_SIZE 56 +*/ + +/* Memory context definitions */ +#include "zb_mem_config_context.h" + +#endif /* ZB_MEM_CONFIG_MAXIMUM_H */ diff --git a/zboss/include/zb_mem_config_med.h b/zboss/include/zb_mem_config_med.h new file mode 100644 index 0000000000..b4afe7b5d6 --- /dev/null +++ b/zboss/include/zb_mem_config_med.h @@ -0,0 +1,94 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: The medium configuration: ZC, medium network size, moderate load, medium complexity +*/ +#ifndef ZB_MEM_CONFIG_MAXIMUM_H +#define ZB_MEM_CONFIG_MAXIMUM_H 1 + +/** + @addtogroup configurable_mem + @{ + @cond skip_this + @{ +*/ +#define ZB_CONFIG_ROLE_ZC +/*#define ZB_CONFIG_ROLE_ZR*/ +/*#define ZB_CONFIG_ROLE_ZED*/ + +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 128*/ +#define ZB_CONFIG_OVERALL_NETWORK_SIZE 32 +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 16*/ + +/** + @} + @endcond +*/ + +/*#define ZB_CONFIG_HIGH_TRAFFIC*/ +/** + Medium routing and application traffic from/to that device. + */ +#define ZB_CONFIG_MODERATE_TRAFFIC +/*#define ZB_CONFIG_LIGHT_TRAFFIC*/ + +/*#define ZB_CONFIG_APPLICATION_COMPLEX*/ +/** + Medium user's application complexity at that device: medium relations to other devices. + */ +#define ZB_CONFIG_APPLICATION_MODERATE +/*#define ZB_CONFIG_APPLICATION_SIMPLE*/ + +/** + @} +*/ + +/* Now common logic derives numerical parameters from the defined configuration. */ +#include "zb_mem_config_common.h" + +/* Now if you REALLY know what you do, you can study zb_mem_config_common.h and redefine some configuration parameters, like: +#undef ZB_CONFIG_SCHEDULER_Q_SIZE +#define ZB_CONFIG_SCHEDULER_Q_SIZE 56 +*/ + +/* Memory context definitions */ +#include "zb_mem_config_context.h" + +#endif /* ZB_MEM_CONFIG_MAXIMUM_H */ diff --git a/zboss/include/zb_mem_config_min.h b/zboss/include/zb_mem_config_min.h new file mode 100644 index 0000000000..a5b7aa0705 --- /dev/null +++ b/zboss/include/zb_mem_config_min.h @@ -0,0 +1,98 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: The smallest pissible configuration: ZC, small net, small load, low complexity +*/ +#ifndef ZB_MEM_CONFIG_MAXIMUM_H +#define ZB_MEM_CONFIG_MAXIMUM_H 1 + +/** + @addtogroup configurable_mem + @{ + @cond skip_this + @{ +*/ + + +#define ZB_CONFIG_ROLE_ZC +/*#define ZB_CONFIG_ROLE_ZR*/ +/*#define ZB_CONFIG_ROLE_ZED*/ + +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 128*/ +/*#define ZB_CONFIG_OVERALL_NETWORK_SIZE 32*/ +#define ZB_CONFIG_OVERALL_NETWORK_SIZE 16 + + +/** + @} + @endcond +*/ + +/*#define ZB_CONFIG_HIGH_TRAFFIC*/ +/*#define ZB_CONFIG_MODERATE_TRAFFIC*/ +/** + Light routing and application traffic from/to that device. + */ +#define ZB_CONFIG_LIGHT_TRAFFIC + +/*#define ZB_CONFIG_APPLICATION_COMPLEX*/ +/*#define ZB_CONFIG_APPLICATION_MODERATE*/ +/** + Simple user's application at that device: not too many relations to other devices. + */ +#define ZB_CONFIG_APPLICATION_SIMPLE + +/** + @} +*/ + + +/* Now common logic derives numerical parameters from the defined configuration. */ +#include "zb_mem_config_common.h" + +/* Now if you REALLY know what you do, you can study zb_mem_config_common.h and redefine some configuration parameters, like: +#undef ZB_CONFIG_SCHEDULER_Q_SIZE +#define ZB_CONFIG_SCHEDULER_Q_SIZE 56 +*/ + +/* Memory context definitions */ +#include "zb_mem_config_context.h" + +#endif /* ZB_MEM_CONFIG_MAXIMUM_H */ diff --git a/zboss/include/zb_osif.h b/zboss/include/zb_osif.h new file mode 100644 index 0000000000..90eebc8f0a --- /dev/null +++ b/zboss/include/zb_osif.h @@ -0,0 +1,780 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Main header for OS and platform depenednt stuff +*/ + +#ifndef ZB_OSIF_H +#define ZB_OSIF_H 1 + + +/** + @internal + + \addtogroup ZB_OSIF */ +/*! @{ */ + +/** +@par OS/HW abstraction +OS/HW platform abstraction is necessary to achieve high portability. +C language tool to separate abstraction layer is C preprocessor. + +Main idea is to avoid number of ifdefs related to portability in the code, and +decrease number of ifdefs in the header files not related to the OS abstraction +layer. + +Platform abstraction is implemented as C functions placed into OS abstraction +layers and platform-dependent global typedefs and definitions placed into header +files. All platform-related stuff is in osif/ directory. Global definitions +and typedefs can be used anywhere - that is why on the architecture picture OS +abstraction layer depicted as global. + +Following things are platform-dependent: +* typedefs for base types (8-bit controller vs 32-bit Linux device) +* definitions for different 8051 compilers (SDCC and Keil) +* transceiver i/o (interrupts handling for 8051 vs file i/o in Linux); +* wait for i/o (device sleep for 8051, wait in select() in Linux) +* trace i/o (UART for 8051, file in Linux); +* MAC traffic dump (UART for 8051, file in Linux); +* Timer (8051 timer at device, select() timeout in Linux) + + */ + + + +#ifdef __IAR_SYSTEMS_ICC__ +#ifndef ZB_IAR +#define ZB_IAR +#endif +#endif + /** +OSIF platform selection. One of pre-defined platform should be selected in +zb_config.h configurations. +zb_osif_platform.h is different in different platforms repo. +*/ +#include "zb_osif_platform.h" + +#include "zb_ringbuffer.h" + +#ifndef ZB_PLATFORM_INIT +#error Define ZB_PLATFORM_INIT in you platform file +//#define ZB_PLATFORM_INIT() +#endif + +/* Default (C standard) definition of MAIN() if not redefined in zb_osif_platform.h */ +#ifndef MAIN +#define MAIN() int main(int argc, char *argv[]) +#define FAKE_ARGV +#define ARGV_UNUSED ZVUNUSED(argc) ; ZVUNUSED(argv) +#define MAIN_RETURN(v) return (v) +#endif + +#ifndef ZB_SET_TRACE_TRANSPORT +/* + * If platform supports choosing transport at runtime + * (i.e. Telink can choose between UART and USB debug interface) + * define this macro. + * Note that this is intended to be called before ZB_TRACE_INIT is called as + * only one interface will be configured and the rest of them will be left as is + * so that it would be usable from non-Zigbee purposes (application) if needed. + */ +#define ZB_SET_TRACE_TRANSPORT(transport) +#endif + +/* + * If platform supports NCP architecture and the ability to put the SoC to + * sleep state, this function should be implemented. + * + * This function is meant to be called from zboss_signal_handler(), after + * receiving ZB_COMMON_SIGNAL_CAN_SLEEP signal. + * It should configure the NCP transport in a way that is can wake up the MCU + * through external interrupt and call the zb_sleep_now(). + * Afterwards, it should recover the NCP transport, so it is able to continue + * its normal operation. + */ +#ifndef ZB_OSIF_NCP_TRANSPORT_PREPARE_TO_SLEEP +#define ZB_OSIF_NCP_TRANSPORT_PREPARE_TO_SLEEP() +#endif + +#if !defined ZB_KICK_HW_WATCHDOG +#define ZB_KICK_HW_WATCHDOG() +#endif + +/*! @} */ + + +/* common osif API */ +zb_uint32_t zb_random_seed(void); +zb_uint32_t zb_get_utc_time(void); + +zb_uint32_t osif_get_time_ms(void); + +/* note: that api is only for some platforms */ +zb_ret_t osif_set_transmit_power(zb_uint8_t channel, zb_int8_t power); +void osif_set_default_trasnmit_powers(zb_int8_t *tx_powers); + +#if defined ZB_MACSPLIT_TRANSPORT_SERIAL +void zb_osif_serial_transport_init(); +void zb_osif_serial_transport_put_bytes(zb_uint8_t *buf, zb_short_t len); +#endif + +/*! \addtogroup uart */ +/*! @{ */ + +#if defined ZB_HAVE_SERIAL || defined DOXYGEN + +/* Serial interface (trace, traffic dump, serial transport) */ + +/** + Type of callback called by serial interface when it receives a single byte. + + @param byte - received byte + */ +typedef void (*zb_osif_uart_byte_received_cb_t)(zb_uint8_t byte); + +/** + Initialize UART low level. + + If ZBOSS uses UART for trace or traffic dump, it calls zb_osif_serial_init() + itself. + If UART is used by application, application must call zb_osif_serial_init(). + */ +void zb_osif_serial_init(void); + +/** + Setup callback to be called when single byte reecived over UART + + @param hnd user's rx callback + */ +void zb_osif_set_uart_byte_received_cb(zb_osif_uart_byte_received_cb_t hnd); + +/** @cond internals_doc */ + + +/** @endcond*/ /* internals_doc */ + +/** + Set user's buffer to be used by UART TX logic. + + ZBOSS normally uses its internal UART buffer. The buffer is not too big - + about 200 bytes which is enough for its usage by ZBOSS (trace). + Some applications needs large io buffers. So declare there type placeholder for use ringbuffer zb_byte_array_t; + by default application will set user tx buffer to stack tx buffer and access it through pointer; + User can override this pointer to use it's own serial buffer. + + @param buf_ptr user's buffer + @param capacity buffer capacity + */ +void zb_osif_set_user_io_buffer(zb_byte_array_t *buf_ptr, zb_ushort_t capacity); + +/** + Set user callback that will be called from uart IRQ handler. + Replaces zboss uart irq handler. + + Note: that call is to be used when application initializes and uses UART + itself. + Do not use this call if use ZBOSS serial port API. + Call to that functions disables ZBOSS debug trace and traffic dump. +*/ +void zb_osif_set_uart_user_irq_handler(void (*irq_hnd)()); + +/** + Prepare UART to a sleep. Shall be invoked before putting ZBOSS to a sleep. + Perform OS-dependent actions. +*/ +void zb_osif_uart_sleep(void); + +/** + Restore UART from a sleep. Shall be invoked after wake up. + Perform OS-dependent actions. +*/ +void zb_osif_uart_wake_up(void); + +#if defined(ZB_HAVE_ASYNC_SERIAL) || defined(DOXYGEN) +/* Asynchronous API extension for serial interface. */ + +#define SERIAL_SEND_SUCCESS 0 /**< Serial interface has sent the data. */ +#define SERIAL_SEND_BUSY 1 /**< Serial interface is busy. */ +#define SERIAL_SEND_TIMEOUT_EXPIRED 2 /**< Transmission operation timed out. */ +#define SERIAL_SEND_ERROR 255 /**< Serial interface internal error. */ + + +/** + Type of callback called by serial interface when it received requested buffer. + + @param buf - pointer to data received + @param len - length of received data + */ +typedef void (*serial_recv_data_cb_t)(zb_uint8_t *buf, zb_ushort_t len); + +/** + Type of callback called by serial interface when it completed transmission of data. + + @param status - status of the transmission + */ +typedef void (*serial_send_data_cb_t)(zb_uint8_t status); + + +/** + Receive data from serial interface. + + @param buf - pointer to the buffer for received data + @param len - length of the buffer + */ +void zb_osif_serial_recv_data(zb_uint8_t *buf, zb_ushort_t len); + +/** + Set serial interface callback for receiving completion. + + @param cb - receiving completion callback + */ +void zb_osif_serial_set_cb_recv_data(serial_recv_data_cb_t cb); + +/** + Send data over serial interface. + + @param buf - pointer to the buffer with data to send + @param len - length of the buffer + */ +void zb_osif_serial_send_data(zb_uint8_t *buf, zb_ushort_t len); + +/** + Set serial interface callback for transmission completion. + + @param cb - transmission completion callback + */ +void zb_osif_serial_set_cb_send_data(serial_send_data_cb_t cb); + +#endif /* ZB_HAVE_ASYNC_SERIAL */ +#endif /* ZB_HAVE_SERIAL || DOXYGEN */ + +#if defined ZB_BINARY_TRACE || defined ZB_HAVE_SERIAL || defined ZB_TRACE_OVER_USART || defined DOXYGEN || defined ZB_NSNG + +/** + TX data over UART + + Put data to internal buffer to be transmitted over UART. + It is guaranteed that all data will be sent. + Block is no space in the buffer waiting for previous TX complete. + + Note: this is low level routine. Its direct usage may conflict with ZBOSS + debug trace and traffic dump (if enabled). + + @param buf data buffer + @param len data length. + */ +void zb_osif_serial_put_bytes(zb_uint8_t *buf, zb_short_t len); +#endif + +/*! @} */ + + + +#ifdef ZB_TRACE_OVER_SIF +void zb_osif_sif_put_bytes(zb_uint8_t *buf, zb_short_t len); +void zb_osif_sif_init(void); +zb_void_t zb_osif_sif_debug_trace(zb_uint8_t param); +#endif + +#ifdef ZB_HAVE_FILE +/* File */ +zb_uint32_t zb_osif_get_file_size(zb_char_t *name); +zb_bool_t zb_osif_check_file_exist(const zb_char_t *name, const zb_uint8_t mode); +void zb_osif_file_copy(const zb_char_t *name_src, const zb_char_t *name_dst); +zb_osif_file_t *zb_osif_file_open(const zb_char_t *name, const zb_char_t *mode); +zb_osif_file_t *zb_osif_init_trace(zb_char_t *name); +zb_osif_file_t *zb_osif_file_stdout(void); +void zb_osif_file_close(zb_osif_file_t *f); +int zb_osif_file_remove(const zb_char_t *name); +void zb_osif_trace_printf(zb_osif_file_t *f, zb_char_t *format, ...); +void zb_osif_trace_vprintf(zb_osif_file_t *f, zb_char_t *format, va_list arglist); +void zb_osif_trace_lock(void); +void zb_osif_trace_unlock(void); +zb_osif_file_t *zb_osif_init_dump(zb_char_t *name); +int zb_osif_file_read(zb_osif_file_t *f, zb_uint8_t *buf, zb_uint_t len); +int zb_osif_file_write(zb_osif_file_t *f, zb_uint8_t *buf, zb_uint_t len); +int zb_osif_file_flush(zb_osif_file_t *f); +int zb_osif_file_seek(zb_osif_file_t *f, zb_uint32_t off, zb_uint8_t mode); +int zb_osif_file_truncate(zb_osif_file_t *f, zb_uint32_t off); +int zb_osif_file_sync(zb_osif_file_t *f); +void zb_osif_trace_get_time(zb_uint_t *sec, zb_uint_t *msec); +zb_osif_file_t *zb_osif_popen(zb_char_t *arg); + +enum zb_file_path_base_type_e +{ + ZB_FILE_PATH_BASE_ROMFS_BINARIES, /* ROM FS */ /* elf binaries, etc */ + ZB_FILE_PATH_BASE_MNTFS_BINARIES, /* RW FS */ /* prod config, etc */ + ZB_FILE_PATH_BASE_MNTFS_USER_DATA, /* RW FS */ /* nvram. etc */ + ZB_FILE_PATH_BASE_RAMFS_UNIX_SOCKET, /* RAM FS */ + ZB_FILE_PATH_BASE_RAMFS_TRACE_LOGS, /* RAM FS */ + ZB_FILE_PATH_BASE_RAMFS_TMP_DATA, /* RAM FS */ + + ZB_FILE_PATH_BASE_MAX_TYPE +}; + +#define ZB_MAX_FILE_PATH_SIZE 256 + +#ifdef ZB_FILE_PATH_MGMNT +#ifndef ZB_FILE_PATH_MAX_TYPES +#define ZB_FILE_PATH_MAX_TYPES (ZB_FILE_PATH_BASE_MAX_TYPE - 1) +#endif + +typedef struct zb_file_path_base_type_s +{ + zb_bool_t declared; + char base[ZB_MAX_FILE_PATH_SIZE]; +} zb_file_path_base_type_t; + +void zb_file_path_init(void); +zb_ret_t zb_file_path_declare(zb_uint8_t base_type, const char *base); +const char* zb_file_path_get(zb_uint8_t base_type, const char *default_base); +void zb_file_path_get_with_postfix(zb_uint8_t base_type, const char *default_base, const char *postfix, char *file_path); +#define ZB_FILE_PATH_GET(base_type, default_base) \ + zb_file_path_get(base_type, default_base) +#define ZB_FILE_PATH_GET_WITH_POSTFIX(base_type, default_base, postfix, file_path) \ + zb_file_path_get_with_postfix(base_type, default_base, postfix, file_path) +#else +#define ZB_FILE_PATH_GET(base_type, default_base) default_base +#define ZB_FILE_PATH_GET_WITH_POSTFIX(base_type, default_base, postfix, file_path) \ + { \ + zb_uint_t sn_ret; \ + sn_ret = snprintf(file_path, ZB_MAX_FILE_PATH_SIZE, "%s", (default_base postfix)); \ + ZB_ASSERT(sn_ret > 0); \ + ZB_ASSERT(sn_ret < ZB_MAX_FILE_PATH_SIZE); \ + } +#endif /* ZB_FILE_PATH_MGMNT */ +#endif /* ZB_HAVE_FILE */ + +/*! \addtogroup zb_platform */ +/*! @{ */ + +/** + Platform dependent soft reset +*/ +zb_void_t zb_reset(zb_uint8_t param); +zb_void_t zb_syslog_msg(const zb_char_t *msg); + +/*! @} */ + +/** + * + * @brief Get stack current parameters. + * + * @param s_head [OUT] - pointer to stack head. + * @param s_size [OUT] - current size of stack. + * @param s_direction [OUT] - stack growing direction (ZB_TRUE - UP, ZB_FALSE - DOWN). + */ +void zb_osif_get_stack(zb_uint8_t **s_head, zb_uint32_t *s_size, zb_uint8_t *s_direction); + +void osif_set_reset_at_crash(void); +void osif_handle_crash(void); + +#if defined ZB_USE_NVRAM || defined doxygen +/** + * @brief osif NVRAM initializer + */ +void zb_osif_nvram_init(const zb_char_t *name); + +/** + * @brief Get NVRAM page length + * + * @return NVRAM page length + */ +zb_uint32_t zb_get_nvram_page_length(void); + +/** + * @brief Get NVRAM page count + * + * @return NVRAM page count + */ +zb_uint8_t zb_get_nvram_page_count(void); + +/** + * @brief Read from NVRAM directly, by address + * Read some bytes from NVRAM use address + * + * @param address - NVRAM address + * @param len - count bytes from read data + * @param buf - (in) buffer for contains read data + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_read_memory(zb_uint32_t address, zb_uint16_t len, zb_uint8_t *buf); + +/** + * @brief Read from NVRAM page + * Read some bytes from NVRAM + * + * @param page - NVRAM page + * @param pos - Start position + * @param buf - (in) buffer for contains read data + * @param len - count bytes from read data + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_read(zb_uint8_t page, zb_uint32_t pos, zb_uint8_t *buf, zb_uint16_t len ); + +/** + * @brief Read from NVRAM page with test + * Read some bytes from NVRAM with test contents. + * If all byte equal 0xFF then return RET_ERROR + * Exists not for all platforms. + * + * @param page - NVRAM page + * @param pos - Start position + * @param buf - (in) buffer for contains read data + * @param len - count bytes from read data + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_read_test(zb_uint8_t page, zb_uint32_t pos, zb_uint8_t *buf, zb_uint16_t len ); + +/** + * @brief Write from NVRAM page + * Write some bytes to NVRAM + * + * @param page - NVRAM page + * @param pos - Start position + * @param buf - buffer contains data for write + * @param len - count bytes for write data + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_write(zb_uint8_t page, zb_uint32_t pos, void *buf, zb_uint16_t len ); + +/** + * @brief Write to NVRAM directly, by address + * Write bytes into NVRAM use address + * + * @param address - NVRAM address + * @param len - count bytes for write data + * @param buf - (in) buffer contains data to write + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_write_memory(zb_uint32_t address, zb_uint16_t len, zb_uint8_t *buf); + +/** + * @brief Erase NVRAM directly, by address + * + * @param address - NVRAM address + * @param len - count bytes for erase, aligned + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_erase_memory(zb_uint32_t address, zb_uint32_t len); + + +/** + * @brief Erase NVRAM page + * Fill NVRAM page by 0xFF. + * + * @param page - page index + * + * @return RET_OK if success or code error + */ +zb_ret_t zb_osif_nvram_erase_async(zb_uint8_t page); + +void zb_osif_nvram_wait_for_last_op(void); + +/** + * @brief Flush NVRAM page + * Flish NVRAM page to file or NVRAM. + * Different to hardware device + * + */ +void zb_osif_nvram_flush(void); + +#endif + +#ifdef ZB_USE_OSIF_OTA_ROUTINES +/** + * @addtogroup ll + * @{ + */ + +/** + * @defgroup ota Low level API for OTA + */ +/*! @{ */ + +/** + * Size of sub-element includes OTA header. + * + * @see Zigbee Cluster Library specification revision 7 subsection 11.4.3 Sub-element Format + */ +#define OTA_UPGRADE_HEADING_DATA \ + (sizeof(zb_zcl_ota_upgrade_file_header_t) + 2 /* fw tag Id */ + 4 /* fw length */) + +/** + * Size of the OTA image hash. + * + * @see Zigbee Cluster Library specification revision 7 subsection 11.7.2.1 Hash Value Calculation + */ +#define OTA_UPGRADE_HASH_SIZE 16 + +/** + * Size of sub-element includes a hash value. + * + * @see Zigbee Cluster Library specification revision 7 subsection 11.4.8 Image Integrity Code Sub-element + */ +#define OTA_UPGRADE_TRAILING_DATA \ + (2 /* hash tag Id */ + 4 /* hash length */ + OTA_UPGRADE_HASH_SIZE /* Hash */) + + +/** + Open device to be used for OTA image write or read. + + Take into account which flash (A or B) current FW is running at. + @see zb_osif_ota_close_storage + + @return handle + */ +void *zb_osif_ota_open_storage(void); + +/** + Close device used for OTA image write + + @param dev flash device handle used to write OTA image @see zb_osif_ota_open_storage +*/ +void zb_osif_ota_close_storage(void *dev); + +/** + Erase flash to be used for OTA image store. + + @note: offset and size must be aligned to minimal eraseable page boundary - + see zb_osif_ota_get_erase_portion(). + + @param dev flash device handle @see zb_osif_ota_open_storage + @param offset file offset in flash memory + @param size OTA file image size + */ +void zb_osif_ota_erase_fw(void *dev, zb_uint_t offset, zb_uint_t size); + +/** + Get portion of OTA storage which can be erased at once. + + @return erase block size in bytes + */ +zb_uint32_t zb_osif_ota_get_erase_portion(void); + +/** + Write OTA image data to flash. + + Deal with alignment. + + @param dev flash device handle @see zb_osif_ota_open_storage + @param data pointer to the data to write + @param off offset in OTA file + @param block_size amount of data to write + @param image_size total image size + */ +void zb_osif_ota_write(void *dev, zb_uint8_t *data, zb_uint32_t off, zb_uint32_t block_size, zb_uint32_t image_size); + +/** + Mark FW as downloaded and ready to use by bootloader. + + To be called when finishing OTA, after FW loaded and verified. + + @param ota_dev flash device handle used to write OTA image @see zb_osif_ota_open_storage + @param size OTA image size, without CRC + @param revision OTA image revision + */ +void zb_osif_ota_mark_fw_ready(void *ota_dev, zb_uint32_t size, zb_uint32_t revision); + + +/** + Mark new FW as absent so bootloader does not attempt to re-flash it. + + To be called when starting OTA. + */ +void zb_osif_ota_mark_fw_absent(void); + + +/** + Mark FW upgrade finished, so bootloader just loads current FW. + + To be called from newly started application FW. + Usually not need to be called by the application. ZBOSS kernel cares about it. + */ +void zb_osif_ota_mark_fw_updated(void); + +/** + Verify OTA file image written to device @p dev. + + @param dev flash device handle used to write OTA image @see zb_osif_ota_open_storage + @param raw_len - OTA image file length + @return ZB_TRUE if ok, ZB_FALSE if error + */ +zb_bool_t zb_osif_ota_verify_integrity(void *dev, zb_uint32_t raw_len); + +/** + Verify OTA file image written to device @p dev asynchronously. + + @param dev flash device handle used to write OTA image @see zb_osif_ota_open_storage + @param raw_len - OTA image file length + @return ZB_TRUE if ok, ZB_FALSE if error + */ +zb_bool_t zb_osif_ota_verify_integrity_async(void *dev, zb_uint32_t raw_len); + +/** + * Check whether OTA image recording was successful and finalize OTA. + * + * @param integrity_is_ok - is verification of OTA image recording successfull + */ +zb_void_t zb_osif_ota_verify_integrity_done(zb_uint8_t integrity_is_ok); + +/** + * Read OTA image data from flash. + * + * @param dev flash device handle @see zb_osif_ota_open_storage + * @param data pointer to the read data + * @param addr + * @param size amount of data to read + */ +void zb_osif_ota_read(void *dev, zb_uint8_t *data, zb_uint32_t addr, zb_uint32_t size); + +/** + Check whether the current device flash memory has enough space for the OTA file image. + + @param image_size OTA file image size + @return ZB_TRUE if ok, ZB_FALSE if error + */ +zb_bool_t zb_osif_ota_fw_size_ok(zb_uint32_t image_size); + +/** + Get OTA image data at OTA server + + @param dev flash device handle used to write OTA image @see zb_osif_ota_open_storage + @param offset offset in the OTA image + @param len - length of image block to get + @return pointer to image block + */ +zb_uint8_t *zb_osif_ota_srv_get_image(void *dev, zb_uint32_t offset, zb_uint32_t len); + +/** + Get OTA header at OTA server + + @param dev flash device handle used to write OTA image @see zb_osif_ota_open_storage + @return pointer to header block + */ +zb_uint8_t *zb_osif_ota_srv_get_image_header(void *dev); + +/** @} */ /* ota */ +/** @} */ /* ll */ + +#endif /* ZB_USE_OSIF_OTA_ROUTINES */ + +#if defined ZB_PROFILE_STACK_USAGE +/* Both functions are platform-specific */ + +/** + * @brief Prepare stack profiler. + * Fill stack area with a predefined pattern. + * + */ +zb_void_t zb_stack_profiler_pre(void); + +/** + * @brief Get stack usage by previously called function. + * + * @return Count of bytes in stack area used + */ +zb_uint16_t zb_stack_profiler_usage(void); + +#endif /* ZB_PROFILE_STACK_USAGE */ + + +#ifdef ZB_USE_SLEEP +zb_uint32_t zb_osif_sleep(zb_uint32_t sleep_tmo); +zb_void_t zb_osif_wake_up(void); +#endif + +#ifdef ZB_PRODUCTION_CONFIG + +/* Check whether production configuration block is present in memory */ +zb_bool_t zb_osif_production_configuration_check_presence(void); + +zb_bool_t zb_osif_production_configuration_check_header(void); + +/* Read data from production configuration header + * + * @param prod_cfg_hdr - pointer to production configarution header + * @param hdr_len - size of production configarution header + * + * @return RET_OK is success, RET_ERROR otherwise + */ +zb_ret_t zb_osif_production_configuration_read_header(zb_uint8_t *prod_cfg_hdr, zb_uint16_t hdr_len); + +/* Read data from production configuration block + * + * @param buffer - buffer to read into + * @param len - length of block to read + * @param offset - offset to read from + * + * @return + */ +zb_ret_t zb_osif_production_configuration_read(zb_uint8_t *buffer, zb_uint16_t len, zb_uint16_t offset); + +/* Set transmit power of radio on selected channel + * + * @param channel - channle on which radio applies new transmit power + * @param power - transmit power in dBm + * + * return RET_OK if power was set successfully, RET_ERROR otherwise + */ +zb_ret_t zb_osif_set_transmit_power(zb_uint8_t channel, zb_int8_t power); + +#endif + +/* Wait for a given number of empty cycle iterations. Timeout of 1 iteration is platform-specific + * + * @param count - number of empty wait cycles + */ +void zb_osif_busy_loop_delay(zb_uint32_t count); + + +/* Get OSIF timer counter value in microseconds + * + * @return Timer counter value in microseconds + */ +zb_uint16_t zb_osif_get_timer_reminder(void); + +#endif /* ZB_OSIF_H */ diff --git a/zboss/include/zb_pooled_list.h b/zboss/include/zb_pooled_list.h new file mode 100644 index 0000000000..a77cc97225 --- /dev/null +++ b/zboss/include/zb_pooled_list.h @@ -0,0 +1,612 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: simple lists operations (macroses). Use 1- or 2-bytes insed +instead of pointer. +*/ +#ifndef POOLED_LIST_H +#define POOLED_LIST_H 1 + +/*! @cond internals_doc */ +/** + @addtogroup ZB_BASE + @{ +*/ + + +#ifndef ZB_POOLED_LIST_INCLUDED +#define ZB_POOLED_LIST_INCLUDED + +#define ZP_POOLED_LIST_NULL -1 + +#define ZP_TYPE8( x ) ( ( zb_uint8_t ) ( x ) ) +#define ZP_RIND8( x ) ( ( x ) - ZP_TYPE8( 1 ) ) + +#define ZP_TYPE16( x ) ( ( zb_uint16_t ) ( x ) ) +#define ZP_RIND16( x ) ( ( x ) - ZP_TYPE16( 1 ) ) + +#define ZP_NULL8 ( ZP_TYPE8 ( ZP_POOLED_LIST_NULL ) ) +#define ZP_NULL16 ( ZP_TYPE16 ( ZP_POOLED_LIST_NULL ) ) + +#define ZB_POOLED_LIST8_FIELD( link_field ) zb_uint8_t link_field ## _next; zb_uint8_t link_field ## _prev +#define ZB_POOLED_LIST16_FIELD( link_field ) zb_uint16_t link_field ## _next; zb_uint16_t link_field ## _prev + +#define ZB_POOLED_LIST8_DEF( list ) zb_uint8_t list = ZP_NULL8 +#define ZB_POOLED_LIST16_DEF( list ) zb_uint16_t list = ZP_NULL16 + +#define ZB_POOLED_LIST8_DEFINE( list ) zb_uint8_t list +#define ZB_POOLED_LIST16_DEFINE( list ) zb_uint16_t list + + +#define ZB_POOLED_LIST8_INIT( list ) (list) = ZP_NULL8 +#define ZB_POOLED_LIST16_INIT( list ) (list) = ZP_NULL16 + + +#define ZB_POOLED_LIST8_IS_EMPTY( list ) ( ( list ) == ZP_NULL8 ) +#define ZB_POOLED_LIST8_IS_NOT_EMPTY( list ) ( ( list ) != ZP_NULL8 ) + +#define ZB_POOLED_LIST16_IS_EMPTY( list ) ( ( list ) == ZP_NULL16 ) +#define ZB_POOLED_LIST16_IS_NOT_EMPTY( list ) ( ( list ) != ZP_NULL16 ) + +#define ZB_POOLED_LIST8_NEXT( base, index, link_field ) ( ( ZP_NULL8 == index ) ? ZP_NULL8 : base[ index ].link_field##_next) +#define ZB_POOLED_LIST8_PREV( base, index, link_field ) ( ( ZP_NULL8 == index ) ? ZP_NULL8 : base[ index ].link_field##_prev) + +#define ZB_POOLED_LIST8_GET_HEAD( base, list, link_field ) ( list ) +#define ZB_POOLED_LIST8_GET_TAIL( base, list, link_field ) ( ( ZP_NULL8 != list ) ? base[ list ].link_field##_prev : ZP_NULL8 ) + +#define ZB_POOLED_LIST16_GET_HEAD( base, list, link_field ) ( list ) +#define ZB_POOLED_LIST16_GET_TAIL( base, list, link_field ) ( ( ZP_NULL16 != list ) ? base[ list ].link_field##_prev : ZP_NULL16 ) + +#define ZB_POOLED_LIST16_NEXT( base, index, link_field ) ( ( ZP_NULL16 == index ) ) ? ZP_NULL16 : base[ index ].link_field##_next ) ) +#define ZB_POOLED_LIST16_PREV( base, index, link_field ) ( ( ZP_NULL16 == index ) ) ? ZP_NULL16 : base[ index ].link_field##_prev ) ) + +/** + Remove element from the list head, and store it in removed_entry + */ + +#define ZB_POOLED_LIST8_CUT_HEAD( base,list, link_field, removed_elem_index ) do \ +{ \ + removed_elem_index = list; \ + if( ( list ) != ZP_NULL8 ) \ + { \ + if( base[ list ].link_field##_next != ZP_NULL8 ) \ + { \ + base[ base[ list ].link_field##_next ].link_field##_prev = \ + base[ list ].link_field##_prev; \ + } \ + base[ list ].link_field##_prev = ZP_NULL8; \ + ( list ) = base[ list ].link_field##_next ; \ + } \ +} while (0) \ + + +/** + Insert to the list head + */ + +#define ZB_POOLED_LIST8_INSERT_HEAD( base, list, link_field, elem_index ) do \ +{ \ + ZB_ASSERT( ( elem_index ) != ZP_NULL8 ); \ + base[ elem_index ].link_field##_next = ( list ); \ + if( ( list ) != ZP_NULL8 ) \ + { \ + base[ elem_index ].link_field##_prev = base[ list ].link_field##_prev; \ + base[ list ].link_field##_prev = elem_index ; \ + } \ + else \ + { \ + base[ elem_index ].link_field##_prev = elem_index; \ + } \ + ( list ) = ( elem_index ); \ +} while( 0 ) + + +/** + Insert to the list tail + */ + +#define ZB_POOLED_LIST8_INSERT_TAIL( base, list, link_field, elem_index ) do \ +{ \ + ZB_ASSERT( ( elem_index ) != ZP_NULL8 ); \ + base[ elem_index ].link_field##_next = ZP_NULL8; \ + if( ( list ) != ZP_NULL8 ) \ + { \ + base[ elem_index ].link_field##_prev = base[ list ].link_field##_prev; \ + base[ base[ list ].link_field##_prev ].link_field##_next = elem_index; \ + base[ list ].link_field##_prev = elem_index; \ + } \ + else \ + { \ + base[ elem_index ].link_field##_prev = elem_index; \ + ( list ) = ( elem_index ); \ + } \ +} while (0) + + +/** + Insert after existend elem_indexry + */ + +#define ZB_POOLED_LIST8_INSERT_AFTER( base, list, link_field, elem_index, new_elem_index ) do \ +{ \ + ZB_ASSERT( new_elem_index != ZP_NULL8 ); \ + if( elem_index != ZP_NULL8 ) \ + { \ + if( elem_index == ZB_POOLED_LIST8_GET_TAIL( base, list, link_field ) ) \ + { \ + ZB_POOLED_LIST8_INSERT_TAIL( base, list, link_field, new_elem_index ); \ + } \ + else \ + { \ + base[ new_elem_index ].link_field##_next = base[ elem_index ].link_field##_next ; \ + base[ new_elem_index ].link_field##_prev = elem_index; \ + base[ base[ elem_index ].link_field##_next ].link_field##_prev = new_elem_index; \ + base[ elem_index ].link_field##_next = ( new_elem_index ); \ + } \ + } \ +} while(0) + + +/** + Remove from the list head + */ + +#define ZB_POOLED_LIST8_REMOVE_HEAD( base, list, link_field ) do \ +{ \ + if( list != ZP_NULL8 ) \ + { \ + if( base[ list ].link_field##_next != ZP_NULL8 ) \ + { \ + base[ base[ list ].link_field##_next ].link_field##_prev = base[ list ].link_field##_prev; \ + } \ + base[ list ].link_field##_prev = ZP_NULL8; \ + list = base[ list ].link_field##_next; \ + } \ +} while (0) + +/** + Remove from the list tail + */ + +#define ZB_POOLED_LIST8_REMOVE_TAIL( base, list, link_field ) do \ +{ \ + if( list != ZP_NULL8 ) \ + { \ + if( base[ list ].link_field ## _prev == ( list ) ) /* made an empty list */ \ + { \ + base[ list ].link_field ## _prev = ZP_NULL8; \ + ( list ) = ZP_NULL8; \ + } \ + else \ + { \ + base[ base[ base[ list ].link_field##_prev ].link_field##_prev ].link_field##_next = ZP_NULL8; \ + \ + /* This is a bit tricky: we need to assign list->prev and set \ + * tail->prev to 0, but we can't use temporary variable because \ + * we have no type here. Use _next as temporary variable. */ \ + \ + base[ base[ list ].link_field##_prev ].link_field##_next = \ + base[ base[ list ].link_field##_prev ].link_field##_prev; \ + \ + base[ base[ list ].link_field##_prev ].link_field##_prev = ZP_NULL8; \ + \ + base[ list ].link_field##_prev = base[ base[ list ].link_field##_prev ].link_field##_next; \ + } \ + } \ +} while (0) + +#define ZB_POOLED_LIST8_ITERATE( base, list, link_field, elem_index ) \ + for( ( elem_index ) = ( list ) ; ( elem_index != ZP_NULL8 ) ; ( elem_index ) = base[ elem_index ].link_field##_next ) + + +#define ZB_POOLED_LIST8_ITERATE_BACK( base, list, link_field, elem_index) \ + for( ( elem_index ) = ( list ) ? base[ list ].link_field##_prev : ZP_NULL8; \ + ( elem_index != ZP_NULL8 ); \ + ( elem_index ) = ( ( base[ base[ elem_index ].link_field##_prev ].link_field##_next != ZP_NULL8 ) ? \ + base[ elem_index ].link_field##_prev : ZP_NULL8 ) ) + +/* NOTE! elem_index is just some index from base array, but not + ordinary number of the list. So, if you remove elem_index == 2, + it doesn't mean that you remove third element from the list. It means + just that you remove some element placed in base[ 2 ] from the list which can + be actualy any ordinary number of the list. +*/ + +#define ZB_POOLED_LIST8_REMOVE( base, list, link_field, elem_index ) \ +do \ +{ \ + ZB_ASSERT( elem_index != ZP_NULL8 ); \ + if( base[ elem_index ].link_field##_prev != ZP_NULL8 ) \ + { \ + if( base[ elem_index ].link_field##_next != ZP_NULL8 ) /* this is not a tail */ \ + { \ + base[ base[ elem_index ].link_field##_next ].link_field##_prev = base[ elem_index ].link_field##_prev; \ + } \ + else /* this is a tail */ \ + { \ + base[ list ].link_field##_prev = base[ elem_index ].link_field##_prev; \ + } \ + if( ( elem_index ) == ( list ) ) /* this is a head */ \ + { \ + ( list ) = base[ elem_index ].link_field##_next; \ + } \ + else /* this is not a head */ \ + { \ + base[ base[ elem_index ].link_field##_prev ].link_field##_next = base[ elem_index ].link_field##_next; \ + } \ + base[ elem_index ].link_field##_prev = ZP_NULL8; \ + } \ +} \ +while( 0 ) \ + + +/** + Remove element from the list head, and store it in removed_entry + */ +#define ZB_POOLED_LIST16_CUT_HEAD( base,list, link_field, removed_elem_index ) do \ +{ \ + ZB_ASSERT( removed_elem_index != ZP_NULL16 ); \ + removed_elem_index = list; \ + if( ( list ) != ZP_NULL16 ) \ + { \ + if( base[ list ].link_field##_next != ZP_NULL16 ) \ + { \ + base[ base[ list ].link_field##_next ].link_field##_prev = \ + base[ list ].link_field##_prev; \ + } \ + base[ list ].link_field##_prev = ZP_NULL16; \ + ( list ) = base[ list ].link_field##_next ; \ + } \ +} while (0) + + +/** + Insert to the list head + */ + +#define ZB_POOLED_LIST16_INSERT_HEAD( base, list, link_field, elem_index ) do \ +{ \ + ZB_ASSERT( ( elem_index ) != ZP_NULL16 ); \ + base[ elem_index ].link_field##_next = ( list ); \ + if( ( list ) != ZP_NULL16 ) \ + { \ + base[ elem_index ].link_field##_prev = base[ list ].link_field##_prev; \ + base[ list ].link_field##_prev = elem_index ; \ + } \ + else \ + { \ + base[ elem_index ].link_field##_prev = elem_index; \ + } \ + ( list ) = ( elem_index ); \ +} while( 0 ) + + +/** + Insert to the list tail + */ + +#define ZB_POOLED_LIST16_INSERT_TAIL( base, list, link_field, elem_index ) do \ +{ \ + ZB_ASSERT( ( elem_index ) != ZP_NULL16 ); \ + base[ elem_index ].link_field##_next = ZP_NULL16; \ + if( ( list ) != ZP_NULL16 ) \ + { \ + base[ elem_index ].link_field##_prev = base[ list ].link_field##_prev; \ + base[ base[ list ].link_field##_prev ].link_field##_next = elem_index; \ + base[ list ].link_field##_prev = elem_index; \ + } \ + else \ + { \ + base[ elem_index ].link_field##_prev = elem_index; \ + ( list ) = ( elem_index ); \ + } \ +} while (0) + + +/** + Insert after existend elem_indexry + */ + +#define ZB_POOLED_LIST16_INSERT_AFTER( base, list, link_field, elem_index, new_elem_index ) do \ +{ \ + ZB_ASSERT( new_elem_index != ZP_NULL16 ); \ + if( elem_index != ZP_NULL16 ) \ + { \ + if( elem_index == ZB_POOLED_LIST16_GET_TAIL( base, list, link_field ) ) \ + { \ + ZB_POOLED_LIST16_INSERT_TAIL( base, list, link_field, new_elem_index ); \ + } \ + else \ + { \ + base[ new_elem_index ].link_field##_next = base[ elem_index ].link_field##_next ; \ + base[ new_elem_index ].link_field##_prev = elem_index; \ + base[ base[ elem_index ].link_field##_next ].link_field##_prev = new_elem_index; \ + base[ elem_index ].link_field##_next = ( new_elem_index ); \ + } \ + } \ +} while(0) + + +/** + Remove from the list head + */ + +#define ZB_POOLED_LIST16_REMOVE_HEAD( base, list, link_field ) do \ +{ \ + if( list != ZP_NULL16 ) \ + { \ + if( base[ list ].link_field##_next != ZP_NULL16 ) \ + { \ + base[ base[ list ].link_field##_next ].link_field##_prev = base[ list ].link_field##_prev; \ + } \ + base[ list ].link_field##_prev = ZP_NULL16; \ + list = base[ list ].link_field##_next; \ + } \ +} while (0) + +/** + Remove from the list tail + */ + +#define ZB_POOLED_LIST16_REMOVE_TAIL( base, list, link_field ) do \ +{ \ + if( list != ZP_NULL16 ) \ + { \ + if( base[ list ].link_field ## _prev == ( list ) ) /* made an empty list */ \ + { \ + base[ list ].link_field ## _prev = ZP_NULL16; \ + ( list ) = ZP_NULL16; \ + } \ + else \ + { \ + base[ base[ base[ list ].link_field##_prev ].link_field##_prev ].link_field##_next = ZP_NULL16; \ + \ + /* This is a bit tricky: we need to assign list->prev and set \ + * tail->prev to 0, but we can't use temporary variable because \ + * we have no type here. Use _next as temporary variable. */ \ + \ + base[ base[ list ].link_field##_prev ].link_field##_next = \ + base[ base[ list ].link_field##_prev ].link_field##_prev; \ + \ + base[ base[ list ].link_field##_prev ].link_field##_prev = ZP_NULL16; \ + \ + base[ list ].link_field##_prev = base[ base[ list ].link_field##_prev ].link_field##_next; \ + } \ + } \ +} while (0) + +#define ZB_POOLED_LIST16_ITERATE( base, list, link_field, elem_index ) \ + for( ( elem_index ) = ( list ) ; ( elem_index != ZP_NULL16 ) ; ( elem_index ) = base[ elem_index ].link_field##_next ) + + +#define ZB_POOLED_LIST16_ITERATE_BACK( base, list, link_field, elem_index) \ + for( ( elem_index ) = ( list ) ? base[ list ].link_field##_prev : ZP_NULL16; \ + ( elem_index != ZP_NULL16 ); \ + ( elem_index ) = ( ( base[ base[ elem_index ].link_field##_prev ].link_field##_next != ZP_NULL16 ) ? \ + base[ elem_index ].link_field##_prev : ZP_NULL16 ) ) + +/* NOTE! elem_index is just some index from base array, but not + ordinary number of the list. So, if you remove elem_index == 2, + it doesn't mean that you remove third element from the list. It means + just that you remove some element placed in base[ 2 ] from the list which can + be actualy any ordinary number of the list. +*/ + +#define ZB_POOLED_LIST16_REMOVE( base, list, link_field, elem_index ) \ +do \ +{ \ + ZB_ASSERT( elem_index != ZP_NULL16 ); \ + if( base[ elem_index ].link_field##_prev != ZP_NULL16 ) \ + { \ + if( base[ elem_index ].link_field##_next != ZP_NULL16 ) /* this is not a tail */ \ + { \ + base[ base[ elem_index ].link_field##_next ].link_field##_prev = base[ elem_index ].link_field##_prev; \ + } \ + else /* this is a tail */ \ + { \ + base[ list ].link_field##_prev = base[ elem_index ].link_field##_prev; \ + } \ + if( ( elem_index ) == ( list ) ) /* this is a head */ \ + { \ + ( list ) = base[ elem_index ].link_field##_next; \ + } \ + else /* this is not a head */ \ + { \ + base[ base[ elem_index ].link_field##_prev ].link_field##_next = base[ elem_index ].link_field##_next; \ + } \ + base[ elem_index ].link_field##_prev = ZP_NULL16; \ + } \ +} \ +while( 0 ) + + +/* Single liked lists */ +#define ZP_POOLED_SL_LIST8_NULL 255 + + +#define ZB_POOLED_SL_LIST8_DEFINE(type, list) type list ## _head; type list ## _tail + +#define ZB_POOLED_SL_LIST8_INIT(list) list ## _head = ZP_POOLED_SL_LIST8_NULL; list ## _tail = ZP_POOLED_SL_LIST8_NULL + + +#define ZB_POOLED_SL_LIST8_FIELD(type, name) type name ## _next + + +#define ZB_POOLED_SL_LIST8_NEXT(base, index, name) ( ( (index) == ZP_POOLED_SL_LIST8_NULL ) ? ZP_POOLED_SL_LIST8_NULL : (base)[index].name ## _next ) + +#define ZB_POOLED_SL_LIST8_HEAD(list) list ## _head + +#define ZB_POOLED_SL_LIST8_TAIL(list) list ## _tail + +#define ZB_POOLED_SL_LIST8_IS_EMPTY(list) ( list ## _head == ZP_POOLED_SL_LIST8_NULL ) +#define ZB_POOLED_SL_LIST8_IS_NOT_EMPTY(list) ( list ## _head != ZP_POOLED_SL_LIST8_NULL ) + + +/** + Insert to the list head + */ +#define ZB_POOLED_SL_LIST8_INSERT_HEAD(base, list, name, index) \ +do \ +{ \ + (base)[index].name ## _next = list ## _head; \ + if ( (list ## _head) + 1 == ZP_POOLED_SL_LIST8_NULL ) \ + { \ + (list ## _tail) = (index); \ + } \ + list ## _head = (index); \ +} while( 0 ) + + +/** + Insert to the list tail + */ +#define ZB_POOLED_SL_LIST8_INSERT_TAIL(base, list, name, index) \ +do \ +{ \ + (base)[index].name##_next = ZP_POOLED_SL_LIST8_NULL; \ + if ( (list ## _tail) != ZP_POOLED_SL_LIST8_NULL) \ + { \ + (base)[list ## _tail].name##_next = index; \ + list ## _tail = (index); \ + } \ + else \ + { \ + (list ## _head) = (index); \ + (list ## _tail) = (index); \ + } \ +} while (0) + + +/** + Remove from the list head + */ +#define ZB_POOLED_SL_LIST8_REMOVE_HEAD(base, list, name) \ +do \ +{ \ + if ( (list ## _head) != ZP_POOLED_SL_LIST8_NULL ) \ + { \ + list ## _head = (base)[list ## _head].name ## _next; \ + if ( (list ## _head) == ZP_POOLED_SL_LIST8_NULL) \ + { \ + (list ## _tail) = ZP_POOLED_SL_LIST8_NULL; \ + } \ + } \ +} while (0) + + +/** + Remove element from the list head, and store it in index + */ +#define ZB_POOLED_SL_LIST8_CUT_HEAD(base, list, name, index) \ +do \ +{ \ + if ( (list ## _head) != ZP_POOLED_SL_LIST8_NULL ) \ + { \ + (index) = (list ## _head); \ + (list ## _head) = (base)[list ## _head].name ## _next; \ + if ( (list ## _head) == ZP_POOLED_SL_LIST8_NULL) \ + { \ + (list ## _tail) = ZP_POOLED_SL_LIST8_NULL; \ + } \ + } \ + else \ + { \ + (index) = ZP_POOLED_SL_LIST8_NULL; \ + } \ +} while (0) + + +/** + Remove element from the list tail + */ +#define ZB_POOLED_SL_LIST8_CUT_TAIL(base, list, name, index) \ +do \ +{ \ + (index) = (list ## _tail); \ + ZB_POOLED_SL_LIST8_REMOVE(base, list, name, index); \ +} while (0) + + +/** + Remove index from list + */ +#define ZB_POOLED_SL_LIST8_REMOVE(base, list, name, index) \ +do \ +{ \ + zb_uint8_t p; \ + zb_uint8_t prev = ZP_POOLED_SL_LIST8_NULL; \ + for (p = (list ## _head); \ + p != ZP_POOLED_SL_LIST8_NULL; \ + prev = p, p = (base)[p].name ## _next ) \ + { \ + if ( p == (index) ) \ + { \ + if ( prev != ZP_POOLED_SL_LIST8_NULL ) \ + { \ + (base)[prev].name ## _next = (base)[p].name ## _next; \ + if ((list ## _tail) == index) \ + { \ + (list ## _tail) = prev; \ + } \ + } \ + else \ + { \ + (list ## _head) = (base)[p].name ## _next; \ + } \ + if ( (list ## _head) == ZP_POOLED_SL_LIST8_NULL ) \ + { \ + (list ## _tail) = ZP_POOLED_SL_LIST8_NULL; \ + } \ + break; \ + } \ + } \ +} \ +while( 0 ) + + +#define ZB_POOLED_SL_LIST8_ITERATE(base, list, name, index) \ + for( (index) = (list); (index != ZP_POOLED_SL_LIST8_NULL); (index) = base[index].name##_next ) + +#endif + +/*! @} */ +/*! @endcond */ + +#endif diff --git a/zboss/include/zb_ringbuffer.h b/zboss/include/zb_ringbuffer.h new file mode 100644 index 0000000000..8d72e8ec2e --- /dev/null +++ b/zboss/include/zb_ringbuffer.h @@ -0,0 +1,516 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Declare ring buffer internals +*/ + +#ifndef ZB_RINGBUFFER_H +#define ZB_RINGBUFFER_H 1 + +/*! @cond internals_doc */ +/** + @addtogroup ZB_BASE + @{ +*/ + + +/** + \par Generic ring buffer macros + */ + +/** + Declare ring buffer for entries of given type and capacity. + This is typedef, not variable declaration. + + @param type_name_prefix - prefix for names (like xxx_s, xxx_t) + @param ent_type - type of the ring buffer entry + @param capacity - ring buffer capacity + */ +#define ZB_RING_BUFFER_DECLARE(type_name_prefix, ent_type, capacity) \ +typedef struct type_name_prefix ## _s \ +{ \ + zb_ushort_t read_i; \ + zb_ushort_t write_i; \ + zb_ushort_t written; \ + ent_type ring_buf[capacity]; \ +} type_name_prefix ## _t + + +/** + * Initialize ring buffer internals + */ +#define ZB_RING_BUFFER_INIT(rb) ( (rb)->read_i = (rb)->write_i = (rb)->written = 0) + +/** + * Return ring buffer capacity + * + * @param rb - ring buffer pointer. + */ +#define ZB_RING_BUFFER_CAPACITY(rb) ((sizeof((rb)->ring_buf) / sizeof((rb)->ring_buf[0]))) + +/** + * Return 1 if ring buffer is full + * + * @param rb - ring buffer pointer. + */ +#define ZB_RING_BUFFER_IS_FULL(rb) ((zb_uint_t)(rb)->written >= ZB_RING_BUFFER_CAPACITY(rb)) + +/** + * Return 1 if ring buffer is empty + * + * @param rb - ring buffer pointer. + */ +#define ZB_RING_BUFFER_IS_EMPTY(rb) ((rb)->written == 0) + + +/** + * Return free space available in the ring buffer + * + * @param rb - ring buffer pointer. + */ +#define ZB_RING_BUFFER_FREE_SPACE(rb) (ZB_RING_BUFFER_CAPACITY(rb) - (zb_uint_t)(rb)->written) + +/** + * Reserve slot in the ring buffer but do not update pointers + * + * @param rb - ring buffer pointer. + * @return Pointer to the ring buffer entry or NULL if ring buffer is full + */ +#define ZB_RING_BUFFER_PUT_RESERVE(rb) \ +( \ + ZB_RING_BUFFER_IS_FULL(rb) ? NULL \ + : (rb)->ring_buf + (rb)->write_i \ + ) + +#define ZB_RING_BUFFER_PUT_HEAD_RESERVE_IDX(rb) \ +( \ + ((rb)->read_i > 0) ? \ + ((rb)->read_i - 1) : (ZB_RING_BUFFER_CAPACITY(rb) - 1) \ + ) + +#define ZB_RING_BUFFER_PUT_HEAD_RESERVE(rb) \ +( \ + ZB_RING_BUFFER_IS_FULL(rb) ? NULL \ + : ((rb)->ring_buf + ZB_RING_BUFFER_PUT_HEAD_RESERVE_IDX(rb)) \ + ) + +/** + * Put to the ring buffer. + * Get free slot from the ring buffer, return pointer to it. + * + * @param rb - ring buffer pointer. + * @return nothing + */ +#define ZB_RING_BUFFER_FLUSH_PUT(rb) \ +( \ + (rb)->written++, \ + (rb)->write_i = ((rb)->write_i + 1) % ZB_RING_BUFFER_CAPACITY(rb) \ + ) + +#define ZB_RING_BUFFER_FLUSH_PUT_HEAD(rb) \ +{ \ + (rb)->written++; \ + if ((rb)->read_i > 0) \ + { \ + --((rb)->read_i); \ + } \ + else \ + { \ + (rb)->read_i = ZB_RING_BUFFER_CAPACITY(rb) - 1; \ + } \ +} + + + +/** + Return amount of data which can be put into ring buffer tail starting from write_i + + @param rb - ring buffer pointer + @param size - requested data size + */ +#define ZB_RING_BUFFER_LINEAR_PORTION(rb, size) \ +( \ + ZB_RING_BUFFER_CAPACITY(rb) - (rb)->write_i < size ? \ + ZB_RING_BUFFER_CAPACITY(rb) - (rb)->write_i : size \ +) + +/** + * Get the size of available for writing continuous portion in ring buffer. + * + * That portion is from write_i index to the end of the buffer or + * from write_i index to the beginning of previously written but still not read data + * + * @param buf - ring buffer pointer + * @return size of available continuous portion + */ +#define ZB_RING_BUFFER_AVAILABLE_CONTINUOUS_PORTION(rb) \ + ZB_RING_BUFFER_LINEAR_PORTION((rb), ZB_RING_BUFFER_FREE_SPACE(rb)) + +/** + Batch put data inro ringbuffer + + To be used to copy from external buffer to ring buffer + + @param rb - ring buffer pointer + @param data - data ptr + @param size - requested data size + @param written - (out) amount of data put + */ +#define ZB_RING_BUFFER_BATCH_PUT(rb, data, size, written) \ +{ \ + (written) = ZB_RING_BUFFER_LINEAR_PORTION((rb), (size)); \ + ZB_MEMCPY((rb)->ring_buf + (rb)->write_i, (data), (written)); \ + (rb)->written += (written); \ + (rb)->write_i = ((rb)->write_i + (written) % ZB_RING_BUFFER_CAPACITY(rb)); \ +} + + +/** + * Flush after put more then 1 element to the ring buffer + * + * Do not check for write_i overflow! + * + * @param rb - ring buffer pointer. + * @param size - number of items put + * @return nothing + */ +#define ZB_RING_BUFFER_FLUSH_BATCH_PUT(rb, size) \ +( \ + (rb)->written += size, \ + (rb)->write_i = (((rb)->write_i) + size) % ZB_RING_BUFFER_CAPACITY(rb) \ + ) + + +/** + * Put value to the ring buffer. + * + * @param rb - ring buffer pointer. + * @param value - value to put to ring buffer + * @return nothing + */ +#define ZB_RING_BUFFER_PUT(rb, value) \ +( \ + (rb)->ring_buf[(rb)->write_i] = (value), \ + (rb)->written++, \ + (rb)->write_i = ((rb)->write_i + 1) % ZB_RING_BUFFER_CAPACITY(rb) \ + ) + + +/** + * Put value to the ring buffer using memcpy. + * + * @param rb - ring buffer pointer. + * @param value_ptr - pointer to value to put to ring buffer + * @return nothing + */ +#define ZB_RING_BUFFER_PUT_PTR(rb, value_ptr) \ +( \ + memcpy(&((rb)->ring_buf[(rb)->write_i]), (value_ptr), sizeof((rb)->ring_buf[0])), \ + (rb)->written++, \ + (rb)->write_i = ((rb)->write_i + 1) % ZB_RING_BUFFER_CAPACITY(rb) \ + ) + + +/** + * Reinsert last value into the ring buffer using memcpy. + * + * @param rb - ring buffer pointer. + * @param value_ptr - pointer to value to put to ring buffer + * @return nothing + */ +#define ZB_RING_BUFFER_PUT_REUSE_LAST(rb, value_ptr) \ +( \ + memcpy(&((rb)->ring_buf[((rb)->write_i ? (rb)->write_i - 1 : (rb)->write_i + ZB_RING_BUFFER_CAPACITY(rb) - 1)]), \ + (value_ptr), \ + sizeof((rb)->ring_buf[0])) \ + ) + + +/** + * Get entry from the ring buffer read pointer position + * + * @param rb - ring buffer pointer. + * + * @return pointer to the ring buffer entry or NULL if it is empty + */ +#define ZB_RING_BUFFER_PEEK(rb) \ +( \ + ZB_RING_BUFFER_IS_EMPTY(rb) ? NULL \ + : (rb)->ring_buf + (rb)->read_i \ + ) + +/** + * Get entry from the ring buffer read pointer position + * + * @param rb - ring buffer pointer. + * + * @return pointer to the ring buffer entry + */ +#define ZB_RING_BUFFER_GET(rb) \ +( \ + (rb)->ring_buf + (rb)->read_i \ + ) + +/** + * Get entry from the ring buffer write pointer position + * + * @param rb - ring buffer pointer. + * + * @return pointer to the ring buffer entry + */ +#define ZB_RING_BUFFER_GETW(rb) \ +( (rb)->ring_buf + (rb)->write_i ) + +/** + * Move ring buffer read pointer. + * + * To be used after ZB_RING_BUFFER_PEEK(). + * @note This macro does not check for an empty ring buffer. + * + * @param rb - ring buffer pointer. + * @return nothing + */ +#define ZB_RING_BUFFER_FLUSH_GET(rb) \ +( \ + (rb)->written--, \ + ((rb)->read_i = ((rb)->read_i + 1) % ZB_RING_BUFFER_CAPACITY(rb)) \ + ) + + +/** + * Get entries from the ring buffer read pointer position which can be get at once + * + * @param rb - ring buffer pointer. + * @param size - (out) number of entries which can be got + * + * @return pointer to the ring buffer entry + */ +#define ZB_RING_BUFFER_GET_BATCH(rb, size) \ + ( \ + size = ((rb)->written <= (ZB_RING_BUFFER_CAPACITY(rb) - (rb)->read_i) \ + ? \ + (rb)->written \ + : \ + (ZB_RING_BUFFER_CAPACITY(rb) - (rb)->read_i)), \ + (rb)->ring_buf + (rb)->read_i \ + ) \ + + + +/** + * Move ring buffer read pointer for more than 1 element + * + * @note This macro does not check for empty ring buffer. + * + * @param rb - ring buffer pointer. + * @param size - number of elements to mark as read + * @return nothing + */ +#define ZB_RING_BUFFER_FLUSH_GET_BATCH(rb, size) \ +( \ + (rb)->written -= size, \ + ((rb)->read_i = ((rb)->read_i + size) % ZB_RING_BUFFER_CAPACITY(rb)) \ + ) + +/** + * Move ring buffer's read and write pointers to the specified pos + * + * @param rb - ring buffer pointer. + * @param b - new position of read_i buffer's pointer + * @param e - new position of write_i buffer's pointer + * @return nothing + */ +#define ZB_RING_BUFFER_LOCATE(rb, b, e) \ + ( (rb)->read_i = b, \ + (rb)->write_i = e, \ + (rb)->written = e - b \ + ) + +/** + * Returns number of used entries + * + * @param rb - ring buffer pointer. + */ + +#define ZB_RING_BUFFER_USED_SPACE(rb) \ +( \ + (rb)->written \ + ) + +#define ZB_RING_BUFFER_SEARCH_GET(_rb, _i) \ +( \ + ZB_RING_BUFFER_IS_EMPTY(_rb) ? NULL \ + : (_rb)->ring_buf + ((_rb)->read_i +(_i)) % ZB_RING_BUFFER_CAPACITY(_rb) \ + ) + + +/** + * This is a fake type used for type casting. + * Represents array of bytes, used for serial trace e.t.c. + * + * @Example: + * @code + * ZB_RING_BUFFER_DECLARE(sniffer_io_buffer, zb_uint8_t, 4096); + * ... + * zb_osif_set_user_io_buffer((zb_byte_array_t*)&gs_sniffer_io_buf, 4096); + * @endcode + */ +ZB_RING_BUFFER_DECLARE(zb_byte_array, zb_uint8_t, 1); + +/** + * @see ZB_RING_BUFFER_IS_EMPTY + */ +#define ZB_BYTE_ARRAY_IS_EMPTY(rb) ZB_RING_BUFFER_IS_EMPTY(rb) + +/** + * @see ZB_RING_BUFFER_PEEK + */ +#define ZB_BYTE_ARRAY_PEEK(rb) ZB_RING_BUFFER_PEEK(rb) + +/** + * Return 1 if ring buffer is full + * + * @param rb - ring buffer pointer. + * @param cap - ring buffer capacity (number of bytes) + */ +#define ZB_BYTE_ARRAY_IS_FULL(rb, cap) ((zb_uint_t)(rb)->written >= cap) + +/** + * Move ring buffer read pointer. + * + * To be used after ZB_BYTE_ARRAY_PEEK(). + * @note This macro does not check for empty ring buffer. + * + * @param rb - ring buffer pointer. + * @param cap - ring buffer capacity (number of bytes) + * @return nothing + */ +#define ZB_BYTE_ARRAY_FLUSH_GET(rb, cap) \ +( \ + (rb)->written--, \ + ((rb)->read_i = ((rb)->read_i + 1) % cap) \ + ) + +/* 10/04/17 CR Ustimenko start */ +/** + * Get entries from the ring buffer read pointer position which can be get at once + * + * @param rb - ring buffer pointer. + * @param size - (out) number of entries which can be got + * @param cap - ring buffer capacity (number of bytes) + * + * @return pointer to the ring buffer entry + */ +#define ZB_BYTE_ARRAY_GET_BATCH(rb, size, cap) \ + ( \ + size = ((rb)->written <= (cap - (rb)->read_i) \ + ? \ + (rb)->written \ + : \ + (cap - (rb)->read_i)), \ + (rb)->ring_buf + (rb)->read_i \ + ) + +/** + * Move ring buffer read pointer for more than 1 element + * + * This macro does not check for an empty ring buffer. + * + * @param rb - ring buffer pointer. + * @param size - number of elements to mark as read + * @param cap - ring buffer capacity (number of bytes) + * @return nothing + */ +#define ZB_BYTE_ARRAY_FLUSH_GET_BATCH(rb, size, cap) \ +( \ + (rb)->written -= size, \ + ((rb)->read_i = ((rb)->read_i + size) % cap) \ + ) +/* 10/04/17 CR Ustimenko end */ + +/** + * Put value to the ring buffer. + * + * @param rb - ring buffer pointer. + * @param value - value to put to ring buffer + * @param cap - ring buffer capacity (number of bytes) + * @return nothing + */ +#define ZB_BYTE_ARRAY_PUT(rb, value, cap) \ +( \ + (rb)->ring_buf[(rb)->write_i] = (value), \ + (rb)->written++, \ + (rb)->write_i = ((rb)->write_i + 1) % cap \ + ) + +#define ZB_BYTE_ARRAY_PUT_HEAD_RESERVE_IDX(rb, cap) \ +( \ + ((rb)->read_i > 0) ? \ + ((rb)->read_i - 1) : ((cap) - 1) \ + ) + +#define ZB_BYTE_ARRAY_PUT_HEAD_RESERVE(rb, cap) \ +( \ + ((rb)->ring_buf + ZB_BYTE_ARRAY_PUT_HEAD_RESERVE_IDX(rb, (cap))) \ + ) + +#define ZB_BYTE_ARRAY_FLUSH_PUT_HEAD(rb, cap) \ +{ \ + (rb)->written++; \ + if ((rb)->read_i > 0) \ + { \ + --((rb)->read_i); \ + } \ + else \ + { \ + (rb)->read_i = (cap) - 1; \ + } \ +} + +#define ZB_BYTE_ARRAY_FLUSH_PUT(rb, cap) \ +( \ + (rb)->written++, \ + (rb)->write_i = ((rb)->write_i + 1) % (cap) \ + ) + +/*! @} */ +/*! @endcond */ + +#endif /* ZB_RINGBUFFER_H */ diff --git a/zboss/include/zb_trace.h b/zboss/include/zb_trace.h new file mode 100644 index 0000000000..449d917537 --- /dev/null +++ b/zboss/include/zb_trace.h @@ -0,0 +1,1085 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZigBee trace. Application should include it. +*/ +#ifndef ZB_LOGGER_H +#define ZB_LOGGER_H 1 + +/** @cond DOXYGEN_DEBUG_SECTION */ +/** + * @addtogroup ZB_TRACE Debug trace + * @{ + */ +/** @cond DSR_TRACE */ +/** + * @addtogroup ZB_TRACE_CONFIG Trace configuration + * @{ + */ +/** @endcond */ /* DSR_TARCE */ + +/** @cond internals_doc */ +extern zb_uint8_t g_trace_level, g_o_trace_level; +extern zb_uint16_t g_trace_mask; +extern zb_uint_t g_trace_inside_intr; +/** @endcond */ /* internals_doc */ + +/** + Set trace level at runtime + + That macro can switch trace level on and off. Trace level must be included + into build at compile time by setting ZB_TRACE_LEVEL compiler time define. + + @param l - new trace level. + + @par Example + @snippet thermostat/thermostat_zr/thermostat_zr.c set_trace + @par + */ +#define ZB_SET_TRACE_LEVEL(l) g_trace_level = (l); + +/** + Set trace mask at runtime + + That macro can switch trace mask on and off. Trace mask must be included + into build at compile time by setting ZB_TRACE_MASK compiler time define. + + @param m - new trace mask. + + @par Example + @snippet thermostat/thermostat_zr/thermostat_zr.c set_trace + @par + */ +#define ZB_SET_TRACE_MASK(m) g_trace_mask = (m); + +/** + Switch off all trace at runtime + */ +#define ZB_SET_TRACE_OFF() g_o_trace_level = g_trace_level, g_trace_level = 0 +/** + Switch on trace at runtime + + That macro enables trace which was active before call to ZB_SET_TRACE_OFF(). + + @snippet light_sample/dimmable_light/bulb.c switch_trace_on + */ +#define ZB_SET_TRACE_ON() g_trace_level = g_o_trace_level +/** @cond DSR_TRACE */ +/** @} */ /* ZB_TRACE_CONFIG */ +/** @endcond */ /* DSR_TRACE */ + +/** @cond DSR_TRACE */ +/** + * @addtogroup TRACE_SUBSYSTEMS + * @{ + */ +#define TRACE_SUBSYSTEM_COMMON 0x0001 /**< Common subsystem. */ +#define TRACE_SUBSYSTEM_MEM 0x0002 /**< MEM subsystem (buffers pool). */ +#define TRACE_SUBSYSTEM_MAC 0x0004 /**< MAC subsystem. */ +#define TRACE_SUBSYSTEM_NWK 0x0008 /**< NWK subsystem. */ + +#define TRACE_SUBSYSTEM_APS 0x0010 /**< APS subsystem. */ +#define TRACE_SUBSYSTEM_CLOUD 0x0020 /**< Interface to the Cloud if used, else free */ +#define TRACE_SUBSYSTEM_ZDO 0x0040 /**< ZDO subsystem. */ +#define TRACE_SUBSYSTEM_SECUR 0x0080 /**< Security subsystem. */ + +#define TRACE_SUBSYSTEM_ZCL 0x0100 /**< ZCL subsystem. */ +/** @cond DOXYGEN_ZLL_SECTION*/ +#define TRACE_SUBSYSTEM_ZLL 0x0200 /**< ZLL subsystem. */ +/** @endcond */ /* DOXYGEN_ZLL_SECTION */ +/** @cond internals_doc */ +#define TRACE_SUBSYSTEM_JSON TRACE_SUBSYSTEM_ZLL /**< JSON decoding is used in app, + * else free */ +#define TRACE_SUBSYSTEM_SSL 0x0400 /**< SSL subsystem */ +/** @endcond */ /* internals_doc */ +/** @endcond */ /* DSR_TRACE */ +#define TRACE_SUBSYSTEM_APP 0x0800 /**< User Application */ + +/** @cond internals_doc */ +#define TRACE_SUBSYSTEM_LWIP 0x1000 /* LWIP is used, else free */ +#define TRACE_SUBSYSTEM_ALIEN 0x2000 /* Some special debug */ +/** @endcond */ /* internals_doc */ +#define TRACE_SUBSYSTEM_ZGP 0x4000 /**< ZGP subsystem */ +/** @cond internals_doc */ +#define TRACE_SUBSYSTEM_USB 0x8000 +/** @endcond */ /* internals_doc */ + +#define TRACE_SUBSYSTEM_OTA TRACE_SUBSYSTEM_ZGP /**< OTA subsystem */ +#define TRACE_SUBSYSTEM_ZSE TRACE_SUBSYSTEM_CLOUD /**< ZSE subsystem. Not conflicting + * with cloud, let's use it */ + +/** @cond internals_doc */ +/* SPI trace usage is limited (now only in + * application\comcast\spi\css_sensor_spi.c). Not conflict with USB, so let's + * use it. */ +#define TRACE_SUBSYSTEM_SPI TRACE_SUBSYSTEM_USB +#define TRACE_SUBSYSTEM_HTTP TRACE_SUBSYSTEM_USB /* HTTP == LWIP usage (tcp), + * but not SSL */ + +#define TRACE_SUBSYSTEM_TRANSPORT TRACE_SUBSYSTEM_LWIP +#define TRACE_SUBSYSTEM_UART TRACE_SUBSYSTEM_LWIP + +#define TRACE_SUBSYSTEM_SPECIAL1 TRACE_SUBSYSTEM_ALIEN +#define TRACE_SUBSYSTEM_MACLL TRACE_SUBSYSTEM_ALIEN + +#define TRACE_SUBSYSTEM_BATTERY TRACE_SUBSYSTEM_SSL +#define TRACE_SUBSYSTEM_MAC_API TRACE_SUBSYSTEM_SSL +/** @endcond */ /* internals_doc */ +/* to be continued... */ + +/** @} */ /* TRACE_SUBSYSTEMS */ +/** @} */ /* ZB_TRACE */ + +/** @cond DSR_TRACE */ +/** + * @addtogroup ZB_TRACE Debug trace + * @{ + */ +#if defined ZB_TRACE_LEVEL || defined DOXYGEN +/** + * @addtogroup ZB_TRACE_CONFIG Trace configuration + * @{ + */ + +/** @cond internals_doc */ +#define TRACE_ENABLED_(mask,lev) ((lev) <= ZB_TRACE_LEVEL && ((mask) & ZB_TRACE_MASK)) +/** @endcond */ /* internals_doc */ + +/** + * @brief Check that trace is enabled for provided level. + * To be used in constructions like: + * @code + * if (TRACE_ENABLED(TRACE_APS3)) + * { + * call_some_complex_trace(); + * } + * @endcode + * @param m - trace level macro. + * @return 1 if enabled, 0 if disabled. + */ +#define TRACE_ENABLED(m) TRACE_ENABLED_(m) + +/** @cond internals_doc */ +zb_uint32_t zb_trace_get_counter(void); +/** @endcond */ /* internals_doc */ + +#ifdef DOXYGEN +/** + Trace file id used by win_com_dump to identify source file. + + Must be first define in the .c file, just before first include directive. + @par Example + @snippet light_sample/dimmable_light/bulb.c trace_file_id + @par +*/ +#define ZB_TRACE_FILE_ID 12345 +#endif +/** @} */ /* ZB_TRACE_CONFIG */ + +/** @cond internals_doc */ +#ifdef ZB_INTERRUPT_SAFE_CALLBACKS +/* If HW can detect that we are inside ISR, let's use it and do not trace from ISR. */ +zb_bool_t zb_osif_is_inside_isr(void); +#define ZB_HW_IS_INSIDE_ISR() zb_osif_is_inside_isr() +#else +#define ZB_HW_IS_INSIDE_ISR() 0 +#endif + +#define TRACE_ENTER_INT() g_trace_inside_intr = 1 +#define TRACE_LEAVE_INT() g_trace_inside_intr = 0 +#define ZB_TRACE_INSIDE_INTR() (g_trace_inside_intr || ZB_HW_IS_INSIDE_ISR()) + +#ifndef ZB_TRACE_FROM_INTR +#define ZB_TRACE_INSIDE_INTR_BLOCK() ZB_TRACE_INSIDE_INTR() +#else +#define ZB_TRACE_INSIDE_INTR_BLOCK() 0 +#endif +/** @endcond */ + +#if defined ZB_TRACE_TO_FILE || defined ZB_TRACE_TO_SYSLOG || defined DOXYGEN +/** @cond internals_doc */ +/** + \par Trace to file means trace to disk file using printf() or its analog. + Tricks to decrease code size by excluding format strings are not used. + */ +void zb_trace_init_file(zb_char_t *name); +void zb_trace_deinit_file(void); +void zb_file_trace_commit(void); + +/** + + Initialize trace subsystem + + @param name - trace file name component +*/ +#define TRACE_INIT(name) zb_trace_init_file(name) + +/** + Deinitialize trace subsystem +*/ +#define TRACE_DEINIT zb_trace_deinit_file + +#define _T0(...) __VA_ARGS__ + +#if defined ZB_BINARY_TRACE && !defined ZB_TRACE_TO_SYSLOG +/** + * @brief Print trace message. + */ +void zb_trace_msg_file( + zb_uint_t mask, + zb_uint_t level, + zb_uint16_t file_id, + zb_int_t line_number, + zb_int_t args_size, ...); + +#define _T1(s, l, fmts, args) if ((zb_int_t)ZB_TRACE_LEVEL>=(zb_int_t)l && ((s) & ZB_TRACE_MASK)) zb_trace_msg_file(s, l, _T0 args) +#else +/** + * @brief Print trace message. + */ +void zb_trace_msg_file( + zb_uint_t mask, + zb_uint_t level, + zb_char_t *format, + zb_char_t *file_name, + zb_int_t line_number, + zb_int_t args_size, ...); + +#define _T1(s, l, fmts, args) if ((zb_int_t)ZB_TRACE_LEVEL>=(zb_int_t)l && ((s) & ZB_TRACE_MASK)) zb_trace_msg_file(s, l, fmts, _T0 args) +#endif + +/** @endcond */ /* internals_doc */ + +/** + * @brief Put trace output. + * @param lm - trace subsystem and level marker. + * @param fmts - printf()-like format string. + * @param args - format string substitution parameters with a size marker. + * + * @par Example + * @snippet light_sample/dimmable_light/bulb.c trace_msg + * @par + */ +#define TRACE_MSG(lm, fmts, args) \ + do { \ + _T1(lm, fmts, args); \ + } while (0) + +#elif (defined ZB_TRACE_TO_PORT || defined ZB_TRACE_OVER_SIF) + +/* + 8051 trace does not use format string in the code to save code space. + +- will modify trace at device only, Linux will work as before +- trace implementation will hex dump all arguments as set of bytes +- external utility will parse dump, divide trace arguments dump into separate arguments and +convert hex-int, unsigned etc. +- utility will get argument strings from the source files (trace macros) and find it +by file:line +- Add one more parameter to the trace macro: sum of the trace argument sizes. +Define readable constants like +#define FMT_D_HD_X 5 +- create script/program to modify existing trace calls +- combine dump parse utility functionality with win_com_dump, so it will produce human-readable trace + + */ + +#ifdef ZB_TRACE_OVER_SIF +#define TRACE_INIT(name) zb_osif_sif_init() +#else +#ifndef ZB_SERIAL_FOR_TRACE +#define TRACE_INIT(name) +#else +#define TRACE_INIT(name) zb_osif_serial_init() +#endif +#endif +/* No trace deinit */ +#define TRACE_DEINIT() + +#ifndef ZB_BINARY_TRACE +void zb_trace_msg_port( + zb_char_t ZB_IAR_CODE *file_name, + zb_int_t line_number, + zb_uint8_t args_size, ...); + +#else + +#ifndef ZB_TRACE_FILE_ID +#ifndef ZB_DONT_NEED_TRACE_FILE_ID +#warning ZB_TRACE_FILE_ID undefined! Insert #define ZB_TRACE_FILE_ID NNN before 1-st #include +#endif +#define ZB_TRACE_FILE_ID 0 +#else +ZB_ASSERT_COMPILE_DECL(ZB_TRACE_FILE_ID < ZB_UINT16_MAX); +#endif + +void zb_trace_msg_port( + zb_uint_t mask, + zb_uint_t level, + zb_uint16_t file_id, + zb_uint16_t line_number, + zb_uint_t args_size, ...); + +#endif + +#ifdef ZB_BINARY_TRACE +#define _T0(...) __VA_ARGS__ +#define _T1(s, l, args) if ((zb_int_t)ZB_TRACE_LEVEL>=(zb_int_t)l && ((s) == (zb_uint_t)-1 || (s) & ZB_TRACE_MASK) && !ZB_TRACE_INSIDE_INTR_BLOCK()) zb_trace_msg_port(s, l, _T0 args) + +#else +#define _T1(s, l, args) \ + if ((zb_int_t)ZB_TRACE_LEVEL>=(zb_int_t)l && ((s) == -1 || ((s) & ZB_TRACE_MASK)) && !ZB_TRACE_INSIDE_INTR_BLOCK()) zb_trace_msg_port args +#endif + + +#define TRACE_MSG(lm, fmt, args) \ + do { \ + _T1(lm, args); \ + } while (0) + +#else + +#error Must define either ZB_TRACE_TO_FILE or ZB_TRACE_TO_PORT || ZB_TRACE_OVER_SIF + +#endif /* trace type */ + + +#else /* if trace off */ + +#ifndef KEIL +#define TRACE_MSG(...) +#else +/* Keil does not support vararg macros */ +#define TRACE_MSG(a,b,c) +#endif + +#define TRACE_INIT(name) +#define TRACE_DEINIT(c) + +#define TRACE_ENABLED(m) 0 + +#endif /* trace on/off */ + + +/** + * @addtogroup TRACE_DATA_FORMAT_ADDITIONAL Trace data format for keys + * @{ + */ +#if defined ZB_TRACE_TO_FILE || defined ZB_TRACE_TO_SYSLOG || defined DOXYGEN +/** + Trace format for 64-bit address. + + @snippet light_sample/dimmable_light/bulb.c trace_64_example_variable + @snippet light_sample/dimmable_light/bulb.c trace_64_example +*/ +#define TRACE_FORMAT_64 "%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx" + +/** + Trace format for 128-bit number (key etc). + + @snippet se/energy_service_interface/se_esi_zc.c TRACE_128 +*/ +#define TRACE_FORMAT_128 "%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx:%02hx" + +/** + Trace format arguments for 64-bit address. + + @snippet light_sample/dimmable_light/bulb.c trace_64_example_variable + @snippet light_sample/dimmable_light/bulb.c trace_64_example +*/ +#define TRACE_ARG_64(a) (zb_uint8_t)((a)[7]),(zb_uint8_t)((a)[6]),(zb_uint8_t)((a)[5]),(zb_uint8_t)((a)[4]),(zb_uint8_t)((a)[3]),(zb_uint8_t)((a)[2]),(zb_uint8_t)((a)[1]),(zb_uint8_t)((a)[0]) + +/** + Trace format arguments for 128-bit numver. + + @snippet se/energy_service_interface/se_esi_zc.c TRACE_128 +*/ +#define TRACE_ARG_128(a) (zb_uint8_t)((a)[0]),(zb_uint8_t)((a)[1]),(zb_uint8_t)((a)[2]),(zb_uint8_t)((a)[3]),(zb_uint8_t)((a)[4]),(zb_uint8_t)((a)[5]),(zb_uint8_t)((a)[6]),(zb_uint8_t)((a)[7]),(zb_uint8_t)((a)[8]),(zb_uint8_t)((a)[9]),(zb_uint8_t)((a)[10]),(zb_uint8_t)((a)[11]),(zb_uint8_t)((a)[12]),(zb_uint8_t)((a)[13]),(zb_uint8_t)((a)[14]),(zb_uint8_t)((a)[15]) + + +#else + +/** @brief Trace format for 64-bit address - single argument for 8051. */ +#define TRACE_FORMAT_64 "%A" +#define TRACE_FORMAT_128 "%A:%A" + +/** @cond internals_doc */ +typedef struct zb_addr64_struct_s +{ + zb_64bit_addr_t addr; +} ZB_PACKED_STRUCT zb_addr64_struct_t; + +typedef struct zb_byte128_struct_s +{ + zb_uint8_t d[16]; +} ZB_PACKED_STRUCT zb_byte128_struct_t; + +/* Pass 8-bytes address as structure by value */ +#define TRACE_ARG_64(a) *((zb_addr64_struct_t *)a) +/* Pass 16-bytes key as structure by value */ +#define TRACE_ARG_128(a) *((zb_byte128_struct_t *)a) +/** @endcond */ /* internals_doc */ + +#endif /* ti file / !to file */ +/** @} */ /* TRACE_DATA_FORMAT_ADDITIONAL */ + + + +/** @cond DSR_TRACE */ +/** + * @addtogroup TRACE_GENERAL_MESSAGES + * @{ + */ +/** @brief Error message. */ +#define TRACE_ERROR (zb_uint_t)-1, 1 +/** @brief Information message level 1. */ +#define TRACE_INFO1 (zb_uint_t)-1, 2 +/** @brief Information message level 2. */ +#define TRACE_INFO2 (zb_uint_t)-1, 3 +/** @brief Information message level 3. */ +#define TRACE_INFO3 (zb_uint_t)-1, 4 + +/** @} */ /* TRACE_GENERAL_MESSAGES */ + +#ifdef ZB_TRACE_LEVEL +#ifndef ZB_TRACE_MASK +#define ZB_TRACE_MASK -1 +#endif /* if not defined trace_mask */ +#endif /* if defined trace level */ + +/** + * @addtogroup TRACE_DATA_FORMAT + * @{ + */ + +/* + Trace format constants for serial trace +*/ + +/* Keil and sdcc put byte values to the stack as is, but IAR/8051 casts it to 16-bit + * integers, so constant lengths differs */ + +/** + * @brief Calculates trace argument size. + * @param n_h - number of Hs/Cs. + * @param n_d - number of Ds. + * @param n_l - number of Ls. + * @param n_p - number of Ps. + * @param n_a - number of As. + * @hideinitializer + */ +#ifdef KEIL + +/* Keil pass 1-byte to varargs as is, pointer is 3-bytes, short is 2-bytes */ + +#ifndef ZB_BINARY_TRACE +#define TRACE_ARG_SIZE(n_h, n_d, n_l, n_p, n_a) __FILE__,__LINE__, (n_h + n_d*2 + n_l*4 + n_p*3 + n_a*8) +#else +#define TRACE_ARG_SIZE(n_h, n_d, n_l, n_p, n_a) ZB_TRACE_FILE_ID,__LINE__, (n_h + n_d*2 + n_l*4 + n_p*3 + n_a*8) +#endif + +#else /* IAR & GCC - 32-bit */ +/* IAR for Cortex passes 1-byte abd 2-bytes arguments as 4-bytes to vararg functions. + * Pointers are 4-bytes. */ + +#if defined ZB_BINARY_TRACE && !defined ZB_TRACE_TO_SYSLOG +#define TRACE_ARG_SIZE(n_h, n_d, n_l, n_p, n_a) ZB_TRACE_FILE_ID,__LINE__, (n_h*4 + n_d*4 + n_l*4 + n_p*4 + n_a*8) +#else +#define TRACE_ARG_SIZE(n_h, n_d, n_l, n_p, n_a) __FILE__,__LINE__, (n_h*4 + n_d*4 + n_l*4 + n_p*4 + n_a*8) +#endif + +#endif + + +#define FMT__0 TRACE_ARG_SIZE(0,0,0,0,0) +#define FMT__A TRACE_ARG_SIZE(0,0,0,0,1) +#define FMT__A_A TRACE_ARG_SIZE(0,0,0,0,2) +#define FMT__A_A_A_A TRACE_ARG_SIZE(0,0,0,0,4) +#define FMT__A_D_A_P TRACE_ARG_SIZE(0,1,0,1,2) +#define FMT__A_D_D TRACE_ARG_SIZE(0,2,0,0,1) +#define FMT__A_D_D_P_H TRACE_ARG_SIZE(1,2,0,1,1) +#define FMT__A_D_H TRACE_ARG_SIZE(1,1,0,0,1) +#define FMT__A_D_P_H_H_H TRACE_ARG_SIZE(3,1,0,1,1) +#define FMT__A_H TRACE_ARG_SIZE(1,0,0,0,1) +#define FMT__A_H_H TRACE_ARG_SIZE(2,0,0,0,1) +#define FMT__A_H_H_H TRACE_ARG_SIZE(3,0,0,0,1) +#define FMT__A_D_H_H_H TRACE_ARG_SIZE(3,1,0,0,1) +#define FMT__A_P TRACE_ARG_SIZE(0,0,0,1,1) +#define FMT__AA TRACE_ARG_SIZE(0,0,0,0,2) +#define FMT__C TRACE_ARG_SIZE(1,0,0,0,0) +#define FMT__C_C_H_H TRACE_ARG_SIZE(4,0,0,0,0) +#define FMT__C_H TRACE_ARG_SIZE(2,0,0,0,0) +#define FMT__D TRACE_ARG_SIZE(0,1,0,0,0) +#define FMT__D_A TRACE_ARG_SIZE(0,1,0,0,1) +#define FMT__D_A_A_H TRACE_ARG_SIZE(1,1,0,0,2) +#define FMT__D_A_D_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,9,0,0,1) +#define FMT__D_A_D_P_H_H_H TRACE_ARG_SIZE(3,2,0,1,1) +#define FMT__D_A_H_H TRACE_ARG_SIZE(2,1,0,0,1) +#define FMT__D_A_P TRACE_ARG_SIZE(0,1,0,1,1) +#define FMT__D_C TRACE_ARG_SIZE(1,1,0,0,0) +#define FMT__D_D TRACE_ARG_SIZE(0,2,0,0,0) +#define FMT__D_D_A TRACE_ARG_SIZE(0,2,0,0,1) +#define FMT__D_D_A_A TRACE_ARG_SIZE(0,2,0,0,2) +#define FMT__D_D_A_D TRACE_ARG_SIZE(0,3,0,0,1) +#define FMT__D_D_A_D_D_D_D TRACE_ARG_SIZE(0,6,0,0,1) +#define FMT__D_D_D TRACE_ARG_SIZE(0,3,0,0,0) +#define FMT__D_D_D_C TRACE_ARG_SIZE(1,3,0,0,0) +#define FMT__D_D_D_D TRACE_ARG_SIZE(0,4,0,0,0) +#define FMT__D_D_D_D_D TRACE_ARG_SIZE(0,5,0,0,0) +#define FMT__D_D_D_D_D_D TRACE_ARG_SIZE(0,6,0,0,0) +#define FMT__D_D_D_D_D_D_D TRACE_ARG_SIZE(0,7,0,0,0) +#define FMT__D_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,8,0,0,0) +#define FMT__D_D_D_D_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,11,0,0,0) +#define FMT__D_D_D_D_D_D_D_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,14,0,0,0) +#define FMT__D_D_D_D_D_D_D_D_D_D_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,17,0,0,0) +#define FMT__D_D_D_D_D_D_P TRACE_ARG_SIZE(0,6,0,1,0) +#define FMT__D_D_D_D_H TRACE_ARG_SIZE(1,4,0,0,0) +#define FMT__D_D_D_H TRACE_ARG_SIZE(1,3,0,0,0) +#define FMT__D_D_D_H_H TRACE_ARG_SIZE(2,3,0,0,0) +#define FMT__D_D_D_L_L TRACE_ARG_SIZE(0,3,2,0,0) +#define FMT__D_D_D_P TRACE_ARG_SIZE(0,3,0,1,0) +#define FMT__D_D_H TRACE_ARG_SIZE(1,2,0,0,0) +#define FMT__D_D_H_D_H TRACE_ARG_SIZE(2,3,0,0,0) +#define FMT__D_D_H_H TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__D_D_H_P_D TRACE_ARG_SIZE(1,3,0,1,0) +#define FMT__D_D_L TRACE_ARG_SIZE(0,2,1,0,0) +#define FMT__D_D_L_P TRACE_ARG_SIZE(0,2,1,1,0) +#define FMT__D_D_P TRACE_ARG_SIZE(0,2,0,1,0) +#define FMT__D_D_P_D TRACE_ARG_SIZE(0,3,0,1,0) +#define FMT__D_D_P_D_D TRACE_ARG_SIZE(0,4,0,1,0) +#define FMT__D_D_P_D_L TRACE_ARG_SIZE(0,3,1,1,0) +#define FMT__D_D_P_H TRACE_ARG_SIZE(1,2,0,1,0) +#define FMT__D_D_P_H_H_H TRACE_ARG_SIZE(3,2,0,1,0) +#define FMT__D_D_P_P_P TRACE_ARG_SIZE(0,2,0,3,0) +#define FMT__D_H TRACE_ARG_SIZE(1,1,0,0,0) +#define FMT__D_H_D TRACE_ARG_SIZE(1,2,0,0,0) +#define FMT__D_H_D_D TRACE_ARG_SIZE(1,3,0,0,0) +#define FMT__D_H_D_D_H_D TRACE_ARG_SIZE(2,4,0,0,0) +#define FMT__D_H_D_H TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__D_H_D_H_H TRACE_ARG_SIZE(3,2,0,0,0) +#define FMT__D_H_D_P TRACE_ARG_SIZE(1,2,0,1,0) +#define FMT__D_H_D_P_D TRACE_ARG_SIZE(1,3,0,1,0) +#define FMT__D_H_H TRACE_ARG_SIZE(2,1,0,0,0) +#define FMT__D_H_H_D TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__D_H_H_D_D_D_D TRACE_ARG_SIZE(2,5,0,0,0) +#define FMT__D_H_H_H TRACE_ARG_SIZE(3,1,0,0,0) +#define FMT__D_H_H_H_H TRACE_ARG_SIZE(4,1,0,0,0) +#define FMT__D_H_H_H_H_H TRACE_ARG_SIZE(5,1,0,0,0) +#define FMT__D_H_H_H_H_H_H_D_D_D_D TRACE_ARG_SIZE(6,5,0,0,0) +#define FMT__D_H_L TRACE_ARG_SIZE(1,1,1,0,0) +#define FMT__D_H_P TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__D_L TRACE_ARG_SIZE(0,1,1,0,0) +#define FMT__D_L_L TRACE_ARG_SIZE(0,1,2,0,0) +#define FMT__D_L_L_D TRACE_ARG_SIZE(0,2,2,0,0) +#define FMT__D_L_L_H TRACE_ARG_SIZE(1,1,2,0,0) +#define FMT__D_L_L_L TRACE_ARG_SIZE(0,1,3,0,0) +#define FMT__D_P TRACE_ARG_SIZE(0,1,0,1,0) +#define FMT__D_P_D TRACE_ARG_SIZE(0,2,0,1,0) +#define FMT__D_P_D_D TRACE_ARG_SIZE(0,3,0,1,0) +#define FMT__D_P_H_H_D_D TRACE_ARG_SIZE(2,3,0,1,0) +#define FMT__D_P_H_H_D_H_H TRACE_ARG_SIZE(4,2,0,1,0) +#define FMT__D_P_H_H_H_H TRACE_ARG_SIZE(4,1,0,1,0) +#define FMT__D_P_H_H_H_H_H TRACE_ARG_SIZE(5,1,0,1,0) +#define FMT__D_P_H_H_H_H_H_H TRACE_ARG_SIZE(6,1,0,1,0) +#define FMT__D_P_H_P TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__D_P_P TRACE_ARG_SIZE(0,1,0,2,0) +#define FMT__D_P_P_D_D TRACE_ARG_SIZE(0,3,0,2,0) +#define FMT__D_P_P_D_D_P TRACE_ARG_SIZE(0,3,0,3,0) +#define FMT__D_P_P_D_D_H_H TRACE_ARG_SIZE(2,3,0,2,0) +#define FMT__D_P_P_H TRACE_ARG_SIZE(1,1,0,2,0) +#define FMT__H TRACE_ARG_SIZE(1,0,0,0,0) +#define FMT__H_A TRACE_ARG_SIZE(1,0,0,0,1) +#define FMT__H_A_A TRACE_ARG_SIZE(1,0,0,0,2) +#define FMT__H_A_A_H_H TRACE_ARG_SIZE(3,0,0,0,2) +#define FMT__H_A_H TRACE_ARG_SIZE(2,0,0,0,1) +#define FMT__H_A_H_H_H TRACE_ARG_SIZE(4,0,0,0,1) +#define FMT__H_A_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(9,0,0,0,1) +#define FMT__H_C_D_C TRACE_ARG_SIZE(3,1,0,0,0) +#define FMT__H_C_H_C TRACE_ARG_SIZE(4,0,0,0,0) +#define FMT__H_D TRACE_ARG_SIZE(1,1,0,0,0) +#define FMT__H_D_L TRACE_ARG_SIZE(1,1,1,0,0) +#define FMT__H_D_A TRACE_ARG_SIZE(1,1,0,0,1) +#define FMT__H_D_A_H_D TRACE_ARG_SIZE(2,2,0,0,1) +#define FMT__H_D_A_H_H TRACE_ARG_SIZE(3,1,0,0,1) +#define FMT__H_D_A_H_H_H_H TRACE_ARG_SIZE(5,1,0,0,1) +#define FMT__H_D_D TRACE_ARG_SIZE(1,2,0,0,0) +#define FMT__H_D_D_D TRACE_ARG_SIZE(1,3,0,0,0) +#define FMT__H_D_D_D_D TRACE_ARG_SIZE(1,4,0,0,0) +#define FMT__H_D_D_D_D_H TRACE_ARG_SIZE(2,4,0,0,0) +#define FMT__H_D_D_D_H_H_D TRACE_ARG_SIZE(3,4,0,0,0) +#define FMT__H_D_D_H TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__H_D_D_H_D TRACE_ARG_SIZE(2,3,0,0,0) +#define FMT__H_D_D_H_D_H TRACE_ARG_SIZE(3,3,0,0,0) +#define FMT__H_D_D_H_H TRACE_ARG_SIZE(3,2,0,0,0) +#define FMT__H_D_D_H_H_H TRACE_ARG_SIZE(4,2,0,0,0) +#define FMT__H_D_D_H_H_H_H TRACE_ARG_SIZE(5,2,0,0,0) +#define FMT__H_D_D_H_P TRACE_ARG_SIZE(2,2,0,1,0) +#define FMT__H_D_D_P TRACE_ARG_SIZE(1,2,0,1,0) +#define FMT__H_D_H TRACE_ARG_SIZE(2,1,0,0,0) +#define FMT__H_D_H_D TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__H_D_H_D_D TRACE_ARG_SIZE(2,3,0,0,0) +#define FMT__H_D_H_D_H_H TRACE_ARG_SIZE(4,2,0,0,0) +#define FMT__H_D_H_H TRACE_ARG_SIZE(3,1,0,0,0) +#define FMT__H_D_H_H_H TRACE_ARG_SIZE(4,1,0,0,0) +#define FMT__H_D_H_H_H_H TRACE_ARG_SIZE(5,1,0,0,0) +#define FMT__H_D_H_H_H_H_H_H TRACE_ARG_SIZE(7,1,0,0,0) +#define FMT__H_D_P_H_H_H_H_H TRACE_ARG_SIZE(6,1,0,1,0) +#define FMT__H_D_P_H_H_H_H_H_H_H TRACE_ARG_SIZE(8,1,0,1,0) +#define FMT__H_D_P_P_P TRACE_ARG_SIZE(1,1,0,3,0) +#define FMT__H_H TRACE_ARG_SIZE(2,0,0,0,0) +#define FMT__H_H_A TRACE_ARG_SIZE(2,0,0,0,1) +#define FMT__H_H_A_A TRACE_ARG_SIZE(2,0,0,0,2) +#define FMT__H_H_D TRACE_ARG_SIZE(2,1,0,0,0) +#define FMT__H_H_D_D TRACE_ARG_SIZE(2,2,0,0,0) +#define FMT__H_H_D_D_D TRACE_ARG_SIZE(2,3,0,0,0) +#define FMT__H_H_D_H TRACE_ARG_SIZE(3,1,0,0,0) +#define FMT__H_H_D_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(10,1,0,0,0) +#define FMT__D_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(8,1,0,0,0) +#define FMT__H_H_D_H_P TRACE_ARG_SIZE(3,1,0,1,0) +#define FMT__H_D_P TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__H_H_D_P TRACE_ARG_SIZE(2,1,0,1,0) +#define FMT__H_H_H TRACE_ARG_SIZE(3,0,0,0,0) +#define FMT__H_H_H_D TRACE_ARG_SIZE(3,1,0,0,0) +#define FMT__H_H_H_D_D TRACE_ARG_SIZE(3,2,0,0,0) +#define FMT__H_H_H_D_D_H_A_H_A TRACE_ARG_SIZE(5,2,0,0,2) +#define FMT__D_H_H_H_D_D_H_A_H_A TRACE_ARG_SIZE(5,3,0,0,2) +#define FMT__H_H_H_D_D_D TRACE_ARG_SIZE(3,3,0,0,0) +#define FMT__H_H_H_D_H TRACE_ARG_SIZE(4,1,0,0,0) +#define FMT__H_H_H_D_H_P TRACE_ARG_SIZE(4,1,0,1,0) +#define FMT__H_H_H_H TRACE_ARG_SIZE(4,0,0,0,0) +#define FMT__H_H_H_H_D TRACE_ARG_SIZE(4,1,0,0,0) +#define FMT__H_H_H_H_D_H TRACE_ARG_SIZE(5,1,0,0,0) +#define FMT__H_H_H_H_H TRACE_ARG_SIZE(5,0,0,0,0) +#define FMT__H_H_H_H_H_H TRACE_ARG_SIZE(6,0,0,0,0) +#define FMT__H_H_H_H_H_H_H TRACE_ARG_SIZE(7,0,0,0,0) +#define FMT__H_H_H_H_H_H_H_H TRACE_ARG_SIZE(8,0,0,0,0) +#define FMT__H_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(9,0,0,0,0) +#define FMT__H_H_H_H_H_H_H_H_P_P TRACE_ARG_SIZE(8,0,0,2,0) +#define FMT__H_H_H_H_H_H_P_P TRACE_ARG_SIZE(6,0,0,2,0) +#define FMT__H_H_H_H_H_H_P_P_P_P TRACE_ARG_SIZE(6,2,0,4,0) +#define FMT__H_H_H_H_P_P_P TRACE_ARG_SIZE(4,0,0,3,0) +#define FMT__H_H_H_P TRACE_ARG_SIZE(3,0,0,1,0) +#define FMT__H_H_L TRACE_ARG_SIZE(2,0,1,0,0) +#define FMT__H_H_L_H TRACE_ARG_SIZE(3,0,1,0,0) +#define FMT__H_H_H_L TRACE_ARG_SIZE(3,0,1,0,0) +#define FMT__H_H_L_H_P TRACE_ARG_SIZE(3,0,1,4,0) +#define FMT__H_H_P TRACE_ARG_SIZE(2,0,0,1,0) +#define FMT__H_H_P_D TRACE_ARG_SIZE(2,1,0,1,0) +#define FMT__H_H_P_P_P TRACE_ARG_SIZE(2,0,0,3,0) +#define FMT__H_L TRACE_ARG_SIZE(1,0,1,0,0) +#define FMT__H_L_A TRACE_ARG_SIZE(1,0,1,0,1) +#define FMT__H_L_D TRACE_ARG_SIZE(1,1,1,0,0) +#define FMT__H_L_L TRACE_ARG_SIZE(1,0,2,0,0) +#define FMT__H_L_H TRACE_ARG_SIZE(2,0,1,0,0) +#define FMT__H_L_D_D TRACE_ARG_SIZE(1,2,1,0,0) +#define FMT__H_L_D_P TRACE_ARG_SIZE(1,1,1,1,0) +#define FMT__H_L_H_D TRACE_ARG_SIZE(2,1,1,0,0) +#define FMT__H_L_H_D_D TRACE_ARG_SIZE(2,2,1,0,0) +#define FMT__H_L_H_H_H_H_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(13,0,1,0,0) +#define FMT__H_D_H_H_H_H_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(13,1,0,0,0) +#define FMT__H_L_H_H_P TRACE_ARG_SIZE(3,0,1,4,0) +#define FMT__H_L_L_H_A TRACE_ARG_SIZE(2,0,2,0,1) +#define FMT__H_L_D_D_H TRACE_ARG_SIZE(2,2,1,0,0) +#define FMT__H_P TRACE_ARG_SIZE(1,0,0,1,0) +#define FMT__H_P_D TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__H_P_D_D_H_P TRACE_ARG_SIZE(2,2,0,2,0) +#define FMT__H_P_H TRACE_ARG_SIZE(2,0,0,1,0) +#define FMT__H_P_H_D TRACE_ARG_SIZE(2,1,0,1,0) +#define FMT__H_P_H_D_H TRACE_ARG_SIZE(3,1,0,1,0) +#define FMT__H_P_H_H TRACE_ARG_SIZE(3,0,0,1,0) +#define FMT__H_P_H_H_H TRACE_ARG_SIZE(4,0,0,1,0) +#define FMT__H_P_H_H_D TRACE_ARG_SIZE(3,1,0,1,0) +#define FMT__H_P_H_H_H_H TRACE_ARG_SIZE(5,0,0,1,0) +#define FMT__H_P_H_P TRACE_ARG_SIZE(2,0,0,2,0) +#define FMT__H_P_H_P_H TRACE_ARG_SIZE(3,0,0,2,0) +#define FMT__H_P_H_P_H_H TRACE_ARG_SIZE(4,0,0,2,0) +#define FMT__H_P_H_P_H_H_P TRACE_ARG_SIZE(4,0,0,3,0) +#define FMT__H_P_L_H TRACE_ARG_SIZE(2,0,1,1,0) +#define FMT__H_P_P_P TRACE_ARG_SIZE(1,0,0,3,0) +#define FMT__H_P_P_P_D_P_P TRACE_ARG_SIZE(1,1,0,5,0) +#define FMT__H_P_P_P_P TRACE_ARG_SIZE(1,0,0,4,0) +#define FMT__H_P_P_P_P_P TRACE_ARG_SIZE(1,0,0,5,0) +#define FMT__L TRACE_ARG_SIZE(0,0,1,0,0) +#define FMT__L_A TRACE_ARG_SIZE(0,0,1,0,1) +#define FMT__L_D TRACE_ARG_SIZE(0,1,1,0,0) +#define FMT__L_D_D TRACE_ARG_SIZE(0,2,1,0,0) +#define FMT__L_D_D_D TRACE_ARG_SIZE(0,3,1,0,0) +#define FMT__L_H TRACE_ARG_SIZE(1,0,1,0,0) +#define FMT__L_H_H TRACE_ARG_SIZE(2,0,1,0,0) +#define FMT__L_H_H_H TRACE_ARG_SIZE(3,0,1,0,0) +#define FMT__L_L TRACE_ARG_SIZE(0,0,2,0,0) +#define FMT__L_L_L TRACE_ARG_SIZE(0,0,3,0,0) +#define FMT__L_L_A_A TRACE_ARG_SIZE(0,0,2,0,2) +#define FMT__L_D_A TRACE_ARG_SIZE(0,1,1,0,1) +#define FMT__L_D_A_A TRACE_ARG_SIZE(0,1,1,0,2) +#define FMT__L_L_A_A_H_L_H_H_H_H_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(13,0,3,0,2) +#define FMT__L_L_D_D TRACE_ARG_SIZE(0,2,2,0,0) +#define FMT__L_L_H_L_H_H_H_H_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(13,0,3,0,0) +#define FMT__L_L_L_D TRACE_ARG_SIZE(0,1,3,0,0) +#define FMT__L_L_L_L TRACE_ARG_SIZE(0,0,4,0,0) +#define FMT__L_L_L_L_L TRACE_ARG_SIZE(0,0,5,0,0) +#define FMT__L_L_L_L_L_L_L TRACE_ARG_SIZE(0,0,7,0,0) +#define FMT__L_P TRACE_ARG_SIZE(0,0,1,1,0) +#define FMT__L_P_L TRACE_ARG_SIZE(0,0,2,1,0) +#define FMT__P TRACE_ARG_SIZE(0,0,0,1,0) +#define FMT__P_A TRACE_ARG_SIZE(0,0,0,1,1) +#define FMT__P_D TRACE_ARG_SIZE(0,1,0,1,0) +#define FMT__P_D_D TRACE_ARG_SIZE(0,2,0,1,0) +#define FMT__P_D_D_D TRACE_ARG_SIZE(0,3,0,1,0) +#define FMT__P_D_D_D_D TRACE_ARG_SIZE(0,4,0,1,0) +#define FMT__P_D_D_H_D TRACE_ARG_SIZE(1,3,0,1,0) +#define FMT__P_D_D_D_D_D TRACE_ARG_SIZE(0,5,0,1,0) +#define FMT__P_D_D_D_D_D_D TRACE_ARG_SIZE(0,6,0,1,0) +#define FMT__P_D_D_D_D_D_D_D TRACE_ARG_SIZE(0,7,0,1,0) +#define FMT__P_D_D_D_H_D TRACE_ARG_SIZE(1,4,0,1,0) +#define FMT__P_D_D_H TRACE_ARG_SIZE(1,2,0,1,0) +#define FMT__P_D_D_L_L_P TRACE_ARG_SIZE(0,2,2,2,0) +#define FMT__P_D_H TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__P_D_P TRACE_ARG_SIZE(0,1,0,2,0) +#define FMT__P_D_L TRACE_ARG_SIZE(0,1,1,1,0) +#define FMT__P_D_P_D TRACE_ARG_SIZE(0,2,0,2,0) +#define FMT__P_H TRACE_ARG_SIZE(1,0,0,1,0) +#define FMT__P_H_D TRACE_ARG_SIZE(1,1,0,1,0) +#define FMT__P_H_D_D TRACE_ARG_SIZE(1,2,0,1,0) +#define FMT__P_H_D_D_H TRACE_ARG_SIZE(2,2,0,1,0) +#define FMT__P_H_D_P TRACE_ARG_SIZE(1,1,0,2,0) +#define FMT__P_H_D_H TRACE_ARG_SIZE(2,1,0,1,0) +#define FMT__P_H_D_L TRACE_ARG_SIZE(1,1,1,1,0) +#define FMT__P_H_H TRACE_ARG_SIZE(2,0,0,1,0) +#define FMT__P_H_H_D_D TRACE_ARG_SIZE(2,2,0,1,0) +#define FMT__P_H_H_H TRACE_ARG_SIZE(3,0,0,1,0) +#define FMT__P_H_H_H_A TRACE_ARG_SIZE(3,0,0,1,1) +#define FMT__P_H_H_H_D TRACE_ARG_SIZE(3,1,0,1,0) +#define FMT__P_H_H_H_H TRACE_ARG_SIZE(4,0,0,1,0) +#define FMT__P_H_H_H_H_D TRACE_ARG_SIZE(4,1,0,1,0) +#define FMT__P_H_H_H_H_H_H TRACE_ARG_SIZE(6,0,0,1,0) +#define FMT__P_H_H_H_H_H_H_H TRACE_ARG_SIZE(7,0,0,1,0) +#define FMT__P_H_H_H_L TRACE_ARG_SIZE(3,0,1,1,0) +#define FMT__P_H_H_L TRACE_ARG_SIZE(2,0,1,1,0) +#define FMT__P_H_L TRACE_ARG_SIZE(1,0,1,1,0) +#define FMT__P_H_L_H_L TRACE_ARG_SIZE(2,0,2,1,0) +#define FMT__P_H_P TRACE_ARG_SIZE(1,0,0,2,0) +#define FMT__P_H_P_D TRACE_ARG_SIZE(1,1,0,2,0) +#define FMT__P_H_P_D_D TRACE_ARG_SIZE(1,2,0,2,0) +#define FMT__P_H_P_D_D_D TRACE_ARG_SIZE(1,3,0,2,0) +#define FMT__P_H_P_H TRACE_ARG_SIZE(2,0,0,2,0) +#define FMT__P_H_P_H_L TRACE_ARG_SIZE(2,0,1,2,0) +#define FMT__P_H_P_P TRACE_ARG_SIZE(1,0,0,3,0) +#define FMT__P_H_P_L TRACE_ARG_SIZE(1,0,1,2,0) +#define FMT__P_H_P_P_H TRACE_ARG_SIZE(2,0,0,3,0) +#define FMT__P_H_P_P_P TRACE_ARG_SIZE(1,0,0,4,0) +#define FMT__P_L TRACE_ARG_SIZE(0,0,1,1,0) +#define FMT__P_L_D TRACE_ARG_SIZE(0,1,1,1,0) +#define FMT__P_L_H TRACE_ARG_SIZE(1,0,1,1,0) +#define FMT__P_L_P TRACE_ARG_SIZE(0,0,1,2,0) +#define FMT__P_L_L_D TRACE_ARG_SIZE(0,1,2,1,0) +#define FMT__P_L_L_L TRACE_ARG_SIZE(0,0,3,1,0) +#define FMT__P_L_P_L TRACE_ARG_SIZE(0,0,2,2,0) +#define FMT__P_L_P_P_P TRACE_ARG_SIZE(0,0,1,4,0) +#define FMT__P_P TRACE_ARG_SIZE(0,0,0,2,0) +#define FMT__P_P_L TRACE_ARG_SIZE(0,0,1,2,0) +#define FMT__P_P_D TRACE_ARG_SIZE(0,1,0,2,0) +#define FMT__P_P_D_D TRACE_ARG_SIZE(0,2,0,2,0) +#define FMT__P_P_D_D_H TRACE_ARG_SIZE(1,2,0,2,0) +#define FMT__P_P_D_D_P TRACE_ARG_SIZE(0,2,0,3,0) +#define FMT__P_P_D_H_H TRACE_ARG_SIZE(2,1,0,2,0) +#define FMT__P_P_D_H_P TRACE_ARG_SIZE(1,1,0,3,0) +#define FMT__P_P_D_P TRACE_ARG_SIZE(0,1,0,3,0) +#define FMT__P_P_D_P_D TRACE_ARG_SIZE(0,2,0,3,0) +#define FMT__P_P_D_P_H TRACE_ARG_SIZE(1,1,0,3,0) +#define FMT__P_P_H TRACE_ARG_SIZE(1,0,0,2,0) +#define FMT__P_P_H_D TRACE_ARG_SIZE(1,1,0,2,0) +#define FMT__P_P_H_H TRACE_ARG_SIZE(2,0,0,2,0) +#define FMT__P_P_H_H_P TRACE_ARG_SIZE(2,0,0,3,0) +#define FMT__P_P_H_H_H TRACE_ARG_SIZE(3,0,0,2,0) +#define FMT__P_P_H_P TRACE_ARG_SIZE(1,0,0,3,0) +#define FMT__P_P_H_P_D_P TRACE_ARG_SIZE(1,2,0,4,0) +#define FMT__P_P_H_P_H TRACE_ARG_SIZE(2,0,0,3,0) +#define FMT__P_P_L_D TRACE_ARG_SIZE(0,1,1,2,0) +#define FMT__P_P_P TRACE_ARG_SIZE(0,0,0,3,0) +#define FMT__P_P_P_H TRACE_ARG_SIZE(1,0,0,3,0) +#define FMT__P_P_P_D TRACE_ARG_SIZE(0,1,0,3,0) +#define FMT__P_P_P_D_P TRACE_ARG_SIZE(0,1,0,4,0) +#define FMT__P_P_P_H_H TRACE_ARG_SIZE(2,0,0,3,0) +#define FMT__P_P_P_P TRACE_ARG_SIZE(0,0,0,4,0) +#define FMT__D_D_L_D TRACE_ARG_SIZE(0,3,1,0,0) +#define FMT__D_D_L_L TRACE_ARG_SIZE(0,2,2,0,0) +#define FMT__D_D_D_D_L_L TRACE_ARG_SIZE(0,4,2,0,0) +#define FMT__L_D_D_D_D_L_L TRACE_ARG_SIZE(0,4,3,0,0) +#define FMT__L_L_L_D_D TRACE_ARG_SIZE(0,2,3,0,0) +#define FMT__D_H_P_H TRACE_ARG_SIZE(2,1,0,1,0) +#define FMT__H_D_H_H_D TRACE_ARG_SIZE(3,2,0,0,0) +#define FMT__D_A_B_H_H TRACE_ARG_SIZE(2,1,0,0,3) +#define FMT__A_A_P TRACE_ARG_SIZE(0,0,0,1,2) +#define FMT__B TRACE_ARG_SIZE(0,0,0,0,2) +#define FMT__B_H_B TRACE_ARG_SIZE(1,0,0,0,4) +#define FMT__A_D TRACE_ARG_SIZE(0,1,0,0,1) +#define FMT__L_D_P_H TRACE_ARG_SIZE(1,1,1,1,0) +#define FMT__D_D_H_H_H TRACE_ARG_SIZE(3,2,0,0,0) +#define FMT__P_B_D_D TRACE_ARG_SIZE(0,2,0,1,2) +#define FMT__H_B_H_B TRACE_ARG_SIZE(2,0,0,0,4) +#define FMT__B_A TRACE_ARG_SIZE(0,0,0,0,3) +#define FMT__D_H_A TRACE_ARG_SIZE(1,1,0,0,1) +#define FMT__D_A_H TRACE_ARG_SIZE(1,1,0,0,1) +#define FMT__D_D_D_A_B TRACE_ARG_SIZE(0,3,0,0,3) +#define FMT__D_B_A TRACE_ARG_SIZE(0,1,0,0,3) +#define FMT__H_B_A TRACE_ARG_SIZE(1,0,0,0,3) +#define FMT__D_D_H_H_D_D_D_D TRACE_ARG_SIZE(2,6,0,0,0) +#define FMT__P_D_H_H_H_A TRACE_ARG_SIZE(3,1,0,1,1) +#define FMT__H_A_H_H_H_H_H TRACE_ARG_SIZE(6,0,0,0,1) +#define FMT__H_D_A_H TRACE_ARG_SIZE(2,1,0,0,1) +#define FMT__D_A_H_D TRACE_ARG_SIZE(1,2,0,0,1) +#define FMT__P_H_H_H_H_H_H_H_H TRACE_ARG_SIZE(8,0,0,1,0) +#define FMT__D_D_H_L_H_H TRACE_ARG_SIZE(3,2,1,0,0) +#define FMT__D_H_L_H_H TRACE_ARG_SIZE(3,1,1,0,0) +#define FMT__D_H_L_L_D_D_D TRACE_ARG_SIZE(1,4,2,0,0) +#define FMT__H_D_H_L_H_H TRACE_ARG_SIZE(4,1,1,0,0) +#define FMT__D_H_D_H_L_H_H TRACE_ARG_SIZE(4,2,1,0,0) +#define FMT__D_D_H_H_H_D_D_D_D TRACE_ARG_SIZE(3,6,0,0,0) +#define FMT__H_D_H_L TRACE_ARG_SIZE(2,1,1,0,0) +#define FMT__H_H_L_L TRACE_ARG_SIZE(2,0,2,0,0) +#define FMT__D_D_H_H_D_H_D_D_D_D TRACE_ARG_SIZE(3,7,0,0,0) +#define FMT__D_A_D_A TRACE_ARG_SIZE(0,2,0,0,2) +#define FMT__D_D_A TRACE_ARG_SIZE(0,2,0,0,1) +#define FMT__H_H_H_L_H_H_H TRACE_ARG_SIZE(6,0,1,0,0) +#define FMT__H_D_D_D_D_D TRACE_ARG_SIZE(1,5,0,0,0) +#define FMT__P_P_D_D_L TRACE_ARG_SIZE(0,2,1,2,0) +#define FMT__P_L_L TRACE_ARG_SIZE(0,0,2,1,0) +#define FMT__P_P_L_L TRACE_ARG_SIZE(0,0,2,2,0) +#define FMT__D_D_H_D_D_H TRACE_ARG_SIZE(2,4,0,0,0) +#define FMT__NC(N) TRACE_ARG_SIZE(N,0,0,0,0) +#define FMT__H_L_H_H TRACE_ARG_SIZE(3,0,1,0,0) +#define FMT__A_B TRACE_ARG_SIZE(0,0,0,1,1) +#define FMT__D_H_H_L_D_D_D TRACE_ARG_SIZE(2,4,1,0,0) +#define FMT__H_H_D_D_H TRACE_ARG_SIZE(3,3,0,0,0) +#define FMT__L_D_H_H_H_H TRACE_ARG_SIZE(4,1,1,0,0) +#define FMT__P_A_A TRACE_ARG_SIZE(0,0,0,1,2) +#define FMT__D_D_P_H_H_H_H TRACE_ARG_SIZE(4,2,1,0,0) +#define FMT__P_P_D_D_D TRACE_ARG_SIZE(0,4,2,0,0) +#define FMT__D_D_H_H_H_H TRACE_ARG_SIZE(2,4,0,0,0) +#define FMT__P_D_P_D_P_P TRACE_ARG_SIZE(4,2,0,0,0) +#define FMT__D_A_D TRACE_ARG_SIZE(0,2,0,0,1) +#define FMT__D_H_D_D_D_D TRACE_ARG_SIZE(1,5,0,0,0) +#define FMT__H_D_D_D_H_H TRACE_ARG_SIZE(3,3,0,0,0) +#define FMT__P_H_D_D_D_H_H TRACE_ARG_SIZE(3,3,1,0,0) +#define FMT__H_H_H_D_H_L_H_H TRACE_ARG_SIZE(6,1,1,0,0) +#define FMT__D_D_P_P TRACE_ARG_SIZE(0,2,0,2,0) +#define FMT__D_D_P_P_D_D TRACE_ARG_SIZE(0,4,0,2,0) +#define FMT__H_P_P_H_H TRACE_ARG_SIZE(3,0,0,2,0) +#define FMT__H_P_H_H_P TRACE_ARG_SIZE(3,0,0,2,0) +#define FMT__H_P_P TRACE_ARG_SIZE(1,0,0,2,0) +#define FMT__H_P_P_H TRACE_ARG_SIZE(2,0,0,2,0) + + + +/** @} */ /* TRACE_DATA_FORMAT */ + +/** + * @addtogroup TRACE_FIRST_ARG + * @{ + */ +#define TRACE_COMMON1 TRACE_SUBSYSTEM_COMMON, 1 +#define TRACE_COMMON2 TRACE_SUBSYSTEM_COMMON, 2 +#define TRACE_COMMON3 TRACE_SUBSYSTEM_COMMON, 3 + +/** @cond internals_doc */ +/* osif subsystem is nearly not used. Place it to the same with common and free + * 1 bit for buffers. */ +#define TRACE_OSIF1 TRACE_SUBSYSTEM_COMMON, 1 +#define TRACE_OSIF2 TRACE_SUBSYSTEM_COMMON, 2 +#define TRACE_OSIF3 TRACE_SUBSYSTEM_COMMON, 3 + +#define TRACE_MAC1 TRACE_SUBSYSTEM_MAC, 1 +#define TRACE_MAC2 TRACE_SUBSYSTEM_MAC, 2 +#define TRACE_MAC3 TRACE_SUBSYSTEM_MAC, 3 + +#define TRACE_MACLL1 TRACE_SUBSYSTEM_MACLL, 1 +#define TRACE_MACLL2 TRACE_SUBSYSTEM_MACLL, 2 +#define TRACE_MACLL3 TRACE_SUBSYSTEM_MACLL, 3 + +#define TRACE_NWK1 TRACE_SUBSYSTEM_NWK, 1 +#define TRACE_NWK2 TRACE_SUBSYSTEM_NWK, 2 +#define TRACE_NWK3 TRACE_SUBSYSTEM_NWK, 3 + +#define TRACE_APS1 TRACE_SUBSYSTEM_APS, 1 +#define TRACE_APS2 TRACE_SUBSYSTEM_APS, 2 +#define TRACE_APS3 TRACE_SUBSYSTEM_APS, 3 + +#define TRACE_AF1 TRACE_SUBSYSTEM_AF, 1 +#define TRACE_AF2 TRACE_SUBSYSTEM_AF, 2 +#define TRACE_AF3 TRACE_SUBSYSTEM_AF, 3 + +#define TRACE_ZDO1 TRACE_SUBSYSTEM_ZDO, 1 +#define TRACE_ZDO2 TRACE_SUBSYSTEM_ZDO, 2 +#define TRACE_ZDO3 TRACE_SUBSYSTEM_ZDO, 3 + +#define TRACE_SECUR1 TRACE_SUBSYSTEM_SECUR, 1 +#define TRACE_SECUR2 TRACE_SUBSYSTEM_SECUR, 2 +#define TRACE_SECUR3 TRACE_SUBSYSTEM_SECUR, 3 + +#define TRACE_ZCL1 TRACE_SUBSYSTEM_ZCL, 1 +#define TRACE_ZCL2 TRACE_SUBSYSTEM_ZCL, 2 +#define TRACE_ZCL3 TRACE_SUBSYSTEM_ZCL, 3 + +#define TRACE_ZLL1 TRACE_SUBSYSTEM_ZLL, 1 +#define TRACE_ZLL2 TRACE_SUBSYSTEM_ZLL, 2 +#define TRACE_ZLL3 TRACE_SUBSYSTEM_ZLL, 3 + +#define TRACE_ZGP1 TRACE_SUBSYSTEM_ZGP, 1 +#define TRACE_ZGP2 TRACE_SUBSYSTEM_ZGP, 2 +#define TRACE_ZGP3 TRACE_SUBSYSTEM_ZGP, 3 +#define TRACE_ZGP4 TRACE_SUBSYSTEM_ZGP, 4 + +#define TRACE_ZSE1 TRACE_SUBSYSTEM_ZSE, 1 +#define TRACE_ZSE2 TRACE_SUBSYSTEM_ZSE, 2 +#define TRACE_ZSE3 TRACE_SUBSYSTEM_ZSE, 3 +#define TRACE_ZSE4 TRACE_SUBSYSTEM_ZSE, 4 + +#define TRACE_SPI1 TRACE_SUBSYSTEM_SPI, 1 +#define TRACE_SPI2 TRACE_SUBSYSTEM_SPI, 2 +#define TRACE_SPI3 TRACE_SUBSYSTEM_SPI, 3 + +#define TRACE_SSL1 TRACE_SUBSYSTEM_SSL, 1 +#define TRACE_SSL2 TRACE_SUBSYSTEM_SSL, 2 +#define TRACE_SSL3 TRACE_SUBSYSTEM_SSL, 3 + +#define TRACE_APP1 TRACE_SUBSYSTEM_APP, 1 +#define TRACE_APP2 TRACE_SUBSYSTEM_APP, 2 +#define TRACE_APP3 TRACE_SUBSYSTEM_APP, 3 +#define TRACE_APP4 TRACE_SUBSYSTEM_APP, 4 + +#define TRACE_SPECIAL1 TRACE_SUBSYSTEM_SPECIAL1, 1 +#define TRACE_SPECIAL2 TRACE_SUBSYSTEM_SPECIAL1, 2 +#define TRACE_SPECIAL3 TRACE_SUBSYSTEM_SPECIAL1, 3 + +#define TRACE_USB1 TRACE_SUBSYSTEM_USB, 1 +#define TRACE_USB2 TRACE_SUBSYSTEM_USB, 2 +#define TRACE_USB3 TRACE_SUBSYSTEM_USB, 3 + +#define TRACE_MEMDBG1 TRACE_SUBSYSTEM_MEM, 1 +#define TRACE_MEMDBG2 TRACE_SUBSYSTEM_MEM, 2 +#define TRACE_MEMDBG3 TRACE_SUBSYSTEM_MEM, 3 + +#define TRACE_CLOUD1 TRACE_SUBSYSTEM_CLOUD, 1 +#define TRACE_CLOUD2 TRACE_SUBSYSTEM_CLOUD, 2 +#define TRACE_CLOUD3 TRACE_SUBSYSTEM_CLOUD, 3 +#define TRACE_CLOUD4 TRACE_SUBSYSTEM_CLOUD, 4 + +#define TRACE_HTTP1 TRACE_SUBSYSTEM_HTTP, 1 +#define TRACE_HTTP2 TRACE_SUBSYSTEM_HTTP, 2 +#define TRACE_HTTP3 TRACE_SUBSYSTEM_HTTP, 3 + +#define TRACE_JSON1 TRACE_SUBSYSTEM_JSON, 1 +#define TRACE_JSON2 TRACE_SUBSYSTEM_JSON, 2 +#define TRACE_JSON3 TRACE_SUBSYSTEM_JSON, 3 + +#define TRACE_LWIP1 TRACE_SUBSYSTEM_LWIP, 1 +#define TRACE_LWIP2 TRACE_SUBSYSTEM_LWIP, 2 +#define TRACE_LWIP3 TRACE_SUBSYSTEM_LWIP, 3 + +#define TRACE_VENSTAR1 TRACE_SUBSYSTEM_VENSTAR, 1 +#define TRACE_VENSTAR2 TRACE_SUBSYSTEM_VENSTAR, 2 +#define TRACE_VENSTAR3 TRACE_SUBSYSTEM_VENSTAR, 3 + +#define TRACE_TRANSPORT1 TRACE_SUBSYSTEM_TRANSPORT, 1 +#define TRACE_TRANSPORT2 TRACE_SUBSYSTEM_TRANSPORT, 2 +#define TRACE_TRANSPORT3 TRACE_SUBSYSTEM_TRANSPORT, 3 + +#define TRACE_UART1 TRACE_SUBSYSTEM_UART, 1 +#define TRACE_UART2 TRACE_SUBSYSTEM_UART, 2 +#define TRACE_UART3 TRACE_SUBSYSTEM_UART, 3 + +#define TRACE_BATTERY1 TRACE_SUBSYSTEM_BATTERY, 1 +#define TRACE_BATTERY2 TRACE_SUBSYSTEM_BATTERY, 2 +#define TRACE_BATTERY3 TRACE_SUBSYSTEM_BATTERY, 3 + +#define TRACE_OTA1 TRACE_SUBSYSTEM_OTA, 1 +#define TRACE_OTA2 TRACE_SUBSYSTEM_OTA, 2 +#define TRACE_OTA3 TRACE_SUBSYSTEM_OTA, 3 + +#define TRACE_MAC_API1 TRACE_SUBSYSTEM_MAC_API, 1 +#define TRACE_MAC_API2 TRACE_SUBSYSTEM_MAC_API, 2 +#define TRACE_MAC_API3 TRACE_SUBSYSTEM_MAC_API, 3 +/** @endcond */ /* internals_doc */ + +#ifndef ZB_SET_TRACE_LEVEL + +/* empty definitions if not implemented */ +#define ZB_SET_TRACE_LEVEL(l) +#define ZB_SET_TRACE_MASK(m) +#define ZB_SET_TRACE_OFF() +#define ZB_SET_TRACE_ON() +#define TRACE_ENTER_INT() +#define TRACE_LEAVE_INT() + +#endif + +/** @} */ /* TRACE_FIRST_ARG */ +/** @} */ /* Debug trace */ +/** @endcond */ /* DSR_TRACE */ + +/** + @addtogroup DUMP_ON_OFF + @{ +*/ +#if defined ZB_TRAFFIC_DUMP_ON || defined DOXYGEN +/** @cond internals_doc */ +extern zb_uint8_t g_traf_dump; +/** @endcond */ + +/** + * Switch Zigbee traffic dump OFF + */ +#define ZB_SET_TRAF_DUMP_OFF() g_traf_dump = 0 +/** + * Switch Zigbee traffic dump ON + * + * That function works only if traffic dump is enabled at compile time. + */ +#define ZB_SET_TRAF_DUMP_ON() g_traf_dump = 1 +#else +#define ZB_SET_TRAF_DUMP_OFF() +#define ZB_SET_TRAF_DUMP_ON() +#endif +/** @} */ /* DUMP_ON_OFF */ + +/** @endcond */ /* DOXYGEN_DEBUG_SECTION */ + +#endif /* ZB_LOGGER_H */ diff --git a/zboss/include/zb_types.h b/zboss/include/zb_types.h new file mode 100644 index 0000000000..828f8ce006 --- /dev/null +++ b/zboss/include/zb_types.h @@ -0,0 +1,1506 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: general-purpose typedefs +*/ + +#ifndef ZB_TYPES_H +#define ZB_TYPES_H 1 + +#ifndef ZB_CONFIG_H +#error zb_config.h must be included before zb_types.h. Dont do it directly. Include zb_common.h or zboss_api.h instead. +#endif + +/** + * @addtogroup base_types + * @{ + */ + +#define ZB_32BIT_WORD + +/* Really need xdata declaration here, not in osif: don't want to include osig.h here */ +#ifdef ZB_IAR +#define ZB_XDATA +#define ZB_CODE +#define ZB_IAR_CODE +#elif defined KEIL +#define ZB_XDATA xdata +#define ZB_CODE code +#define ZB_IAR_CODE code +#else +#define ZB_XDATA +#define ZB_CODE +#define ZB_IAR_CODE +#endif + +/* register modifier for variables. Can be defined to "register". Will it help to the compiler? */ +/* #define ZB_REGISTER */ +#define ZB_REGISTER register + +#define ZB_VOID_ARGLIST void + +/* Not sure all C compilers support 'const'. Let's add some conditional + * compilation when we will find such compiler */ +#define ZB_CONST const + +/* inline directive for functions placed into .h files in C */ +#if defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus +#define ZB_INLINE inline +#define ZB_INLINE_IN_C +#define ZB_BITFIELD_CAST(x) (x) +#elif defined _MSC_VER +#define ZB_INLINE __inline +#define ZB_BITFIELD_CAST(x) (zb_uint_t)(x) +#else +/* which other C compiler knows about inline? */ +#define ZB_INLINE +#define ZB_BITFIELD_CAST(x) (x) +#endif + + +#define ZB_CPP_STR2(x) #x +/** + Create a string at compile time, like 0 - "0" + */ +#define ZB_CPP_STR(x) ZB_CPP_STR2(x) + + +/** @brief General purpose parameter type. */ +enum zb_param_e +{ + ZB_UNUSED_PARAM = 0 +}; + +/** @brief General purpose boolean type. */ +enum zb_bool_e +{ + ZB_FALSE = 0, /**< False value literal. */ + ZB_TRUE = 1 /**< True value literal. */ +}; + +#if defined WIN32 && !defined ZB_WINDOWS +#define ZB_WINDOWS +#endif + +#if (! defined UNIX) || (defined ZB_WINDOWS) + +/* base types */ + +typedef char zb_char_t; + +typedef unsigned char zb_uchar_t; + +typedef unsigned char zb_uint8_t; + +typedef signed char zb_int8_t; + +typedef unsigned short zb_uint16_t; + +typedef signed short zb_int16_t; +#if defined ZB_16BIT_WORD + +typedef unsigned long zb_uint32_t; + +typedef signed long zb_int32_t; + +typedef zb_uint16_t zb_bitfield_t; +typedef zb_uint32_t zb_lbitfield_t; + +typedef zb_int16_t zb_sbitfield_t; + +/* FIXME: 16 or 32? */ +typedef zb_uint32_t zb_size_t; + +typedef long long zb_int64_t; +typedef unsigned long long zb_uint64_t; + +#else /* defined ZB8051 */ +/* + project-local 4-byte unsigned int type +*/ +typedef unsigned int zb_uint32_t; +/* + project-local 4-byte signed int type +*/ +typedef signed int zb_int32_t; + + +/* + type to be used for unsigned bit fields inside structure +*/ +#if defined ZB_TI_ARM_CODE_COMPOSER +typedef zb_uint8_t zb_bitfield_t; +#elif defined ZB_IAR +typedef zb_uint8_t zb_bitfield_t; +#else +typedef zb_uint32_t zb_bitfield_t; +#endif + +typedef zb_uint32_t zb_lbitfield_t; +/* + type to be used for signed bit fields inside structure +*/ +typedef zb_int32_t zb_sbitfield_t; + +typedef zb_uint32_t zb_size_t; + +typedef long long zb_int64_t; +typedef unsigned long long zb_uint64_t; + +#endif /* defined ZB8051 */ + + +#else /* ! defined UNIX || ZB_WINDOWS */ +/* Unix */ + +#include + +#ifdef __GNUC__ +#include "stddef.h" +#endif + +typedef uint8_t zb_uint8_t; +typedef int8_t zb_int8_t; +typedef uint16_t zb_uint16_t; +typedef int16_t zb_int16_t; +typedef uint32_t zb_uint32_t; +typedef int32_t zb_int32_t; + +typedef long long zb_int64_t; +typedef unsigned long long zb_uint64_t; + +typedef char zb_char_t; +typedef unsigned char zb_uchar_t; + +typedef unsigned zb_bitfield_t; +typedef unsigned zb_lbitfield_t; +typedef signed zb_sbitfield_t; + +/* Integer with size equal to the pointer size. */ +typedef size_t zb_size_t; +typedef zb_size_t zb_ptrsize_uint_t; + + +#endif /* ! defined UNIX */ + +/* + Our short and int definition. + Short size == 8051 register size, int size is 2 bytes. + */ +#ifdef ZB_8BIT_WORD +/* + Short int (can fit into single CPU register) + */ +typedef zb_int8_t zb_short_t; +/* + short unsigned int (can fit into single CPU register) + */ +typedef zb_uint8_t zb_ushort_t; +/* + short unsigned int (can fit into single CPU register) used as a loop index + */ +typedef zb_ushort_t zb_uindex_t; +/* + int (at least 2 bytes) + */ +typedef zb_int16_t zb_int_t; +/* + unsigned int (at least 2 bytes) + */ +typedef zb_uint16_t zb_uint_t; +/* + long int (at least 4 bytes) + */ +typedef zb_int32_t zb_long_t; +/* + unsigned long int (at least 4 bytes) + */ +typedef zb_uint32_t zb_ulong_t; + +#elif defined ZB_16BIT_WORD +/* + short int (can fit into single CPU register) + */ +typedef int zb_short_t; +/* + unsigned short int (can fit into single CPU register) + */ +typedef unsigned int zb_ushort_t; +/* + short unsigned int (can fit into single CPU register) used as a loop index + */ +typedef zb_ushort_t zb_uindex_t; +/* + int (at least 2 bytes) + */ +typedef int zb_int_t; +/* + unsigned int (at least 2 bytes) + */ +typedef unsigned int zb_uint_t; +/* + long int (at least 4 bytes) + */ +typedef zb_int32_t zb_long_t; +/* + unsigned long int (at least 4 bytes) + */ +typedef zb_uint32_t zb_ulong_t; + +#else /* 32-bit word */ +/* + short int (can fit into single CPU register) + */ +typedef int zb_short_t; +/* + unsigned short int (can fit into single CPU register) + */ +typedef unsigned int zb_ushort_t; +/* + short unsigned int (can fit into single CPU register) used as a loop index + */ +typedef zb_ushort_t zb_uindex_t; +/* + int (at least 2 bytes) + */ +typedef int zb_int_t; +/* + unsigned int (at least 2 bytes) + */ +typedef unsigned int zb_uint_t; +/* + long int (at least 4 bytes) + */ +typedef zb_int_t zb_long_t; +/* + unsigned long int (at least 4 bytes) + */ +typedef zb_uint_t zb_ulong_t; +#endif + +typedef void * zb_voidp_t; +typedef void zb_void_t; + +/** @brief General purpose boolean type. */ +typedef enum zb_bool_e zb_bool_t; + +#define ZB_INT8_MIN (-127 - 1) +#define ZB_INT8_MAX 127 +#define ZB_UINT8_MIN 0 +#define ZB_UINT8_MAX 255 + +#define ZB_INT16_MIN (-32767 - 1) +#define ZB_INT16_MAX 32767 +#define ZB_UINT16_MIN 0 +#define ZB_UINT16_MAX 65535 + +/* 2147483648 is unsigned indeed - can't change its sign. prevent warning from + * msvc 8 */ +#define ZB_INT32_MIN (-2147483647L - 1) +#define ZB_INT32_MAX 2147483647L +#define ZB_UINT32_MIN 0UL +#define ZB_UINT32_MAX 4294967295UL + +#define ZB_UINT_MIN 0UL + +/* + Short defined as register size, int as large enough int on this platform. + 32 bit on PC, 8 and 16 bit on 8051 + */ + + +/* + Max value constants per type + */ +#ifdef ZB_32BIT_WORD + +#define ZB_SHORT_MIN ZB_INT32_MIN +#define ZB_SHORT_MAX ZB_INT32_MAX +#define ZB_USHORT_MAX ZB_UINT32_MAX + +#define ZB_INT_MIN ZB_INT32_MIN +#define ZB_INT_MAX ZB_INT32_MAX +#define ZB_UINT_MAX ZB_UINT32_MAX + +#define ZB_INT_MASK 0x7fffffff + +#elif defined ZB_16BIT_WORD + +#define ZB_SHORT_MIN ZB_INT8_MIN +#define ZB_SHORT_MAX ZB_INT8_MAX +#define ZB_USHORT_MAX ZB_UINT8_MAX + +#define ZB_INT_MIN ZB_INT16_MIN +#define ZB_INT_MAX ZB_INT16_MAX +#define ZB_UINT_MAX ZB_UINT16_MAX + +#define ZB_INT_MASK 0x7fff + +#elif defined ZB_8BIT_WORD + +#define ZB_SHORT_MIN ZB_INT8_MIN +#define ZB_SHORT_MAX ZB_INT8_MAX +#define ZB_USHORT_MAX ZB_UINT8_MAX + +#define ZB_INT_MIN ZB_INT16_MIN +#define ZB_INT_MAX ZB_INT16_MAX +#define ZB_UINT_MAX ZB_UINT16_MAX + +#define ZB_INT_MASK 0x7fff + +#else +#error Portme +#endif + +#if defined __GNUC__ || defined __TI_COMPILER_VERSION__ + #define ZB_PACKED_STRUCT __attribute__ ((packed)) + #define ZB_WEAK __attribute__ ((weak)) +#else + #define ZB_PACKED_STRUCT +#endif + +/* IAR or Keil ARM CPU */ +#if (defined __IAR_SYSTEMS_ICC__ || defined __ARMCC_VERSION) && !defined ZB8051 +#define ZB_PACKED_PRE __packed +#define ZB_WEAK_PRE __weak +#else +#define ZB_PACKED_PRE +#endif + +#ifndef ZB_WEAK_PRE +#define ZB_WEAK_PRE +#endif +#ifndef ZB_WEAK +#define ZB_WEAK +#endif + +#if (defined __ARMCC_VERSION) && !defined ZB8051 +#define ZB_ALIGNED_PRE __attribute__((aligned)) +#endif + +#ifndef ZB_ALIGNED_PRE +#define ZB_ALIGNED_PRE +#endif + + +/* + 8-bytes address (xpanid or long device address) base type + */ +typedef zb_uint8_t zb_64bit_addr_t[8]; + +/* + 8-bytes data base type + */ +typedef zb_uint8_t zb_64bit_data_t[8]; + + +extern ZB_CODE ZB_CONST zb_64bit_addr_t g_zero_addr; +extern ZB_CODE ZB_CONST zb_64bit_addr_t g_unknown_ieee_addr; + +/* + Return true if long address is zero + */ + /* g_zero_addr is declared as ZB_CONST which allows IAR to place it in CODE memory. + Compiled this by IAR 7.60 for 8051. + This placement changes pointer type making it unusable + Is this cast needed here? + */ +#define ZB_IS_64BIT_ADDR_ZERO(addr) (!ZB_MEMCMP((addr), (void const*)g_zero_addr, 8)) +#define ZB_IS_64BIT_ADDR_UNKNOWN(addr) (!ZB_MEMCMP((addr), (void const*)g_unknown_ieee_addr, 8)) + +/* + Clear long address + */ +#define ZB_64BIT_ADDR_ZERO(addr) \ + ZB_MEMSET((addr), 0, 8) + +/* + Make long address unknown + */ +#define ZB_64BIT_ADDR_UNKNOWN(addr) \ + ZB_MEMSET((addr), -1, 8) + +/* + Copy long address + */ +#define ZB_64BIT_ADDR_COPY(dst, src) ZB_MEMCPY(dst, src, sizeof(zb_64bit_addr_t)) + +/* + Return 1 if long addresses are equal + */ +#define ZB_64BIT_ADDR_CMP(one, two) ((zb_bool_t)!ZB_MEMCMP((one), (two), 8)) + +/* + Long (64-bit) device address + */ +typedef zb_64bit_addr_t zb_ieee_addr_t; +/* + Long (64-bit) Extented Pan id + */ +typedef zb_64bit_addr_t zb_ext_pan_id_t; + +#define ZB_EXTPANID_IS_ZERO ZB_IS_64BIT_ADDR_ZERO +#define ZB_EXTPANID_ZERO ZB_64BIT_ADDR_ZERO +#define ZB_EXTPANID_COPY ZB_64BIT_ADDR_COPY +#define ZB_EXTPANID_CMP ZB_64BIT_ADDR_CMP + +#define ZB_IEEE_ADDR_IS_ZERO ZB_IS_64BIT_ADDR_ZERO +#define ZB_IEEE_ADDR_IS_UNKNOWN ZB_IS_64BIT_ADDR_UNKNOWN +#define ZB_IEEE_ADDR_ZERO ZB_64BIT_ADDR_ZERO +#define ZB_IEEE_ADDR_UNKNOWN ZB_64BIT_ADDR_UNKNOWN +#define ZB_IEEE_ADDR_COPY ZB_64BIT_ADDR_COPY +#define ZB_IEEE_ADDR_CMP ZB_64BIT_ADDR_CMP + +#define ZB_CCM_KEY_IS_ZERO(k) (ZB_IS_64BIT_ADDR_ZERO((zb_uint8_t*)(k)) && ZB_IS_64BIT_ADDR_ZERO(((zb_uint8_t*)(k)) + 8)) +#define ZB_IEEE_ADDR_IS_VALID(addr) !(ZB_IEEE_ADDR_IS_ZERO(addr)||ZB_IEEE_ADDR_IS_UNKNOWN(addr)) + +#define ZB_ADDR_CMP(addr_mode, addr1, addr2) \ + ((addr_mode == ZB_ADDR_16BIT_DEV_OR_BROADCAST) ? \ + (addr1.addr_short == addr2.addr_short) : ZB_64BIT_ADDR_CMP(addr1.addr_long, addr2.addr_long)) + +typedef ZB_PACKED_PRE union zb_addr_u_t +{ + zb_uint16_t addr_short; + zb_ieee_addr_t addr_long; +} ZB_PACKED_STRUCT +zb_addr_u; + +/* + definitions for constants of given type +*/ +#define ZB_INT8_C(c) c +#define ZB_UINT8_C(c) c ## U + +#define ZB_INT16_C(c) c +#define ZB_UINT16_C(c) c ## U + +#define ZB_INT32_C(c) c ## L +#define ZB_UINT32_C(c) c ## UL + +#if (defined __GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define ZB_OFFSETOF(t, f) __builtin_offsetof(t,f) +#else +#define ZB_OFFSETOF(t, f) ((zb_size_t)(&((t *)0)->f)) +#endif + +#define ZB_OFFSETOF_VAR(s, f) (zb_size_t)(((zb_int8_t *)(&(s)->f)) - ((zb_int8_t *)(s))) + +#define ZB_SIZEOF_FIELD(type, field) (sizeof(((type*)0)->field)) + +#define ZB_ARRAY_SIZE(arr) (sizeof((arr))/sizeof((arr)[0])) + + +#define ZB_SIGNED_SHIFT(v, s) ((zb_int_t)(v) >> (s)) + +#define ZB_ASSERT_IF_NOT_ALIGNED(data_type,length) \ + ZB_ASSERT_COMPILE_DECL(((sizeof(data_type) % (length)) == 0)); + +#define ZB_ASSERT_IF_NOT_ALIGNED_TO_4(data_type) ZB_ASSERT_IF_NOT_ALIGNED(data_type,4) + +#define ZB_ASSERT_VALUE_ALIGNED(const_expr, length) \ + ZB_ASSERT_COMPILE_DECL((((const_expr) % (length)) == 0)); + +#define ZB_ASSERT_VALUE_ALIGNED_TO_4(const_expr) ZB_ASSERT_VALUE_ALIGNED(const_expr, 4) + +/** + * @name Endian change API. + * Macros to change words endian and access words at potentially + * non-aligned pointers. + * + * Zigbee uses little endian, see ZB spec, subclause 1.2.1.3. + * @{ + */ + +/** + */ + +#define ZB_8BIT_SIZE 1 +#define ZB_16BIT_SIZE 2 +#define ZB_24BIT_SIZE 3 +#define ZB_32BIT_SIZE 4 +#define ZB_48BIT_SIZE 6 +#define ZB_64BIT_SIZE 8 + +#ifdef ZB_LITTLE_ENDIAN + +#ifdef ZB_NEED_ALIGN +/** + Convert 16-bits integer from the host endian to the little endian + + @param ptr - destination pointer. It is ok if it not aligned to 2. + @param val - source pointer. It is ok if it not aligned to 2. +*/ + +#define ZB_HTOLE16(ptr, val) ZB_MEMCPY((ptr), (val), ZB_16BIT_SIZE) +#define ZB_HTOLE32(ptr, val) ZB_MEMCPY((ptr), (val), ZB_32BIT_SIZE) +#define ZB_HTOLE64(ptr, val) ZB_MEMCPY((ptr), (val), ZB_64BIT_SIZE) +#else + +#define ZB_HTOLE16(ptr, val) (((zb_uint16_t *)(ptr))[0] = *((zb_uint16_t *)(val))) +#define ZB_HTOLE32(ptr, val) (((zb_uint32_t *)(ptr))[0] = *((zb_uint32_t *)(val))) +/* +#define ZB_HTOLE64(ptr, val) \ + (((zb_uint32_t *)(ptr))[0] = ((zb_uint32_t *)(val))[0], \ + ((zb_uint32_t *)(ptr))[1] = ((zb_uint32_t *)(val))[1]) +*/ +#define ZB_HTOLE64(ptr, val) zb_memcpy8(ptr, val) +#endif /* need_align */ + + +#define ZB_HTOLE16_ONPLACE(v) + +#define ZB_HTOLE32_ONPLACE(v) + +#define ZB_HTOLE64_ONPLACE(v) + +#define ZB_HTOBE16(ptr, val) \ + (((zb_uint8_t *)(ptr))[0] = ((zb_uint8_t *)(val))[1], \ + ((zb_uint8_t *)(ptr))[1] = ((zb_uint8_t *)(val))[0] \ + ) + +void zb_htobe32(zb_uint8_t ZB_XDATA *ptr, zb_uint8_t ZB_XDATA *val); +#define ZB_HTOBE32(ptr, val) zb_htobe32((zb_uint8_t*)(ptr), (zb_uint8_t*)(val)) + +#define ZB_HTOBE16_VAL(ptr, val) \ +{ \ + zb_uint16_t _v = (val); \ + ZB_HTOBE16((ptr), &_v); \ +} + +#else /* !little endian */ + +void zb_htole16(zb_uint8_t ZB_XDATA *ptr, zb_uint8_t ZB_XDATA *val); +#define ZB_HTOLE16(ptr, val) zb_htole16((zb_uint8_t*)(ptr), (zb_uint8_t*)(val)) + +#define ZB_HTOLE16_ONPLACE(val) \ +{ \ + zb_uint8_t *pval = (zb_uint8_t*)val; \ + zb_uint8_t a = pval[0]; \ + pval[0] = pval[1]; \ + pval[1] = a; \ +} + +#define ZB_HTOLE32_ONPLACE(val) { zb_uint32_t _v = *(val); ZB_HTOLE32((val), &_v); } + +void zb_htole32(zb_uint8_t ZB_XDATA *ptr, zb_uint8_t ZB_XDATA *val); +#define ZB_HTOLE32(ptr, val) zb_htole32((zb_uint8_t*)(ptr), (zb_uint8_t*)(val)) + +#define ZB_HTOBE32(ptr, val) ZB_MEMCPY(ptr, val, 4) + +#define ZB_HTOBE16(ptr, val) (*(zb_uint16_t *)(ptr)) = *((zb_uint16_t *)(val)) + +#ifdef ZB_NEED_ALIGN + +#define ZB_HTOBE16_VAL(ptr, val) \ +{ \ + zb_uint16_t _v = (val); \ + ZB_MEMCPY((ptr), &_v, 2); \ +} + +#else /* ZB_NEED_ALIGN */ + +#define ZB_HTOBE16_VAL(ptr, val) ((zb_uint16_t *)(ptr))[0] = (val) + +#endif /* ZB_NEED_ALIGN */ + +/* Let's not rotate 64-bit address: store it as + * 8-byte array in the order it transmitted. */ +#define ZB_HTOLE64(ptr, val) zb_memcpy8(ptr, val) + +#endif /* ZB_LITTLE_ENDIAN */ + +#define ZB_HTOLE32_VAL(ptr, val) \ +{ \ + zb_uint32_t tmp_val = (val); \ + ZB_HTOLE32((ptr), &tmp_val); \ +} + +#define ZB_HTOLE16_VAL(ptr, val) \ +{ \ + zb_uint16_t tmp_val = (val); \ + ZB_HTOLE16((ptr), &tmp_val); \ +} + +/** + Put next 2-bute value into buffer, move pointer + + To be used for headers compose. + + @param dst - (in/out) address os the buffer pointer + As a side effect it will be incremented by 2. + @param val - value + */ +//void zb_put_next_htole16(zb_uint8_t **dst, zb_uint16_t val); +void* zb_put_next_htole16(zb_uint8_t *dst, zb_uint16_t val); + +#ifdef ZB_LITTLE_ENDIAN +#define ZB_PUT_NEXT_HTOLE16(ptr, val) \ +{ \ +*((ptr)++) = (val) & 0xff; \ +*((ptr)++) = ((val) >> 8) & 0xff; \ +} + +#else +#define ZB_PUT_NEXT_HTOLE16(ptr, val) \ +{ \ + *((ptr)++) = ((val) >> 8) & 0xff; \ + *((ptr)++) = (val) & 0xff; \ +} +#endif /* ZB_LITTLE_ENDIAN */ + +void* zb_put_next_htole32(zb_uint8_t *dst, zb_uint32_t val1); + +#define ZB_PUT_NEXT_HTOLE32(ptr, val) (ptr) = zb_put_next_htole32((ptr), (val)) + +#ifndef ZB_IAR +void zb_get_next_letoh16(zb_uint16_t *dst, zb_uint8_t **src); +#else +/* for IAR define as macro due to problems with packet structs */ +#define zb_get_next_letoh16(dst, src) \ +{ \ + ZB_LETOH16((dst), *(src)); \ + (*(src)) = (void *)(((char *)(*(src))) + 2); \ +} +#endif + +void* zb_put_next_2_htole16(zb_uint8_t *dst, zb_uint16_t val1, zb_uint16_t val2); +void* zb_put_next_2_htole32(zb_uint8_t *dst, zb_uint32_t val1, zb_uint32_t val2); +#define ZB_LETOH64(dst, src) zb_memcpy8((zb_uint8_t*)dst, (zb_uint8_t*)src) + +/** + Convert 16-bits integer from the little endian to the host endian + + @param ptr - destination pointer. It is ok if it not aligned to 2. + @param val - source pointer. It is ok if it not aligned to 2. +*/ +#define ZB_LETOH16 ZB_HTOLE16 +#define ZB_LETOH24 ZB_HTOLE24 +#define ZB_LETOH48 ZB_HTOLE48 +#define ZB_LETOH32 ZB_HTOLE32 +#define ZB_BETOH16 ZB_HTOBE16 +#define ZB_BETOH32 ZB_HTOBE32 + +#define ZB_LETOH16_ONPLACE ZB_HTOLE16_ONPLACE +#define ZB_LETOH32_ONPLACE ZB_HTOLE32_ONPLACE + +/** @} */ /* Endian change API. */ + +#define ZB_GET_LOW_BYTE(val) ((val) & 0xFF) +#define ZB_GET_HI_BYTE(val) (((val) >> 8) & 0xFF) + +#define ZB_SET_LOW_BYTE(res, val) (res) = (((res) & 0xFF00) | ((val) & 0xFF)) +#define ZB_SET_HI_BYTE(res, val) (res) = ((((val) << 8) & 0xFF00) | ((res) & 0xFF)) + +#define ZB_PKT_16B_ZERO_BYTE 0 +#define ZB_PKT_16B_FIRST_BYTE 1 + +#ifdef ZB_NEED_ALIGN + +#define ZB_ASSIGN_UINT16(ptr, vp) ZB_MEMCPY((ptr), (vp), 2) +#define ZB_ASSIGN_INT16(ptr, vp) ZB_MEMCPY((ptr), (vp), 2) +#define ZB_COPY_UINT24(ptr, vp) ZB_MEMCPY((ptr), (vp), 3) +#define ZB_COPY_INT24(ptr, vp) ZB_MEMCPY((ptr), (vp), 3) +#define ZB_ASSIGN_UINT32(ptr, vp) ZB_MEMCPY((ptr), (vp), 4) +#define ZB_ASSIGN_INT32(ptr, vp) ZB_MEMCPY((ptr), (vp), 4) + +#else + +#define ZB_ASSIGN_UINT16(ptr, vp) *((zb_uint16_t*)(ptr)) = *(zb_uint16_t*)(vp) +#define ZB_ASSIGN_INT16(ptr, vp) *((zb_int16_t*)(ptr)) = *(zb_int16_t*)(vp) +#define ZB_COPY_UINT24(ptr, vp) *((zb_uint24_t*)(ptr)) = *(zb_uint24_t*)(vp) +#define ZB_COPY_INT24(ptr, vp) *((zb_int24_t*)(ptr)) = *(zb_int24_t*)(vp) +#define ZB_ASSIGN_UINT32(ptr, vp) *((zb_uint32_t*)(ptr)) = *(zb_uint32_t*)(vp) +#define ZB_ASSIGN_INT32(ptr, vp) *((zb_int32_t*)(ptr)) = *(zb_int32_t*)(vp) + + +#endif /* ZB_NEED_ALIGN */ + +#define ZB_REVERSE16(ptr, val) \ + (((zb_uint8_t *)(ptr))[0] = ((zb_uint8_t *)(val))[1], \ + ((zb_uint8_t *)(ptr))[1] = ((zb_uint8_t *)(val))[0]) + +#define ZB_REVERSE64(ptr, val) \ + *((zb_uint8_t*)(ptr)+7) = *((zb_uint8_t*)(val) ), \ + *((zb_uint8_t*)(ptr)+6) = *((zb_uint8_t*)(val)+1), \ + *((zb_uint8_t*)(ptr)+5) = *((zb_uint8_t*)(val)+2), \ + *((zb_uint8_t*)(ptr)+4) = *((zb_uint8_t*)(val)+3), \ + *((zb_uint8_t*)(ptr)+3) = *((zb_uint8_t*)(val)+4), \ + *((zb_uint8_t*)(ptr)+2) = *((zb_uint8_t*)(val)+5), \ + *((zb_uint8_t*)(ptr)+1) = *((zb_uint8_t*)(val)+6), \ + *((zb_uint8_t*)(ptr) ) = *((zb_uint8_t*)(val)+7) + +#define ZB_ARRAY_IDX_BY_ELEM(ar, el) ((el) - (ar)) + +#define ZB_ARRAY_IDX_BY_STRUCT_ELEM(ar, el, el_size) ( ((zb_size_t)(el) - (zb_size_t)(ar)) / (el_size) ) + +/** + * @name Base types. + * @{ + * @typedef zb_char_t + * @brief Project-local char type. + * + * @typedef zb_uchar_t + * @brief Project-local unsigned char type. + * + * @typedef zb_uint8_t + * @brief Project-local 1-byte unsigned int type. + * + * @typedef zb_int8_t + * @brief Project-local 1-byte signed int type. + * + * @typedef zb_uint16_t + * @brief Project-local 2-byte unsigned int type. + * + * + * @typedef zb_int16_t + * @brief Project-local 2-byte signed int type. + * + * @typedef zb_int32_t + * @brief Project-local 4-byte signed int type. + * + * @typedef zb_uint32_t + * @brief Project-local 4-byte unsigned int type. + * + * @typedef zb_bitfield_t + * @brief Type to be used for unsigned bit fields inside structure. + * + * @typedef zb_sbitfield_t + * @brief Type to be used for signed bit fields inside structure. + * + * @typedef zb_size_t + * @brief Project-local size_t type. + * + * @typedef zb_short_t + * @brief Short int (can fit into single CPU register). + * + * @typedef zb_ushort_t + * @brief Short unsigned int (can fit into single CPU register). + * + * @typedef zb_int_t + * @brief Int (at least 2 bytes). + * + * @typedef zb_uint_t + * @brief Unsigned int (at least 2 bytes). + * + * @typedef zb_long_t + * @brief Long int (at least 4 bytes). + * + * @typedef zb_ulong_t + * @brief Unsigned long int (at least 4 bytes). + * + * @typedef zb_void_t + * @brief Project-local void type. + * + * @typedef zb_voidp_t + * @brief Project-local "pointer to void" type. + * + * @typedef zb_bool_t + * @brief Boolean type can be ZB_TRUE or ZB_FALSE + * @} + */ + +/** + * @name Address types and API. + * @{ + * @typedef zb_64bit_addr_t + * @brief 8-bytes address (xpanid or long device address) base type. + * + * @typedef zb_ieee_addr_t + * @brief Long (64-bit) device address. + * + * @typedef zb_ext_pan_id_t + * @brief Long (64-bit) extended Pan Id. + * + * @union zb_addr_u + * @brief Union to address either long or short address. + * + * @def ZB_IS_64BIT_ADDR_ZERO + * @brief Checks that long address is a zero one. + * @param addr address to check. + * @returns ZB_TRUE if address is zero, ZB_FALSE otherwise. + * + * @def ZB_64BIT_ADDR_ZERO + * @brief Clears long address. + * @param addr address to clear. + * + * @def ZB_64BIT_ADDR_COPY + * @brief Copy long address. + * @param dst where to copy the address. + * @param src address to copy. + * + * @def ZB_64BIT_ADDR_CMP + * @brief Check two long addresses are equal. + * @param one address to compare. + * @param two address to compare to. + * @returns ZB_TRUE if addresses are equal, ZB_FALSE otherwise. + * @} + */ + + +#define MIN_SIGNED_24BIT_VAL ((zb_int32_t)0xFF800001) /* FIXME: which value to prefer? Because 0x800000 is reserved in ZCL */ +#define MAX_SIGNED_24BIT_VAL ((zb_int32_t)0x7FFFFF) + +#define MIN_SIGNED_48BIT_VAL ((zb_int32_t)0xFFFF800000000001) +#define MAX_SIGNED_48BIT_VAL ((zb_int32_t)0x7FFFFFFFFFFF) + +#define ZB_S64_FROM_S48(x) ((x & 0xFFFFFFFFFFFF) | ((x & 0x800000000000) ? 0xFFFF000000000000 : 0x0)) + +#define ZB_S64_TO_S48(x) ((zb_int64_t)(x & 0xFFFFFFFFFFFF)) + +#define ZB_S32_FROM_S24(x) ((x & 0xFFFFFF) | ((x & 0x800000) ? 0xFF000000 : 0x0)) + +#define ZB_S32_TO_S24(x) ((zb_int32_t)(x & 0xFFFFFF)) + +#ifdef ZB_UINT24_48_SUPPORT + +#define ZB_INT32_MINUS_ONE (0xFFFFFFFF) +#define ZB_INT24_MAX_POSITIVE (0x7FFFFF) + +#define ZB_INT24_IS_NEGATIVE(int24_val) \ + ((int24_val).high & 0x80) + + +#if defined ZB_LITTLE_ENDIAN + +typedef ZB_PACKED_PRE struct zb_int24_s +{ + zb_uint16_t low; + zb_int8_t high; +} ZB_PACKED_STRUCT zb_int24_t; + +typedef ZB_PACKED_PRE struct zb_uint24_s +{ + zb_uint16_t low; + zb_uint8_t high; +} ZB_PACKED_STRUCT zb_uint24_t; + +typedef ZB_PACKED_PRE struct zb_uint48_s +{ + zb_uint32_t low; + zb_uint16_t high; +} ZB_PACKED_STRUCT zb_uint48_t; + + +typedef ZB_PACKED_PRE struct zb_int48_s +{ + zb_uint32_t low; + zb_int16_t high; +} ZB_PACKED_STRUCT zb_int48_t; + +#else /* defined ZB_BIG_ENDIAN */ + +typedef ZB_PACKED_PRE struct zb_int24_s +{ + zb_int8_t high; + zb_uint16_t low; +} ZB_PACKED_STRUCT zb_int24_t; + +typedef ZB_PACKED_PRE struct zb_uint24_s +{ + zb_uint8_t high; + zb_uint16_t low; +} ZB_PACKED_STRUCT zb_uint24_t; + +typedef ZB_PACKED_PRE struct zb_uint48_s +{ + zb_uint16_t high; + zb_uint32_t low; +} ZB_PACKED_STRUCT zb_uint48_t; + +typedef ZB_PACKED_PRE struct zb_int48_s +{ + zb_int16_t high; + zb_uint32_t low; +} ZB_PACKED_STRUCT zb_int48_t; + +#endif /* ZB_LITTLE_ENDIAN/ZB_BIG_ENDIAN */ + +#define ZB_INIT_INT24(high_val, low_val) \ +{ \ + .low = (low_val), \ + .high = (high_val) \ +} + +#define ZB_ASSIGN_INT24(var, high_val, low_val) \ +{ \ + var.low = (low_val); \ + var.high = (high_val); \ +} + +#define ZB_GET_INT32_FROM_INT24(int24_val) \ + (zb_int32_t) \ + ( \ + ((ZB_INT24_IS_NEGATIVE(int24_val))? ((zb_uint32_t)0xFF << 24): 0) | \ + ((zb_uint32_t)(int24_val).high << 16) | \ + (int24_val).low \ + ) + +#define ZB_ASSIGN_UINT24_FROM_UINT32(uint32_val) \ +{ \ + .low = (zb_uint16_t)((uint32_val) & 0xFFFF), \ + .high = (zb_uint8_t)((uint32_val) >> 16) \ +} + +#define ZB_GET_UINT32_FROM_UINT24(uint24_val) \ +((((zb_uint32_t) (uint24_val).high) << 16) + (uint24_val).low) + +#define ZB_INIT_UINT48(high_val, low_val) \ +{ \ + .low = (low_val), \ + .high = (high_val) \ +} + +#define ZB_INIT_UINT24(high_val, low_val) \ +{ \ + .low = (low_val), \ + .high = (high_val) \ +} + +#define ZB_ASSIGN_UINT48(var, high_val, low_val) \ +{ \ + var.low = (low_val); \ + var.high = (high_val); \ +} + +#define ZB_ASSIGN_UINT24(var, high_val, low_val) \ +{ \ + var.low = (low_val); \ + var.high = (high_val); \ +} + +/* TODO: test for negative int24 */ +#define ZB_UINT48_ADD_INT24(uint48_val, int24_val) \ + if (ZB_INT24_IS_NEGATIVE(int24_val)) \ + { \ + if ((uint48_val).low < (zb_uint32_t)((int24_val).low + (int24_val).high)) \ + { \ + (uint48_val).high -= 1; \ + } \ + (uint48_val).low -= (int24_val).low + (int24_val).high; \ + } \ + else \ + { \ + if (((zb_uint64_t) (uint48_val).low) + ZB_GET_UINT32_FROM_UINT24(int24_val) > ZB_UINT32_MAX) \ + { \ + (uint48_val).high += 1; \ + } \ + (uint48_val).low += ZB_GET_UINT32_FROM_UINT24(int24_val); \ + } + +#define ZB_UINT48_IS_EQUAL(val1, val2) \ + (((val1).high == (val2).high) && ((val1).low == (val2).low)) + +#define ZB_UINT48_IS_GREAT(val1, val2) \ + ((val1).high > (val2).high || \ + ((val1).high == (val2).high && (val1).low > (val2).low)) + +#define ZB_UINT48_IS_LESS(val1, val2) \ + (!ZB_UINT48_IS_EQUAL(val1, val2) && !ZB_UINT48_IS_GREAT(val1, val2)) + +#define ZB_UINT48_IS_GREAT_OR_EQUAL(val1, val2) \ + (!ZB_UINT48_IS_LESS(val1, val2)) + +#define ZB_UINT48_IS_LESS_OR_EQUAL(val1, val2) \ + (!ZB_UINT48_IS_GREAT(val1, val2)) + +#if defined ZB_LITTLE_ENDIAN + +#define ZB_HTOLE24(ptr, val) ZB_MEMCPY((ptr), (val), ZB_24BIT_SIZE) +#define ZB_HTOLE48(ptr, val) ZB_MEMCPY((ptr), (val), ZB_48BIT_SIZE) + +#else /* ZB_BIG_ENDIAN */ + +zb_void_t zb_reverse_bytes(zb_uint8_t *ptr, zb_uint8_t *val, zb_uint8_t size); + +#define ZB_HTOLE24(ptr, val) zb_reverse_bytes((zb_uint8_t*)(ptr), (val), ZB_24BIT_SIZE) +#define ZB_HTOLE48(ptr, val) zb_reverse_bytes((zb_uint8_t*)(ptr), (val), ZB_48BIT_SIZE) + +#endif /* ZB_BIG_ENDIAN */ + +/** + * @name 24-bit and 48-bit arithmetic API + * @{ + */ + +/** Return statuses of mathematical operations */ +enum zb_math_status_e +{ + ZB_MATH_OK = 0, + ZB_MATH_OVERFLOW, + ZB_MATH_ERROR, +}; + + +/** + * Convert unsigned 32-bit value to unsigned 24-bit value + * @param[in] var - unsigned 32-bit value + * @param[out] res - pointer to unsigned 24-bit value + */ +void zb_uint32_to_uint24(zb_uint32_t var, zb_uint24_t *res); + + +/** + * Convert signed 24-bit value to signed 32-bit value + * @param[in] var - pointer to signed 24-bit value + * @return signed 32-bit representation of 24-bit value + */ +zb_int32_t zb_int24_to_int32(const zb_int24_t *var); + + +/** + * Convert signed 32-bit value to signed 24-bit value + * @param[in] var - signed 32-bit value + * @param[out] res - pointer to signed 24-bit value + */ +void zb_int32_to_int24(zb_int32_t var, zb_int24_t *res); + + +/** + * Convert signed 32-bit value to unsigned 24-bit value + * @param[in] var - signed 32-bit value + * @param[out] res - pointer to unsigned 24-bit value + */ +void zb_int32_to_uint24(zb_int32_t var, zb_uint24_t *res); + + +/** + * Convert unsigned 24-bit value to signed 32-bit value + * @param[in] var - pointer to unsigned 24-bit value + * @return signed 32-bit representation of unsigned 24-bit value + */ +zb_int32_t zb_uint24_to_int32(const zb_uint24_t *var); + + +/** + * Addition of two unsigned 24-bit values + * @param[in] f - pointer to first unsigned 24-bit operand + * @param[in] s - pointer to second unsigned 24-bit operand + * @param[out] r - pointer to unsigned 24-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint24_add(const zb_uint24_t *f, const zb_uint24_t *s, zb_uint24_t *r); + + +/** + * Addition of two signed 24-bit values + * @param[in] f - pointer to first signed 24-bit operand + * @param[in] s - pointer to second signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_add(const zb_int24_t *f, const zb_int24_t *s, zb_int24_t *r); + + +/** + * Subtraction of two signed 24-bit values + * @param[in] f - pointer to first signed 24-bit operand + * @param[in] s - pointer to second signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_sub(const zb_int24_t *f, const zb_int24_t *s, zb_int24_t *r); + + +/** + * Subtraction of two unsigned 24-bit values + * @param[in] f - pointer to first unsigned 24-bit operand + * @param[in] s - pointer to second unsigned 24-bit operand + * @param[out] r - pointer to 24-bit unsigned variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint24_sub(const zb_uint24_t *f, const zb_uint24_t *s, zb_uint24_t *r); + + +/** + * Negation of signed 24-bit values + * @param[in] f - pointer to signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_neg(const zb_int24_t *f, zb_int24_t *r); + + +/** + * Multiplication of two unsigned 24-bit values + * @param[in] f - pointer to first unsigned 24-bit operand + * @param[in] s - pointer to second unsigned 24-bit operand + * @param[out] r - pointer to 24-bit unsigned variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint24_mul(const zb_uint24_t *f, const zb_uint24_t *s, zb_uint24_t *r); + + +/** + * Multiplication of two signed 24-bit values + * @param[in] f - pointer to first signed 24-bit operand + * @param[in] s - pointer to second signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_mul(const zb_int24_t *f, const zb_int24_t *s, zb_int24_t *r); + + +/** + * Integer division of two unsigned 24-bit values + * @param[in] f - pointer to first unsigned 24-bit operand + * @param[in] s - pointer to second unsigned 24-bit operand + * @param[out] r - pointer to unsigned 24-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint24_div(const zb_uint24_t *f, const zb_uint24_t *s, zb_uint24_t *r); + + +/** + * Integer division of two signed 24-bit values + * @param[in] f - pointer to first signed 24-bit operand + * @param[in] s - pointer to second signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_div(const zb_int24_t *f, const zb_int24_t *s, zb_int24_t *r); + + +/** + * Modular division of two unsigned 24-bit values + * @param[in] f - pointer to first unsigned 24-bit operand + * @param[in] s - pointer to second unsigned 24-bit operand + * @param[out] r - pointer to unsigned 24-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint24_mod(const zb_uint24_t *f, const zb_uint24_t *s, zb_uint24_t *r); + + +/** + * Modular division of two signed 24-bit values + * @param[in] f - pointer to first signed 24-bit operand + * @param[in] s - pointer to second signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int24_mod(const zb_int24_t *f, const zb_int24_t *s, zb_int24_t *r); + + +/** + * Convert 64-bit value to 48-bit representation + * @param[in] var - 64-bit value + * @param[out] res - pointer to 48-bit variable + */ +void zb_uint64_to_uint48(zb_uint64_t var, zb_uint48_t *res); + + +/** + * Convert signed 48-bit value to signed 64-bit value + * @param[in] var - pointer to signed 48-bit value + * @return signed 64-bit representation of signed 48-bit value + */ +zb_int64_t zb_int48_to_int64(const zb_int48_t *var); + + +/** + * Convert signed 64-bit value to signed 48-bit value + * @param[in] var - signed 64-bit value + * @param[out] res - pointer to signed 48-bit value + */ +void zb_int64_to_int48(zb_int64_t var, zb_int48_t *res); + + +/** + * Convert signed 64-bit value to unsigned 48-bit value + * @param[in] var - signed 64-bit value + * @param[out] res - unsigned 48-bit value + * @return [description] + */ +void zb_int64_to_uint48(zb_int64_t var, zb_uint48_t *res); + + +/** + * Convert unsigned 48-bit value to signed 64-bit value + * @param[in] var - pointer to unsigned 64-bit value + * @return signed 64-bit representation of unsigned 48-bit value + */ +zb_int64_t zb_uint48_to_int64(const zb_uint48_t *var); + + +/** + * Addition of two unsigned 48-bit values + * @param[in] f - pointer to first insigne4824-bit operand + * @param[in] s - pointer to second insigne4824-bit operand + * @param[out] r - pointer to 48signed 24-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint48_add(const zb_uint48_t *f, const zb_uint48_t *s, zb_uint48_t *r); + + +/** + * Addition of two signed 48-bit values + * @param[in] f - pointer to first signed 48-bit operand + * @param[in] s - pointer to second signed 48-bit operand + * @param[out] r - pointer to 48-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_add(const zb_int48_t *f, const zb_int48_t *s, zb_int48_t *r); + + +/** + * Subtraction of two signed 48-bit values + * @param[in] f - pointer to first signed 48-bit operand + * @param[in] s - pointer to second signed 48-bit operand + * @param[out] r - pointer to 48-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_sub(const zb_int48_t *f, const zb_int48_t *s, zb_int48_t *r); + + +/** + * Subtraction of two unsigned 48-bit values + * @param[in] f - pointer to first unsigne4824-bit operand + * @param[in] s - pointer to second unsigne4824-bit operand + * @param[out] r - pointer to 48-bit unsigned variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint48_sub(const zb_uint48_t *f, const zb_uint48_t *s, zb_uint48_t *r); + + +/** + * Negation of signed 24-bit values + * @param[in] f - pointer to signed 24-bit operand + * @param[out] r - pointer to 24-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_neg(const zb_int48_t *f, zb_int48_t *r); + + +/** + * Multiplication of two unsigned 48-bit values + * @param[in] f - pointer to first unsigned 48-bit operand + * @param[in] s - pointer to second unsigned 48-bit operand + * @param[out] r - pointer to 48-bit unsigned variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint48_mul(const zb_uint48_t *f, const zb_uint48_t *s, zb_uint48_t *r); + + +/** + * Multiplication of two signed 48-bit values + * @param[in] f - pointer to first signed 48-bit operand + * @param[in] s - pointer to second signed 48-bit operand + * @param[out] r - pointer to 48-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_mul(const zb_int48_t *f, const zb_int48_t *s, zb_int48_t *r); + + +/** + * Integer division of two unsigned 48-bit values + * @param[in] f - pointer to first unsigned 48-bit operand + * @param[in] s - pointer to second unsigned 48-bit operand + * @param[out] r - pointer to unsigned 48-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint48_div(const zb_uint48_t *f, const zb_uint48_t *s, zb_uint48_t *r); + + +/** + * Integer division of two signed 48-bit values + * @param[in] f - pointer to first signed 48-bit operand + * @param[in] s - pointer to second signed 48-bit operand + * @param[out] r - pointer to 48-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_div(const zb_int48_t *f, const zb_int48_t *s, zb_int48_t *r); + + +/** + * Modular division of two unsigned 48-bit values + * @param[in] f - pointer to first unsigned 48-bit operand + * @param[in] s - pointer to second unsigned 48-bit operand + * @param[out] r - pointer to unsigned 48-bit variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_uint48_mod(const zb_uint48_t *f, const zb_uint48_t *s, zb_uint48_t *r); + + +/** + * Modular division of two signed 48-bit values + * @param[in] f - pointer to first signed 48-bit operand + * @param[in] s - pointer to second signed 48-bit operand + * @param[out] r - pointer to 48-bit signed variable to store result of operation + * @return @e ZB_MATH_OK on success, @e ZB_MATH_OVERFLOW on arithmetic overflow + * and @e ZB_MATH_ERROR on failure (see @ref zb_math_status_e). + */ +zb_uint8_t zb_int48_mod(const zb_int48_t *f, const zb_int48_t *s, zb_int48_t *r); + +/** @} */ /* 24_and_48_bit_arithm */ + +#define ZB_UINT48_ADD(val1, val2) zb_uint48_add(&val1, &val2, &val1) + +#define ZB_UINT48_SUB(val1, val2) zb_uint48_sub(&val1, &val2, &val1) + +#define ZB_INT24_FROM_INT32(var, int32_val) \ +{ \ + if (int32_val >= 0) \ + { \ + if (int32_val > (zb_int32_t)ZB_INT24_MAX_POSITIVE) \ + { \ + int32_val = (zb_int32_t)ZB_INT24_MAX_POSITIVE; \ + } \ + } \ + else \ + { \ + if (int32_val < (zb_int32_t)ZB_INT32_MINUS_ONE - (zb_int32_t)ZB_INT24_MAX_POSITIVE) \ + { \ + int32_val = (zb_int32_t)ZB_INT32_MINUS_ONE - (zb_int32_t)ZB_INT24_MAX_POSITIVE; \ + } \ + } \ + zb_int32_to_int24(int32_val, &var); \ +} + +#else /* ZB_UINT24_48_SUPPORT */ + +/* Now U48 type implemented as U32 */ +/* Now S24 type implemented as S32 */ + +typedef zb_uint64_t zb_uint48_t; +typedef zb_int64_t zb_int48_t; +typedef zb_int32_t zb_int24_t; +typedef zb_uint32_t zb_uint24_t; + + +#define ZB_INIT_UINT48(high_val, low_val) \ + (high_val) + +#define ZB_ASSIGN_UINT48(high_val, low_val) \ + (high_val) + +/* Stubs for operations with this types */ +#define ZB_UINT48_ADD(val1, val2) ((val1) + (val2)) +#define ZB_UINT48_SUB(val1, val2) ((val1) - (val2)) +#define ZB_UINT48_ADD_INT24(uint48_val, int24_val) ((zb_uint48_t)((uint48_val) + (int24_val))) + +#define ZB_ASSIGN_INT24_FROM_INT32(int32_val) \ + (int32_val) + +#define ZB_GET_INT32_FROM_INT24(int24_val) \ + (int24_val) + +#define ZB_ASSIGN_UINT24_FROM_UINT32(uint32_val) \ + (uint32_val) + +#define ZB_GET_UINT32_FROM_UINT24(uint24_val) \ + (uint24_val) + +#ifdef ZB_LITTLE_ENDIAN + +#define ZB_HTOLE24(ptr, val) ZB_MEMCPY((ptr), (val), ZB_24BIT_SIZE) +#define ZB_HTOLE48(ptr, val) ZB_MEMCPY((ptr), (val), ZB_48BIT_SIZE) + +#else + +#define ZB_HTOLE24(ptr, val) ZB_HTOLE32((ptr), (val)) +#define ZB_HTOLE48(ptr, val) ZB_HTOLE32((ptr), (val)) + +#endif + +#define ZB_UINT48_IS_EQUAL(val1, val2) \ + ((val1) == (val2)) + +#define ZB_UINT48_IS_GREAT(val1, val2) \ + ((val1) > (val2)) + +#define ZB_UINT48_IS_LESS(val1, val2) \ + ((val1) < (val2)) + +#define ZB_UINT48_IS_GREAT_OR_EQUAL(val1, val2) \ + (!ZB_UINT48_IS_LESS(val1, val2)) + +#define ZB_UINT48_IS_LESS_OR_EQUAL(val1, val2) \ + (!ZB_UINT48_IS_GREAT(val1, val2)) + +#endif /* ZB_UINT24_48_SUPPORT */ + +#define PUT_DATA24(ptr, val) (ZB_HTOLE24(ptr, val), (ptr) += ZB_24BIT_SIZE) +#define PUT_DATA24_VAL(ptr, val) \ +{ \ + zb_int24_t tmp_val = (val); \ + ZB_HTOLE24((ptr), &tmp_val); \ + (ptr) += ZB_24BIT_SIZE; \ +} + +#define PUT_DATA48(ptr, val) (ZB_HTOLE48(ptr, val), (ptr) += ZB_48BIT_SIZE) +#define PUT_DATA48_VAL(ptr, val) \ +{ \ + zb_uint48_t tmp_val = (val); \ + ZB_HTOLE48((ptr), &tmp_val); \ + (ptr) += ZB_48BIT_SIZE; \ +} + +/* take MSB nibble from uint8_t */ +#define ZB_UINT8_MSB_NIBBLE(X) (((X) >> 4) & 0x0F) + +/* take LSB nibble from uint8_t */ +#define ZB_UINT8_LSB_NIBBLE(X) ((X) & 0x0F) + +/* convert pair of nibbles into uint8_t */ +#define ZB_UINT4x2_TO_UINT8(MSB_N, LSB_N) \ + ((MSB_N << 4) | ZB_UINT8_LSB_NIBBLE(LSB_N)) + + +/** @} */ + +#endif /* ! defined ZB_TYPES_H */ diff --git a/zboss/include/zb_version.h b/zboss/include/zb_version.h new file mode 100644 index 0000000000..812093b0dc --- /dev/null +++ b/zboss/include/zb_version.h @@ -0,0 +1,62 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS version declare +*/ + +#ifndef _ZB_VERSION_H_ +#define _ZB_VERSION_H_ 1 + +#include "zb_revision_r22.h" + + +/* + ZBOSS SDK version: A.B.C.D + - ZBOSS_MAJOR (defines ZBOSS core version) + - ZBOSS_MINOR (defines ZBOSS core version) + - ZBOSS SDK type (HA/ZLL/etc.) + - ZBOSS SDK revision +*/ + +#define ZBOSS_MAJOR 3 +/* 2 - MM_SE enabled */ +#define ZBOSS_MINOR 3 + +#endif diff --git a/zboss/include/zb_zgp_default_match_info.h b/zboss/include/zb_zgp_default_match_info.h new file mode 100644 index 0000000000..be55a86493 --- /dev/null +++ b/zboss/include/zb_zgp_default_match_info.h @@ -0,0 +1,100 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Provides example of matching table declaration for ZGPS sink +*/ + +#ifndef ZB_ZGP_DEFAULT_MATCH_INFO_H +#define ZB_ZGP_DEFAULT_MATCH_INFO_H 1 + +#include "zb_common.h" + +#ifdef ZB_ENABLE_ZGP_SINK +#include "zboss_api_zgp.h" + +/** + * @ingroup zgp_sink + * @file zb_zgp_default_match_info.h + * Provides example of matching table declaration for ZGPS sink + * @include zb_zgp_default_match_info.h + */ + +/** + * Default matching table. + */ +zgps_dev_match_rec_t g_zgps_match_tbl[] = +{ +#ifdef ZGPS_MATCH_TBL_TEMPERATURE_SENSOR_ENTRY + { + ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT, + ZB_ZCL_CLUSTER_CLIENT_ROLE, + {ZB_GPDF_CMD_ATTR_REPORT, ZB_GPDF_CMD_MULTI_CLUSTER_ATTR_REPORT, 0}, + ZB_ZGP_TEMPERATURE_SENSOR_DEV_ID, + }, +#endif + +}; + + +/** + * Mapping of ZGPD commands IDs to Zigbee ZCL commands IDs + */ +zgp_to_zb_cmd_mapping_t g_cmd_mapping[] = +{ +#if defined ZGPS_MATCH_TBL_TEMPERATURE_SENSOR_ENTRY + {ZB_GPDF_CMD_ATTR_REPORT, ZB_ZCL_CMD_REPORT_ATTRIB}, +#endif +}; + + +/** + * Default matching info + */ +zb_zgps_match_info_t g_default_zgps_match_info = +{ + ZB_ARRAY_SIZE(g_zgps_match_tbl), + g_zgps_match_tbl, + ZB_ARRAY_SIZE(g_cmd_mapping), + g_cmd_mapping, + 0, + NULL +}; +#endif /* ZB_ENABLE_ZGP_SINK */ +#endif //ZB_ZGP_DEFAULT_MATCH_INFO_H diff --git a/zboss/include/zboss_api.h b/zboss/include/zboss_api.h new file mode 100644 index 0000000000..1de8eeaeed --- /dev/null +++ b/zboss/include/zboss_api.h @@ -0,0 +1,1126 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS API header +*/ +#ifndef ZBOSS_API_H +#define ZBOSS_API_H 1 + +#include "zb_version.h" +#include "zboss_api_core.h" +#include "zboss_api_buf.h" +#include "zboss_api_internal.h" +#include "zboss_api_nwk.h" +#include "zboss_api_af.h" +#include "zboss_api_zdo.h" +#include "zboss_api_aps.h" +#ifdef ZB_ENABLE_HA +#include "zb_ha.h" +#endif +#include "zb_address.h" +#include "zboss_api_zcl.h" +#ifdef ZB_ENABLE_ZGP +#include "zboss_api_zgp.h" +#endif + +/** @cond (!DOXYGEN_ERL_SECTION) */ +/*! @cond DOXYGEN_SECUR_SECTION */ +/*! @addtogroup secur_api */ +/*! @{ */ + +/** @fn void zb_secur_setup_nwk_key(zb_uint8_t *key, zb_uint8_t i) + * @brief Setup nwk key to be used by ZCP tests. + * @param key - key to be used + * @param i - key number (0-3) + * @details Call this routine at TC to change random nwk key generated from zb_ib_set_defaults + * to well-known key. To be used in certification tests. + * @snippet simple_gw/simple_gw.c zb_secur_setup_preconfigured_key_value + * @snippet simple_gw/simple_gw.c zb_secur_setup_preconfigured_key + * @see TP_R20_BV-01 sample. + */ +void zb_secur_setup_nwk_key(zb_uint8_t *key, zb_uint8_t i); + +/** + * Initiate procedure of NWk key switching. + * + * Generate next NWK key if it not exists, broadcast new NWK key, after delay broadcast NWK key switch command. + * Can run at TC only. + * + * @param param - work buffer id or 0 (is zero, function allocates buffer itself) + */ +void zb_secur_nwk_key_switch_procedure(zb_uint8_t param); + +/** + * Specifies whether Trust Center Rejoin is allowed. + * + * If set to ZB_FALSE, devices that attempted unsecure rejoin will not be authorized. + * + * @param enable - whether to enable or disable TC Rejoin. + */ +void zb_secur_set_tc_rejoin_enabled(zb_bool_t enable); +/*! @} */ /* secur_api*/ +/** @endcond */ /* DOXYGEN_SECUR_SECTION */ + +/*! @cond DOXYGEN_SE_SECTION */ +/*! @addtogroup se_secur */ +/*! @{ */ + +/** + * Initiate procedure of NWk key switching. + * + * Generate link key with device, update link key. + * Can run at TC only. + * + * @param addr_of_interest - network address of ZC to ask ZC for KEC. + */ +#ifdef ZB_COORDINATOR_ROLE +#ifndef ZB_LITE_NO_TRUST_CENTER_REQUIRE_KEY_EXCHANGE +void se_tc_update_link_key(zb_uint16_t addr_of_interest); +#endif +#endif + + +typedef enum { + ZB_IC_TYPE_48 = 0, + ZB_IC_TYPE_64, + ZB_IC_TYPE_96, + ZB_IC_TYPE_128, + ZB_IC_TYPE_MAX +} zb_ic_types_t; + +/** @fn zb_ret_t zb_secur_ic_add(zb_ieee_addr_t address, zb_uint8_t ic_type, zb_uint8_t *ic) + * @brief Add install code for the device with specified long address + * @param[in] address - long address of the device to add the install code + * @param[in] ic_type - install code type as enumerated in + * @if ZB_SECUR + * @ref zb_ic_types_t + * @else + * zb_ic_types_t + * @endif + * @param[in] ic - pointer to the install code buffer + * @details This call allows to add install codes for several devices into NVRAM. It makes + * sense for Trust Center/Coordinator devices only as usual device doesn't need to have + * someone's else install codes. + * @note This call is valid only for the TC (ZC)! + * @return RET_OK on success or RET_CONVERSION_ERROR on error in install code + * @par Example + * @snippet doxygen_snippets.dox wrong_ic_snippet_cs_ick_tc_02_dut_using_ic_c + */ +zb_ret_t zb_secur_ic_add(zb_ieee_addr_t address, zb_uint8_t ic_type, zb_uint8_t *ic); + + +/** @fn zb_ret_t zb_secur_ic_set(zb_uint8_t ic_type, zb_uint8_t *ic) + * @brief Set install code for the device + * @param[in] ic_type - install code type as enumerated in + * @if ZB_SECUR + * @ref zb_ic_types_t + * @else + * zb_ic_types_t + * @endif + * @param[in] ic - pointer to the install code buffer + * @details This call allows to set the install code for the current device. It is assumed + * that device can have only one install code. + * @note This function is to be run at client side (not at TC). + * @return RET_OK on success or RET_CONVERSION_ERROR on error in install code + */ +zb_ret_t zb_secur_ic_set(zb_uint8_t ic_type, zb_uint8_t *ic); + +/** + Get list of the install codes. + + It is valid only for the TC (ZC). + + @param table - pointer to the allocated space for the entries. + @param cnt - pointer to the counter that indicates count of the output items in the table. + + @return RET_OK on success or RET_ERROR in case of fail +*/ +zb_ret_t zb_secur_ic_get_list(zb_uint8_t* table, zb_uint8_t *cnt); + +/** + Get the install code by index. + + It is valid only for the TC (ZC). + + @param param - pointer to the allocated space for the entry. + @param index - the index of the entry in the install codes table. + + @return RET_OK on success or RET_ERROR in case of fail +*/ + +zb_ret_t zb_secur_ic_get_by_idx(zb_uint8_t* param, zb_uint8_t index); + +/** + Remove the install code for the device with specified long + address. + + It is valid only for the TC (ZC). + + @param address - long address of the device for which the install code is to be deleted. + + @return RET_OK on success or RET_NO_MATCH if installcode + for address isn't present +*/ +zb_ret_t zb_secur_ic_remove(zb_ieee_addr_t address); + +/** + Remove the install code for all devices. + + It is valid only for the TC (ZC). + + @return RET_OK on success or RET_ERROR in case of fail +*/ +zb_ret_t zb_secur_ic_remove_all(void); + + +/** @fn zb_ret_t zb_secur_ic_str_set(char *ic_str) + * @brief Set install code for the device from character string + * @param[in] ic_str - install code text string + * @details This call allows to set the install code for the current device. It is assumed + * that device can have only one install code. + * @note This function is to be run at client side (not at TC). + * @returns RET_OK on success. + */ +zb_ret_t zb_secur_ic_str_set(char *ic_str); + +/** @fn zb_ret_t zb_secur_ic_str_add(zb_ieee_addr_t address, char *ic_str) + * @brief Add install code for the device from character string + * @param[in] address - long address of the device to add the install code for + * @param[in] ic_str - install code text string + * @details This call allows to add install codes for several devices into NVRAM. It makes + * sense for Trust Center/Coordinator devices only as usual device doesn't need to have + * someone's else install codes. + * @note This call is valid only for the TC (ZC)! + * @returns RET_OK on success. + */ +zb_ret_t zb_secur_ic_str_add(zb_ieee_addr_t address, char *ic_str); + +/** + Set installcode policy flag. + + @param allow_ic_only - use ZB_TRUE value to check installcodes +*/ +void zb_set_installcode_policy(zb_bool_t allow_ic_only); + +#ifdef ZB_ROUTER_ROLE +/** + Disable APS-encryption of Transport Key from the ZC. + + This valid is only for the TC (ZC). +*/ +void zb_disable_transport_key_aps_encryption(void); +/** + Enable APS-encryption of Transport Key from the ZC. + + This valid is only for the TC (ZC). +*/ +void zb_enable_transport_key_aps_encryption(void); +/** + Get the status of the APS-encryption of Transport Key from the ZC. + + This valid is only for the TC (ZC). + + @return ZB_TRUE when APS-encryption of Transport Key is enabled, ZB_FALSE otherwise +*/ +zb_bool_t zb_is_transport_key_aps_encryption_enabled(void); +#endif /* ZB_ROUTER_ROLE */ + +/*! @} */ /* se_secur */ +/*! @endcond */ /* DOXYGEN_SE_SECTION */ +/*! @endcond */ /* DOXYGEN_ERL_SECTION */ + +/*! @cond DOXYGEN_GENERAL_SECTION */ +/*! @addtogroup zboss_general_api */ +/*! @{ */ + +#ifdef DOXYGEN +/** + ZBOSS application entry point. + + Application program using ZBOSS must use MAIN() as an entry point and do not implement function main(). + At some, but not at all platforms MAIN() is an alias for main(). + */ +#define MAIN() main(a,v) + + +/** + Return statement of ZBOSS application entry point. + Corresponds to exit() call from main(). + Platform-dependent. + */ +#define MAIN_RETURN(retc) return (retc) + +#endif /* DOXYGEN */ + +/** @cond internals_doc */ +/** + Check whether the right library is selected at application compilation time + + To be called from ZB_INIT() at start. + */ +#ifdef ZB_ED_ROLE +#define ZB_CHECK_LIBRARY() since_you_got_that_symbol_unresolved_you_probably_use_ZB_ED_ROLE_preprocessor_define_while_linking_with_zc_library(); +void since_you_got_that_symbol_unresolved_you_probably_use_ZB_ED_ROLE_preprocessor_define_while_linking_with_zc_library(void); +#else +#define ZB_CHECK_LIBRARY() since_you_got_that_symbol_unresolved_you_probably_forget_use_ZB_ED_ROLE_preprocessor_define_while_linking_with_zed_library(); +void since_you_got_that_symbol_unresolved_you_probably_forget_use_ZB_ED_ROLE_preprocessor_define_while_linking_with_zed_library(void); +#endif /* ZB_ED_ROLE */ + +/* minor internal hack for CI system */ +#define ZB_SET_NS_UART_CB_STUB() + +/** @endcond*/ /*internals_doc*/ + +/*! @addtogroup zb_general_start */ +/*! @{ */ +#if defined ZB_INIT_HAS_ARGS || defined DOXYGEN +/** + Global stack initialization. + + To be called from MAIN() at start. + + Usual initialization sequence: ZB_INIT(), then assign some IB values, then zboss_start(). + + @param trace_comment - trace file name component (valid for Unix, ignored at MCU) + + @b Example: +@code + ZB_INIT("zdo_zc"); +@endcode + + See any sample + */ +#define ZB_INIT(trace_comment) \ +{ \ + ZB_CHECK_LIBRARY(); \ + zb_init((zb_char_t *)trace_comment); \ + ZB_SET_NS_UART_CB_STUB(); \ +} +/** @cond internals_doc */ +/** @brief Global stack initialization. + + Don't call directly, use ZB_INIT() instead +*/ +void zb_init(zb_char_t *trace_comment); +/** @endcond */ /* internals_doc */ +#else +/** + Global stack initialization. + + To be called from MAIN() at start. + + Usual initialization sequence: ZB_INIT(), then assign some IB values, then zboss_start(). + + @param trace_comment - trace file name component (valid for Unix, ignored at MCU) + + @b Example: +@code + ZB_INIT("zdo_zc"); +@endcode + + See any sample + */ +#define ZB_INIT(trace_comment) \ +{ \ + ZB_CHECK_LIBRARY(); \ + zb_init(); \ + ZB_SET_NS_UART_CB_STUB(); \ +} +void zb_init(void); +#endif /* ZB_INIT_HAS_ARGS || defined DOXYGEN */ +/*! @} */ /* zb_general_start */ + +/*! @addtogroup zb_general_set */ +/*! @{ */ +/** + Set channel mask on device. + @param channel_mask - Zigbee channel mask + + @b Example: +@code + zb_set_channel((1l<<13) | (1l<<14)); +@endcode +*/ +void zb_set_channel_mask(zb_uint32_t channel_mask); + +/** @cond DOXYGEN_BDB_SECTION */ + +#ifdef ZB_OSIF_CONFIGURABLE_TX_POWER +/** + Set transmit power. + @param tx_power - Transmit power [dBm]. + + @b Example: +@code + zb_set_tx_power(0x32); +@endcode +*/ +zb_ret_t zb_set_tx_power(zb_uint8_t tx_power); +#endif + +/** @endcond */ /* DOXYGEN_BDB_SECTION */ + +/** + Set RxOnWhenIdle attribute + @param rx_on - attribute value + + + @b Example: +@code + zb_set_rx_on_when_idle(ZB_FALSE); // switch device to rx off +@endcode +*/ +void zb_set_rx_on_when_idle(zb_bool_t rx_on); + +/*! @} */ /* zb_general_set */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ + +/** + Returns current state of RX-ON-When-Idle of Zigbee ZED + + @return ZB_TRUE if ZED is not sleepy ZED, ZB_FALSE if ZED is a sleepy ZED + */ +zb_bool_t zb_get_rx_on_when_idle(void); + +/*! @} */ /* zb_general_get */ + +/*! @addtogroup zb_general_start */ +/*! @{ */ + +/** @brief ZBOSS start function. + * + * Typical device start: init, load some parameters from nvram and proceed with startup. + * + * Startup means either Formation (for ZC), rejoin or discovery/association join. After startup + * complete @ref zboss_signal_handler callback is called, so application will know when to do + * some useful things. + * + * Precondition: stack must be inited by @ref ZB_INIT() call. @ref ZB_INIT() sets default IB + * parameters, so caller has a chance to change some of them. Note that NVRAM will be loaded after + * zboss_start() call. + * @note ZB is not looped in this routine. Instead, it schedules callback and returns. Caller + * must run @ref zboss_main_loop() after this routine. + * + * @return RET_OK on success. + */ +zb_ret_t zboss_start(void); + + +/*! @} */ /* zb_general_start */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ +/** + * @brief Get ZBOSS version. + * @returns Pointer to zero-terminated version string. + */ +const zb_char_t ZB_IAR_CODE *zb_get_version(void); +/*! @} */ /* zb_general_get */ + +/*! @addtogroup zb_general_start */ +/*! @{ */ + +/** + Start ZBOSS with only minimal initialization, without starting commissioning. + + This function initializes scheduler and buffers pool, but not MAC and upper layers. + Typically zboss_start_no_autostart() is used when application wants to do something before + starting joining the network. + + For example, you can use this function if it is needed to enable leds, timers + or any other devices on periphery to work with them before starting working in a network. It's + also usefull if you want to run something localy during joining. + + Application should later call ZBOSS commissioning initiation - for + instance, + @if zb_bdb_mode + @ref bdb_start_top_level_commissioning(). + @else + bdb_start_top_level_commissioning() + @endif + + + To finish node initialization without triggering commissioning call @ref + bdb_start_top_level_commissioning() with commissioning mask 0 (no steering, no formation, + initialization only). + + @return RET_OK on success. + */ +zb_ret_t zboss_start_no_autostart(void); + +void zboss_start_continue(void); + +#ifdef ZB_PROMISCUOUS_MODE + +/** + Start ZBOSS in the sniffer mode + + Initialize ZBOSS MAC layer to work as a sniffer. + Once ZBOSS is intialized in the sniffer mode, it can't be commissioned in the + normal mode until reboot. + */ +zb_ret_t zboss_start_in_sniffer_mode(void); + +/** + Start sniffing + + ZBOSS must be started in the sniffer mode. + + @param channel - channel to work on + @param data_ind_cb - callback to be called to pass data to the sniffer application + */ +void zboss_sniffer_start(zb_uint8_t channel, zb_callback_t data_ind_cb); + +/** + Stop sniffing or do nothing if not sniffing now. + + ZBOSS must be started in the sniffer mode. + */ +void zboss_sniffer_stop(void); +#endif /* ZB_PROMISCUOUS_MODE */ + +/*! @} */ /* zb_general_start */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ + +/** @cond internals_doc */ +zb_bool_t zb_zdo_joined(void); +/** @endcond */ + +/** + Checks that device is joined to the network. + @return true if device is joined; false - otherwise +*/ +#define ZB_JOINED() zb_zdo_joined() + +/*! @} */ /*zb_general_get */ + +/*! @addtogroup zb_general_main_loop */ +/*! @{ */ + +/** + ZBOSS main loop. + Must be called after ZB_INIT() and zboss_start(). + Loops infinitely. + + @snippet light_sample/dimmable_light/bulb.c zboss_main_loop_init + @snippet light_sample/dimmable_light/bulb.c zboss_main_loop +*/ +void zboss_main_loop(void); + +/** + ZBOSS main loop iteration. + + This function is useful if application wants to do something special in the + main loop without involving ZBOSS scheduler. + + Must be called after ZB_INIT() and zboss_start() / zboss_start_no_autostart() + inside the application's main cycle. + @snippet onoff_server/on_off_switch_zed.c zboss_main_loop_iteration_declaring + @snippet onoff_server/on_off_switch_zed.c zboss_main_loop_iteration_usage +*/ + +void zboss_main_loop_iteration(void); + +/*! @} */ /* zb_general_main_loop */ + +/*! @addtogroup zb_general_set */ +/*! @{ */ + +/** + Set 64-bit long address + @param addr - long address structure +*/ +void zb_set_long_address(const zb_ieee_addr_t addr); + +/** @fn void zb_set_pan_id(zb_uint16_t pan_id) + * @brief Set 16-bit PAN ID + * @param[in] pan_id - PAN ID + */ +void zb_set_pan_id(zb_uint16_t pan_id); + +/** + Set Manufacturer code of Node Descriptor + @param manuf_code - Manufacturer code +*/ +void zb_set_node_descriptor_manufacturer_code(zb_uint16_t manuf_code); + +/*! @} */ /* zb_general_set */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ + +/** + Get 64-bit long address + @param addr - pointer to memory where result will be stored + */ +void zb_get_long_address(zb_ieee_addr_t addr); + +/*! @} */ /* zb_general_get */ + +/*! @addtogroup zb_general_set */ +/*! @{ */ + +/** + Set Extended Pan ID (apsUseExtendedPANID attribute) + @param ext_pan_id - Long (64-bit) Extended Pan ID +*/ +void zb_set_extended_pan_id(const zb_ext_pan_id_t ext_pan_id); + +/*! @} */ /* zb_general_set */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ + +/** + Get Extended Pan ID (nwkExtendedPANId attribute) + @param ext_pan_id - pointer to memory where result will be stored + */ +void zb_get_extended_pan_id(zb_ext_pan_id_t ext_pan_id); + +/*! @} */ /* zb_general_get */ + +/*! @addtogroup zb_general_set */ +/*! @{ */ + +/** + Initiate device as a Zigbee 3.0 (not SE!) coordinator + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_coordinator_role(zb_uint32_t channel_mask); +/** + Initiate device as a legacy (pre-r21) Zigbee coordinator + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_coordinator_role_legacy(zb_uint32_t channel_mask); + +/** + Initiate device as a Zigbee Zigbee 3.0 (not SE!) router + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_router_role(zb_uint32_t channel_mask); +/** + Initiate device as a legacy (pre-r21) Zigbee router + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_router_role_legacy(zb_uint32_t channel_mask); + +/** + Initiate device as a Zigbee Zigbee 3.0 (not SE!) End Device + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_ed_role(zb_uint32_t channel_mask); + +/** + Initiate device as a legacy (pre-r21) Zigbee End Device + @param channel_mask - Zigbee channel mask +*/ +void zb_set_network_ed_role_legacy(zb_uint32_t channel_mask); + +/*! @} */ /* zb_general_set */ + +/*! @addtogroup zb_general_get */ +/*! @{ */ + +/** + * Returns the device role ID + * + * @return - zb_nwk_device_type_t device_role_id + */ +zb_nwk_device_type_t zb_get_network_role(void); + +/*! @} */ /* zb_general_get */ + +/** @addtogroup zb_general_set +@{ +*/ + +void zb_se_set_bdb_mode_enabled(zb_uint8_t enabled); + +/** + Enum for channel pages' numbers + */ +enum zb_channel_page_num_e +{ + ZB_CHANNEL_PAGE0_2_4_GHZ = 0, + ZB_CHANNEL_PAGE28_SUB_GHZ = 28, + ZB_CHANNEL_PAGE29_SUB_GHZ = 29, + ZB_CHANNEL_PAGE30_SUB_GHZ = 30, + ZB_CHANNEL_PAGE31_SUB_GHZ = 31, +}; + +/** + Initialize a channel list + @param channel_list - pointer to a channel list + */ +void zb_channel_list_init(zb_channel_list_t channel_list); + + +/** + Add channel mask for a specified channel page in a channel list + @param channel_list - pointer to a channel list + @param page_num - channel page number - @ref zb_channel_page_num_e + @param channel_mask - Zigbee channel mask + + @return RET_OK if ok, else error code + */ +zb_ret_t zb_channel_list_add(zb_channel_list_t channel_list, zb_uint8_t page_num, zb_uint32_t channel_mask); + +/** + Set the maximum number of connected devices. Used for coordinators + and routers + @param max_children - maximum number of connected devices. +*/ +void zb_set_max_children(zb_uint8_t max_children); + + +/** + * Enumeration, which store all values, which can be used in End Device timeout request + */ +typedef enum nwk_requested_timeout_e +{ + ED_AGING_TIMEOUT_10SEC = 0, /*!< 10 second timeout */ + ED_AGING_TIMEOUT_2MIN, /*!< 2 minutes */ + ED_AGING_TIMEOUT_4MIN, /*!< 4 minutes */ + ED_AGING_TIMEOUT_8MIN, /*!< 8 minutes */ + ED_AGING_TIMEOUT_16MIN, /*!< 16 minutes */ + ED_AGING_TIMEOUT_32MIN, /*!< 32 minutes */ + ED_AGING_TIMEOUT_64MIN, /*!< 64 minutes */ + ED_AGING_TIMEOUT_128MIN, /*!< 128 minutes */ + ED_AGING_TIMEOUT_256MIN, /*!< 256 minutes */ + ED_AGING_TIMEOUT_512MIN, /*!< 512 minutes */ + ED_AGING_TIMEOUT_1024MIN, /*!< 1024 minutes */ + ED_AGING_TIMEOUT_2048MIN, /*!< 2048 minutes */ + ED_AGING_TIMEOUT_4096MIN, /*!< 4096 minutes */ + ED_AGING_TIMEOUT_8192MIN, /*!< 8192 minutes */ + ED_AGING_TIMEOUT_16384MIN /*!< 16384 minutes */ +} nwk_requested_timeout_t; + +/** + Set end device timeout. + + Use it on End Device to specify End Device timeout period used in ED Timeout request. + @param to - index in @ref nwk_requested_timeout_e +*/ +void zb_set_ed_timeout(zb_uint_t to); + +/** + Set keep alive timeout. + + Use it on End Device to specify how often device should poll its parent. + @param to - timeout, in beacon intervals +*/ +void zb_set_keepalive_timeout(zb_uint_t to); + +/** @} */ /* zb_general_set */ + + +/** + * @addtogroup zb_comm_signals + * @{ + */ + +/** + ZBOSS application signal handler. + + Mandatory for all applications implemented on the top of ZBOSS stack. + See @ref zb_zdo_app_signal_type_e. + + @param param - reference to the buffer which contains signal. See @ref zb_get_app_signal. +*/ +void zboss_signal_handler(zb_uint8_t param); + +/** @} */ /* zb_comm_signals */ + +/*! @endcond */ /* DOXYGEN_GENERAL_SECTION */ + +/*! @cond DOXYGEN_LL_SECTION */ +/*! @addtogroup zboss_nvram */ +/** @{ */ + +/** + * Enum All NVRAM dataset types + * + * ZB_NVRAM_DATASET_NUMBER - count of dataset types. Not a real dataset type! + */ +typedef enum zb_nvram_dataset_types_e +{ + /* Do not use 0 as dataset type: it can be used internally */ + ZB_NVRAM_RESERVED = 0, /**< Reserved value */ + ZB_NVRAM_COMMON_DATA = 1, /**< Dataset, contains common Zigbee data */ + ZB_NVRAM_HA_DATA = 2, /**< Dataset, contains HA profile Zigbee data */ + ZB_NVRAM_ZCL_REPORTING_DATA = 3, /**< Dataset, contains ZCL reporting data */ + ZB_NVRAM_APS_SECURE_DATA_GAP = 4, /**< Reserved value */ + ZB_NVRAM_APS_BINDING_DATA_GAP = 5, /**< Reserved value */ + ZB_NVRAM_HA_POLL_CONTROL_DATA = 6, /**< Dataset, contains HA POLL CONTROL data */ + ZB_IB_COUNTERS = 7, /**< Dataset, contains NIB outgoing frame counter */ + ZB_NVRAM_DATASET_GRPW_DATA = 8, /**< Green Power dataset */ + ZB_NVRAM_APP_DATA1 = 9, /**< Application-specific data #1 */ + ZB_NVRAM_APP_DATA2 = 10, /**< Application-specific data #2 */ + ZB_NVRAM_ADDR_MAP = 11, /**< Dataset stores address map info */ + ZB_NVRAM_NEIGHBOUR_TBL = 12, /**< Dataset stores Neighbour table info */ + ZB_NVRAM_INSTALLCODES = 13, /**< Dataset contains APS installcodes data */ + ZB_NVRAM_APS_SECURE_DATA = 14, /**< Dataset, contains APS secure keys data */ + ZB_NVRAM_APS_BINDING_DATA = 15, /**< Dataset, contains APS binding data */ + ZB_NVRAM_DATASET_GP_PRPOXYT = 16, /**< Green Power Proxy table */ + ZB_NVRAM_DATASET_GP_SINKT = 17, /**< Green Power Sink table */ + ZB_NVRAM_DATASET_GP_CLUSTER = 18, /**< Green Power Cluster data */ + ZB_NVRAM_APS_GROUPS_DATA = 19, /**< Dataset, contains APS groups data */ + ZB_NVRAM_DATASET_SE_CERTDB = 20, /**< Smart Energy Dataset - Certificates DataBase */ + ZB_NVRAM_ZCL_WWAH_DATA = 21, /**< Dataset, contains ZCL WWAH data */ + + /* Note: added new app_data datasets down and created a hole for new system datasets. + */ + ZB_NVRAM_APP_DATA3 = 27, /**< Application-specific data #3 */ + ZB_NVRAM_APP_DATA4 = 28, /**< Application-specific data #4 */ + ZB_NVRAM_DATASET_NUMBER, /**< Count of Dataset */ + ZB_NVRAM_DATA_SET_TYPE_PAGE_HDR = 0x1e /**< Special internal dataset type */ +} zb_nvram_dataset_types_t; + + +/** + * Declares application callback used for reading application datasets from NVRAM. + * + * @param page - page in NVRAM from data will be read + * @param pos - offset in page + * @param payload_length - number of bytes to read + */ +typedef void (*zb_nvram_read_app_data_t)(zb_uint8_t page, zb_uint32_t pos, zb_uint16_t payload_length); + +/** + * Declares application callback used for writing application datasets into NVRAM. + * + * @param page - page in NVRAM where data will be stored + * @param pos - offset in page + * + * @return - RET_OK on successful write + */ +typedef zb_ret_t (*zb_nvram_write_app_data_t)(zb_uint8_t page, zb_uint32_t pos); + +/** + * Returns size of application datasets + * + * @return - size of application dataset in bytes + */ +typedef zb_uint16_t (*zb_nvram_get_app_data_size_t)(void); + +/** + * Register application callback for reading @ref ZB_NVRAM_APP_DATA1 from NVRAM + * + * @param cb - callback that will be called upon reading dataset + */ +void zb_nvram_register_app1_read_cb(zb_nvram_read_app_data_t cb); + +/** + * Register application callback for reading @ref ZB_NVRAM_APP_DATA2 from NVRAM + * + * @param cb - callback that will be called upon reading dataset + */ +void zb_nvram_register_app2_read_cb(zb_nvram_read_app_data_t cb); + +/** + * Register application callback for reading @ref ZB_NVRAM_APP_DATA3 from NVRAM + * + * @param cb - callback that will be called upon reading dataset + */ +void zb_nvram_register_app3_read_cb(zb_nvram_read_app_data_t cb); + +/** + * Register application callback for reading @ref ZB_NVRAM_APP_DATA4 from NVRAM + * + * @param cb - callback that will be called upon reading dataset + */ +void zb_nvram_register_app4_read_cb(zb_nvram_read_app_data_t cb); + +/** + * Register application callback for writing @ref ZB_NVRAM_APP_DATA1 to NVRAM + * + * @param wcb - callback that will be called upon writing + * @param gcb - this callback will be called upon writing to determine dataset size + */ +void zb_nvram_register_app1_write_cb( + zb_nvram_write_app_data_t wcb, + zb_nvram_get_app_data_size_t gcb); + +/** + * Register application callback for writing @ref ZB_NVRAM_APP_DATA2 to NVRAM + * + * @param wcb - callback that will be called upon writing + * @param gcb - this callback will be called upon writing to determine dataset size + */ +void zb_nvram_register_app2_write_cb( + zb_nvram_write_app_data_t wcb, + zb_nvram_get_app_data_size_t gcb); + +/** + * Register application callback for writing @ref ZB_NVRAM_APP_DATA3 to NVRAM + * + * @param wcb - callback that will be called upon writing + * @param gcb - this callback will be called upon writing to determine dataset size + */ +void zb_nvram_register_app3_write_cb( + zb_nvram_write_app_data_t wcb, + zb_nvram_get_app_data_size_t gcb); + +/** + * Register application callback for writing @ref ZB_NVRAM_APP_DATA4 to NVRAM + * + * @param wcb - callback that will be called upon writing + * @param gcb - this callback will be called upon writing to determine dataset size + */ +void zb_nvram_register_app4_write_cb( + zb_nvram_write_app_data_t wcb, + zb_nvram_get_app_data_size_t gcb); + +/** + * Write specified dataset into NVRAM + * + * @param t - dataset index, see @ref zb_nvram_dataset_types_e + * + * @b Example @b: + * @snippet light_sample/dimmable_light/bulb.c nvram_usage_example + * + * See light_sample + */ +void zb_nvram_write_dataset(zb_nvram_dataset_types_t t); +/** @cond internals_doc */ +/** + * Clears all datasets except @ref ZB_IB_COUNTERS and application datasets. + */ +void zb_nvram_clear(void); +/** @endcond */ +/** + Erase Informational Bases to NVRAM or other persistent storage + */ +void zb_nvram_erase(void); + +/** + Enable or disable NVRAM erasing on every application startup. + @param erase - 1 to enable erasing; 0 - disable. + Erasing is disabled by default. +*/ +void zb_set_nvram_erase_at_start(zb_bool_t erase); + +/** + Start NVRAM transaction. + + Start writing multiple datasets at once. + A transaction must finished by calling zb_nvram_transaction_commit(). + */ +void zb_nvram_transaction_start(void); + +/** + Commit NVRAM transaction. + + Finish writing multiple datasets at once. + A transaction must started by calling zb_nvram_transaction_start(). + */ +void zb_nvram_transaction_commit(void); + +/** @} */ /* zboss_nvram */ +/*! @endcond */ /* DOXYGEN_LL_SECTION */ + +/** @cond internals_doc */ +#define ZB_INVALID_TX_POWER_VALUE 0x7F +/** @endcond */ + +#ifdef ZB_PRODUCTION_CONFIG +/** @cond internals_doc */ + +/** Maximum size of production configuration */ +#define ZB_PRODUCTION_CONFIG_APP_MAX_SIZE 128 + +typedef ZB_PACKED_PRE struct zb_production_config_hdr_s +{ + zb_uint32_t crc; /*!< crc for the whole production configuration (including application specific part) */ + zb_uint16_t len; /*!< length of production configuration (including application specific part) */ + zb_uint16_t version; /*!< Version of production configuration (reserved for future changes) */ +} +ZB_PACKED_STRUCT zb_production_config_hdr_t; + +typedef ZB_PACKED_PRE struct zb_production_config_ver_1_s +{ + zb_production_config_hdr_t hdr; /*!< Header */ + zb_uint32_t aps_channel_mask; /*!< APS Channel Mask */ + zb_64bit_addr_t extended_address; /*!< IEEE address */ + zb_int8_t mac_tx_power[16]; /*!< Tx power specified for every possible channel */ + zb_uint8_t install_code[ZB_CCM_KEY_SIZE+2]; /*!< Installation code + its own crc */ +} +ZB_PACKED_STRUCT zb_production_config_ver_1_t; + +#define ZB_PROD_CFG_APS_CHANNEL_LIST_SIZE 5 +#define ZB_PROD_CFG_MAC_TX_POWER_CHANNEL_N 27 + +#define ZB_PROD_CFG_OPTIONS_IC_TYPE_MASK 0x03 +#define ZB_PROD_CFG_OPTIONS_CERT_PRESENT_MASK 0x80 + +typedef ZB_PACKED_PRE struct zb_production_config_ver_2_s +{ + zb_production_config_hdr_t hdr; /*!< Header */ + zb_channel_page_t aps_channel_mask_list[ZB_PROD_CFG_APS_CHANNEL_LIST_SIZE]; /*!< Channel mask for device to operate on */ + zb_64bit_addr_t extended_address; /*!< IEEE address */ + zb_int8_t mac_tx_power[ZB_PROD_CFG_APS_CHANNEL_LIST_SIZE][ZB_PROD_CFG_MAC_TX_POWER_CHANNEL_N]; /*! < Tx power specified for every possible channel */ + zb_uint8_t options;/*low 2 bits - ic_type field *//*7th bit - certificates block presents*/ + zb_uint8_t install_code[ZB_CCM_KEY_SIZE+2]; /*!< Installation code + its own crc */ +} +ZB_PACKED_STRUCT zb_production_config_ver_2_t; + +typedef zb_production_config_ver_2_t zb_production_config_t; + +#define ZB_CS1_PUBLISHER_PUBLIC_KEY_SIZE 22 +#define ZB_CS1_CERTIFICATE_SIZE 48 +#define ZB_CS1_PRIVATE_KEY_SIZE 21 + +#define ZB_CS2_PUBLISHER_PUBLIC_KEY_SIZE 37 +#define ZB_CS2_CERTIFICATE_SIZE 74 +#define ZB_CS2_PRIVATE_KEY_SIZE 36 + +typedef ZB_PACKED_PRE struct zb_cs1_key_material_s +{ + zb_uint8_t publisher_public_key[ZB_CS1_PUBLISHER_PUBLIC_KEY_SIZE]; + zb_uint8_t certificate[ZB_CS1_CERTIFICATE_SIZE]; + zb_uint8_t private_key[ZB_CS1_PRIVATE_KEY_SIZE]; +} ZB_PACKED_STRUCT zb_cs1_key_material_t; + +typedef ZB_PACKED_PRE struct zb_cs2_key_material_s +{ + zb_uint8_t publisher_public_key[ZB_CS2_PUBLISHER_PUBLIC_KEY_SIZE]; + zb_uint8_t certificate[ZB_CS2_CERTIFICATE_SIZE]; + zb_uint8_t private_key[ZB_CS2_PRIVATE_KEY_SIZE]; +} ZB_PACKED_STRUCT zb_cs2_key_material_t; + +typedef ZB_PACKED_PRE struct zb_cs_key_material_header_s +{ + zb_uint16_t certificate_mask; +} ZB_PACKED_STRUCT zb_cs_key_material_header_t; + +#define ZB_PROD_CFG_IS_PRESENT_CERT_ANY(v) ((v->options) & 0x80) +/** @endcond */ /*internals_doc*/ + +/** + * Disable usage of production configuration at runtime. + * + * @param val - ZB_TRUE means production configuration is disabled, ZB_FALSE - enabled. + */ +void zb_production_config_disable(zb_bool_t val); + +/** + * Get state of production configuration disabling. + * + * @return ZB_TRUE if production configuration is disabled, ZB_FALSE - enabled. + */ +zb_bool_t zb_is_production_config_disabled(void); + +zb_ret_t zb_production_config_check(zb_production_config_hdr_t *prod_cfg_hdr); + +#endif /* ZB_PRODUCTION_CONFIG */ + + + + +#ifdef ZB_USE_SLEEP +/*! @cond DOXYGEN_LL_SECTION */ +/*! @addtogroup sleep_api */ +/*! @{ */ + +/** Default sleep threshold. Do not sleep when it is less then 1 Beacon Interval to wake up. */ +#define ZB_SCHED_SLEEP_THRESHOLD_MS 20 + +/** Maximum sleep threshold. */ +#define ZB_MAXIMUM_SLEEP_THRESHOLD_MS 86400000 + +/** + Set sleep threshold on device; when scheduler detects that device can be put in sleep mode + it will notify application with signal @see ZB_COMMON_SIGNAL_CAN_SLEEP. + Device can not be put into sleep mode when sleep interval less than this threshold. + + @param threshold_ms - sleep threshold in milliseconds + If threshold is 0, means zero threshold, application will be notified each time when stack is ready to sleep + (no immediate callbacks in queue). + @return RET_OK if new threshold is valid and applied + @return RET_ERROR if user wants to set threshold greater that @ref ZB_MAXIMUM_SLEEP_THRESHOLD_MS or lesser than ZB_SCHED_SLEEP_THRESHOLD_MS. +*/ +zb_ret_t zb_sleep_set_threshold(zb_uint32_t threshold_ms); + +/** + Get sleep threshold value from stack. + @return threshold value in milliseconds +*/ +zb_uint32_t zb_get_sleep_threshold(void); + +/** + Blocking function responsible for putting device into sleep mode. + +*/ +void zb_sleep_now(void); + +/*! @} */ /* sleep_api */ +/*! @endcond */ /* DOXYGEN_LL_SECTION */ +#endif /* ZB_USE_SLEEP */ + + + +#ifdef ZB_SECURITY_INSTALLCODES +/** + Set using of install codes by TC + + @param use_ic - enable/disable install code usage +*/ +void zb_tc_set_use_installcode(zb_uint8_t use_ic); +#endif /* ZB_SECURITY_INSTALLCODES */ + +#if defined ZB_ED_FUNC && defined ZB_CONTROL4_NETWORK_SUPPORT +/** + Permit joining Control4 Network +*/ +void zb_permit_control4_network(void); +#endif /* defined ZB_ED_FUNC && defined ZB_CONTROL4_NETWORK_SUPPORT */ + +/** + * @brief Set the 'macTransactionPersistenceTime' attribute in the MAC PIB + * + * @param ms - value in milliseconds + */ +void zb_set_mac_transaction_persistence_time(zb_uint16_t ms); + +#endif /*ZBOSS_API_H*/ diff --git a/zboss/include/zboss_api_af.h b/zboss/include/zboss_api_af.h new file mode 100644 index 0000000000..e582e5d00e --- /dev/null +++ b/zboss/include/zboss_api_af.h @@ -0,0 +1,700 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS AF API +*/ + +#ifndef ZBOSS_API_AF_H +#define ZBOSS_API_AF_H 1 + +/** + * @addtogroup af_api + * @{ + */ + +/** + * @addtogroup af_data_service AF data service + * @{ + */ + +/** + Node descriptor + */ +typedef ZB_PACKED_PRE struct zb_af_node_desc_s +{ + zb_uint16_t node_desc_flags; /*!< node description */ + zb_uint8_t mac_capability_flags; /*!< mac capability */ + zb_uint16_t manufacturer_code; /*!< Manufacturer code */ + zb_uint8_t max_buf_size; /*!< Maximum buffer size */ + zb_uint16_t max_incoming_transfer_size; /*!< Maximum incoming transfer size */ + zb_uint16_t server_mask; /*!< Server mask */ + zb_uint16_t max_outgoing_transfer_size; /*!< Maximum outgoing transfer size */ + zb_uint8_t desc_capability_field; /*!< Descriptor capability field */ +} +ZB_PACKED_STRUCT +zb_af_node_desc_t; + +typedef zb_nwk_device_type_t zb_logical_type_t; + +/** @} */ /* af_data_service */ + +/** + * @addtogroup af_node_desc_dev_types AF device types + * @{ + */ +/** Device type - Coordinator */ +#define ZB_COORDINATOR ZB_NWK_DEVICE_TYPE_COORDINATOR +/** Device type - Router */ +#define ZB_ROUTER ZB_NWK_DEVICE_TYPE_ROUTER +/** Device type - End Device */ +#define ZB_END_DEVICE ZB_NWK_DEVICE_TYPE_ED +/*! @} */ /* af_node_desc_dev_types */ + +/** + * @addtogroup af_common_constants AF common constants + * @{ + */ +/** + Node descriptor - frequency value + */ +enum zb_freq_band_e +{ + ZB_FREQ_BAND_868 = 1, /*!< 868-868.6 MHz BPSK */ + ZB_FREQ_BAND_902 = 1 << 2, /*!< 902-928 MHz BPSK */ + ZB_FREQ_BAND_2400 = 1 << 3, /*!< 2400-2483.5 MHz */ + ZB_FREQ_BAND_SUB_GHZ_EU_FSK = 1 << 4, /*!< Zigbee R22: European FSK sub-GHz + * bands (863-876MHz, 915-921MHz) */ +}; + +/** + Node descriptor - server mask + */ +enum zb_server_mask_bit_e +{ + ZB_PRIMARY_TRUST_CENTER = 1, /*!< Primary Trust Center */ + ZB_BACKUP_TRUST_CENTER = 1 << 1, /*!< Backup Trust Center */ + ZB_PRIMARY_BINDING_TABLE_CENTER = 1 << 2, /*!< Primary Binding Table Center */ + ZB_BACKUP_BINDING_TABLE_CENTER = 1 << 3, /*!< Backup Binding Table Center */ + ZB_PRIMARY_DISCOVERY_CACHE = 1 << 4, /*!< Primary Discovery Cache */ + ZB_BACKUP_DISCOVERY_CACHE = 1 << 5, /*!< Backup Discovery Cache */ + ZB_NETWORK_MANAGER = 1 << 6 /*!< Network Manager */ +}; + +/** + Node descriptor - capability mask + */ +enum zb_desc_capability_e +{ + ZB_EXT_ACTIVE_EP_LIST = 1, /*!< Extended Active Endpoint List Available */ + ZB_EXT_SIMPLE_DESC_LIST = 1 <<1 /*!< Extended Simple Descriptor List Available */ +}; + +/** + Power descriptor types + */ +typedef enum zb_current_power_mode_e +{ + ZB_POWER_MODE_SYNC_ON_WHEN_IDLE = 0, + /*!< Receiver synchronized with the receiver on when idle subfield of the node descriptor. */ + ZB_POWER_MODE_COME_ON_PERIODICALLY = 1, + /*!< Receiver comes on periodically as defined by the node power descriptor. */ + ZB_POWER_MODE_COME_ON_WHEN_STIMULATED = 2 + /*!< Receiver comes on when stimulated, for example, by a user pressing a button. */ +} +zb_current_power_mode_t; + +/** + Power source type + */ +typedef enum zb_power_src_e +{ + ZB_POWER_SRC_CONSTATNT = 1, /*!< Constant (mains) power */ + ZB_POWER_SRC_RECHARGEABLE_BATTERY = 1 << 1, /*!< Rechargeable battery */ + ZB_POWER_SRC_DISPOSABLE_BATTERY = 1 << 2 /*!< Disposable battery */ +} +zb_power_src_t; + +/** + Power source level values + */ +typedef enum zb_power_source_level_e +{ + ZB_POWER_LEVEL_CRITICAL = 0, /*!< Critical */ + ZB_POWER_LEVEL_33 = 4, /*!< 33% */ + ZB_POWER_LEVEL_66 = 8, /*!< 66% */ + ZB_POWER_LEVEL_100 = 12 /*!< 100% */ +} +zb_power_source_level_t; +/** @} */ /* af_common_constants */ + +/** + * @addtogroup af_data_service AF data service + * @{ + */ + +/** + Node power descriptor + */ +typedef ZB_PACKED_PRE struct zb_af_node_power_desc_s +{ +/** Field name Bits + * Current power mode: 4@n + * Available power sources: 4@n + * Current power source: 4@n + * Current power source level: 4 + */ + zb_uint16_t power_desc_flags; +} ZB_PACKED_STRUCT zb_af_node_power_desc_t; + + +/** @cond internals_doc */ +#define __CAT__(a, b, c, d, e) a##b##c##d##e +/** @endcond */ /*internals_doc */ + +/** Generate simple descriptor type name */ +#define ZB_AF_SIMPLE_DESC_TYPE(in_num, out_num) __CAT__(zb_af_simple_desc_,in_num,_,out_num,_t) + +/** + Declares Simple descriptor type + + @param in_clusters_count - number of input clusters in descriptor + @param out_clusters_count - number of output clusters in descriptor + + @b Example: + @code + ZB_DECLARE_SIMPLE_DESC(5, 5); + @endcode + */ + +#define ZB_DECLARE_SIMPLE_DESC(in_clusters_count, out_clusters_count) \ + typedef ZB_PACKED_PRE struct zb_af_simple_desc_ ## in_clusters_count ## _ ## out_clusters_count ## _s \ + { \ + zb_uint8_t endpoint; /* Endpoint */ \ + zb_uint16_t app_profile_id; /* Application profile identifier */ \ + zb_uint16_t app_device_id; /* Application device identifier */ \ + zb_bitfield_t app_device_version:4; /* Application device version */ \ + zb_bitfield_t reserved:4; /* Reserved */ \ + zb_uint8_t app_input_cluster_count; /* Application input cluster count */ \ + zb_uint8_t app_output_cluster_count; /* Application output cluster count */ \ + /* Application input and output cluster list */ \ + zb_uint16_t app_cluster_list[in_clusters_count + out_clusters_count]; \ + } ZB_PACKED_STRUCT \ + zb_af_simple_desc_ ## in_clusters_count ## _ ## out_clusters_count ## _t + +/** @} */ /* af_data_service */ + +/** + * @addtogroup af_management_service AF management service + * @{ + */ +/** General descriptor type */ +ZB_DECLARE_SIMPLE_DESC(1,1); +/** ZDO descriptor type */ +ZB_DECLARE_SIMPLE_DESC(8,9); + +/** + Set simple descriptor parameters + @param simple_desc - pointer to simple descriptor + @param endpoint - Endpoint + @param app_profile_id - Application profile identifier + @param app_device_id - Application device identifier + @param app_device_version - Application device version + @param app_input_cluster_count - Application input cluster count + @param app_output_cluster_count - Application output cluster count + + @par Example + @snippet doxygen_snippets.dox zb_set_simple_descriptor_certification_TP_ZDO_BV-09_tp_zdo_bv_09_zc_c + @par + + See tp_zdo_bv_09, tp_zdo_bv-11 samples +*/ +void zb_set_simple_descriptor(zb_af_simple_desc_1_1_t *simple_desc, + zb_uint8_t endpoint, zb_uint16_t app_profile_id, + zb_uint16_t app_device_id, zb_bitfield_t app_device_version, + zb_uint8_t app_input_cluster_count, zb_uint8_t app_output_cluster_count); + +/** + Set input cluster item + @param simple_desc - pointer to simple descriptor + @param cluster_number - cluster item number + @param cluster_id - cluster id + + @par Example + @snippet doxygen_snippets.dox zb_set_simple_descriptor_certification_TP_ZDO_BV-09_tp_zdo_bv_09_zc_c + @par + + See tp_zdo_bv_09, tp_zdo_bv-11 samples +*/ +void zb_set_input_cluster_id(zb_af_simple_desc_1_1_t *simple_desc, zb_uint8_t cluster_number, zb_uint16_t cluster_id); + +/*! @brief Set output cluster item + @param simple_desc - pointer to simple descriptor + @param cluster_number - cluster item number + @param cluster_id - cluster id + + @par Example + @snippet doxygen_snippets.dox zb_set_simple_descriptor_certification_TP_ZDO_BV-09_tp_zdo_bv_09_zc_c + @par + + See tp_zdo_bv_09, tp_zdo_bv-11 samples +*/ +void zb_set_output_cluster_id(zb_af_simple_desc_1_1_t *simple_desc, zb_uint8_t cluster_number, zb_uint16_t cluster_id); + +/** + Set default descriptors values for FFD. + @param device_type - device type ZB_COORDINATOR or ZB_ROUTER + + @code + zb_set_default_ffd_descriptor_values(ZB_COORDINATOR); + @endcode + + See tp_zdo_bv_09, tp_zdo_bv-11 samples + */ +void zb_set_default_ffd_descriptor_values(zb_logical_type_t device_type); + +/** + Set default descriptors values for end device. + */ +void zb_set_default_ed_descriptor_values(void); +/** @} */ /* af_management_service */ + +/** + * @addtogroup af_common_constants AF common constants + * @{ + */ +/*! Profile identifiers */ +enum zb_af_profile_id_e +{ + /** ZDO profile id */ + ZB_AF_ZDO_PROFILE_ID = 0x0000, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE1_ID = 0x0101, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE2_ID = 0x0102, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE3_ID = 0x0103, + /** HA profile id */ + ZB_AF_HA_PROFILE_ID = 0x0104, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE4_ID = 0x0105, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE5_ID = 0x0106, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE6_ID = 0x0107, + /** Legacy profile */ + ZB_AF_LEGACY_PROFILE7_ID = 0x0108, + /** SE profile id */ + ZB_AF_SE_PROFILE_ID = 0x0109, + /** ZLL profile identifier. */ + ZB_AF_ZLL_PROFILE_ID = 0xc05e, + /** Wildcard profile identifier. */ + ZB_AF_WILDCARD_PROFILE_ID = 0xffff, +/** GreenPower profile id */ + ZB_AF_GP_PROFILE_ID = 0xA1E0, +#ifdef ZB_CONTROL4_NETWORK_SUPPORT + /** Control4 profile identifier. */ + ZB_AF_CONTROL4_PROFILE_ID = 0xC25D, +#endif +}; +/** @} */ /* af_common_constants */ + +/** @cond internals_doc */ +#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) +struct zb_zcl_reporting_info_s; /* Forward declration */ +#endif +struct zb_zcl_cluster_desc_s; /* Forward declration */ +/** @endcond */ /* internals_doc */ + +/** + * @addtogroup af_management_service AF management service + * @{ + */ +/** + * Device command handler + * + * @param param - index of buffer with ZCL command + * @return status (see @ref zb_bool_t) + */ +typedef zb_uint8_t (*zb_device_handler_t)(zb_uint8_t param); +/** @} */ /* af_management_service */ +/** + * @addtogroup af_data_service AF data service + * @{ + */ + +/** Endpoint description for user applications. */ + +/*! @brief Endpoint descriptor. */ +typedef ZB_PACKED_PRE struct zb_af_endpoint_desc_s +{ + zb_uint8_t ep_id; /*!< Endpoint ID */ + zb_uint16_t profile_id; /*!< Application profile, which implemented on endpoint */ + zb_device_handler_t device_handler; /*!< Device specific callback, handles all commands */ + /*! @brief Identify notification callback + + If set, will be called on identification start and stop indicating start + event with a non-zero argument + */ + zb_callback_t identify_handler; + zb_uint8_t reseved_size; /*!< Unused parameter (reserved for future use) */ + zb_voidp_t reserved_ptr; /*!< Unused parameter (reserved for future use) */ + zb_uint8_t cluster_count; /*!< Number of supported clusters */ + struct zb_zcl_cluster_desc_s *cluster_desc_list; /*!< Supported clusters list */ + zb_af_simple_desc_1_1_t *simple_desc; /*!< Simple descriptor */ +#if defined ZB_ENABLE_ZLL || defined DOXYGEN + zb_uint8_t group_id_count; +#endif /* defined ZB_ENABLE_ZLL || defined DOXYGEN */ + + /* Moved here from device descriptor */ + zb_uint8_t rep_info_count; /*!< Number of reporting info slots */ + /* Reporting info structure should be better stored in ZCL main, + * moved here to allow compile-time memory allocating for + * reporting_info array, see ZB_AF_DECLARE_DEVICE_CTX() */ + struct zb_zcl_reporting_info_s *reporting_info; /*!< Attributes reporting information */ + + zb_uint8_t cvc_alarm_count; /*!< Number of continuous value change alarm slots */ + struct zb_zcl_cvc_alarm_variables_s *cvc_alarm_info; +}ZB_PACKED_STRUCT +zb_af_endpoint_desc_t; +/** @} */ /* af_data_service */ + +/** + * @addtogroup af_management_service AF management service + * @{ + */ + +/** + * @brief Search for endpoint (device) descriptor by endpoint ID. + * @param ep_id - identifier of the endpoint. + * @returns NULL if no endpoint found, or pointer to the endpoint descriptor. + */ +zb_af_endpoint_desc_t* zb_af_get_endpoint_desc(zb_uint8_t ep_id); + +/** + * @brief Check endpoint registration in ZCL. + * @param _ep - identifier of the endpoint under consideration. + * @returns ZB_TRUE if endpoint is registered, ZB_FALSE otherwise. + */ +#define ZB_AF_IS_EP_REGISTERED( _ep ) (zb_af_get_endpoint_desc( _ep ))?(ZB_TRUE):(ZB_FALSE) +/** @} */ /* af_management_service */ +/** @cond internals_doc */ + +/** + AF device context, contains a list of registered endpoints +*/ +typedef ZB_PACKED_PRE struct zb_af_device_ctx_s +{ + zb_uint8_t ep_count; /*!< Number of endpoints on device */ + zb_af_endpoint_desc_t **ep_desc_list; /*!< Endpoint list */ +}ZB_PACKED_STRUCT +zb_af_device_ctx_t; + +/** @endcond */ /* internals_doc */ + +/** + * @addtogroup af_management_service AF management service + * @{ + */ +/** + General macro to declare endpoint description list + @param ep_list_name - name of ep list structure +*/ +#define ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_name) \ + zb_af_endpoint_desc_t *ep_list_name[] = { + +/** + @brief Initialize endpoint descriptor + + @param ep_name - endpoint name + @param ep_id - endpoint id + @param profile_id - id of profile deployed on this endpoint + @param reserved_length - unused parameter + @param reserved_ptr - unused parameter + @param cluster_number - number of clusters deployed on endpoint + @param cluster_list - pointer to cluster list + @param simple_desc - pointer to simple descriptor + @param rep_count - maximum number of attributes that are + being reported on a device + @param rep_ctx - reporting context variable name (NULL if no reporting context) + @param lev_ctrl_count - number of level control attributes + @param lev_ctrl_ctx - level control context variable name (NULL if no level control context) + @see DR-TAR-TC-02 sample +*/ +#define ZB_AF_DECLARE_ENDPOINT_DESC( \ + ep_name, \ + ep_id, \ + profile_id, \ + reserved_length, \ + reserved_ptr, \ + cluster_number, \ + cluster_list, \ + simple_desc, \ + rep_count, \ + rep_ctx, \ + lev_ctrl_count, \ + lev_ctrl_ctx) \ + zb_af_endpoint_desc_t ep_name = \ + { \ + ep_id, \ + profile_id, \ + NULL, \ + NULL, \ + reserved_length, \ + (zb_voidp_t)reserved_ptr, \ + cluster_number, \ + cluster_list, \ + simple_desc, \ + rep_count, \ + rep_ctx, \ + lev_ctrl_count, \ + lev_ctrl_ctx \ + } + +/** Finishes endpoint list declaration */ +#define ZB_AF_FINISH_DECLARE_ENDPOINT_LIST } + +/** + * @brief Allows application to register cluster commands handler for a specific endpoint + * @param endpoint - Endpoint number + * @param handler - Pointer to a function, function type zb_device_handler_t + * @attention Endpoint should be registered. ZB_AF_SET_ENDPOINT_HANDLER() should be called after + * device context is registered, using call to ZB_AF_REGISTER_DEVICE_CTX() + * + * See HA samples + */ +#define ZB_AF_SET_ENDPOINT_HANDLER(endpoint, handler) \ + (zb_af_get_endpoint_desc((endpoint))->device_handler = (handler)) + +/*! @brief Sets identify notification handler for endpoint + + Utilized by ZCL Identify cluster + @param endpoint number + @param handler to set + @attention Assumes that endpoint already registered + * + * See HA samples +*/ +#define ZB_AF_SET_IDENTIFY_NOTIFICATION_HANDLER(endpoint, handler) \ + (zb_af_get_endpoint_desc((endpoint))->identify_handler = (handler)) + +#define ZB_ZCL_CLUSTER_DESC(cluster_id, attr_count, attr_desc_list, cluster_role_mask, manuf_code) \ +{ \ + (cluster_id), \ + (attr_count), \ + (attr_desc_list), \ + (cluster_role_mask), \ + (manuf_code), \ + (((cluster_role_mask) == ZB_ZCL_CLUSTER_SERVER_ROLE) ? cluster_id##_SERVER_ROLE_INIT : \ + (((cluster_role_mask) == ZB_ZCL_CLUSTER_CLIENT_ROLE) ? cluster_id##_CLIENT_ROLE_INIT : NULL)) \ +} + +/** WARNING: This API is deprecated, use ZBOSS_DECLARE_DEVICE_CTX instead. */ +#define ZB_AF_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_name, ep_count, reporting_attr_count) \ + zb_zcl_reporting_info_t reporting_info## device_ctx_name[reporting_attr_count]; \ + zb_af_device_ctx_t device_ctx_name = \ + { \ + ep_count, \ + ep_list_name, \ + reporting_attr_count, \ + reporting_info## device_ctx_name, \ + 0, \ + NULL \ + } + +/** WARNING: This API is deprecated, use ZBOSS_DECLARE_DEVICE_CTX instead. */ +#define ZB_AF_DECLARE_DEVICE_CTX_NO_REP(device_ctx_name, ep_list_name, ep_count) \ + zb_af_device_ctx_t device_ctx_name = \ + { \ + ep_count, \ + ep_list_name, \ + 0, \ + NULL, \ + 0, \ + NULL \ + } + +/** + Declare device reporting context + @param rep_ctx - reporting context variable name + @param rep_count - number of reporting attributes +*/ +#define ZBOSS_DEVICE_DECLARE_REPORTING_CTX(rep_ctx, rep_count) \ + zb_zcl_reporting_info_t rep_ctx[rep_count] + +/** + Declare device level control context + @param lev_ctrl_ctx - level control context variable name + @param lev_ctrl_count - number of level control attributes +*/ +#define ZBOSS_DEVICE_DECLARE_LEVEL_CONTROL_CTX(lev_ctrl_ctx, lev_ctrl_count) \ + zb_zcl_cvc_alarm_variables_t lev_ctrl_ctx[lev_ctrl_count] + +/** + Declare application's device context + @param device_ctx_name - device context variable name + @param ep_list_name - name of endpoint list + @param ep_count - number of supported endpoints +*/ +#define ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_name, ep_count) \ + zb_af_device_ctx_t device_ctx_name = \ + { \ + ep_count, \ + ep_list_name, \ + } + +/** + Declare application's device context for single-endpoint device + + @note Device has an additional Green Power endpoint if it is ZC or ZR + and GPPB feature is enabled (Mandatory for Zigbee 3.0 ZC/ZR). + + @param device_ctx_name - device context variable name + @param ep_name - variable holding endpoint context +*/ +#define ZBOSS_DECLARE_DEVICE_CTX_1_EP(device_ctx_name, ep_name) \ + ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_##device_ctx_name) \ + &ep_name, \ + ZB_AF_FINISH_DECLARE_ENDPOINT_LIST; \ + ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \ + (ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))) + +/** + Declare application's device context for two-endpoint device + + @note Device has an additional Green Power endpoint if it is ZC or ZR + and GPPB feature (Mandatory for Zigbee 3.0 ZC/ZR) is enabled. + + @param device_ctx_name - device context variable name + @param ep1_name - variable holding context for endpoint 1 + @param ep2_name - variable holding context for endpoint 2 +*/ +#define ZBOSS_DECLARE_DEVICE_CTX_2_EP(device_ctx_name, ep1_name, ep2_name) \ + ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_##device_ctx_name) \ + &ep1_name, \ + &ep2_name, \ + ZB_AF_FINISH_DECLARE_ENDPOINT_LIST; \ + ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \ + (ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))) + +/** + Declare application's device context for three-endpoint device + + @note Device has an additional Green Power endpoint if it is ZC or ZR + and GPPB feature (Mandatory for Zigbee 3.0 ZC/ZR) is enabled. + + @param device_ctx_name - device context variable name + @param ep1_name - variable holding context for endpoint 1 + @param ep2_name - variable holding context for endpoint 2 + @param ep3_name - variable holding context for endpoint 3 +*/ +#define ZBOSS_DECLARE_DEVICE_CTX_3_EP(device_ctx_name, ep1_name, ep2_name, ep3_name) \ + ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_##device_ctx_name) \ + &ep1_name, \ + &ep2_name, \ + &ep3_name, \ + ZB_AF_FINISH_DECLARE_ENDPOINT_LIST; \ + ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \ + (ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))) + +/** + Declare application's device context for for-endpoint device + + @note Device has an additional Green Power endpoint if it is ZC or ZR + and GPPB feature (Mandatory for Zigbee 3.0 ZC/ZR) is enabled. + + @param device_ctx_name - device context variable name + @param ep1_name - variable holding context for endpoint 1 + @param ep2_name - variable holding context for endpoint 2 + @param ep3_name - variable holding context for endpoint 3 + @param ep4_name - variable holding context for endpoint 4 +*/ +#define ZBOSS_DECLARE_DEVICE_CTX_4_EP(device_ctx_name, ep1_name, ep2_name, ep3_name, ep4_name) \ + ZB_AF_START_DECLARE_ENDPOINT_LIST(ep_list_##device_ctx_name) \ + &ep1_name, \ + &ep2_name, \ + &ep3_name, \ + &ep4_name, \ + ZB_AF_FINISH_DECLARE_ENDPOINT_LIST; \ + ZBOSS_DECLARE_DEVICE_CTX(device_ctx_name, ep_list_##device_ctx_name, \ + (ZB_ZCL_ARRAY_SIZE(ep_list_##device_ctx_name, zb_af_endpoint_desc_t*))) + + +/** @cond internals_doc */ +void zb_zcl_init_reporting_ctx(void); +void zb_zcl_reset_reporting_ctx(void); + + +/** + Register device context. + @param device_ctx - pointer to device context + */ +void zb_af_register_device_ctx(zb_af_device_ctx_t *device_ctx); +/*! @endcond */ +/** + Register device context. + @param _device_ctx - Pointer to the device context + + @b Example: + @snippet onoff_server/on_off_output_zc.c af_register_device_context +*/ +#define ZB_AF_REGISTER_DEVICE_CTX(_device_ctx) zb_af_register_device_ctx(_device_ctx) + +/** + * @brief Set Device user application callback. + * The macro sets a callback being called upon to need inform User App about change device attribute or + * need to execute H/W command + * @param func_ptr - a callback to set (of type @ref zb_callback_t). + * @hideinitializer + * + * @b Example: + * @snippet onoff_server/on_off_output_zc.c zcl_register_device_cb_example_cb + * @par Register callback: + * @snippet onoff_server/on_off_output_zc.c zcl_register_device_cb +*/ +#define ZB_ZCL_REGISTER_DEVICE_CB(func_ptr) ZCL_CTX().device_cb = (func_ptr) + +/** + Callback for notifying user about status of ZCL/ZDO command transmission + */ +typedef void (*zb_af_transmission_res_cb_t) (zb_uint8_t status); +/** @} */ /* af_management_service */ +/*! @} */ + +#endif /* ZBOSS_API_AF_H */ diff --git a/zboss/include/zboss_api_aps.h b/zboss/include/zboss_api_aps.h new file mode 100644 index 0000000000..75a440c5e1 --- /dev/null +++ b/zboss/include/zboss_api_aps.h @@ -0,0 +1,535 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Public APS layer API +*/ +#ifndef ZB_ZBOSS_API_APS_H +#define ZB_ZBOSS_API_APS_H 1 + +/*! \addtogroup aps_api */ +/*! @{ */ + +/** @addtogroup aps_common_constants APS common constants + * @{ + */ + +#include "zb_config.h" +#include "zb_address.h" + +/** @brief APS status constants. */ +typedef enum zb_aps_status_e +{ + ZB_APS_STATUS_SUCCESS = 0x00, /*!< A request has been executed + * successfully. */ + ZB_APS_ASDU_TOO_LONG = 0xa0, /*!< A transmit request failed since + the ASDU is too large and fragmentation + is not supported.*/ + ZB_APS_DEFRAG_DEFERRED = 0xa1, /* A received fragmented frame could not be + defragmented at the current time. */ + ZB_APS_DEFRAG_UNSUPPORTED = 0xa2, /* A received fragmented frame could not be + defragmented since the device does not + support fragmentation. */ + ZB_APS_STATUS_ILLEGAL_REQUEST = 0xa3, /*!< A parameter value was out of range. */ + ZB_APS_STATUS_INVALID_BINDING = 0xa4, /*!< An APSME-UNBIND.request failed due to + the requested binding link not existing in the + binding table. */ + ZB_APS_STATUS_INVALID_GROUP = 0xa5, /*!< An APSME-REMOVE-GROUP.request has + been issued with a group identifier that does + not appear in the group table. */ + ZB_APS_STATUS_INVALID_PARAMETER = 0xa6, /*!< A parameter value was invalid or out of + range. */ + ZB_APS_STATUS_NO_ACK = 0xa7, /*!< An APSDE-DATA.request requesting + acknowledged transmission failed due to no + acknowledgement being received. */ + ZB_APS_STATUS_NO_BOUND_DEVICE = 0xa8, /*!< An APSDE-DATA.request with a destination + addressing mode set to 0x00 failed due to + there being no devices bound to + this device. */ + ZB_APS_STATUS_NO_SHORT_ADDRESS = 0xa9, /*!< An APSDE-DATA.request with a destination + addressing mode set to 0x03 failed due to no + corresponding short address found in the + address map table. */ + ZB_APS_STATUS_NOT_SUPPORTED = 0xaa, /*!< An APSDE-DATA.request with a destination + addressing mode set to 0x00 failed due to a + binding table not being supported on the + device. */ + ZB_APS_STATUS_SECURED_LINK_KEY = 0xab, /*!< An ASDU was received that was secured + using a link key. */ + ZB_APS_STATUS_SECURED_NWK_KEY = 0xac, /*!< An ASDU was received that was secured + using a network key. */ + ZB_APS_STATUS_SECURITY_FAIL = 0xad, /*!< An APSDE-DATA.request requesting + security has resulted in an error during the + corresponding security + processing. */ + ZB_APS_STATUS_TABLE_FULL = 0xae, /*!< An APSME-BIND.request or APSME.ADD- + GROUP.request issued when the binding or + group tables, respectively, were + full. */ + ZB_APS_STATUS_UNSECURED = 0xaf, /*!< An ASDU was received without + * any security */ + ZB_APS_STATUS_UNSUPPORTED_ATTRIBUTE = 0xb0 /*!< An APSME-GET.request or APSME- + SET.request has been issued with an + unknown attribute identifier. */ +} zb_aps_status_t; + +/** @brief APS addressing mode constants. */ +typedef enum zb_aps_addr_mode_e +{ + ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT = 0, /*!< 0x00 = DstAddress and + * DstEndpoint not present */ + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT = 1, /*!< 0x01 = 16-bit group + * address for DstAddress; + * DstEndpoint not present */ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT = 2, /*!< 0x02 = 16-bit address for DstAddress and + DstEndpoint present */ + ZB_APS_ADDR_MODE_64_ENDP_PRESENT = 3 /*!< 0x03 = 64-bit extended address for + DstAddress and DstEndpoint present */ +} zb_aps_addr_mode_t; + +/** @brief Minimum valid endpoint number. */ +#define ZB_MIN_ENDPOINT_NUMBER 1 + +/** @brief Maximum valid endpoint number. */ +#define ZB_MAX_ENDPOINT_NUMBER 240 + +/** @brief Broadcast endpoint number. */ +#define ZB_APS_BROADCAST_ENDPOINT_NUMBER 255 + +/** @} */ + +/** @} */ /* aps_api */ + +/** @cond internals_doc */ +/*! \addtogroup aps_ib */ +/*! @{ */ + +/** @brief APS Information Base constants. */ +typedef enum zb_aps_aib_attr_id_e +{ + ZB_APS_AIB_BINDING = 0xc1, /*!< The current set of binding table entries in the device + (see subclause 2.2.8.2.1). */ + ZB_APS_AIB_DESIGNATED_COORD = 0xc2, /*!< TRUE if the device should become the Zigbee Coordinator on + startup, FALSE if otherwise. */ + ZB_APS_AIB_CHANNEL_MASK_LIST = 0xc3, /*!< The list of masks of allowable channels for this device + to use for network operations. */ + ZB_APS_AIB_USE_EXT_PANID = 0xc4, /*!< The 64-bit address of a network to form or to join. */ + ZB_APS_AIB_GROUP_TABLE = 0xc5, /*!< The current set of group table entries (see Table 2.25). */ + ZB_APS_AIB_NONMEMBER_RADIUS = 0xc6, /*!< The value to be used for the NonmemberRadius + parameter when using NWK layer multicast. */ + ZB_APS_AIB_PERMISSION_CONFIG = 0xc7, /*!< The current set of permission configuration items. */ + ZB_APS_AIB_USE_INSECURE_JOIN = 0xc8, /*!< A flag controlling the use of insecure join at startup. */ + ZB_APS_AIB_INTERFRAME_DELAY = 0xc9, /*!< Fragmentation parameter - the standard delay, in + milliseconds, between sending two blocks of a + fragmented transmission (see subclause 2.2.8.4.5). */ + ZB_APS_AIB_LAST_CHANNEL_ENERGY = 0xca, /*!< The energy measurement for the channel energy + scan performed on the previous channel just + before a channel change (in accordance with [B1]). */ + ZB_APS_AIB_LAST_CHANNEL_FAILURE_RATE = 0xcb, /*!< The latest percentage of transmission network + transmission failures for the previous channel just before + a channel change (in percentage of failed transmissions + to the total number of transmissions attempted) */ + ZB_APS_AIB_CHANNEL_TIMER = 0xcc, /*!< A countdown timer (in + * hours) indicating the time to + * the next permitted frequency + * agility channel change. A value of NULL + * indicates the channel has not + * been changed previously. + */ + ZB_APS_AIB_MAX_WINDOW_SIZE = 0xcd, /*!< A table with the active + * endpoints and their respective + * apsMaxWin-dowSize where + * frag-mentation is used + * (active endpoints not + * supporting fragmentations + * shall be omitted from the + * list). + */ + ZB_APS_AIB_PARENT_ANNOUNCE_TIMER = 0xce /*!< The value of the current + * countdown timer before the + * next Parent_annce is sent. + */ +} zb_aps_aib_attr_id_t; + +/*! @} */ /* aps_ib */ +/** @endcond */ /* internals_doc */ + +/** @addtogroup aps_api + * @{ + */ + +/** @addtogroup aps_data_service APS data service + * @{ + */ + +/** @brief Parsed APS header. + */ +typedef ZB_PACKED_PRE struct zb_aps_hdr_s +{ + zb_uint8_t fc; /*!< Frame control. */ + zb_uint16_t src_addr; /*!< Source address of packet originator. */ + zb_uint16_t dst_addr; /*!< The destination address of the packet. */ + zb_uint16_t group_addr; /*!< If send to group then group address destination else 0. */ + zb_uint8_t dst_endpoint; /*!< The destination endpoint of the packet receiver. */ + zb_uint8_t src_endpoint; /*!< The source endpoint from which that packet was send. */ + zb_uint16_t clusterid; /*!< The identifier of the cluster on the source device. */ + zb_uint16_t profileid; /*!< Profile Id */ + zb_uint8_t aps_counter; /*!< APS Counter for check APS dup command. */ + zb_uint16_t mac_src_addr; /*!< Source address of device that transmit that packet. */ + zb_uint16_t mac_dst_addr; /*!< Next hop address used for frame transmission. */ + zb_uint8_t lqi; + zb_uint8_t rssi; + /* attributes of the key used to unsecure this frame */ + zb_bitfield_t aps_key_source:1; /*!< @if ZB_SECUR + * @ref zb_secur_key_sources_e + * @endif + */ + zb_bitfield_t aps_key_attrs:2; /*!< @if ZB_SECUR + * @ref zb_secur_key_attributes_e + * @endif + */ + zb_bitfield_t aps_key_from_tc:1; /* Denotes that packet received from TC and propertly + * encrypted with TCLK by any appropriate method: + * 1) BDB Request key (with Key Type: TCLK) -> + * Transport Key -> Verify Key + * 2) BDB+SE Mixed CBKE + * 3) SE CBKE */ + zb_bitfield_t reserved:4; + + #define FIRST_INTERNAL_APSIND_FIELD tsn + zb_uint8_t tsn; /*!< Transaction sequence number for ZDO/ZCL command. */ + zb_uint8_t extended_fc; /*!< Extended frame control. */ + zb_uint8_t block_num; /*!< Fragmentation: block number. */ + zb_uint8_t block_ack; /*!< Fragmentation: block ack. */ +} ZB_PACKED_STRUCT zb_aps_hdr_t; + + +/** + Parameters of the APSDE-DATA.indication primitive. + + Also used as a parameter in different APS calls. + */ +typedef zb_aps_hdr_t zb_apsde_data_indication_t; + +/** @} */ /* APS data service */ +/** @} */ + +/** @addtogroup aps_api + * @{ + */ + +/** @addtogroup aps_management_service APS management service + * @{ + */ + +/** @brief APSME binding structure. + * + * This data structure passed to @ref zb_apsme_bind_request() + * and to @ref zb_apsme_unbind_request(). + */ +typedef struct zb_apsme_binding_req_s +{ + zb_ieee_addr_t src_addr; /*!< The source IEEE address for the binding entry. */ + zb_uint8_t src_endpoint; /*!< The source endpoint for the binding entry. */ + zb_uint16_t clusterid; /*!< The identifier of the cluster on the source + device that is to be bound to the destination device.*/ + zb_uint8_t addr_mode; /*!< The type of destination address supplied by + the DstAddr parameter - see @ref zb_aps_addr_mode_e */ + zb_addr_u dst_addr; /*!< The destination address for the binding entry. */ + zb_uint8_t dst_endpoint; /*!< This parameter will be present only if + the DstAddrMode parameter has a value of + 0x03 and, if present, will be the + destination endpoint for the binding entry.*/ +} zb_apsme_binding_req_t; + +/** @brief APSME-ADD-GROUP.request primitive parameters. */ +typedef struct zb_apsme_add_group_req_s +{ + zb_uint16_t group_address; /*!< The 16-bit address of the group being added. */ + zb_uint8_t endpoint; /*!< The endpoint to which the given group is being added. */ +} zb_apsme_add_group_req_t; + +/** @brief APSME-ADD-GROUP.confirm primitive parameters. */ +typedef struct zb_apsme_add_group_conf_s +{ + zb_uint16_t group_address; /*!< The 16-bit address of the group being added. */ + zb_uint8_t endpoint; /*!< The endpoint to which the given group is being added. */ + zb_ret_t status; /*!< Request send status. */ +} zb_apsme_add_group_conf_t; + +/** @brief APSME-REMOVE-GROUP.request primitive parameters. */ +typedef struct zb_apsme_add_group_req_s zb_apsme_remove_group_req_t; + +/** @brief APSME-REMOVE-GROUP.confirm primitive parameters. */ +typedef struct zb_apsme_add_group_conf_s zb_apsme_remove_group_conf_t; + +/** @brief APSME-REMOVE-ALL-GROUPS.request primitive parameters. */ +typedef struct zb_apsme_remove_all_groups_req_s +{ + zb_uint8_t endpoint; /*!< The endpoint to which the given group is being removed. */ +} zb_apsme_remove_all_groups_req_t; + +/** @brief APSME-REMOVE-ALL-GROUPS.confirm primitive parameters. */ +typedef struct zb_apsme_remove_all_groups_conf_s +{ + zb_uint8_t endpoint; /*!< The endpoint which is to be removed from all groups. */ + zb_ret_t status; /*!< The status of the request to remove all groups. */ +} zb_apsme_remove_all_groups_conf_t; + +zb_uint8_t zb_aps_is_endpoint_in_group( + zb_uint16_t group_id, + zb_uint8_t endpoint); + +/** @cond internals_doc */ +/** @brief APSME GET request structure. */ +typedef struct zb_apsme_get_request_s +{ + zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute to read. */ + zb_callback_t confirm_cb; /*!< User's callback to be called as APSME-GET.confirm */ +} zb_apsme_get_request_t; + +/** @brief APSME GET confirm structure. */ +typedef ZB_PACKED_PRE struct zb_apsme_get_confirm_s +{ + zb_ret_t status; /*!< The results of the request to read an AIB attribute value. */ + zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute that was read.*/ + zb_uint8_t aib_length; /*!< The length, in octets, of the attribute value being returned.*/ + /* Various */ /* The value of the AIB attribute that was read.*/ +} ZB_PACKED_STRUCT zb_apsme_get_confirm_t; + +/** @brief APSME SET request structure. */ +typedef ZB_PACKED_PRE struct zb_apsme_set_request_s +{ + zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute to be written. */ + zb_uint8_t aib_length; /*!< The length, in octets, of the attribute value being set. */ + zb_callback_t confirm_cb; /*!< User's callback to be called as APSME-SET.confirm */ + /* Various */ /* The value of the AIB attribute that should be written. */ +} ZB_PACKED_STRUCT zb_apsme_set_request_t; + +/** @brief APSME SET confirm structure. */ +typedef ZB_PACKED_PRE struct zb_apsme_set_confirm_s +{ + zb_ret_t status; /*!< The result of the request to write the AIB Attribute. */ + zb_aps_aib_attr_id_t aib_attr; /*!< The identifier of the AIB attribute that was written. */ +} ZB_PACKED_STRUCT zb_apsme_set_confirm_t; + +/** @endcond */ + +/** @brief APSME-BIND.request primitive. + * @param param - index of buffer containing request data (see @ref + * zb_apsme_binding_req_t). + * + * @par Example + * @snippet light_sample/light_control/light_control.c apsme_bind_req + * @par + * + * See light_sample + */ +void zb_apsme_bind_request(zb_uint8_t param); + +/** @brief APSME-UNBIND.request primitive. + * @param param - index of buffer containing request data (see @ref + * zb_apsme_binding_req_t). + * + * @par Example + * @snippet doxygen_snippets.dox zb_apsme_unbind_request_tests_aps_bind_aps_binding_test_c + * @par + * + * See aps_binding_test sample + */ +void zb_apsme_unbind_request(zb_uint8_t param); + +/** @brief Perform unbind all entries. This custom function and it is not described + * in Zigbee specificatoin. + * @param param - not used. + */ +void zb_apsme_unbind_all(zb_uint8_t param); + +/** @brief APSME-ADD-GROUP.request primitive. + * + * @internal + * Use macro @ref ZDO_REGISTER_CALLBACK to register APSME-ADD-GROUP.confirm callback. + * @endinternal + * @param param - index of buffer with parameter. See @ref zb_apsme_add_group_req_t. + * + * @par Example + * @snippet scenes/scenes_zed.c apsme_add_group_req + * @par + * + * See scenes sample + */ +void zb_apsme_add_group_request(zb_uint8_t param); + +/** @brief APSME-REMOVE-GROUP.request primitive. + * + * @internal + * Use macro @ref ZDO_REGISTER_CALLBACK to register APSME-REMOVE-GROUP.confirm callback. + * @endinternal + * @param param - index of buffer with parameter. See @ref zb_apsme_remove_group_req_t. + * + * @par Example + * @snippet doxygen_snippets.dox zb_apsme_remove_group_request_certification_TP_APS_BV-17_tp_aps_bv-17_zed_c + * @par + * + * See tp_aps_bv-17 sample + */ +void zb_apsme_remove_group_request(zb_uint8_t param); + +/** @brief APSME-REMOVE-ALL-GROUPS.request primitive. + * + * @internal + * Use macro @ref ZDO_REGISTER_CALLBACK to register APSME-REMOVE-ALL-GROUPS.confirm callback. + * @endinternal + * @param param - index of buffer with parameter. See @ref zb_apsme_remove_all_groups_req_t. + * + * @par Example + * @snippet doxygen_snippets.dox zb_apsme_remove_all_groups_request_tests_certification_TP_APS_BV-18_tp_aps_bv-18_zed_c + * @par + * + * See tp_aps_bv-18 sample + */ +void zb_apsme_remove_all_groups_request(zb_uint8_t param); + +/** @} */ /* APS management service data structures and API. */ + +/*! @} */ /* aps_api */ + + +#ifdef APS_FRAGMENTATION + + +void zb_aps_add_max_trans_size(zb_uint16_t short_addr, zb_uint16_t max_trans_size, zb_uint8_t max_buffer_size); +zb_uint16_t zb_aps_get_max_trans_size(zb_uint16_t short_addr); +zb_uint8_t zb_aps_get_max_buffer_size(zb_uint16_t short_addr); + +#endif + +#ifdef ZB_APS_USER_PAYLOAD +/** @addtogroup aps_api + * @{ + */ +/*! @addtogroup aps_user_payload APS user payload */ +/*! @{ */ + +/*! + * @brief + * Callback to notify an application of sending an APS user payload status + * + * @param param - index of buffer with an APS user payload + */ +typedef void (*zb_aps_user_payload_callback_t)(zb_uint8_t param); + +/*! + * @brief + * APS user payload transmission status + * + * Stored in the buf->u.hdr.status field + */ +typedef enum zb_aps_user_payload_cb_status_e +{ + /*! APS user payload transmition is successful*/ + ZB_APS_USER_PAYLOAD_CB_STATUS_SUCCESS = (zb_uint8_t)0x00, + /* Failed to transmit APS user payload - No confirmation from MAC*/ + ZB_APS_USER_PAYLOAD_CB_STATUS_NO_MAC_ACK = (zb_uint8_t)0xe9, + /* Failed to transmit APS user payload - No confirmation from APS*/ + ZB_APS_USER_PAYLOAD_CB_STATUS_NO_APS_ACK = (zb_uint8_t)0xbe +} zb_aps_user_payload_cb_status_t; + +/*! + * @brief Send user payload using APS + * + * @param param - reference to a buffer + * @param dst_addr - destination address + * @param profile_id - profile ID for which this frame is intended for + * @param cluster_id - object ID for which this frame is intended for + * @param dst_endpoint - either the endpoint ID + * of the entity to which the ASDU is being + * transferred or the broadcast endpoint (0xff) + * @param src_endpoint - the individual endpoint of the entity from + * which the ASDU is being transferred + * @param addr_mode - the type of destination address supplied by + * the dst_addr parameter - see @ref zb_aps_addr_mode_e + * @param aps_ack_is_enabled - enable (ZB_TRUE) or disable (ZB_FALSE) APS acknowledging + * @param *payload_ptr - pointer to user data + * @param payload_size - size of user data; not more than 82 bytes + * + * @return RET_OK - if transmission was successful scheduled; + * @return RET_INVALID_PARAMETER_1 - if the buffer is invalid + * @return RET_INVALID_PARAMETER_2 - if the payload_ptr parameter is invalid + * @return RET_INVALID_PARAMETER_3 - if the payload_size parameter is too large + */ +zb_ret_t zb_aps_send_user_payload( + zb_uint8_t param, + zb_addr_u dst_addr, + zb_uint16_t profile_id, + zb_uint16_t cluster_id, + zb_uint8_t dst_endpoint, + zb_uint8_t src_endpoint, + zb_uint8_t addr_mode, + zb_bool_t aps_ack_is_enabled, + zb_uint8_t *payload_ptr, + zb_uint8_t payload_size); + +/*! + * @brief Get pointer to an APS payload + * + * @param param - reference to a buffer + * @param aps_payload_size - [out] pointer to a variable to store + * an APS payload size + * + * @return Pointer to an APS payload; + * @return NULL if a buffer is invalid or an aps_payload_size pointer is invalid. + */ +zb_uint8_t *zb_aps_get_aps_payload(zb_uint8_t param, zb_uint8_t *aps_payload_size); + +/*! + * @brief Set callback to notify results of transmitting + * an APS frame with user payload + * + * @param cb - pointer to a callback + */ +void zb_aps_set_user_data_tx_cb(zb_aps_user_payload_callback_t cb); + +/*! @} */ /* addtogroup aps_user_payload */ + +/*! @} */ + +#endif /* #ifdef ZB_APS_USER_PAYLOAD */ + +#endif /* #ifndef ZB_ZBOSS_API_APS_H */ diff --git a/zboss/include/zboss_api_buf.h b/zboss/include/zboss_api_buf.h new file mode 100644 index 0000000000..736f762d1b --- /dev/null +++ b/zboss/include/zboss_api_buf.h @@ -0,0 +1,666 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Public buffer pool API (new version) +*/ +#ifndef ZBOSS_API_BUF_H +#define ZBOSS_API_BUF_H 1 + +/*! \addtogroup buf */ +/*! @{ */ + +/* + Moved here buffer structure to implement configurable mem without enabling legacy buffers + */ + +#define ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE 3u + +/** + Packet buffer header. + */ +typedef ZB_PACKED_PRE struct zb_buf_hdr_s +{ +/* 07/12/2019 EE CR:MAJOR really can pack that 3 fields into 4 bytes. Into 3 bytes if cut bits from handle (can be done later) */ + zb_uint16_t len; /*!< current layer buffer length */ + zb_uint16_t data_offset; /*!< data offset in buffer buf*/ + zb_uint8_t multiplicity; /*!< if greater that 1, then the following (multiplicity - 1) buffers + * are occupied with payload data and should not be treated as + * having valid headers, etc. + */ + zb_uint8_t handle; /*!< The handle associated with the NSDU to be + * transmitted by the NWK layer entity. */ + zb_bitfield_t is_in_buf:1; /*!< if 1, this is input buffer */ + + zb_bitfield_t encrypt_type:3; /*!< payload must be encrypted before send, if + * !0. \see zb_secur_buf_encr_type_e. + */ + zb_bitfield_t use_same_key:1; /*!< if 1, use same nwk key# packet was + * encrypted by */ + zb_bitfield_t zdo_cmd_no_resp:1; /*!< if 1, this is ZDO command with no + * response - call callback at confirm */ + zb_bitfield_t is_rx_buf:1; /*!< if 1, this is buffer with received packet and + * nwk_mac_addrs_t is at buffer tail */ + zb_bitfield_t has_aps_payload:1; /*!< if 1, than packet comes from APS */ + zb_int16_t status; /*!< some status to be passed with packet */ + zb_uint8_t reserved_to_align[ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE]; /*!< this field serves to keep + following buf[ZB_IO_BUF_SIZE] + aligned to a word*/ +} ZB_PACKED_STRUCT zb_buf_hdr_t; + +/* if there is a platform with failed assertion, ZB_RESERVED_BUF_TO_ALIGN_HDR_SIZE + should be changed to appropriate value*/ +ZB_ASSERT_COMPILE_DECL((sizeof(zb_buf_hdr_t) % sizeof(zb_uint32_t)) == 0); + +#ifdef ZB_DEBUG_BUFFERS_EXT +#define ZB_LINE_IS_UNDEF 0xFFFF + +/** + Extended buffer debug: tracking buffer access + */ + +typedef struct zb_buf_usage_s +{ + /* In most cases zb_time_t is zb_uint32_t. + * To save memory we we use zb_uint16_t so store time. */ + zb_uint16_t time; + zb_uint16_t file; + zb_uint16_t line; +} +zb_buf_usage_t; +#endif + + +/** + Packet buffer + */ +typedef struct zb_mult_buf_s +{ +#ifdef ZB_BUF_SHIELD + zb_uint8_t hdr_signature; +#endif +/* 07/12/2019 EE CR:MINOR Lagecy code will access u.hdr, so need to keep u as union or structure + AN: Legacy code inside ZBOSS will use zb_leg_buf_t instead of zb_mult_buf_t. + EE: I mean legacy API for the new bufs implementation. + */ + zb_buf_hdr_t hdr; /*!< Buffer header, if buffer is used */ + zb_uint8_t buf[ZB_IO_BUF_SIZE]; /*!< Data*/ +#ifdef ZB_DEBUG_BUFFERS_EXT + zb_buf_usage_t buf_allocation; + zb_buf_usage_t buf_usages[ZB_DEBUG_BUFFERS_EXT_USAGES_COUNT]; +#endif +#ifdef ZB_BUF_SHIELD + zb_uint8_t tail_signature; +#endif +} zb_mult_buf_t; + +/** + Packet buffer (legacy) + */ +typedef struct zb_leg_buf_s +{ +#ifdef ZB_BUF_SHIELD + zb_uint8_t hdr_signature; +#endif + union + { + zb_buf_hdr_t hdr; /*!< Buffer header, if buffer is used */ +#ifndef ZB_USE_STD_MALLOC + struct zb_buf_s *next; /*!< Ref to next free buffer, if buffer is not used*/ +#endif + } u; /*!< Buffer header */ +#if defined ZB_USE_STD_MALLOC && defined ZB_USE_ALLOC_FOR_PAYLOAD_DATA + zb_uint8_t *buf; /*!< Dynamically allocated buffer for payload */ +#else + zb_uint8_t buf[ZB_IO_BUF_SIZE]; /*!< Data*/ +#endif +#ifdef ZB_DEBUG_BUFFERS_EXT + zb_buf_usage_t buf_allocation; + zb_buf_usage_t buf_usages[ZB_DEBUG_BUFFERS_EXT_USAGES_COUNT]; +#endif +#ifdef ZB_BUF_SHIELD + zb_uint8_t tail_signature; +#endif +} zb_leg_buf_t; + +#ifdef ZB_LEGACY_BUFS +typedef zb_leg_buf_t zb_buf_ent_t; +#else +typedef zb_mult_buf_t zb_buf_ent_t; +#endif + +/** + Buffer type (direction). + */ +enum zb_buffer_types_e +{ + ZB_OUT_BUFFER = 0, /*!< Out buffer */ + ZB_IN_BUFFER = 1 /*!< In buffer */ +}; + +/** + @typedef zb_uint8_t zb_bufid_t + Buffer handler + */ +typedef zb_uint8_t zb_bufid_t; + +#define ZB_BUF_INVALID 0 +#define ZB_UNDEFINED_BUFFER 0 + +#ifdef ZB_DEBUG_BUFFERS +#define TRACE_PROTO_VOID zb_uint16_t from_file, zb_uint16_t from_line +#define TRACE_PROTO TRACE_PROTO_VOID , +#define TRACE_CALL_VOID ZB_TRACE_FILE_ID, __LINE__ +#define TRACE_CALL TRACE_CALL_VOID , +#else +#define TRACE_PROTO_VOID void +#define TRACE_PROTO +#define TRACE_CALL_VOID +#define TRACE_CALL +#endif /* ZB_DEBUG_BUFFERS */ + +#ifdef ZB_DEBUG_BUFFERS_EXT + void zb_trace_bufs_usage(void); + #define ZB_TRACE_BUFS_USAGE() zb_trace_bufs_usage() +#else + #define ZB_TRACE_BUFS_USAGE() +#endif + +/** @cond internals_doc */ +zb_bufid_t zb_buf_get_func(TRACE_PROTO zb_bool_t is_in, zb_uint_t max_size); +zb_bufid_t zb_buf_get_out_func(TRACE_PROTO_VOID); +zb_bufid_t zb_buf_get_any_func(TRACE_PROTO_VOID); +zb_bufid_t zb_buf_get_hipri_func(TRACE_PROTO zb_bool_t is_in); +zb_uint_t zb_buf_get_max_size_func(TRACE_PROTO zb_bufid_t buf); +zb_ret_t zb_buf_get_out_delayed_func(TRACE_PROTO zb_callback_t callback); +zb_ret_t zb_buf_get_in_delayed_func(TRACE_PROTO zb_callback_t callback); +zb_ret_t zb_buf_get_out_delayed_ext_func(TRACE_PROTO zb_callback2_t callback, zb_uint16_t arg, zb_uint_t max_size); +zb_ret_t zb_buf_get_in_delayed_ext_func(TRACE_PROTO zb_callback2_t callback, zb_uint16_t arg, zb_uint_t max_size); +void zb_buf_free_func(TRACE_PROTO zb_bufid_t buf); +void* zb_buf_begin_func(TRACE_PROTO zb_bufid_t buf); +void* zb_buf_end_func(TRACE_PROTO zb_bufid_t buf); +void* zb_buf_ptr_func(TRACE_PROTO zb_bufid_t buf); +zb_bufid_t zb_buf_from_ptr_func(TRACE_PROTO void *ptr); +void zb_buf_set_data_offset_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t off); +zb_uint_t zb_buf_len_func(TRACE_PROTO zb_bufid_t buf); +void zb_buf_copy_func(TRACE_PROTO zb_bufid_t dst_buf, zb_bufid_t src_buf); +void *zb_buf_initial_alloc_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void *zb_buf_reuse_func(TRACE_PROTO zb_bufid_t buf); +zb_uint_t zb_buf_get_ptr_off_func(TRACE_PROTO zb_bufid_t buf, zb_uint8_t *ptr); +void *zb_buf_alloc_tail_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void *zb_buf_get_tail_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void zb_buf_cut_right_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void *zb_buf_cut_left_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void *zb_buf_alloc_right_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +void *zb_buf_alloc_left_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t size); +/** @endcond */ /* internals_doc */ + +/** + Synchronous buffer allocation. + If no buffers available, does not block. + Note: this is low-level API. Usually user calls blocked alloc API. + + @param is_in if ZB_TRUE, allocate IN buffer, else allocate OUT buffer + @param max_size required maximum buffer payload size (in bytes). It can be bigger or smaller than + the default buffer size. Depending on the specific value, the buffer pool may decide to use + a fraction of buffer or long buffers. Special value 0 means "single default buffer". + @return buffer id or ZB_BUF_INVALID if no buffers available + */ +#define zb_buf_get(is_in,max_size) zb_buf_get_func(TRACE_CALL (is_in), (max_size)) + +/** + Allocate OUT buffer of the default size. + */ +#define zb_buf_get_out() zb_buf_get_out_func(TRACE_CALL_VOID) + +/** + Allocate IN or OUT buffer balancing @ of allocated IN and OUT + + To be used at ZBOSS init time. + */ +#define zb_buf_get_any() zb_buf_get_any_func(TRACE_CALL_VOID) + +/** + Synchronous allocation of the high-priority buffer + */ +#define zb_buf_get_hipri(a) zb_buf_get_hipri_func(TRACE_CALL (a)) + +/** + Return maximum data size for that buffer. + */ +#define zb_buf_get_max_size(a) zb_buf_get_max_size_func(TRACE_CALL (a)) + +/** + * @brief Allocate OUT buffer, call a callback when the buffer is available. + * + * Use default buffer size _func(alloc single standard buffer). + * If buffer is available, schedules callback for execution immediately. If no buffers are available now, + * schedule callback later, when buffer will be available. + * + * @param callback - callback to call. + * @return RET_OK or error code. + */ +#define zb_buf_get_out_delayed(callback) zb_buf_get_out_delayed_func(TRACE_CALL (callback)) + +/** + * @brief Allocate IN buffer, call a callback when the buffer is available. + * + * Use default buffer size _func(alloc single standard buffer). + * If buffer is available, schedules callback for execution immediately. If no buffers are available now, + * schedule callback later, when buffer will be available. + * + * @param callback - callback to call. + * @return RET_OK or error code. + */ +#define zb_buf_get_in_delayed(callback) zb_buf_get_in_delayed_func(TRACE_CALL (callback)) + +/** + * @brief Allocate OUT buffer, call a callback when the buffer is available. + * + * If buffer is available, schedules callback for execution immediately. If no buffers are available now, + * schedule callback later, when buffer will be available. + * + * @param callback - callback to call. + * @param arg - second argument for a callback + @param max_size required maximum buffer payload size (in bytes). It can be bigger or smaller than + the default buffer size. Depending on the specific value, the buffer pool may decide to use + a fraction of buffer or long buffers. Special value 0 means "single default buffer". + * @return RET_OK or error code. + */ +#define zb_buf_get_out_delayed_ext(callback,arg,max_size) zb_buf_get_out_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) + +/** + * @brief Allocate IN buffer, call a callback when the buffer is available. + * + * If buffer is available, schedules callback for execution immediately. If no buffers are available now, + * schedule callback later, when buffer will be available. + * + * @param callback - callback to call. + * @param arg - second argument for a callback + * @param max_size required maximum buffer payload size (in bytes). It can be bigger or smaller than + * the default buffer size. Depending on the specific value, the buffer pool may decide to use + * a fraction of buffer or long buffers. Special value 0 means "single default buffer". + * @return RET_OK or error code. + */ +#define zb_buf_get_in_delayed_ext(callback,arg,max_size) zb_buf_get_in_delayed_ext_func(TRACE_CALL (callback),(arg),(max_size)) + + +/** + * @brief Free packet buffer and put it into freelist. + * + * Can be called from the main loop. + * + * @param buf - buffer ID + * + * See any sample. + */ +#define zb_buf_free(buf) zb_buf_free_func(TRACE_CALL (buf)) + +/** + * Return pointer to data stored in buffer + * + * @param buf - buffer ID + * + * @return pointer to beginning of data in buffer + * + */ +#define zb_buf_begin(buf) zb_buf_begin_func(TRACE_CALL (buf)) + +/** + Return pointer to the data section end + + @param buf - buffer ID + + @return pointer to the first byte after data in the buffer +*/ +#define zb_buf_end(buf) zb_buf_end_func(TRACE_CALL (buf)) + +/** + Return pointer to the memory of the buffer + + @param buf - buffer ID + + @return pointer to the first byte of the buffer memory +*/ +#define zb_buf_ptr(buf) zb_buf_ptr_func(TRACE_CALL (buf)) + + +/** + Return buffer id + + @param ptr - pointer to the first byte of the buffer memory + + @return buffer ID +*/ +#define zb_buf_from_ptr(ptr) zb_buf_from_ptr_func(TRACE_CALL (ptr)) + + +/** + * Set buffer data offset + * + * @param buf - buffer ID + * @param off - data offset + */ +#define zb_buf_set_data_offset(buf, off) zb_buf_set_data_offset_func(TRACE_CALL (buf), (off)) + + +/** + * Return current buffer length + * + * @param buf - buffer ID + * + * @return size of data placed in buffer + */ +#define zb_buf_len(buf) zb_buf_len_func(TRACE_CALL (buf)) + + +/** + Copy one buffer to another + + @param src_buf - source buffer + @param dst_buf - destination buffer + */ +#define zb_buf_copy(src_buf,dst_buf) zb_buf_copy_func(TRACE_CALL (src_buf),(dst_buf)) + +/** + @brief Initial data space allocation in buffer. + + Allocate space in the buffer center (keep space in both buffer head + and tail). Use it at upper layers before filling buffer by data. + Old buffer contents is lost. + + @param buf - buffer ID + @param size - size to allocate + @return pointer to buffer data begin + */ +#define zb_buf_initial_alloc(buf,size) zb_buf_initial_alloc_func(TRACE_CALL (buf),(size)) + +/** + Reuse buffer data space by setting data start and length to 0 and zeroing buffer contents + + @param buf - buffer ID + + @return pointer to the buf data buffer begin + */ +#define zb_buf_reuse(buf) zb_buf_reuse_func(TRACE_CALL (buf)) +/** @cond internals_doc */ +/** + Calculate distance between ptr and buffer's data buffer start. + + That function used internally in ZCL. It is not recommended to be used by the application. + + @param buf - buffer ID + @param ptr - user's ptr inside the buffer + + @return offset between ptr and buffer start returned by zb_buf_reuse() + */ +#define zb_buf_get_ptr_off(buf,ptr) zb_buf_get_ptr_off_func(TRACE_CALL (buf),(ptr)) +/** @endcond */ /* internals_doc */ +/** + Alloc buffer tail of size 'size', initialize by zero. + + Usually used to place external information (some parameters) to the buffer. + + @param buf - buffer ID + @param size - requested size. Must met already allocated size. + + @return pointer to the buffer tail or NULL is buffer has no parameter of such size. +*/ +#define zb_buf_alloc_tail(buf,size) zb_buf_alloc_tail_func(TRACE_CALL (buf),(size)) + +/** + Get or allocate buffer tail of size 'size'. Do not initialize. + + Usually used to get or place external information (some parameters) to the buffer. + + @param buf - buffer ID + @param size - requested size + + @return pointer to the buffer tail + */ +#define zb_buf_get_tail(buf,size) zb_buf_get_tail_func(TRACE_CALL (buf),(size)) + +/** + Get buffer tail of size sizeof(type) + + Usually used to place external information _func(some parameters) to the buffer + + @param buf - buffer ID + @param type - data type that will be placed at the buffer end + + @return pointer to the buffer tail casted to _func(type*) + + @b Example + @code + zb_zdo_nwk_addr_req_param_t *req = ZB_BUF_GET_PARAM(buf, zb_zdo_nwk_addr_req_param_t); + + req->dst_addr = 0xffff; + ZB_IEEE_ADDR_COPY_func(req->ieee_addr, g_ieee_addr_r4); + req->start_index = 0; + req->request_type = 0x00; + zb_zdo_nwk_addr_req(ZB_REF_FROM_BUF_func(buf), NULL); + @endcode + */ +#define ZB_BUF_GET_PARAM(buf, type) ((type *)zb_buf_get_tail_func(TRACE_CALL (buf), sizeof(type))) + +/** + * Cut space at the end of buffer + * + * @param buf - buffer ID + * @param size - size to cut + */ +#define zb_buf_cut_right(buf,size) zb_buf_cut_right_func(TRACE_CALL (buf),(size)) + +/** + * Cut space at the beginning of buffer + * + * @param buf - buffer ID + * @param size - size to cut + * @return pointer to the new data begin +*/ +#define zb_buf_cut_left(buf,size) zb_buf_cut_left_func(TRACE_CALL (buf),(size)) + +/** + * Allocate space at buffer end + * + * @param buf - buffer ID + * @param size - size to allocate + * @return pointer to allocated data data begin + */ +#define zb_buf_alloc_right(buf,size) zb_buf_alloc_right_func(TRACE_CALL (buf),(size)) + +/** + * Allocate space at the beginning of buffer + * + * @param buf - buffer ID + * @param size - size to allocate + * @return pointer to new data begin + */ +#define zb_buf_alloc_left(buf,size) zb_buf_alloc_left_func(TRACE_CALL (buf),(size)) + + +/** + Buffer's internals flags bitmask + */ +typedef enum zb_buf_flags_bm_e +{ + ZB_BUF_IS_IN = (1<<0), +/** + Encrypt flags. That enum is actually bitmask. + */ + ZB_BUF_SECUR_NWK_ENCR = (1<<1), /*!< NWK frame encryption */ + ZB_BUF_SECUR_APS_ENCR = (1<<2), /*!< APS encryption. Analyze APS header to + * define which key to use */ + ZB_BUF_SECUR_MAC_ENCR = (1<<3), /*!< MAC encryption - for 802.15.4 certification + * only */ +#define ZB_BUF_SECUR_ALL_ENCR (ZB_BUF_SECUR_NWK_ENCR | ZB_BUF_SECUR_APS_ENCR | ZB_BUF_SECUR_MAC_ENCR) +#define ZB_BUF_SECUR_NO_ENCR 0 /*!< No encryption */ + ZB_BUF_USE_SAME_KEY = (1<<4), + ZB_BUF_ZDO_CMD_NO_RESP = (1<<5), + ZB_BUF_HAS_APS_PAYLOAD = (1<<6) +} zb_buf_flags_bm_t; + +/** @cond internals_doc */ +void zb_buf_flags_or_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t val); +void zb_buf_flags_clr_func(TRACE_PROTO zb_bufid_t buf, zb_uint_t mask); +void zb_buf_flags_clr_encr_func(TRACE_PROTO zb_bufid_t buf); +zb_uint_t zb_buf_flags_get_func(TRACE_PROTO zb_bufid_t buf); +/** @endcond */ + +/** + Add bits to the buffer's flags + + @param buf - buffer ID + @param val - value to be ORed with buffer' flags + */ +#define zb_buf_flags_or(buf,val) zb_buf_flags_or_func(TRACE_CALL (buf),(val)) + +/** + Clear buffer' flags by mask by doing flags = flags & ~mask + + @param buf - buffer ID + @param mask - value to be cleared from the flags - @see zb_buf_flags_bm_t + */ +#define zb_buf_flags_clr(buf,mask) zb_buf_flags_clr_func(TRACE_CALL (buf),(mask)) + + +/** + Clear buffer's flags related ro encryption + + That function calls zb_buf_flags_clr(buf, ZB_BUF_SECUR_ALL_ENCR) + @param buf - buffer ID + */ +#define zb_buf_flags_clr_encr(buf) zb_buf_flags_clr_encr_func(TRACE_CALL (buf)) + +/** + Get buffer's flags byte + + @param buf - buffer ID + @return flags value - @see zb_buf_flags_bm_t + */ +#define zb_buf_flags_get(buf) zb_buf_flags_get_func(TRACE_CALL (buf)) + +/** + Check if buffer pool is in Out Of Memory (OOM) state + + @return ZB_TRUE if ZBOSS is in OOM state + */ +zb_bool_t zb_buf_is_oom_state(void); + +/** + Trace buffer statistics into ZBOSS trace + */ +void zb_buf_oom_trace(void); + +/** + Check if buffer pool is close to Out Of Memory (OOM) state + + @return ZB_TRUE if ZBOSS is nearly in OOM state + */ +zb_bool_t zb_buf_memory_close_to_low(void); + +/** + Check if buffer pool is close to Out Of Memory (OOM) state + + @return ZB_TRUE if ZBOSS is nearly in OOM state + */ +zb_bool_t zb_buf_memory_low(void); + +/** @cond internals_doc */ +zb_int16_t zb_buf_get_status_func(TRACE_PROTO zb_bufid_t buf); +void zb_buf_set_status_func(TRACE_PROTO zb_bufid_t buf, zb_int16_t status); +zb_uint8_t zb_buf_get_handle_func(TRACE_PROTO zb_bufid_t buf); +void zb_buf_set_handle_func(TRACE_PROTO zb_bufid_t buf, zb_uint8_t handle); +/** @endcond */ + +/** + Get 'status' field of the buffer's header + + @param buf - buffer ID + @return status field value + */ +#define zb_buf_get_status(buf) zb_buf_get_status_func(TRACE_CALL (buf)) + +/** + Set 'status' field of the buffer's header + + @param buf - buffer ID + @param status - new status field value + */ +#define zb_buf_set_status(buf,status) zb_buf_set_status_func(TRACE_CALL (buf), (status)) + +/** + Get 'handle' field of the buffer's header + + @param buf - buffer ID + @return handle field value + */ +#define zb_buf_get_handle(buf) zb_buf_get_handle_func(TRACE_CALL (buf)) + +/** + Set 'handle' field of the buffer's header + + @param buf - buffer ID + @param handle - 'handle' field value + */ +#define zb_buf_set_handle(buf,handle) zb_buf_set_handle_func(TRACE_CALL (buf),(handle)) + +/** + Set or reset "mac needs more buffers" flag. + + To be used internally by ZBOSS. + + @param needs - new "mac needs more buffers" flag value + */ +void zb_buf_set_mac_rx_need(zb_bool_t needs); + +/** + Get "mac needs more buffers" flag. + + To be used internally by ZBOSS. + + @return "mac needs more buffers" flag value + */ +zb_bool_t zb_buf_get_mac_rx_need(void); + +zb_bool_t zb_buf_have_rx_bufs(void); + +/*! @} */ + +#endif /* ZBOSS_API_BUF_H */ diff --git a/zboss/include/zboss_api_core.h b/zboss/include/zboss_api_core.h new file mode 100644 index 0000000000..a64ad671e2 --- /dev/null +++ b/zboss/include/zboss_api_core.h @@ -0,0 +1,505 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS core API header. Time, scheduler and memory buffers API. +*/ + +#ifndef ZB_ZBOSS_API_CORE_H +#define ZB_ZBOSS_API_CORE_H 1 + +#include "zb_vendor.h" +#include "zb_config.h" +#include "zb_types.h" +#include "zb_channel_page.h" +#include "zb_errors.h" +#include "zb_osif.h" +#include "zb_debug.h" +#include "zb_trace.h" + +/*! \addtogroup time */ +/*! @{ */ + +/** + \par Timer functionality. + + The idea is: platform has some timer which can be stopped or run. + When run, it increments (or decrements - depends on platform) some counter + until counter overflow (underflow), then issues interrupt - wakeups main loop + if it sleeping. + Time stored in ticks; time resolution is platform dependent, its usual value + is 15.36 usec - 1 beacon interval. + @note Time type has limited capacity (usually 16 bits) and can overflow. + Macros which works with time handles overflow. It is supposed that time values will + not differ to more then 1/2 of the maximum time value. + + All that timer macros will not be used directly by the application code - it + is scheduler internals. The only API for timer is ZB_SCHEDULE_ALARM() call. + */ + + +/** + Timer type. + */ + +#ifdef ZB_TIMER_32 + typedef zb_uint32_t zb_time_t; +/** + * Maximum timer value, if 32-bit timer is used. + */ + #define ZB_MAX_TIME_VAL ZB_UINT32_MAX +/** + * Minimum timer value, if 32-bit timer is used. + */ + #define ZB_MIN_TIME_VAL ZB_UINT32_MIN +#else +/* 16 bits for 8051 - it will be hw timer value. */ + typedef zb_uint16_t zb_time_t; +/** + * Maximum timer value, if 16-bit timer is used. + */ + #define ZB_MAX_TIME_VAL ZB_UINT16_MAX +/** + * Minimum timer value, if 16-bit timer is used. + */ + #define ZB_MIN_TIME_VAL ZB_UINT16_MIN +#endif + +/** + * A half of defined maximum timer value. + */ +#define ZB_HALF_MAX_TIME_VAL (ZB_MAX_TIME_VAL / 2) + +/** @cond internals_doc */ +/** + * @copydoc ZB_TIMER_GET() + * + * @note Don't call directly, use @ref ZB_TIMER_GET() instead + */ +zb_time_t zb_timer_get(void); +/** @endcond */ /* internals_doc */ + +/** + * @return Get current timer value (beacon intervals) + */ +#define ZB_TIMER_GET() (zb_timer_get()) + +/** + Time subtraction: subtract 'b' from 'a' + + Take overflow into account: change sign (subtraction order) if result > + values_diapason/2. + Suppose a always >= b, so result is never negative. + This macro will be used to calculate, for example, amount of time to sleep + - it is positive by definition. + Do not use it to compare time values! Use ZB_TIME_GE() instead. + @note Both a and b is of type @ref zb_time_t. Can't decrease time (subtract + constant from it) using this macro. + + @param a - time to subtract from + @param b - time to subtract + @return subtraction result + */ +#define ZB_TIME_SUBTRACT(a, b) ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL ? (zb_time_t)((a) - (b)) : (zb_time_t)((b) - (a))) + +/** + Time add: add 'a' to 'b' + + Overflow is possible, but this is ok - it handled by subtraction and compare macros. + + @param a - time to add to + @param b - value to add + @return addition result + */ +#define ZB_TIME_ADD(a, b) (zb_time_t)((a) + (b)) + +/** + Compare times a and b - check that a >= b + + Taking into account overflow and unsigned values arithmetic and supposing + difference between a and b can't be > 1/2 of the overall time values + diapason, + a >= b only if a - b < values_diapason/2 + + @param a - first time value to compare + @param b - second time value to compare + @return 1 is a >= b, 0 otherwise + */ +#define ZB_TIME_GE(a, b) ((zb_time_t)((a) - (b)) < ZB_HALF_MAX_TIME_VAL) + + +/** + One second timeout +*/ +#define ZB_TIME_ONE_SECOND ZB_MILLISECONDS_TO_BEACON_INTERVAL(1000) + + +#ifdef ZB_TIMER_32 +/** + Convert time from milliseconds to beacon intervals (32-bit platforms). +*/ +#define ZB_MILLISECONDS_TO_BEACON_INTERVAL(ms) (((zb_time_t)(ms) * 1000) / ZB_BEACON_INTERVAL_USEC) +#else +/** + Convert time from milliseconds to beacon intervals + Try to not cause overflow in 16-bit arithmetic (with some precision lost...) +*/ +#define ZB_MILLISECONDS_TO_BEACON_INTERVAL(ms) (((10l * (zb_time_t)(ms) + 0) / (ZB_BEACON_INTERVAL_USEC / 100))) +#endif + +/** + * Beacon interval in microseconds + * + * 1 beacon interval = aBaseSuperframeDuration * symbol duration + * + * 1 symbol = 16e-6 sec (mac spec 6.5.3.2 Symbol rate) for 2.4GHz ZB. + * 1 beacon interval = 15.360 ms. + */ +#define ZB_BEACON_INTERVAL_USEC (ZB_SYMBOL_DURATION_USEC * ZB_ABASE_SUPERFRAME_DURATION) + + +#ifdef ZB_TIMER_32 +/** + Convert time from beacon intervals to milliseconds (32-bit platform). +*/ +#define ZB_TIME_BEACON_INTERVAL_TO_MSEC(t) ((ZB_BEACON_INTERVAL_USEC * (zb_time_t)(t)) / 1000) +#else +/** + Convert time from beacon intervals to milliseconds + + Try to not cause overflow in 16-bit arithmetic (with some precision lost...) +*/ +#define ZB_TIME_BEACON_INTERVAL_TO_MSEC(t) ((ZB_BEACON_INTERVAL_USEC / 100 * (t) - 0) / 10) +#endif + +/** + Convert time from beacon intervals to microseconds + +*/ +#define ZB_TIME_BEACON_INTERVAL_TO_USEC(t) ((zb_uint64_t)ZB_BEACON_INTERVAL_USEC * (t)) + +/** + Quarterseconds timeout +*/ +#define ZB_TIME_QUARTERECONDS(n) (ZB_TIME_BEACON_INTERVAL_TO_MSEC((n)) / 250) + +/** + Convert from quarterseconds to msec +*/ +#define ZB_QUARTERECONDS_TO_MSEC(n) 250*(n) + +/** + Convert from quarterseconds to beacon +*/ +#define ZB_QUARTERECONDS_TO_BEACON_INTERVAL(qsec) ZB_MILLISECONDS_TO_BEACON_INTERVAL(250*qsec) + +/** + * Convert from seconds to milliseconds + */ +#define ZB_SECONDS_TO_MILLISECONDS(_s) (1000l*(_s)) +/** + Convert from milliseconds to microseconds +*/ +#define ZB_MILLISECONDS_TO_USEC(ms) ((ms) * (1000)) + +/** + Convert from microseconds to milliseconds +*/ +#define ZB_USECS_TO_MILLISECONDS(usec) ((usec) / (1000)) + +/*! @} */ + +/*! \addtogroup sched */ +/*! @{ */ + +/** + * Callback function typedef. + * Callback is function planned to execute by another function. + * + * @note Callback must be declared as reentrant for sdcc. + * + * @param param - callback parameter - usually, but not always, ref to packet buf + * + * See any sample + */ +typedef void (ZB_CODE * zb_callback_t)(zb_uint8_t param); + +typedef zb_ret_t (ZB_CODE * zb_ret_callback_t)(zb_uint8_t param); + +typedef void (*zb_callback_void_t)(void); + + +/** + * Callback function with 2 parameters typedef. + * Callback is function planned to execute by another function. + * + * @note Callback must be declared as reentrant for sdcc. + * + * @param param - callback parameter - usually, but not always, ref to packet buf + * @param cb_param - additional 2-byte callback parameter, user data. + * + * See any sample + */ +typedef void (ZB_CODE * zb_callback2_t)(zb_uint8_t param, zb_uint16_t cb_param); +/** @cond internals_doc */ +/** Schedule single-param callback execution. + (use ZB_SCHEDULE_APP_CALLBACK() macro instead of this function). + + Schedule execution of function `func' in the main scheduler loop. + + @param func - function to execute + @param param - callback parameter - usually, but not always ref to packet buffer + @param use_2_param - ZB_TRUE whether additional parameter should be used + @param user_param - additional parameter which will be used if use_2_param is ZB_TRUE + @param is_prior - ZB_TRUE is callback is high priority + + @return RET_OK or error code. + + See sched sample +*/ +zb_ret_t zb_schedule_app_callback(zb_callback_t func, zb_uint8_t param, + zb_bool_t use_2_param, zb_uint16_t user_param, zb_bool_t is_prior); +/** @endcond */ /* internals_doc */ +/** + Schedule single-param callback execution. + + Schedule execution of function `func' in the main scheduler loop. + + @param func - function to execute + @param param - callback parameter - usually, but not always ref to packet buffer + + @return RET_OK or RET_OVERFLOW. + + See sched sample + */ +#define ZB_SCHEDULE_APP_CALLBACK(func, param) zb_schedule_app_callback(func, param, ZB_FALSE, 0, ZB_FALSE) + +/** + Schedule two-param callback execution. + Schedule execution of function `func' in the main scheduler loop. + + @param func - function to execute + @param param - zb_uint8_t callback parameter - usually, but not always ref to + packet buffer + @param user_param - zb_uint16_t user parameter - usually, but not + always short address + + @return RET_OK or RET_OVERFLOW. + See sched sample + */ +#define ZB_SCHEDULE_APP_CALLBACK2(func, param, user_param) zb_schedule_app_callback((zb_callback_t)(func), param, ZB_TRUE, user_param, ZB_FALSE) + +/** @cond internals_doc */ +zb_ret_t zb_schedule_app_alarm(zb_callback_t func, zb_uint8_t param, zb_time_t run_after); +/** @endcond */ /* internals_doc */ + +/** + Schedule alarm - callback to be executed after timeout. + + Function will be called via scheduler after timeout expired (maybe, plus some + additional time). + Timer resolution depends on implementation. + Same callback can be scheduled for execution more then once. + + @param func - function to call via scheduler + @param param - parameter to pass to the function + @param timeout_bi - timeout, in beacon intervals + @return RET_OK or RET_OVERFLOW + + See any sample + */ +#define ZB_SCHEDULE_APP_ALARM(func, param, timeout_bi) zb_schedule_app_alarm(func, param, timeout_bi) + +/** + Special parameter for zb_schedule_alarm_cancel(): cancel alarm once without + parameter check + + Cancel only one alarm without check for parameter + */ +#define ZB_ALARM_ANY_PARAM (zb_uint8_t)(-1) + +/** + Special parameter for zb_schedule_alarm_cancel(): cancel alarm for all + parameters + */ +#define ZB_ALARM_ALL_CB (zb_uint8_t)(-2) +/** @cond internals_doc */ +/** + Cancel scheduled alarm (use macro ZB_SCHEDULE_APP_ALARM_CANCEL() or + ZB_SCHEDULE_APP_ALARM_CANCEL_AND_GET_BUF() instead of this function). + + This function cancel previously scheduled alarm. Function is identified by + the pointer. + + @param func - function to cancel + @param param - parameter to cancel. \see ZB_ALARM_ANY_PARAM. \see ZB_ALARM_ALL_CB + @param p_param - [out] pointer of ref buffer from cancelled flag: free buffer if its alarm will be cancel + @return RET_OK or error code + + See reporting_srv sample + */ +zb_ret_t zb_schedule_alarm_cancel(zb_callback_t func, zb_uint8_t param, zb_uint8_t *p_param); +/** @endcond */ /* internals_doc */ +/** + Cancel scheduled alarm. + + This function cancel previously scheduled alarm. Function is identified by + the pointer. + + @param func - function to cancel + @param param - parameter to cancel. \see ZB_ALARM_ANY_PARAM. \see ZB_ALARM_ALL_CB + @return RET_OK or RET_OVERFLOW + + See reporting_srv sample + */ +#define ZB_SCHEDULE_APP_ALARM_CANCEL(func, param) zb_schedule_alarm_cancel((func), (param), NULL) + +/** + Cancel scheduled alarm and get buffer. + + This function cancel previously scheduled alarm and returns buffer ref associated with alarm. + Function is identified by the pointer. + + @param func - function to cancel + @param param - parameter to cancel. \see ZB_ALARM_ANY_PARAM. \see ZB_ALARM_ALL_CB + @param p_param - [out] pointer of ref buffer from cancelled flag: free buffer if its alarm will be cancel + @return RET_OK or error code + + @b Example: + @code + { + zb_uint8_t cancelled_param; + + ZB_SCHEDULE_ALARM_CANCEL_AND_GET_BUF(my_func1, ZB_ALARM_ALL_CB, &cancelled_param); + my_func1(cancelled_param); + } + @endcode + + See reporting_srv sample + */ +#define ZB_SCHEDULE_APP_ALARM_CANCEL_AND_GET_BUF(func, param, p_param) zb_schedule_alarm_cancel((func), (param), p_param) + +/** @cond internals_doc */ +/** + Get Schedule alarm time - seek alarm and return alarm time + + @param func - function to call via scheduler + @param param - parameter to pass to the function + @param timeout_bi - pointer on alarm timeout, in beacon intervals + @return RET_OK or error code + */ +zb_ret_t zb_schedule_get_alarm_time(zb_callback_t func, zb_uint8_t param, zb_time_t *timeout_bi); +/** @endcond */ /* internals_doc */ + +/** + Get Schedule alarm time - seek alarm and return alarm time + + @param func - function to call via scheduler + @param param - parameter to pass to the function + @param timeout_bi - pointer on alarm timeout, in beacon intervals + @return RET_OK or error code +*/ +#define ZB_SCHEDULE_GET_ALARM_TIME(func, param, timeout_bi) zb_schedule_get_alarm_time(func, param, timeout_bi) + +/*! @} */ + + +/*! \addtogroup rng */ +/*! @{ */ + +/** + * Maximal possible value for randomly generated (16-bit) value + */ +#define ZB_RAND_MAX ((zb_uint16_t)0xffff) + +/** + * Generate random value + * + * @return random value between 0 to 0xffff (16 bit) + */ +zb_uint16_t zb_random(void); + + +/** + Generate random value between 0 to max_value (16 bit) + */ +#define ZB_RANDOM_VALUE(max_value) (((zb_uint16_t)(max_value)) ? (zb_random() / (ZB_RAND_MAX / (zb_uint16_t)(max_value))) : 0) + +/*! @} */ + +/** @cond internals_doc */ +/** + Copy 8 byte array (i.e. long address). + */ +void zb_memcpy8(zb_uint8_t *ptr, zb_uint8_t *src); +/** @endcond */ /* internals_doc */ + +/** + Return absolute value +*/ +#define ZB_ABS(a) ((a) < 0 ? -(a) : (a)) + +/** @cond internals_doc */ +/** + * @note Pointer should be aligned. + * Cast is intended to suppress warnings "cast increases required alignment of target type [-Wcast-align]" + * when you perform pointers cast. + */ +#define ZB_SAFE_PTR_CAST(ptr) (void*)(ptr) +/** @endcond */ /* internals_doc */ + +/** + * Set of ZB_BITSx() macros return value with bits set in provided positions. + * ZB_BITS1(0) = 1 + * ZB_BITS2(2,3) = 12 + * ZB_BITS3(0,1,2) = 7 + */ +#define ZB_BITS1(_b) (1ul << (_b)) +#define ZB_BITS2(_b1, _b2) ((1ul << (_b1)) | (1ul << (_b2))) +#define ZB_BITS3(_b1, _b2, _b3) ((1ul << (_b1)) | (1ul << (_b2)) | (1ul << (_b3))) +#define ZB_BITS4(_b1, _b2, _b3, _b4) ((1ul << (_b1)) | (1ul << (_b2)) | (1ul << (_b3)) | (1ul << (_b4))) +#define ZB_BITS5(_b1, _b2, _b3, _b4, _b5) ((1ul << (_b1)) | (1ul << (_b2)) | (1ul << (_b3)) | \ + (1ul << (_b4)) | (1ul << (_b5))) + +#define ZB_SET_BIT_IN_BIT_VECTOR(vector, nbit) ( (vector)[ (nbit) / 8 ] |= ( 1 << ( (nbit) % 8 )) ) +#define ZB_CLR_BIT_IN_BIT_VECTOR(vector, nbit) ( (vector)[ (nbit) / 8 ] &= ~( 1 << ( (nbit) % 8 )) ) +#define ZB_CHECK_BIT_IN_BIT_VECTOR(vector, nbit) ( (vector)[ (nbit) / 8 ] & ( 1 << ( (nbit) % 8 )) ) +#define ZB_SIZE_OF_BIT_VECTOR(bit_count) (bit_count / 8 + !!(bit_count % 8 != 0)) + +#endif /* ZB_ZBOSS_API_CORE_H */ diff --git a/zboss/include/zboss_api_internal.h b/zboss/include/zboss_api_internal.h new file mode 100644 index 0000000000..3d8fce3ede --- /dev/null +++ b/zboss/include/zboss_api_internal.h @@ -0,0 +1,456 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS internal data structures required for configurable memory. +*/ + +#ifndef ZB_ZBOSS_API_INTERNAL_H +#define ZB_ZBOSS_API_INTERNAL_H 1 + +#include "zb_vendor.h" +#include "zb_config.h" +#include "zb_types.h" +#include "zb_errors.h" +#include "zb_osif.h" +#include "zb_debug.h" +#include "zb_trace.h" +#include "zb_pooled_list.h" +#include "zb_address.h" + +/* Data structures moved from subsystem internal headers for configurable memory implementation. */ + +/** + Parameters for storing data in a pending queue + + Moved there from MAC to be able to implement MAC indirect quete size configuration. +*/ +typedef struct zb_mac_pending_data_s +{ + zb_addr_u dst_addr; /**< Destination address */ + zb_uint8_t dst_addr_mode; /**< Destination address mode @ref zb_addr_mode_t */ + zb_uint8_t pending_param; /**< Pointer to pending data */ +} +zb_mac_pending_data_t; + + +/** + APS retransmissions + */ +typedef ZB_PACKED_PRE struct zb_aps_retrans_ent_s +{ + zb_uint16_t addr; /*!< Destination address*/ + zb_uint16_t clusterid; /*!< Cluster ID*/ + zb_uint8_t aps_counter; /*!< APS counter */ + zb_uint8_t src_endpoint; /*!< Source endpoint */ + zb_uint8_t dst_endpoint; /*!< Destination endpoint */ + zb_uint8_t buf; /*!< Buffer index for retranslate */ + + zb_bitfield_t aps_retries:4; /*!< Number of attempts */ + zb_bitfield_t nwk_insecure:1; /*!< Flag 'Is NWK secure' */ + zb_bitfield_t state:3; /*!< \see zb_aps_retrans_ent_state_e */ +} ZB_PACKED_STRUCT zb_aps_retrans_ent_t; + + +typedef ZB_PACKED_PRE struct zb_cb_q_ent_s +{ + zb_callback_t func_ptr; /*!< function to call */ + zb_uint16_t user_param; /*!< user parameter */ + zb_uint8_t param; /*!< parameter to pass to 'func' */ +} +ZB_PACKED_STRUCT +zb_cb_q_ent_t; + + +typedef ZB_PACKED_PRE struct zb_delayed_buf_q_ent_s +{ + zb_callback_t func_ptr; /*!< function to call */ + zb_uint16_t user_param; /*!< user parameter */ + zb_bitfield_t buf_cnt:7; /*!< number of buffers to allocate */ + zb_bitfield_t is_2param:1; /*!< whether this is a 2param calback */ +} +ZB_PACKED_STRUCT +zb_delayed_buf_q_ent_t; + +/** + Delayed (scheduled to run after timeout) callbacks queue entry. + */ +typedef ZB_PACKED_PRE struct zb_tm_q_ent_s +{ + zb_callback_t func; /*!< function to call */ + zb_time_t run_time; /*!< time to run at */ + zb_uint8_t param; /*!< parameter to pass to 'func' */ + ZB_POOLED_LIST8_FIELD(next); +} +ZB_PACKED_STRUCT +zb_tm_q_ent_t; + +/** + Installcode hash for TC + + Do not store installcode itself in RAM - keep only 4 bytes per entry in RAM. + */ +typedef ZB_PACKED_PRE struct zb_aps_installcode_storage_s +{ + zb_uint32_t nvram_offset:28; /*!< offset of zb_aps_installcode_nvram_t + record in nvram. 28 bit supports 256k + page - hope, it is enough */ + zb_bitfield_t nvram_page:4; /*!< nvram page. Hope 16 pages are enough */ +} ZB_PACKED_STRUCT zb_aps_installcode_storage_t; + + +typedef ZB_PACKED_PRE struct zb_aps_device_key_pair_array_s +{ + zb_uint32_t nvram_offset:27; /*!< offset of zb_aps_device_key_pair_storage_t + record in nvram. 27 bit supports 128k + page - hope, it is enough */ + /* Try to fit into 6 bytes instead of 8 */ + zb_lbitfield_t outgoing_frame_counter:21;/*!< Outgoing value for APS frame + * outgoing counter. Used for + * communication with TC only, so + * hope 2^21 ~ 10^10 values are enough + */ +#ifndef ZB_NO_CHECK_INCOMING_SECURE_APS_FRAME_COUNTERS + zb_uint32_t incoming_frame_counter; /*!< Incoming value,for APS frame incoming counter */ +#endif +} ZB_PACKED_STRUCT zb_aps_device_key_pair_array_t; + + + +/** + NWK routing +*/ +typedef ZB_PACKED_PRE struct zb_nwk_routing_s /* do not pack for IAR */ +{ + zb_bitfield_t used:1; /*!< 1 if entry is used, 0 - otherwise */ + zb_bitfield_t status:2; /*!< The status of the route, @see zb_nwk_route_state_t */ +#ifndef ZB_LITE_NO_SOURCE_ROUTING + zb_bitfield_t no_route_cache:1; /*!< Dest does not store source routes. */ + zb_bitfield_t many_to_one:1; /*!< Dest is the concentrator and many-to-one + * request was used */ + zb_bitfield_t route_record_required:1; /*!< Route record command frame should + * be sent to the dest prior to the + * next data packet */ +#endif +#ifndef ZB_NO_NWK_MULTICAST + zb_bitfield_t group_id_flag:1; /*!< Indicates that dest_addr is a Group ID */ +#endif +#if ZB_NWK_ROUTING_TABLE_EXPIRY < 64 + zb_bitfield_t expiry:6; /*!< expiration time. max value - + * ZB_NWK_ROUTING_TABLE_EXPIRY (60) */ +#else + zb_uint8_t expiry; +#endif +#if !defined ZB_CONFIGURABLE_MEM && ZB_IEEE_ADDR_TABLE_SIZE <= 127 + zb_bitfield_t next_hop_addr_ref:7; +#else + zb_uint8_t next_hop_addr_ref; /*!< ref to network address of the next + * hop on the way to the destination */ +#endif + zb_uint16_t dest_addr; /*!< 16-bit network address or Group ID of this route */ +} ZB_PACKED_STRUCT +zb_nwk_routing_t; + +#if defined ZB_PRO_STACK && !defined ZB_LITE_NO_SOURCE_ROUTING +/** + Route Record Table Entry Format, Table 3.45 +*/ +typedef struct zb_nwk_rrec_s /* do not pack for IAR */ +{ + zb_bitfield_t used:1; /*!< Is record used */ + zb_bitfield_t expiry:7; /*!< Expiration time */ + zb_uint8_t count; /*!< Count hops */ + zb_uint16_t addr; /*!< Destination address */ + zb_uint16_t path[ZB_NWK_MAX_PATH_LENGTH]; /*!< Full path */ +} ZB_PACKED_STRUCT zb_nwk_rrec_t; + +#endif + +typedef ZB_PACKED_PRE struct zb_aps_dup_tbl_ent_s +{ + zb_uint8_t addr_ref; /*!< Reference to addr_map */ + zb_uint8_t counter; /*!< APS frame counter */ + zb_bitfield_t clock:7; /*!< Expiry clock counter */ + zb_bitfield_t is_unicast:1; /*!< Is delivery mode unicast */ +} ZB_PACKED_STRUCT zb_aps_dup_tbl_ent_t; + + +/** + Global binding table - source part +*/ +typedef ZB_PACKED_PRE struct zb_aps_bind_src_table_s +{ + zb_address_ieee_ref_t src_addr; /*!< source address as ref from nwkAddressMap */ + zb_uint8_t src_end; /*!< source endpoint */ + zb_uint16_t cluster_id; /*!< cluster id */ +} ZB_PACKED_STRUCT zb_aps_bind_src_table_t; + +/** + Global binding table - destination part with 64-bit address +*/ +typedef ZB_PACKED_PRE struct zb_aps_bind_long_dst_addr_s +{ + zb_address_ieee_ref_t dst_addr; /*!< destination address as ref from nwkAddressMap */ + zb_uint8_t dst_end; /*!< destination endpoint */ +} ZB_PACKED_STRUCT zb_aps_bind_long_dst_addr_t; + +#ifndef ZB_CONFIGURABLE_MEM +#define ZB_APS_BIND_TRANS_TABLE_SIZE ((ZB_IOBUF_POOL_SIZE + 15)/16 *4) + +/* it should be 4-byte aligned if it is stored in NVRAM */ +#define ZB_SINGLE_TRANS_INDEX_SIZE (((ZB_APS_BIND_TRANS_TABLE_SIZE + 31) / 32) * 4) +#endif + +/** + Global binding table - destination part +*/ +typedef ZB_PACKED_PRE struct zb_aps_bind_dst_table_s +{ +#ifdef ZB_CONFIGURABLE_MEM + /* WARNING: this field will be rewritten if APS binding dataset is present in NVRAM */ + zb_uint8_t *trans_index; +#endif /* defined ZB_CONFIGURABLE_MEM */ + + ZB_PACKED_PRE union + { + zb_uint16_t group_addr; /*!< group address */ + zb_aps_bind_long_dst_addr_t long_addr; /*!< @see zb_asp_long_dst_addr_t */ + } u; + +#ifndef ZB_CONFIGURABLE_MEM + zb_uint8_t trans_index[ZB_SINGLE_TRANS_INDEX_SIZE]; +#endif /* defined ZB_CONFIGURABLE_MEM */ + zb_uint8_t align; + + zb_bitfield_t dst_addr_mode:3; /*!< destination address mode flag, 0 + * - group address, otherwise long + * address plus dest endpoint */ + zb_bitfield_t src_table_index:5; /*!< index from zb_asp_src_table_t */ +} ZB_PACKED_STRUCT zb_aps_bind_dst_table_t; + +/** + Neighbor table entry + */ +typedef ZB_PACKED_PRE struct zb_neighbor_tbl_ent_s /* not need to pack it at IAR */ +{ + /* 0 */ + zb_bitfield_t used:1; /*!< Record has used */ + zb_bitfield_t ext_neighbor:1; /*!< if 1, this is ext neighbor + * record, else base neighbor */ + + zb_bitfield_t device_type:2; /*!< Neighbor device type - \see + * zb_nwk_device_type_t */ + + zb_bitfield_t depth:4; /*!< The network depth of this + device. A value of 0x00 + indicates that this device is the + Zigbee coordinator for the + network. */ + /* 1,2 */ + zb_bitfield_t permit_joining:1; /*!< A value of TRUE indicates that at + least one Zigbee router on the + network currently permits joining, + i.e. its NWK has been issued an + NLME-PERMIT-JOINING + primitive and, the time limit if + given, has not yet expired. */ + + zb_bitfield_t rx_on_when_idle:1; /*!< Indicates if neighbor receiver + enabled during idle periods: + TRUE = Receiver is on + FALSE = Receiver is off + This field should be present for + entries that record the parent or + children of a Zigbee router or + Zigbee coordinator. */ + + zb_bitfield_t relationship:3; /*!< The relationship between the + neighbor and the current device: + 0x00=neighbor is the parent + 0x01=neighbor is a child + 0x02=neighbor is a sibling + 0x03=none of the above + 0x04=previous child + 0x05=unauthenticated child + This field shall be present in every + neighbor table entry. + \see zb_nwk_relationship_e + */ + + zb_bitfield_t need_rejoin:1; /*!< Need send rejoin response without receive request */ + + zb_bitfield_t send_via_routing: 1; /*!< Due to bad link to that device send packets + * via NWK routing. + */ + + zb_bitfield_t keepalive_received:1; /*!< This value indicates at least one keepalive + * has been received from the end device since + * the router has rebooted. + */ + + zb_bitfield_t mac_iface_idx:5; /*!< An index into the MAC Interface Table + * indicating what interface the neighbor or + * child is bound to. */ + + zb_bitfield_t transmit_failure_cnt:4; /*!< Transmit failure counter (used to initiate + * device address + * search). */ + /* 3 */ + zb_uint8_t lqi; /*!< Link quality. Also used to calculate + * incoming cost */ + /* 4 */ + zb_int8_t rssi; /*!< Received signal strength indicator */ + /* 5 */ + ZB_PACKED_PRE union { + ZB_PACKED_PRE struct zb_ext_neighbor_s + { + /* 0 */ + zb_uint16_t short_addr; /*!< 16-bit network address of the + neighboring device */ + /* 2 */ + + zb_ieee_addr_compressed_t long_addr; /*!< 64-bit address (packed) */ + /* 8 */ + zb_uint8_t update_id; /*!< This field reflects the value of nwkUpdateId from the NIB. */ + /* 9 */ + zb_bitfield_t panid_ref:5; /*!< ref to the extended Pan id */ + + zb_bitfield_t router_capacity:1; /*!< This value is set to TRUE if this + device is capable of accepting + join requests from router- + capable devices and is set to + FALSE otherwise. */ + zb_bitfield_t end_device_capacity:1; /*!< This value is set to TRUE if the + device is capable of accepting + join requests from end devices + seeking to join the network and + is set to FALSE otherwise. */ + zb_bitfield_t potential_parent:1; /*!< This field usage - see + 3.6.1.4.1.1 Child Procedure: + If the Status parameter indicates a refusal to permit + joining on the part of the neighboring device (that is, PAN at capacity or PAN + access denied), then the device attempting to join should set the Potential parent + bit to 0 in the corresponding neighbor table entry to indicate a failed join attempt. + */ + /* 10 */ + zb_uint8_t channel_page; /*!< The current channel page occupied by the network. */ + /* 11 */ + zb_bitfield_t logical_channel:5; /*!< The current logical channel + occupied by the network. */ + + zb_bitfield_t stack_profile:2; /*!< A ZBOSS profile identifier. */ + + zb_bitfield_t reserved:1; +#ifdef ZB_PARENT_CLASSIFICATION + /* 12 */ + zb_uint8_t classification_mask; +#endif + /* 13 */ + } ZB_PACKED_STRUCT ext; + ZB_PACKED_PRE struct zb_base_neighbor_s + { + zb_uint8_t key_seq_number; /*!< key number for which + * incoming_frame_counter is valid */ +#ifndef ZB_ROUTER_ROLE /* no routing at ZED - simplify*/ + zb_address_ieee_ref_t addr_ref; /*!< address translation entry */ + zb_uint8_t nwk_ed_timeout; /*End device timeout - @see nwk_requested_timeout_t */ +#else /* ZR,ZC */ +#if !defined ZB_CONFIGURABLE_MEM && ZB_IEEE_ADDR_TABLE_SIZE < 128 + /* Won 1 byte here, so base is 11 bytes (== ext) */ + zb_bitfield_t addr_ref:7; /*!< address translation entry */ +#else + /* If configurable mem build, can have >127 addresses, so need a byte here. */ + zb_address_ieee_ref_t addr_ref; +#endif /* if 7 bits are enough */ + + zb_bitfield_t nwk_ed_timeout:4; /*End device timeout - @see nwk_requested_timeout_t */ + + /* Following fields present only if nwkSymLink = TRUE - this is PRO, not 2007 */ + zb_bitfield_t outgoing_cost:3; /*!< The cost of an outgoing + * link. Got from link status. */ + /* In other words, if a device fails to receive nwkRouterAgeLimit link status + messages from a router neighbor in a row, the old outgoing cost information is + discarded. In this case, the neighbor entry is considered stale and may be reused if + necessary to make room for a new neighbor. */ +#ifndef ZB_LITE_NO_CONFIGURABLE_LINK_STATUS + zb_bitfield_t age:5; /*!< The number of nwkLinkStatusPeriod intervals since a + * link status command was received */ +#else + /* actually ZB_NWK_ROUTER_AGE_LIMIT is 3, so 2 bits is enough */ + zb_bitfield_t age:2; +#endif +#endif /* ZB_ROUTER_ROLE */ + zb_uint32_t incoming_frame_counter; /*!< incoming NWK frame counter + * for this device after + * key change */ + zb_time_t time_to_expire; /*Time stamp for ED aging*/ + } ZB_PACKED_STRUCT base; + } ZB_PACKED_STRUCT u; + /* TODO: move it to base ?? */ +#if !defined ZB_ED_ROLE && defined ZB_MAC_DUTY_CYCLE_MONITORING + zb_lbitfield_t is_subghz:1; /*!< if 1, this is Sub-GHz device */ + zb_lbitfield_t suspended:1; /*!< if 1, SuspendZCLMessages was sent to the device */ + zb_lbitfield_t pkt_count:22; /*!< count of packets received from this device */ +#define MAX_NBT_PKT_COUNT ((1u<<22)-1) + zb_lbitfield_t subghz_ep:8; /*!< endpoint with Sub-GHz cluster on remote device */ +#endif +} ZB_PACKED_STRUCT +zb_neighbor_tbl_ent_t; + +/** + Kind of negotiation before TX +*/ +typedef enum zb_mac_tx_wait_e +{ + ZB_MAC_TX_WAIT_ACK, + ZB_MAC_TX_WAIT_CSMACA, + ZB_MAC_TX_WAIT_ZGP, + ZB_MAC_TX_WAIT_NONE, +} zb_mac_tx_wait_t; + +enum zb_mac_tx_status_e +{ + ZB_TRANS_TX_OK = 0, + ZB_TRANS_CHANNEL_BUSY_ERROR, + ZB_TRANS_TX_RETRY_COUNT_EXCEEDED, + ZB_TRANS_TX_LBT_TO, + ZB_TRANS_NO_ACK +}; + +#endif /* ZB_ZBOSS_API_INTERNAL_H */ diff --git a/zboss/include/zboss_api_nwk.h b/zboss/include/zboss_api_nwk.h new file mode 100644 index 0000000000..273c681d32 --- /dev/null +++ b/zboss/include/zboss_api_nwk.h @@ -0,0 +1,560 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Public Network layer API +*/ +#ifndef ZB_ZBOSS_API_NWK_H +#define ZB_ZBOSS_API_NWK_H 1 + +/** \addtogroup nwk_api */ +/** @{ */ + +/** @addtogroup nwk_common_constants NWK common constants + * @{ + */ +/** @brief Network broadcast addresses types. */ +typedef enum zb_nwk_broadcast_address_e +{ + ZB_NWK_BROADCAST_ALL_DEVICES = 0xFFFF, /**< All devices in PAN */ + ZB_NWK_BROADCAST_RX_ON_WHEN_IDLE = 0xFFFD, /**< macRxOnWhenIdle = TRUE */ + ZB_NWK_BROADCAST_ROUTER_COORDINATOR = 0xFFFC, /**< All routers and coordinator */ + ZB_NWK_BROADCAST_LOW_POWER_ROUTER = 0xFFFB, /**< Low power routers only */ + + ZB_NWK_BROADCAST_RESERVED = 0xFFF8 /**< Reserved value */ +} +zb_nwk_broadcast_address_t; +/** @} */ /* nwk_common_constants */ + +/** @addtogroup nwk_management_service NWK management service + * @{ + */ +/** @brief Check that address is broadcast. + * @param addr - 16-bit address + * @return TRUE if address is broadcast, FALSE otherwise + */ +/* #define ZB_NWK_IS_ADDRESS_BROADCAST(addr) ( ((addr) & 0xFFF0) == 0xFFF0 ) */ +#define ZB_NWK_IS_ADDRESS_BROADCAST(addr) ( (addr) >= ZB_NWK_BROADCAST_RESERVED ) +/** @} */ /* nwk_management_service */ + +/** @addtogroup nwk_common_constants NWK common constants + * @{ + */ +/** + Network device type +*/ +typedef enum zb_nwk_device_type_e +{ + ZB_NWK_DEVICE_TYPE_COORDINATOR, /*!< Device - Coordinator */ + ZB_NWK_DEVICE_TYPE_ROUTER, /*!< Device - Router */ + ZB_NWK_DEVICE_TYPE_ED, /*!< Device - End device */ + ZB_NWK_DEVICE_TYPE_NONE /*!< Unknown Device */ +} +zb_nwk_device_type_t; + + +/** @brief Leave types */ +typedef enum zb_nwk_leave_type_e +{ + ZB_NWK_LEAVE_TYPE_RESET = 0x00, /**< Leave without rejoin */ + ZB_NWK_LEAVE_TYPE_REJOIN = 0x01 /**< Leave with rejoin */ +} zb_nwk_leave_type_t; + + +/** @cond internals_doc */ +/** @brief Network command status codes. */ +typedef enum zb_nwk_command_status_e +{ + ZB_NWK_COMMAND_STATUS_NO_ROUTE_AVAILABLE = 0x00, /**< No route available */ + ZB_NWK_COMMAND_STATUS_TREE_LINK_FAILURE = 0x01, /**< Tree link failure */ + ZB_NWK_COMMAND_STATUS_NONE_TREE_LINK_FAILURE = 0x02, /**< None-tree link failure */ + ZB_NWK_COMMAND_STATUS_LOW_BATTERY_LEVEL = 0x03, /**< Low battery level */ + ZB_NWK_COMMAND_STATUS_NO_ROUTING_CAPACITY = 0x04, /**< No routing capacity */ + ZB_NWK_COMMAND_STATUS_NO_INDIRECT_CAPACITY = 0x05, /**< No indirect capacity */ + ZB_NWK_COMMAND_STATUS_INDIRECT_TRANSACTION_EXPIRY = 0x06, /**< Indirect transaction expiry */ + ZB_NWK_COMMAND_STATUS_TARGET_DEVICE_UNAVAILABLE = 0x07, /**< Target device unavailable */ + ZB_NWK_COMMAND_STATUS_TARGET_ADDRESS_UNALLOCATED = 0x08, /**< Target address unallocated */ + ZB_NWK_COMMAND_STATUS_PARENT_LINK_FAILURE = 0x09, /**< Parent link failure */ + ZB_NWK_COMMAND_STATUS_VALIDATE_ROUTE = 0x0a, /**< Validate route */ + ZB_NWK_COMMAND_STATUS_SOURCE_ROUTE_FAILURE = 0x0b, /**< Source route failure */ + ZB_NWK_COMMAND_STATUS_MANY_TO_ONE_ROUTE_FAILURE = 0x0c, /**< Many-to-one route failure */ + ZB_NWK_COMMAND_STATUS_ADDRESS_CONFLICT = 0x0d, /**< Address conflict */ + ZB_NWK_COMMAND_STATUS_VERIFY_ADDRESS = 0x0e, /**< Verify address */ + ZB_NWK_COMMAND_STATUS_PAN_IDENTIFIER_UPDATE = 0x0f, /**< Pan ID update */ + ZB_NWK_COMMAND_STATUS_NETWORK_ADDRESS_UPDATE = 0x10, /**< Network address update */ + ZB_NWK_COMMAND_STATUS_BAD_FRAME_COUNTER = 0x11, /**< Bad frame counter */ + ZB_NWK_COMMAND_STATUS_BAD_KEY_SEQUENCE_NUMBER = 0x12, /**< Bad key sequence number */ + ZB_NWK_COMMAND_STATUS_UNKNOWN_COMMAND = 0x13, /**< Command received is not known */ +} +zb_nwk_command_status_t; +/** @endcond */ /* internals_doc */ +/** @} */ /* nwk_common_constants */ + +/** @cond internals_doc */ +/** @brief Arguments of the NLME-STATUS.indication routine. */ +typedef ZB_PACKED_PRE struct zb_nlme_status_indication_s +{ + zb_uint8_t status; /**< Error code associated with the failure */ + zb_uint16_t network_addr; /**< Network device address associated with the status information */ + zb_uint8_t unknown_command_id; /**< Unknown command id + (required for ZB_NWK_COMMAND_STATUS_UNKNOWN_COMMAND) */ +} ZB_PACKED_STRUCT +zb_nlme_status_indication_t; +/** @endcond */ /* internals_doc */ + +/** @addtogroup nwk_common_constants NWK common constants + * @{ + */ +/** + LQI undefined value + */ +#define ZB_MAC_LQI_UNDEFINED 0 +/** + RSSI undefined value + */ +#define ZB_MAC_RSSI_UNDEFINED 0x7f + + +/** + Number of the first channel +*/ +/* #define ZB_MAC_START_CHANNEL_NUMBER 11 */ +/** + Maximal number of the channels + */ +#define ZB_MAC_MAX_CHANNEL_NUMBER 26 +/** + Total number of supported channels + */ +#define ZB_MAC_SUPPORTED_CHANNELS (ZB_MAC_MAX_CHANNEL_NUMBER + 1) + +/** @cond DOXYGEN_SE_SECTION */ +/* See D.10.2.1.3.2 Channel Pages */ + +/** + The first logical channel for Page 28 Sub GHz +*/ +#define ZB_PAGE28_SUB_GHZ_START_LOGICAL_CHANNEL 0 + +/* 08/21/2017 EE CR:MINOR Am I right this value is always 0 for any page? Do we ever need separate constants? */ +/** + Number of the first channel in channel mask for Page 28 Sub GHz +*/ +#define ZB_PAGE28_SUB_GHZ_START_CHANNEL_NUMBER 0 +/** + The last logical channel for Page 28 Sub GHz +*/ +#define ZB_PAGE28_SUB_GHZ_MAX_LOGICAL_CHANNEL 26 +/** + Number of the last channel in channel mask for Page 28 Sub GHz +*/ +#define ZB_PAGE28_SUB_GHZ_MAX_CHANNEL_NUMBER (ZB_PAGE28_SUB_GHZ_MAX_LOGICAL_CHANNEL - \ + ZB_PAGE28_SUB_GHZ_START_LOGICAL_CHANNEL) + +/** + The first logical channel for Page 29 Sub GHz +*/ +#define ZB_PAGE29_SUB_GHZ_START_LOGICAL_CHANNEL 27 +/** + Number of the first channel in channel mask for Page 29 Sub GHz +*/ +#define ZB_PAGE29_SUB_GHZ_START_CHANNEL_NUMBER 0 +/** + The last logical channel for Page 29 Sub GHz (for solid range 27-34) +*/ +#define ZB_PAGE29_SUB_GHZ_PRE_MAX_LOGICAL_CHANNEL 34 +/** + The last logical channel for Page 29 Sub GHz +*/ +#define ZB_PAGE29_SUB_GHZ_MAX_LOGICAL_CHANNEL 62 +/** + Number of the last channel in channel mask for Page 29 Sub GHz +*/ +#define ZB_PAGE29_SUB_GHZ_MAX_CHANNEL_NUMBER (ZB_PAGE29_SUB_GHZ_PRE_MAX_LOGICAL_CHANNEL - \ + ZB_PAGE29_SUB_GHZ_START_LOGICAL_CHANNEL + 1 /* 62 channel */) + +/** + The first logical channel for Page 30 Sub GHz +*/ +#define ZB_PAGE30_SUB_GHZ_START_LOGICAL_CHANNEL 35 +/** + Number of the first channel in channel mask for Page 30 Sub GHz +*/ +#define ZB_PAGE30_SUB_GHZ_START_CHANNEL_NUMBER 0 +/** + The last logical channel for Page 30 Sub GHz +*/ +#define ZB_PAGE30_SUB_GHZ_MAX_LOGICAL_CHANNEL 61 +/** + Number of the last channel in channel mask for Page 30 Sub GHz +*/ +#define ZB_PAGE30_SUB_GHZ_MAX_CHANNEL_NUMBER (ZB_PAGE30_SUB_GHZ_MAX_LOGICAL_CHANNEL - \ + ZB_PAGE30_SUB_GHZ_START_LOGICAL_CHANNEL) + +/** + The first logical channel for Page 31 Sub GHz +*/ +#define ZB_PAGE31_SUB_GHZ_START_LOGICAL_CHANNEL 0 +/** + Number of the first channel in channel mask for Page 31 Sub GHz +*/ +#define ZB_PAGE31_SUB_GHZ_START_CHANNEL_NUMBER 0 +/** + The last logical channel for Page 31 Sub GHz +*/ +#define ZB_PAGE31_SUB_GHZ_MAX_LOGICAL_CHANNEL 26 +/** + Number of the last channel in channel mask for Page 31 Sub GHz +*/ +#define ZB_PAGE31_SUB_GHZ_MAX_CHANNEL_NUMBER (ZB_PAGE31_SUB_GHZ_MAX_LOGICAL_CHANNEL - \ + ZB_PAGE31_SUB_GHZ_START_LOGICAL_CHANNEL) + /** @endcond */ /* DOXYGEN_SE_SECTION */ +/* ZB_MAC_START_CHANNEL_NUMBER */ +/** + The first logical channel for Page 0 2.4GHz +*/ +#define ZB_PAGE0_2_4_GHZ_START_LOGICAL_CHANNEL 11 +/* Let's keep compatibility with bits layout in ZBOSS without sub-gig: start from 11 in 2.4. + Actually, only subgig pages 28 and 31 are ok too (logical == bit#). Pages 29 and 30 are special case. + */ +/** + Number of the first channel in channel mask for Page 0 2.4GHz +*/ +#define ZB_PAGE0_2_4_GHZ_START_CHANNEL_NUMBER ZB_PAGE0_2_4_GHZ_START_LOGICAL_CHANNEL +/** + The last logical channel in channel mask for Page 0 2.4GHz +*/ +#define ZB_PAGE0_2_4_GHZ_MAX_LOGICAL_CHANNEL ZB_MAC_MAX_CHANNEL_NUMBER +/** + Number of the last channel in channel mask for Page 0 2.4GHz +*/ +#define ZB_PAGE0_2_4_GHZ_MAX_CHANNEL_NUMBER ZB_MAC_MAX_CHANNEL_NUMBER +/* (ZB_PAGE0_2_4_GHZ_MAX_LOGICAL_CHANNEL - \ */ +/* ZB_PAGE0_2_4_GHZ_START_LOGICAL_CHANNEL) */ + +/** @cond DOXYGEN_SE_SECTION */ +/** + Maximal number of channels for Page 28 Sub GHz +*/ +#define ZB_PAGE28_SUB_GHZ_MAX_CHANNELS_COUNT (ZB_PAGE28_SUB_GHZ_MAX_CHANNEL_NUMBER - \ + ZB_PAGE28_SUB_GHZ_START_CHANNEL_NUMBER + 1) +/** + Maximal number of channels for Page 29 Sub GHz +*/ +#define ZB_PAGE29_SUB_GHZ_MAX_CHANNELS_COUNT (ZB_PAGE29_SUB_GHZ_MAX_CHANNEL_NUMBER - \ + ZB_PAGE29_SUB_GHZ_START_CHANNEL_NUMBER + 1) +/** + Maximal number of channels for Page 30 Sub GHz +*/ +#define ZB_PAGE30_SUB_GHZ_MAX_CHANNELS_COUNT (ZB_PAGE30_SUB_GHZ_MAX_CHANNEL_NUMBER - \ + ZB_PAGE30_SUB_GHZ_START_CHANNEL_NUMBER + 1) +/** + Maximal number of channels for Page 31 Sub GHz +*/ +#define ZB_PAGE31_SUB_GHZ_MAX_CHANNELS_COUNT (ZB_PAGE31_SUB_GHZ_MAX_CHANNEL_NUMBER - \ + ZB_PAGE31_SUB_GHZ_START_CHANNEL_NUMBER + 1) +/** @endcond */ /* DOXYGEN_SE_SECTION */ +/** + Maximal number of channels for Page 0 2.4GHz +*/ +#define ZB_PAGE0_2_4_GHZ_MAX_CHANNELS_COUNT (ZB_PAGE0_2_4_GHZ_MAX_CHANNEL_NUMBER - \ + ZB_PAGE0_2_4_GHZ_START_CHANNEL_NUMBER + 1) +/** @cond DOXYGEN_SE_SECTION */ +/** + Maximal number of channels for all pages +*/ +#define ZB_ED_SCAN_MAX_CHANNELS_COUNT \ + ((ZB_IO_BUF_SIZE - sizeof(zb_uint8_t)) / sizeof(zb_energy_detect_channel_info_t)) + +#define ZB_CHANNEL_PAGE_MAX_CHANNELS_COUNT ZB_PAGE28_SUB_GHZ_MAX_CHANNELS_COUNT +/** @endcond */ /* DOXYGEN_SE_SECTION */ +/** @} */ /* nwk_common_constants */ + +/** @cond internals_doc */ +/** @addtogroup nwk_pib_cache PIB cache + * @{ + */ + +/** + Data structure used to cache frequently used PIB attributes. + + Useful whe using alien MAC layer without direct access to PIB: blockable "get" + interface to PIB is too complex and slow. + */ +typedef struct zb_nwk_pib_cache_s +{ + zb_uint16_t mac_short_address; /*!< The 16-bit address that the device uses + to communicate in the PAN. */ + zb_uint16_t mac_pan_id; /*!< The 16-bit identifier of the PAN on which + the device is operating. If this value is 0xffff, + the device is not associated. */ + zb_ieee_addr_t mac_extended_address; /*!< The 64-bit (IEEE) address assigned to the device. */ + + zb_uint8_t mac_association_permit; /*!< Indication of whether a coordinator is currently + allowing association. A value of TRUE indicates*/ + zb_uint8_t mac_rx_on_when_idle; /*!< Indication of whether the MAC sublayer is to enable + its receiver during idle periods. */ + zb_uint8_t phy_current_page; /*!< Index of current physical channel page */ + zb_uint8_t phy_current_channel; /*!< Index of current physical channel */ +} zb_nwk_pib_cache_t; + +/** @} */ + + +/** + * @name PIB cache mirror + * \par Here are cache of PIB / NIB mirror of PIB values. + * + * After that values modified in NWK or upper, must sync it with MAC using MLME-SET. + * + * @{ + */ + +/** + Function used to access PIB cache. + @return pointer to PIB cache. + */ +zb_nwk_pib_cache_t *zb_nwk_get_pib_cache(void); +/** + Macro used to access PIB cache. + @return pointer to PIB cache. + */ +#define ZB_PIB_CACHE() zb_nwk_get_pib_cache() + +/** Cached value of device network address */ +#define ZB_PIBCACHE_NETWORK_ADDRESS() ZB_PIB_CACHE()->mac_short_address +/** Cached value of device Pan ID */ +#define ZB_PIBCACHE_PAN_ID() ZB_PIB_CACHE()->mac_pan_id +/** Cached value of device extended address */ +#define ZB_PIBCACHE_EXTENDED_ADDRESS() ZB_PIB_CACHE()->mac_extended_address +/** Cached value of RxOnWhenIdle attribute */ +#define ZB_PIBCACHE_RX_ON_WHEN_IDLE() ZB_PIB_CACHE()->mac_rx_on_when_idle +/** Cached value of AssociationPermit attribute */ +#define ZB_PIBCACHE_ASSOCIATION_PERMIT() ZB_PIB_CACHE()->mac_association_permit +/** Cached value of CurrentChannel attribute */ +#define ZB_PIBCACHE_CURRENT_CHANNEL() ZB_PIB_CACHE()->phy_current_channel +/** Cached value of CurrentPage attribute */ +#define ZB_PIBCACHE_CURRENT_PAGE() ZB_PIB_CACHE()->phy_current_page + + +/** + Arguments of the NLME-PERMIT_JOINING.request routine. +*/ +typedef ZB_PACKED_PRE struct zb_nlme_permit_joining_request_s +{ + zb_uint8_t permit_duration; /**< Time in seconds during which the coordinator + * or router will allow associations */ +} ZB_PACKED_STRUCT +zb_nlme_permit_joining_request_t; + +/** + NLME-PERMIT-JOINING.request primitive + + Allow/disallow network joining + + @param param - buffer containing parameters - @see + zb_nlme_network_formation_request_t + @return RET_OK on success, error code otherwise. + + @snippet doxygen_snippets.dox zb_nlme_permit_joining_request + */ +void zb_nlme_permit_joining_request(zb_uint8_t param); + + +/** @} */ +/** @endcond */ /* internals_doc */ + +/** @addtogroup nwk_panid_conflicts NWK PAN ID conflicts + * @{ + */ + +#define ZB_PAN_ID_CONFLICT_INFO_MAX_PANIDS_COUNT 16 + +/** Structure describing a detected PAN ID conflict */ +typedef ZB_PACKED_PRE struct zb_pan_id_conflict_info_s +{ + zb_uint16_t panid_count; /* cb_param.gnr.in = _pvalue) + +/** Set OUTPUT device callback parameter with specific value. */ +#define ZB_ZCL_DEVICE_CMD_PARAM_OUT_SET(_param, _pvalue) \ + ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->cb_param.gnr.out = _pvalue) + +/** Init all fields of device callback params. */ +#define ZB_ZCL_DEVICE_CMD_PARAM_INIT_WITH(_param, _cb_id, _status, _cmd_info, _in, _out) \ + (ZB_BZERO(ZB_ZCL_DEVICE_CMD_PARAM(_param), sizeof(*ZB_ZCL_DEVICE_CMD_PARAM(_param))), \ + (ZB_ZCL_DEVICE_CMD_PARAM_CB_ID(_param) = _cb_id, \ + (ZB_ZCL_DEVICE_CMD_PARAM_STATUS(_param) = _status, \ + (ZB_ZCL_DEVICE_CMD_PARAM_CMD_INFO(_param) = _cmd_info, \ + (ZB_ZCL_DEVICE_CMD_PARAM_IN_SET(_param, _in), \ + (ZB_ZCL_DEVICE_CMD_PARAM_OUT_SET(_param, _out))))))) +/** @endcond */ /* internals_doc */ + +/** Get INPUT device callback parameter from buffer reference. + * @param _param - Reference to buffer. + * @param _ptype - Target data type. + * @return - Pointer to @e _ptype data. + * @see @ref zb_zcl_device_callback_param_t. + */ +#define ZB_ZCL_DEVICE_CMD_PARAM_IN_GET(_param, _ptype) \ + ((const _ptype *) ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->cb_param.gnr.in)) + +/** Get OUTPUT device callback parameter from buffer reference. + * @param _param - Reference to buffer. + * @param _ptype - Target data type + * @return - Pointer to @e _ptype data. + */ +#define ZB_ZCL_DEVICE_CMD_PARAM_OUT_GET(_param, _ptype) \ + ((_ptype *) ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->cb_param.gnr.out)) + +/** Get access to @ref zb_zcl_parsed_hdr_t data from device callback parameter. + * @param _param - Reference to buffer. + * @return - Pointer to @ref zb_zcl_parsed_hdr_t structure. + */ +#define ZB_ZCL_DEVICE_CMD_PARAM_CMD_INFO(_param) \ + ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->cb_param.gnr.in_cmd_info) + +/** Get access to @ref zb_zcl_device_callback_param_t::device_cb_id of device callback parameters. + * @param _param - Reference to buffer. + */ +#define ZB_ZCL_DEVICE_CMD_PARAM_CB_ID(_param) \ + ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->device_cb_id) + +/** Get access to @ref zb_zcl_device_callback_param_t::status of device callback parameters. + * @param _param - Reference to buffer. + * @return - zb_ret_t value of current status. + */ +#define ZB_ZCL_DEVICE_CMD_PARAM_STATUS(_param) \ + ((ZB_ZCL_DEVICE_CMD_PARAM(_param))->status) + +/** @cond internals_doc */ +/** @brief ZCL default handler. + * + * This function handles ZCL commands which was not processed by application. + * + * @param param - reference to the buffer containing ZCL packet. + * @return @ref ZB_TRUE if packet was processed; @ref ZB_FALSE - otherwise + */ +zb_uint8_t zb_zcl_handle(zb_uint8_t param); +/** + Get ZCL TSN stored in ZCL frame + @param buffer - pointer to a buffer with ZCL frame + @return TSN value +*/ +zb_uint8_t zb_zcl_get_tsn_from_packet(zb_bufid_t buffer); + +#if !(defined ZB_ZCL_DISABLE_REPORTING) + +void zb_zcl_adjust_reporting_timer(zb_uint8_t param); + +void zb_zcl_update_reporting_info(zb_zcl_reporting_info_t *rep_info); + +zb_ret_t zb_zcl_put_default_reporting_info(zb_zcl_reporting_info_t* default_rep_info_ptr); + +void zb_zcl_remove_default_reporting_info(zb_uint16_t cluster_id, zb_uint8_t cluster_role); + +void zb_zcl_mark_report_not_sent(zb_zcl_reporting_info_t *rep_info); + +#endif + +/** + Register device context. + @param _device_ctx - pointer to device context + + Use @ref ZB_AF_REGISTER_DEVICE_CTX. + */ +void zb_zcl_register_device_ctx(zb_af_device_ctx_t *device_ctx); +zb_bool_t zb_zcl_check_cluster_list(void); +/** @endcond */ /* internals_doc */ +/** @} */ /* ZB_ZCL_INITIALIZATION */ + + +#ifdef ZB_BDB_MODE +/*! \addtogroup zboss_bdb_api +@{ + @defgroup zboss_bdb_comm_params BDB commissioning parameters + @defgroup zboss_bdb_comm_start BDB commissioning start & status + @defgroup zboss_bdb_comm_fb BDB Finding and Binding +@} +*/ + +/** + @addtogroup zboss_bdb_comm_params + @{ +*/ + +/** @cond internals_doc */ +/** + @brief BDB error codes + */ +enum zb_bdb_error_codes_e +{ + ZB_BDB_STATUS_SUCCESS = 0, /*!device_short_addr); +@endcode + */ +#define ZB_ZDO_SIGNAL_GET_PARAMS(sg_p, type) ((type *)ZB_SAFE_PTR_CAST((((zb_uint8_t *)sg_p) + sizeof(zb_zdo_app_signal_hdr_t)))) + + +/** + @brief Cuts ZBOSS signal headers while keeping the signal parameter (if it was in the buffer). + + @param buf - pointer to a zb_buf_t structure. The buffer must be the one passed into zboss_signal_handler. + */ +#define ZB_ZDO_SIGNAL_CUT_HEADER(buf) zb_buf_cut_left(buf, sizeof(zb_zdo_app_signal_hdr_t)) + +/** + @brief Leave parameters + + Stack passes this parameter to application when device leave the network. + */ +typedef struct zb_zdo_signal_leave_params_s +{ + zb_nwk_leave_type_t leave_type; /** Leave type. @ref zb_nwk_leave_type_t */ +} zb_zdo_signal_leave_params_t; + +/** + @brief NLME status indication parameters + + Stack passes this parameter to application when NLME status indication is generated. + */ +typedef struct zb_zdo_signal_nlme_status_indication_params_s +{ + zb_nlme_status_indication_t nlme_status; /** NLME status indication payload */ +} zb_zdo_signal_nlme_status_indication_params_t; + +/** + @brief Leave Indication parameters + + Stack passes this parameter to application upon receipt of leave indication + primitive. + */ +typedef struct zb_zdo_signal_leave_indication_params_s +{ + zb_ieee_addr_t device_addr; /*!< Long address of device requested to leave or leaving device*/ + zb_uint8_t rejoin; /*!< 1 if this was leave with rejoin; 0 - otherwise */ +} zb_zdo_signal_leave_indication_params_t; + +/** @cond DOXYGEN_SE_SECTION */ +/** + * @brief Service Discovery Bind signal parameters + * @details Contains info about the device found during Service Discovery. Stack passes this + * parameter to the application with signal @ref ZB_SE_SIGNAL_SERVICE_DISCOVERY_DO_BIND + */ +typedef struct zb_se_signal_service_discovery_bind_params_s +{ + zb_ieee_addr_t device_addr; /**< Long address of the device */ + zb_uint8_t endpoint; /**< Device endpoint */ + zb_uint16_t cluster_id; /**< Discovered cluster */ + zb_uint8_t commodity_type; /**< Commodity type (for multiple commodity networks) */ +} zb_se_signal_service_discovery_bind_params_t; +/** @endcond */ + +/** @cond DOXYGEN_ZGP_SECTION */ +#if defined DOXYGEN && defined ZB_DOCUMENT_ZGP +/** @addtogroup zgp_sink + * @{ + */ +#endif + +#ifdef ZB_ENABLE_ZGP_SINK +/** + @brief ZGP commissioning parameters + + Stack passes this parameter to application to notify about GPD commissioning + result. + */ +typedef struct zb_zgp_signal_commissioning_params_s +{ + zb_zgpd_id_t zgpd_id; /*!< Pointer to GPD ID */ + zb_zgp_comm_status_t result; /*!< commissining result, see @ref zb_zgp_comm_status_t */ +} zb_zgp_signal_commissioning_params_t; +#endif /* ZB_ENABLE_ZGP_SINK */ +/** @} */ +/** @endcond */ +/** + @brief Association parameters + + Stack passes this parameter to application when some device associates to that. + */ +typedef struct zb_nwk_signal_device_associated_params_s +{ + zb_ieee_addr_t device_addr; /*!< address of associated device */ +} zb_nwk_signal_device_associated_params_t; + +/** + *@brief Association parameters + * + * Stack passes this parameter to application when some device joins/rejoins to + * network. + */ +typedef struct zb_zdo_signal_device_annce_params_s +{ + zb_uint16_t device_short_addr; /*!< address of device that recently joined to network */ + zb_ieee_addr_t ieee_addr; + zb_uint8_t capability; +} zb_zdo_signal_device_annce_params_t; + +/** @cond touchlink */ + +typedef struct zb_bdb_signal_touchlink_nwk_started_params_s +{ + zb_ieee_addr_t device_ieee_addr; /*!< address of device that started the network */ + zb_uint8_t endpoint; + zb_uint16_t profile_id; +} zb_bdb_signal_touchlink_nwk_started_params_t; + +typedef struct zb_bdb_signal_touchlink_nwk_joined_router_s +{ + zb_ieee_addr_t device_ieee_addr; /*!< address of device that started the network */ + zb_uint8_t endpoint; + zb_uint16_t profile_id; +} zb_bdb_signal_touchlink_nwk_joined_router_t; + +/** @endcond */ /* touchlink */ + +/** + @brief Sleep signal parameters. + + Stack passes this parameter to application when device ready to sleep. + */ +typedef struct zb_zdo_signal_can_sleep_params_s +{ + zb_uint32_t sleep_tmo; /*!< sleep duration in milliseconds */ +} zb_zdo_signal_can_sleep_params_t; + +/** + @brief Macsplit device boot parameters. + + Macsplit passes this parameter to application when device is booted. + */ +typedef struct zb_zdo_signal_macsplit_dev_boot_params_s +{ + zb_uint32_t dev_version; /*!< macsplit device version */ +#ifdef USE_HW_LONG_ADDR + zb_ieee_addr_t extended_address; /*!< The 64-bit (IEEE) address assigned to the device. */ +#endif +} zb_zdo_signal_macsplit_dev_boot_params_t; + +/** + * @brief Status codes for F&B Initiator Finished signal + */ +typedef enum zb_zdo_fb_initiator_finished_status_e +{ + ZB_ZDO_FB_INITIATOR_STATUS_SUCCESS = 0, /*!< F&B with a Target on the Initiator side is success + * completed */ + + ZB_ZDO_FB_INITIATOR_STATUS_CANCEL, /*!< F&B on the Initiator side is canceled */ + + ZB_ZDO_FB_INITIATOR_STATUS_ALARM, /*!< F&B on the Initiator side is finished by timeout */ + + ZB_ZDO_FB_INITIATOR_STATUS_ERROR, /*!< F&B on the Initiator side is failure finished */ +} zb_zdo_fb_initiator_finished_status_t; + +/** + * @brief F&B Initiator Finished signal parameters + */ +typedef struct zb_zdo_signal_fb_initiator_finished_params_s +{ + /*!< Status of the F&B procedure on the Initiator side */ + zb_zdo_fb_initiator_finished_status_t status; +} zb_zdo_signal_fb_initiator_finished_params_t; + +/** + * @brief Device Updated signal parameters + */ +typedef struct zb_zdo_signal_device_update_params_s +{ + /*!< Long Address of the updated device */ + zb_ieee_addr_t long_addr; + + /*!< Short Address of the updated device */ + zb_uint16_t short_addr; + + /*!< Indicates the updated status of the device + * + * 0x00 = Standard device secured rejoin + * 0x01 = Standard device unsecured join + * 0x02 = Device left + * 0x03 = Standard device trust center rejoin + * 0x04 – 0x07 = Reserved + * + * see r21 spec, 4.4.3.2 APSME-UPDATE-DEVICE.indication, + * Table 4.15 APSME-UPDATE-DEVICE.indication Parameters + */ + zb_uint8_t status; +} zb_zdo_signal_device_update_params_t; + +/** + * @brief Authorization types for + * @ref ZB_ZDO_SIGNAL_DEVICE_AUTHORIZED + */ +/* TODO: add other types if need (SE CBKE, r23 DLK) */ +typedef enum zb_zdo_authorization_type_e +{ + ZB_ZDO_AUTHORIZATION_TYPE_LEGACY, /*!< Authorization type for legacy devices ( < r21) */ + + ZB_ZDO_AUTHORIZATION_TYPE_R21_TCLK, /*!< Authorization type for r21 device through TCLK */ +} +zb_zdo_authorization_type_t; + +/** + * @brief Authorization statuses for + * ZB_ZDO_AUTHORIZATION_TYPE_LEGACY value + * of @ref zb_zdo_authorization_type_t type + */ +typedef enum zb_zdo_legacy_device_authorization_status_e +{ + ZB_ZDO_LEGACY_DEVICE_AUTHORIZATION_SUCCESS, /*!< Authorization success */ + + ZB_ZDO_LEGACY_DEVICE_AUTHORIZATION_FAILED, /*!< Authorization failed */ +} +zb_zdo_legacy_device_authorization_status_t; + +/** + * @brief Authorization statuses for + * ZB_ZDO_AUTHORIZATION_TYPE_R21_TCLK value + * of @ref zb_zdo_authorization_type_t type + */ +typedef enum zb_zdo_tclk_authorization_status_e +{ + ZB_ZDO_TCLK_AUTHORIZATION_SUCCESS, /*!< Authorization success */ + + ZB_ZDO_TCLK_AUTHORIZATION_TIMEOUT, /*!< Authorization timeout */ + + ZB_ZDO_TCLK_AUTHORIZATION_FAILED, /*!< Authorization failed */ +} +zb_zdo_tclk_authorization_status_t; + +/** + * @brief Device Authorized signal parameters + */ +typedef struct zb_zdo_signal_device_authorized_params_s +{ + /*!< Long Address of the updated device */ + zb_ieee_addr_t long_addr; + + /*!< Short Address of the updated device */ + zb_uint16_t short_addr; + + /*!< Type of the authorization procedure, + * @ref zb_zdo_authorization_type_t + */ + zb_uint8_t authorization_type; + + /*!< Status of the authorization procedure + * (depends on @ref zb_zdo_authorization_type_t) + */ + zb_uint8_t authorization_status; +} zb_zdo_signal_device_authorized_params_t; + +/** Application signal header */ +typedef struct zb_zdo_app_signal_hdr_s +{ + /* 32 bit to have data section aligned well */ + zb_uint32_t sig_type; /** Application signal type, @ref zb_zdo_app_signal_type_t */ +} zb_zdo_app_signal_hdr_t; +/* Legacy API: zb_zdo_app_signal_hdr_t == zb_zdo_app_event_t */ +typedef zb_zdo_app_signal_hdr_t zb_zdo_app_event_t; + +/** @} */ /* comm_signals*/ +/*! \addtogroup zdo_base */ +/*! @{ */ + +#define ZB_ZDO_INVALID_TSN 0xFF + +typedef ZB_PACKED_PRE struct zb_zdo_callback_info_s +{ + zb_uint8_t tsn; + zb_uint8_t status; +} ZB_PACKED_STRUCT zb_zdo_callback_info_t; + +typedef ZB_PACKED_PRE struct zb_zdo_default_resp_s +{ + zb_uint8_t tsn; + zb_uint8_t status; +} ZB_PACKED_STRUCT zb_zdo_default_resp_t; + +/** @} */ +/*! \addtogroup zb_comm_signals */ +/*! @{ */ + +/** + @brief Unpack application signal buffer in zboss_signal_handler() + + @param param - parameter of zboss_signal_handler() + @param sg_p - pointer to the extended signal info, if application wants it. Can be NULL. + + @return Application signal + */ + +zb_zdo_app_signal_type_t zb_get_app_signal(zb_uint8_t param, zb_zdo_app_signal_hdr_t **sg_p); +/** @cond internals_doc */ +/* Legacy API: zb_get_app_event(param, sg_p) == zb_get_app_signal(param, sg_p) */ +#define zb_get_app_event(param, sg_p) zb_get_app_signal(param, sg_p) +/** @endcond */ /* internals_doc */ + +/** + @brief Get status from the application signal + @param param - buffer reference + @return status zb_ret_t + */ +#define ZB_GET_APP_SIGNAL_STATUS(param) zb_buf_get_status(param) + +/** @} */ +/*! \addtogroup zdo_base */ +/*! @{ */ + + +/** + @brief Obtains last known LQI and RSSI values from device with specified short address + + @param short_address - address of device + @param lqi [in] - pointer to @ref zb_uint8_t variable to store lqi value + @param rssi [in] - pointer to @ref zb_uint8_t variable to store rssi value + +@b Example: +@code + zb_uint8_t lqi, rssi; + + zb_zdo_get_diag_data(0x0000, &lqi, &rssi); +@endcode + */ +void zb_zdo_get_diag_data(zb_uint16_t short_address, zb_uint8_t *lqi, zb_int8_t *rssi); + +/*! @} */ + + +/*! \addtogroup zdo_addr */ +/*! @{ */ + + + +#define ZB_ZDO_SINGLE_DEVICE_RESP 0 /*!< Request Type parameter value of @ref zb_zdo_nwk_addr_req_t and @ref zb_zdo_ieee_addr_req_t for receiving a Single device response used in the following commands accordingly: + * - @ref zb_zdo_nwk_addr_req + * - @ref zb_zdo_ieee_addr_req + * @see spec 2.4.3.1, 2.4.4.1 + */ +#define ZB_ZDO_EXTENDED_DEVICE_RESP 1 /*!< Request Type parameter value of @ref zb_zdo_nwk_addr_req_t and @ref zb_zdo_ieee_addr_req_t for receiving an Extended device response used in the following commands accordingly: + * - @ref zb_zdo_nwk_addr_req + * - @ref zb_zdo_ieee_addr_req_t + * @see spec 2.4.3.1, 2.4.4.1 + */ + +/** @brief NWK_addr_req command primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_nwk_addr_req_s +{ + zb_ieee_addr_t ieee_addr; /*!< IEEE address to be matched by the + Remote Device */ + zb_uint8_t request_type; /*!< Request type for this command: + 0x00 Single device response + 0x01 Extended response */ + zb_uint8_t start_index; /*!< If the Request type for this command is + Extended response, the StartIndex + provides the starting index for the + requested elements of the associated + devices list */ +} ZB_PACKED_STRUCT zb_zdo_nwk_addr_req_t; + +/** @brief Parameters for nwk_addr_req command */ +typedef struct zb_zdo_nwk_addr_req_param_s +{ + zb_uint16_t dst_addr; /*!< Destinitions address */ + zb_ieee_addr_t ieee_addr; /*!< IEEE address to be matched by the + Remote Device */ + zb_uint8_t request_type; /*!< Request type for this command: + 0x00 Single device response + 0x01 Extended response */ + zb_uint8_t start_index; /*!< If the Request type for this command is + Extended response, the StartIndex + provides the starting index for the + requested elements of the associated + devices list */ +} +zb_zdo_nwk_addr_req_param_t; + +/** @brief NWK_addr_req response frame. */ +typedef ZB_PACKED_PRE struct zb_zdo_nwk_addr_resp_head_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the NWK_addr_req command. */ + zb_ieee_addr_t ieee_addr; /*!< 64-bit address for the Remote Device. */ + zb_uint16_t nwk_addr; /*!< 16-bit address for the Remote Device. */ +} +ZB_PACKED_STRUCT +zb_zdo_nwk_addr_resp_head_t; + +/** @brief NWK_addr_req response frame tail */ +typedef ZB_PACKED_PRE struct zb_zdo_nwk_addr_resp_ext_s +{ + zb_uint8_t num_assoc_dev; /*!< Count of the ED List. */ +} +ZB_PACKED_STRUCT +zb_zdo_nwk_addr_resp_ext_t; + +/** @brief NWK_addr_req response frame tail */ +typedef ZB_PACKED_PRE struct zb_zdo_nwk_addr_resp_ext2_s +{ + zb_uint8_t start_index; /*!< Starting index to begin reporting for the ED List.*/ +} +ZB_PACKED_STRUCT +zb_zdo_nwk_addr_resp_ext2_t; + +/** @brief Sends NWK_addr_req primitive. + + @param param - index of buffer with primitive parameters - \ref zb_zdo_nwk_addr_req_param_s + @param cb - user's function to call when got response from the + remote. \ref zb_zdo_nwk_addr_resp_head_s passed to cb as parameter. + @return - ZDP transaction sequence number or 0xFF if operation cannot be + performed now (nor enough memory, resources, etc.) + +@b Example: +@code +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_uint8_t tsn; + zb_zdo_nwk_addr_req_param_t *req_param = ZB_BUF_GET_PARAM(buf, zb_zdo_nwk_addr_req_param_t); + + req_param->dst_addr = 0; + zb_address_ieee_by_ref(req_param->ieee_addr, short_addr); + req_param->request_type = ZB_ZDO_SINGLE_DEVICE_RESP; + req_param->start_index = 0; + tsn = zb_zdo_nwk_addr_req(param, zb_get_peer_short_addr_cb); + + if (tsn == ZB_ZDO_INVALID_TSN) + { + TRACE_MSG(TRACE_ZDO2, "request failed", (FMT__0)); + } +} + +void zb_get_peer_short_addr_cb(zb_uint8_t param) +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_zdo_nwk_addr_resp_head_t *resp; + zb_ieee_addr_t ieee_addr; + zb_uint16_t nwk_addr; + zb_address_ieee_ref_t addr_ref; + + TRACE_MSG(TRACE_ZDO2, "zb_get_peer_short_addr_cb param %hd", (FMT__H, param)); + + resp = (zb_zdo_nwk_addr_resp_head_t*)zb_buf_begin(buf); + TRACE_MSG(TRACE_ZDO2, "resp status %hd, nwk addr %d", (FMT__H_D, resp->status, resp->nwk_addr)); + ZB_DUMP_IEEE_ADDR(resp->ieee_addr); + + // additionally check tsn if needed + //if (resp->tsn == my_saved_tsn) + + if (resp->status == ZB_ZDP_STATUS_SUCCESS) + { + ZB_LETOH64(ieee_addr, resp->ieee_addr); + ZB_LETOH16(&nwk_addr, &resp->nwk_addr); + zb_address_update(ieee_addr, nwk_addr, ZB_TRUE, &addr_ref); + } + zb_free_buf(buf); +} +@endcode + +See tp_zdo_bv-31 sample +*/ +zb_uint8_t zb_zdo_nwk_addr_req(zb_uint8_t param, zb_callback_t cb); + +/** @cond internals_doc */ +/** + @brief Broadcast NWK_addr_req primitive. + Used internally in stack. + + @param param - index of buffer with primitive parameters - \ref zb_zdo_nwk_addr_req_param_s + @param ieee_addr - IEEE address to be matched by the Remote Device +*/ +zb_uint8_t zb_zdo_initiate_nwk_addr_req(zb_uint8_t param, zb_ieee_addr_t ieee_addr); +/* Used internally in stack. */ +void zb_zdo_initiate_nwk_addr_req_2param(zb_uint8_t param, zb_uint16_t user_param); +void zb_zdo_initiate_node_desc_req_2param(zb_uint8_t param, zb_uint16_t user_param); +void zb_zdo_initiate_node_desc_req_direct(zb_uint16_t addr, zb_callback_t user_cb); +/** @endcond */ /* internals_doc */ + +/** @brief Parameters of IEEE_addr_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_ieee_addr_req_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ + zb_uint8_t request_type; /*!< Request type for this command: + 0x00 Single device response + 0x01 Extended response */ + zb_uint8_t start_index; /*!< If the Request type for this command is + Extended response, the StartIndex + provides the starting index for the + requested elements of the associated + devices list */ +} ZB_PACKED_STRUCT zb_zdo_ieee_addr_req_t; + +/** @brief Parameters for ieee_addr_req command */ +typedef struct zb_zdo_ieee_addr_req_param_s +{ + zb_uint16_t dst_addr; /*!< Destinitions address */ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ + zb_uint8_t request_type; /*!< Request type for this command: + 0x00 Single device response + 0x01 Extended response */ + zb_uint8_t start_index; /*!< If the Request type for this command is + Extended response, the StartIndex + provides the starting index for the + requested elements of the associated + devices list */ +} +zb_zdo_ieee_addr_req_param_t; + +/** brief ZDO IEEE address response frame */ +typedef ZB_PACKED_PRE struct zb_zdo_ieee_addr_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the NWK_addr_req command. */ + zb_ieee_addr_t ieee_addr_remote_dev; /*!< 64-bit address for the Remote Device. */ + zb_uint16_t nwk_addr_remote_dev; /*!< 16-bit address for the Remote Device. */ +} +ZB_PACKED_STRUCT +zb_zdo_ieee_addr_resp_t; + +/** @brief ZDO IEEE address response frame tail */ +typedef ZB_PACKED_PRE struct zb_zdo_ieee_addr_resp_ext_s +{ + zb_uint8_t num_assoc_dev; /*!< Count of the ED List. */ +} +ZB_PACKED_STRUCT +zb_zdo_ieee_addr_resp_ext_t; + +/** @brief ZDO IEEE address response frame tail */ +typedef ZB_PACKED_PRE struct zb_zdo_ieee_addr_resp_ext2_s +{ + zb_uint8_t start_index; /*!< Starting index to begin reporting for the ED List.*/ +} +ZB_PACKED_STRUCT +zb_zdo_ieee_addr_resp_ext2_t; + +/** @brief IEEE_addr_req primitive. + * + * @param param - index of buffer with primitive parameters \ref zb_zdo_ieee_addr_req_s. + * Parameters must be put into the buffer as data (allocated). + * @param cb - user's function to call when got response from the remote. + * @return - ZDP transaction sequence number or 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @code + * { + * zb_zdo_ieee_addr_req_param_t *req = NULL; + * zb_uint8_t tsn; + * + * req = ZB_BUF_GET_PARAM(buf, zb_zdo_ieee_addr_req_param_t); + * + * req->nwk_addr = ind->src_addr; + * req->dst_addr = req->nwk_addr; + * req->request_type = ZB_ZDO_SINGLE_DEV_RESPONSE; + * req->start_index = 0; + * tsn = zb_zdo_ieee_addr_req(ZB_REF_FROM_BUF(buf), ieee_addr_callback); + * + * if (tsn == ZB_ZDO_INVALID_TSN) + * { + * TRACE_MSG(TRACE_ZDO2, "request failed", (FMT__0)); + * } + * } + * + * void ieee_addr_callback(zb_uint8_t param) + * { + * zb_bufid_t buf = ZB_BUF_FROM_REF(param); + * zb_zdo_nwk_addr_resp_head_t *resp; + * zb_ieee_addr_t ieee_addr; + * zb_uint16_t nwk_addr; + * zb_address_ieee_ref_t addr_ref; + * + * TRACE_MSG(TRACE_ZDO2, "zb_get_peer_short_addr_cb param %hd", (FMT__H, param)); + * + * resp = (zb_zdo_nwk_addr_resp_head_t*)zb_buf_begin(buf); + * TRACE_MSG( + * TRACE_ZDO2, "resp status %hd, nwk addr %d", (FMT__H_D, resp->status, resp->nwk_addr)); + * ZB_DUMP_IEEE_ADDR(resp->ieee_addr); + * if (resp->status == ZB_ZDP_STATUS_SUCCESS) + * { + * ZB_LETOH64(ieee_addr, resp->ieee_addr); + * ZB_LETOH16(&nwk_addr, &resp->nwk_addr); + * zb_address_update(ieee_addr, nwk_addr, ZB_TRUE, &addr_ref); + * } + zb_free_buf(buf); + * } + * + * @endcode + * + * See tp_zdo_bv-31 sample + */ +zb_uint8_t zb_zdo_ieee_addr_req(zb_uint8_t param, zb_callback_t cb); + +/** @cond internals_doc */ +/* Used internally in stack. */ +zb_uint8_t zb_zdo_initiate_ieee_addr_req(zb_uint8_t param, zb_uint16_t nwk_addr); +/** @endcond */ /* internals_doc */ + +/** @} */ + +/** + @addtogroup zdo_disc + @{ +*/ + +/** @brief Parameters of Node_desc_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_node_desc_req_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ +} ZB_PACKED_STRUCT zb_zdo_node_desc_req_t; + + +/** @brief Header of Node_desc_resp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_desc_resp_hdr_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Desc_req command. @ref zb_zdp_status_t */ + zb_uint16_t nwk_addr; /*!< NWK address for the request */ +} ZB_PACKED_STRUCT +zb_zdo_desc_resp_hdr_t; + +/** @brief Parameters of Node_desc_resp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_node_desc_resp_s +{ + zb_zdo_desc_resp_hdr_t hdr; /*!< header for response */ + zb_af_node_desc_t node_desc; /*!< Node Descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_node_desc_resp_t; + +/** @brief Header of simple_desc_resp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_simple_desc_resp_hdr_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Desc_req command. @ref zb_zdp_status_t */ + zb_uint16_t nwk_addr; /*!< NWK address for the request */ + zb_uint8_t length; /*!< Length of the simple descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_simple_desc_resp_hdr_t; + +#ifdef ZB_FIXED_OPTIONAL_DESC_RESPONSES +typedef zb_zdo_simple_desc_resp_hdr_t zb_zdo_complex_desc_resp_hdr_t; +typedef zb_zdo_simple_desc_resp_hdr_t zb_zdo_user_desc_resp_hdr_t; +typedef zb_zdo_desc_resp_hdr_t zb_zdo_user_desc_conf_hdr_t; +#endif + +/** @brief Parameters of simple_desc_resp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_simple_desc_resp_s +{ + zb_zdo_simple_desc_resp_hdr_t hdr; /*!< header for response */ + zb_af_simple_desc_1_1_t simple_desc; /*!< Simple Descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_simple_desc_resp_t; + + +typedef ZB_PACKED_PRE struct zb_zdo_child_info_s +{ + zb_ieee_addr_t ext_addr; /*!< 64-bit IEEE address that is + * unique to every device.*/ +}ZB_PACKED_STRUCT +zb_zdo_child_info_t; + +/** @brief Jitter used for sending Parent Annce */ +#define ZB_PARENT_ANNCE_JITTER() (ZB_APS_PARENT_ANNOUNCE_BASE_TIMER + ZB_RANDOM_JTR(ZB_APS_PARENT_ANNOUNCE_JITTER_MAX)) + + +/** @brief Header of parent_annce primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_parent_annce_s +{ + zb_uint8_t tsn; /*!< ZDO sequence number */ + zb_uint8_t num_of_children; /*!< Length of the simple descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_parent_annce_t; + + +/** @brief Header of parent_annce_rsp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_parent_annce_rsp_hdr_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Desc_req command. @ref zb_zdp_status_t */ + zb_uint8_t num_of_children; /*!< Length of the simple descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_parent_annce_rsp_hdr_t; + +/** @brief Parameters of parent_annce_rsp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_parent_annce_rsp_s +{ + zb_zdo_parent_annce_rsp_hdr_t hdr; /*!< header for response */ +} ZB_PACKED_STRUCT +zb_zdo_parent_annce_rsp_t; + +/** @brief Parameters of Power_desc_resp primitive. */ +typedef ZB_PACKED_PRE struct zb_zdo_power_desc_resp_s +{ + zb_zdo_desc_resp_hdr_t hdr; /*!< header for response */ + zb_af_node_power_desc_t power_desc; /*!< Power Descriptor */ +} ZB_PACKED_STRUCT +zb_zdo_power_desc_resp_t; + +/** @brief Node_desc_req primitive. + * + * @param param - index of buffer with primitive parameters \ref zb_zdo_node_desc_req_s. + * Parameters must be put into buffer as data (allocated). + * @param cb - user's function to call when got response from the remote. + * @return - ZDP transaction sequence number or 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @snippet onoff_server/on_off_switch_zed.c send_node_desc_req + * @snippet onoff_server/on_off_switch_zed.c node_req_cb + * + * See application/onoff_server sample + */ +zb_uint8_t zb_zdo_node_desc_req(zb_uint8_t param, zb_callback_t cb); + + +/** @brief Parameters of Power_desc_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_power_desc_req_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ +} ZB_PACKED_STRUCT zb_zdo_power_desc_req_t; + +/** @brief Power_desc_req primitive. + * + * @param param - index of buffer with primitive parameters \ref zb_zdo_power_desc_req_s. + * Parameters must be put into buffer as data (allocated). + * @param cb - user's function to call when got response from the remote. + * @return - ZDP transaction sequence number or 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @snippet onoff_server/on_off_switch_zed.c send_power_desc_req + * @snippet onoff_server/on_off_switch_zed.c power_desc_cb + * + * See application/onoff_server sample + */ +zb_uint8_t zb_zdo_power_desc_req(zb_uint8_t param, zb_callback_t cb); + + + +/** @brief Parameters of Simple_desc_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_simple_desc_req_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ + zb_uint8_t endpoint; /*!< The endpoint on the destination */ +} ZB_PACKED_STRUCT zb_zdo_simple_desc_req_t; + +/** @brief Simple_desc_req primitive. + * + * @param param - index of buffer with primitive parameters \ref zb_zdo_simple_desc_req_s. + * @param cb - user's function to call when got response from the remote. + * @return - ZDP transaction sequence number or 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @snippet onoff_server/on_off_switch_zed.c send_simple_desc_req + * @snippet onoff_server/on_off_switch_zed.c simple_desc_cb + * + * See application/onoff_server sample + */ +zb_uint8_t zb_zdo_simple_desc_req(zb_uint8_t param, zb_callback_t cb); + + +/** @brief Parameters of Active_desc_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_active_ep_req_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ +} ZB_PACKED_STRUCT zb_zdo_active_ep_req_t; + + +/** @brief Active EP response */ +typedef ZB_PACKED_PRE struct zb_zdo_ep_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Active_EP_req command. */ + zb_uint16_t nwk_addr; /*!< NWK address for the request. */ + zb_uint8_t ep_count; /*!< The count of active endpoints on the Remote Device. */ +} +ZB_PACKED_STRUCT +zb_zdo_ep_resp_t; + +/** + * @brief Active_desc_req primitive. + * + * @param param - index of buffer with primitive parameters \ref zb_zdo_active_ep_req_s. Parameters must be + * put into buffer as data (allocated). + * @param cb - user's function to call when got response from the remote. + * @return - ZDP transaction sequence number or 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @snippet onoff_server/on_off_switch_zed.c send_active_ep_req + * @snippet onoff_server/on_off_switch_zed.c active_ep_cb + * + * See application/onoff_server sample + */ +zb_uint8_t zb_zdo_active_ep_req(zb_uint8_t param, zb_callback_t cb); + +/** @brief Parameters of match_desc_req primitive. + + To be put into buffer as data (means - after space alloc). + */ +typedef ZB_PACKED_PRE struct zb_zdo_match_desc_param_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ + zb_uint16_t addr_of_interest; /*!< NWK address of interest */ + + zb_uint16_t profile_id; /*!< Profile ID to be matched at the + destination. */ + zb_uint8_t num_in_clusters; /*!< The number of Input Clusters + provided for matching within the + InClusterList. */ + zb_uint8_t num_out_clusters; /*!< The number of Output Clusters + provided for matching within + OutClusterList. */ + zb_uint16_t cluster_list[1]; /*!< Variable size: [num_in_clusters] + [num_out_clusters] + List of Input ClusterIDs to be used + for matching; the InClusterList is + the desired list to be matched by + the Remote Device (the elements + of the InClusterList are the + supported output clusters of the + Local Device). + List of Output ClusterIDs to be + used for matching; the + OutClusterList is the desired list to + be matched by the Remote Device + (the elements of the + OutClusterList are the supported + input clusters of the Local + Device). */ +} +ZB_PACKED_STRUCT +zb_zdo_match_desc_param_t; + +/** @brief Match_desc_req head */ +typedef ZB_PACKED_PRE struct zb_zdo_match_desc_req_head_s +{ + zb_uint16_t nwk_addr; /*!< NWK address that is used for IEEE + address mapping. */ + zb_uint16_t profile_id; /*!< Profile ID to be matched at the + destination. */ + zb_uint8_t num_in_clusters; /*!< The number of Input Clusters + provided for matching within the + InClusterList. */ +} +ZB_PACKED_STRUCT +zb_zdo_match_desc_req_head_t; + +/** @brief Match_desc_req tail */ +typedef ZB_PACKED_PRE struct zb_zdo_match_desc_req_tail_s +{ + zb_uint8_t num_out_clusters; /*!< The number of Output Clusters + provided for matching within + OutClusterList. */ +} +ZB_PACKED_STRUCT +zb_zdo_match_desc_req_tail_t; + +/** @brief Match_Desc_rsp response structure + * @see ZB spec, subclause 2.4.4.1.7 + */ +typedef ZB_PACKED_PRE struct zb_zdo_match_desc_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Match_Desc_req command.*/ + zb_uint16_t nwk_addr; /*!< NWK address for the request. */ + zb_uint8_t match_len; /*!< The count of endpoints on the Remote Device that match the + request criteria.*/ +} +ZB_PACKED_STRUCT +zb_zdo_match_desc_resp_t; + + +/** @brief Match_desc_req primitive. + + @param param - index of buffer with primitive parameters \ref zb_zdo_match_desc_param_s. + @param cb - user's function to call when got response from the remote. If command is \n + broadcast, then user's function will be called as many times as number of \n + responses received plus one more time with status \ref ZB_ZDP_STATUS_TIMEOUT + to indicate that no more responses will be received. + @return - ZDP transaction sequence number or 0xFF if operation cannot be + performed now (nor enough memory, resources, etc.) + + @b Example: + @snippet light_sample/light_control/light_control.c zdo_match_desc_req + + See light_sample +*/ +zb_uint8_t zb_zdo_match_desc_req(zb_uint8_t param, zb_callback_t cb); + + +#ifndef ZB_LITE_NO_ZDO_SYSTEM_SERVER_DISCOVERY +/** @brief Request parameters for System_Server_Discovery_req. + * @see ZB spec, subclause 2.4.3.1.13. + */ +typedef ZB_PACKED_PRE struct zb_zdo_system_server_discovery_req_s +{ + zb_uint16_t server_mask; /*!< Server mask for device discovery */ +} +ZB_PACKED_STRUCT +zb_zdo_system_server_discovery_req_t; + +/** @brief Parameters for System_Server_Discovery_req call. + * @see ZB spec, subclause 2.4.3.1.13. + */ +typedef zb_zdo_system_server_discovery_req_t zb_zdo_system_server_discovery_param_t; + + +/** @brief Response parameters for System_Server_Discovery_rsp. + * @see ZB spec, subclause 2.4.4.1.10. + */ +typedef ZB_PACKED_PRE struct zb_zdo_system_server_discovery_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< Status of the operation */ + zb_uint16_t server_mask; /*!< Mask of the supported features */ +} +ZB_PACKED_STRUCT +zb_zdo_system_server_discovery_resp_t; + + +/** + * @brief Performs System_Server_Discovery_req + * @param param - index of buffer with request parameters + * @ref zb_zdo_system_server_discovery_param_t + * @param cb - user's function to call when got response from the remote. \ref + * zb_zdo_system_server_discovery_resp_s + * + * @return ZDP transaction sequence number + * @return 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * @b Example: + * @snippet onoff_server/on_off_switch_zed.c system_server_discovery_req + * @snippet onoff_server/on_off_switch_zed.c system_server_discovery_cb + * + * See application/onoff_server sample + */ +zb_uint8_t zb_zdo_system_server_discovery_req(zb_uint8_t param, zb_callback_t cb); +#endif /*ZB_LITE_NO_ZDO_SYSTEM_SERVER_DISCOVERY */ + +/*! @} */ + +/*! \addtogroup zdo_mgmt */ +/*! @{ */ + + +/** @brief Header of parameters for Mgmt_NWK_Update_req */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_update_req_hdr_s +{ + zb_uint32_t scan_channels; /*!< Channels bitmask */ + zb_uint8_t scan_duration; /*!< A value used to calculate the + * length of time to spend scanning + * each channel. */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_nwk_update_req_hdr_t; + +/** @brief Parameters for Mgmt_NWK_Update_req */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_update_req_s +{ + zb_zdo_mgmt_nwk_update_req_hdr_t hdr; /*!< Request header */ + zb_uint8_t scan_count; /*!< This field represents the number + * of energy scans to be conducted and reported */ + zb_uint8_t update_id; /*!< This value is set by the Network + * Channel Manager prior to sending + * the message. This field shall only + * be present of the ScanDuration is 0xfe or 0xff */ + zb_uint16_t manager_addr; /*!< This field shall be present only + * if the ScanDuration is set to 0xff, + * and, where present, indicates the + * NWK address for the device with the + * Network Manager bit set in its Node Descriptor. */ + zb_uint16_t dst_addr; /*!< Destination address */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_nwk_update_req_t; + +#ifdef ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED + +/** @brief Parameters for Mgmt_NWK_Update_req internal call*/ +typedef struct zb_zdo_mgmt_nwk_enhanced_update_req_param_s +{ + zb_channel_list_t channel_list; /*!< ZBOSS internal channel list */ + zb_uint8_t scan_duration; /*!< A value used to calculate the + * length of time to spend scanning + * each channel. */ + zb_uint8_t scan_count; /*!< This field represents the number + * of energy scans to be conducted and reported */ + zb_uint8_t update_id; /*!< This value is set by the Network + * Channel Manager prior to sending + * the message. This field shall only + * be present of the ScanDuration is 0xfe or 0xff */ + zb_uint16_t manager_addr; /*!< This field shall be present only + * if the ScanDuration is set to 0xff, + * and, where present, indicates the + * NWK address for the device with the + * Network Manager bit set in its Node Descriptor. */ + zb_uint16_t dst_addr; /*!< Destination address */ +} zb_zdo_mgmt_nwk_enhanced_update_req_param_t; + +/** @brief Header of parameters for Mgmt_NWK_Update_req */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_enhanced_update_req_hdr_s +{ + zb_uint8_t channel_page_count; /* The number of Channel Page Structures + * contained within the Channel List Structure */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_nwk_enhanced_update_req_hdr_t; + +#endif /* ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED */ + +/** @brief Header parameters for mgmt_nwk_update_notify */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_update_notify_hdr_s +{ + zb_uint8_t tsn; /*!< tsn value */ + zb_uint8_t status; /*!< The status of the Mgmt_NWK_Update_notify command. */ + zb_uint32_t scanned_channels; /*!< List of channels scanned by the request */ + zb_uint16_t total_transmissions; /*!< Count of the total transmissions reported by the device */ + zb_uint16_t transmission_failures; /*!< Sum of the total transmission failures reported by the + device */ + zb_uint8_t scanned_channels_list_count; /*!< The list shall contain the number of records + * contained in the EnergyValues parameter. */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_nwk_update_notify_hdr_t; + +/** @brief Parameters for mgmt_nwk_update_notify */ +typedef struct zb_zdo_mgmt_nwk_update_notify_param_s +{ + zb_zdo_mgmt_nwk_update_notify_hdr_t hdr; /*!< Fixed parameters set */ + zb_uint8_t energy_values[ZB_MAC_SUPPORTED_CHANNELS]; /*!< ed scan values */ + zb_uint16_t dst_addr; /*!< destination address */ + zb_uint8_t enhanced; /*!< If set to one, send Enhanced notify command */ +} +zb_zdo_mgmt_nwk_update_notify_param_t; + +#ifdef ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED + +typedef zb_zdo_mgmt_nwk_update_notify_param_t zb_zdo_mgmt_nwk_enhanced_update_notify_param_t; + +#endif /* ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED */ + +/** @brief Performs Mgmt_NWK_Update_req request + + @param param - index of buffer with call parameters. Parameters mut be + put into buffer as parameters. \ref zb_zdo_mgmt_nwk_update_req_s + @param cb - user's function to call when got response from the remote. + \ref zb_zdo_mgmt_nwk_update_notify_hdr_s + @return - ZDP transaction sequence number or 0xFF if operation cannot be + performed now (nor enough memory, resources, etc.) + + @b Example: +@code +{ + zb_uint8_t tsn; + zb_zdo_mgmt_nwk_update_req_t *req; + + req = ZB_BUF_GET_PARAM(buf, zb_zdo_mgmt_nwk_update_req_t); + + req->hdr.scan_channels = ZB_MAC_ALL_CHANNELS_MASK; + req->hdr.scan_duration = TEST_SCAN_DURATION; + req->scan_count = TEST_SCAN_COUNT; + req->update_id = ZB_NIB_UPDATE_ID(); + + req->dst_addr = 0; + + tsn = zb_zdo_mgmt_nwk_update_req(param, mgmt_nwk_update_ok_cb); +} + + +void mgmt_nwk_update_ok_cb(zb_uint8_t param) +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_uint8_t *zdp_cmd = zb_buf_begin(buf); + zb_zdo_mgmt_nwk_update_notify_hdr_t *notify_resp = (zb_zdo_mgmt_nwk_update_notify_hdr_t *)zdp_cmd; + + TRACE_MSG(TRACE_APS3, + "notify_resp status %hd, scanned_channels %x %x, total_transmissions %hd, " + "transmission_failures %hd, scanned_channels_list_count %hd, buf len %hd", + (FMT__H_D_D_H_H_H_H, notify_resp->status, (zb_uint16_t)notify_resp->scanned_channels, + *((zb_uint16_t*)¬ify_resp->scanned_channels + 1), + notify_resp->total_transmissions, notify_resp->transmission_failures, + notify_resp->scanned_channels_list_count, zb_buf_len(buf))); + + if (notify_resp->status == ZB_ZDP_STATUS_SUCCESS) + { + TRACE_MSG(TRACE_APS3, "mgmt_nwk_update_notify received, Ok", (FMT__0)); + } + else + { + TRACE_MSG(TRACE_ERROR, "mgmt_nwk_update_notify received, ERROR incorrect status %x", + (FMT__D, notify_resp->status)); + } + + zb_free_buf(buf); +} +@endcode + +See TP_PRO_BV-37 sample + */ +zb_uint8_t zb_zdo_mgmt_nwk_update_req(zb_uint8_t param, zb_callback_t cb); + +#ifdef ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED +/** @brief Performs Mgmt_NWK_Enhanced_Update_req request + + @param param - index of buffer with call parameters. Parameters mut be + put into buffer as parameters. \ref zb_zdo_mgmt_nwk_enhanced_update_req_param_s + @param cb - user's function to call when got response from the remote. + \ref zb_zdo_mgmt_nwk_update_notify_hdr_s + @return - ZDP transaction sequence number or 0xFF if operation cannot be + performed now (nor enough memory, resources, etc.) + +*/ +zb_uint8_t zb_zdo_mgmt_nwk_enhanced_update_req(zb_uint8_t param, zb_callback_t cb); + +/** @brief Notification for Mgmt_NWK_Unsolicited_Enhanced_Update_Notify + * @see ZB spec, subclause 2.4.4.4.12 + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_unsol_enh_update_notify_s +{ + zb_uint8_t status; + zb_channel_page_t channel_in_use; + zb_uint16_t mac_tx_ucast_total; + zb_uint16_t mac_tx_ucast_failures; + zb_uint16_t mac_tx_ucast_retries; + zb_uint8_t period; +} ZB_PACKED_STRUCT +zb_zdo_mgmt_nwk_unsol_enh_update_notify_t; + +/** @brief Parameters for Mgmt_NWK_Unsolicited_Enhanced_Update_Notify + * @see ZB spec, subclause 2.4.4.4.12 + */ +typedef struct zb_zdo_mgmt_nwk_unsol_enh_update_notify_param_s +{ + zb_zdo_mgmt_nwk_unsol_enh_update_notify_t notification; + zb_uint16_t addr; +} +zb_zdo_mgmt_nwk_unsol_enh_update_notify_param_t; + +/** @brief Performs Mgmt_NWK_Enhanced_Update_req request + + @param param - index of buffer with call parameters. Parameters mut be + put into buffer as parameters. \ref zb_zdo_mgmt_nwk_unsol_enh_update_notify_param_t + @param cb - user's function to call when the notification has been sent. +*/ +void zb_zdo_mgmt_nwk_unsol_enh_update_notify(zb_uint8_t param, zb_callback_t cb); + +#endif /* ZB_MGMT_NWK_ENHANCED_UPDATE_ENABLED */ + +/** @brief Parameters for Mgmt_Lqi_req. + * @see ZB spec, subclause 2.4.3.3.2. + */ +typedef struct zb_zdo_mgmt_lqi_param_s +{ + zb_uint8_t start_index; /*!< Starting Index for the requested elements + * of the Neighbor Table */ + zb_uint16_t dst_addr; /*!< destination address */ +} +zb_zdo_mgmt_lqi_param_t; + +/** @brief Request for Mgmt_Lqi_req. + * @see ZB spec, subclause 2.4.3.3.2. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_lqi_req_s +{ + zb_uint8_t start_index; /*!< Starting Index for the requested elements + * of the Neighbor Table */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_lqi_req_t; + +/** @brief Response for Mgmt_Lqi_rsp. + * @see ZB spec, subclause 2.4.4.3.2. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_lqi_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Mgmt_Lqi_req command.*/ + zb_uint8_t neighbor_table_entries; /*!< Total number of Neighbor + * Table entries within the Remote Device */ + zb_uint8_t start_index; /*!< Starting index within the Neighbor + * Table to begin reporting for the NeighborTableList.*/ + zb_uint8_t neighbor_table_list_count; /*!< Number of Neighbor Table + * entries included within NeighborTableList*/ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_lqi_resp_t; + + +/* bits 0 - 1, mask 0x3 */ +/** + Set device type of neighbor table record to type 'type': bits 0 - 1, mask 0x3; + + @param var - neighbor table record type_flags + @param type - Zigbee device type value + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_SET_DEVICE_TYPE(var, type) ( var &= ~3, var |= type ) +/** + Get device type of neighbor table record. + + @param var - neighbor table record type_flags + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_GET_DEVICE_TYPE(var) ( var & 3 ) + +/* bits 2 - 3, mask 0xC */ +/** + Set RxOnWhenIdle attribute of neighbor table record to type 'type': + bits 2 - 3, mask 0xC; + + @param var - neighbor table record type_flags + @param type - RxOnWhenIdle value + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_SET_RX_ON_WHEN_IDLE(var, type) ( var &= ~0xC, var |= (type << 2) ) +/** + Get RxOnWhenIdle of neighbor table record. + + @param var - neighbor table record type_flags + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_GET_RX_ON_WHEN_IDLE(var) ( (var & 0xC) >> 2 ) + +/* bits 4 - 6, mask 0x70 */ +/** + Set relationship attribute of neighbor table record to type 'type': + bits 4 - 6, mask 0x70; + + @param var - neighbor table record type_flags + @param type - Zigbee relationship value + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_SET_RELATIONSHIP(var, type) ( var &= ~0x70, var |= (type << 4) ) +/** + Get relationship of neighbor table record. + + @param var - neighbor table record type_flags + + @ref zb_zdo_neighbor_table_record_s + */ +#define ZB_ZDO_RECORD_GET_RELATIONSHIP(var) ( (var & 0x70) >> 4 ) + +/** @brief NeighborTableList Record Format for Mgmt_Lqi_resp */ +typedef ZB_PACKED_PRE struct zb_zdo_neighbor_table_record_s +{ + zb_ext_pan_id_t ext_pan_id; /*!< 64-bit extended Pan + * ID of the neighboring device.*/ + zb_ieee_addr_t ext_addr; /*!< 64-bit IEEE address that is + * unique to every device.*/ + zb_uint16_t network_addr; /*!< The 16-bit network address of the + * neighboring device */ + zb_uint8_t type_flags; /*!< device type, rx_on_when_idle, + * relationship */ + zb_uint8_t permit_join; /*!< An indication of whether the + * neighbor device is accepting join requests*/ + zb_uint8_t depth; /*!< The tree depth of the neighbor device. */ + zb_uint8_t lqi; /*!< The estimated link quality for RF + * transmissions from this device */ +} +ZB_PACKED_STRUCT +zb_zdo_neighbor_table_record_t; + + +/** @brief Sends Mgmt_Lqi_req (see Zigbee spec 2.4.3.3.2) + @param param - index of buffer with Lqi request parameters. \ref zb_zdo_mgmt_lqi_param_s + @param cb - user's function to call when got response from the remote. + @return - ZDP transaction sequence number or 0xFF if operation cannot be + performed now (nor enough memory, resources, etc.) + @ref zb_zdo_mgmt_lqi_resp_s, \ref zb_zdo_neighbor_table_record_s + + @b Example: +@code +{ + zb_uint8_t tsn; + zb_zdo_mgmt_lqi_param_t *req_param; + + req_param = ZB_BUF_GET_PARAM(buf, zb_zdo_mgmt_lqi_param_t); + req_param->start_index = 0; + req_param->dst_addr = 0; //coord short addr + + tsn = zb_zdo_mgmt_lqi_req(ZB_REF_FROM_BUF(buf), get_lqi_cb); +} + + +void get_lqi_cb(zb_uint8_t param) +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_uint8_t *zdp_cmd = zb_buf_begin(buf); + zb_zdo_mgmt_lqi_resp_t *resp = (zb_zdo_mgmt_lqi_resp_t*)(zdp_cmd); + zb_zdo_neighbor_table_record_t *record = (zb_zdo_neighbor_table_record_t*)(resp + 1); + zb_uint_t i; + + TRACE_MSG(TRACE_APS1, "get_lqi_cb status %hd, neighbor_table_entries %hd, start_index %hd, neighbor_table_list_count %d", + (FMT__H_H_H_H, resp->status, resp->neighbor_table_entries, resp->start_index, resp->neighbor_table_list_count)); + + for (i = 0; i < resp->neighbor_table_list_count; i++) + { + TRACE_MSG(TRACE_APS1, "#%hd: long addr " TRACE_FORMAT_64 " pan id " TRACE_FORMAT_64, + (FMT__H_A_A, i, TRACE_ARG_64(record->ext_addr), TRACE_ARG_64(record->ext_pan_id))); + + TRACE_MSG(TRACE_APS1, + "#%hd: network_addr %d, dev_type %hd, rx_on_wen_idle %hd, relationship %hd, permit_join %hd, depth %hd, lqi %hd", + (FMT_H_D_H_H_H_H_H_H, i, record->network_addr, + ZB_ZDO_RECORD_GET_DEVICE_TYPE(record->type_flags), + ZB_ZDO_RECORD_GET_RX_ON_WHEN_IDLE(record->type_flags), + ZB_ZDO_RECORD_GET_RELATIONSHIP(record->type_flags), + record->permit_join, record->depth, record->lqi)); + + record++; + } +} + +@endcode + +See zdpo_lqi sample +*/ +zb_uint8_t zb_zdo_mgmt_lqi_req(zb_uint8_t param, zb_callback_t cb); + +/** @brief RoutingTableList Record Format for mgmt_rtg_resp */ +typedef ZB_PACKED_PRE struct zb_zdo_routing_table_record_s +{ + zb_uint16_t dest_addr; /*!< The 16-bit network address of the + * destination device */ + zb_uint8_t flags; /*!< Routing flags */ + zb_uint16_t next_hop_addr; /*!< The 16-bit network address of the + * next-hop device */ +} +ZB_PACKED_STRUCT +zb_zdo_routing_table_record_t; + +/** @} */ /* zdo_mgmt */ +/** @addtogroup zdo_bind + @{ + */ + +/** @brief The addressing mode for the destination address used in + * @ref zb_zdo_binding_table_record_s, @ref zb_zdo_bind_req_param_s, + * @ref zb_zdo_bind_req_head_s command. This field can take one of + * the non-reserved values from the list @ref zb_bind_dst_addr_mode_e. + * Values 0x00, 0x02, 0x04-0xff are reserved + * @see ZB Spec, subclause 2.4.3.2.2. + */ +typedef enum zb_bind_dst_addr_mode_e +{ + ZB_BIND_DST_ADDR_MODE_16_BIT_GROUP = 0x01, /*!< 16-bit group address + for DstAddress and DstEndp not present */ + ZB_BIND_DST_ADDR_MODE_64_BIT_EXTENDED = 0x03, /*!< 64-bit extended address + for DstAddress and DstEndp present */ +} zb_bind_dst_addr_mode_t; + +/** @brief Parameters for Mgmt_Bind_req. + * @see ZB spec, subclause 2.4.3.3.4. + */ +typedef struct zb_zdo_mgmt_bind_param_s +{ + zb_uint8_t start_index; /*!< Starting Index for the requested elements + * of the Binding Table */ + zb_uint16_t dst_addr; /*!< destination address */ +} +zb_zdo_mgmt_bind_param_t; + +/** @brief Request for Mgmt_Bind_req. + * @see ZB spec, subclause 2.4.3.3.4. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_bind_req_s +{ + zb_uint8_t start_index; /*!< Starting Index for the requested elements + * of the Binding Table */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_bind_req_t; + +/** @brief Response for Mgmt_Bind_rsp. + * @see ZB spec, subclause 2.4.4.3.4. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_bind_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /*!< The status of the Mgmt_Rtg_req command.*/ + zb_uint8_t binding_table_entries; /*!< Total number of Binding Table + * entries within the Remote Device*/ + zb_uint8_t start_index; /*!< Starting index within the Binding + * Table to begin reporting for the BindingTableList.*/ + zb_uint8_t binding_table_list_count; /*!< Number of Binding Table + * entries included within BindingTableList*/ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_bind_resp_t; + + +/** @brief BindingTableList Record Format for mgmt_bind_resp. See ZB + * spec, Table 2.131 */ +typedef ZB_PACKED_PRE struct zb_zdo_binding_table_record_s +{ + zb_ieee_addr_t src_address; /*!< The source IEEE address for the binding entry. */ + zb_uint8_t src_endp; /*!< The source endpoint for the binding entry. */ + zb_uint16_t cluster_id; /*!< The identifier of the cluster on the + * source device that is bound to the + * destination device. */ + zb_uint8_t dst_addr_mode; /*!< Destination address mode @ref zb_bind_dst_addr_mode_t */ + zb_addr_u dst_address; /*!< The destination address for the + * binding entry.16 or 64 bit. As specified by the + * dst_addr_mode field.*/ + zb_uint8_t dst_endp; /*!< This field shall be present only if the + * DstAddrMode field has a value of + * ZB_BIND_DST_ADDR_MODE_64_BIT_EXTENDED @ref zb_bind_dst_addr_mode_t + * and, if present, shall be the + * destination endpoint for the binding + * entry. */ +} +ZB_PACKED_STRUCT +zb_zdo_binding_table_record_t; + + +/** @brief Sends Mgmt_Bind_req request. + * @param param reference to the buffer to put request data to. + * @param cb callback to be called on operation finish. + * @return ZDP transaction sequence number + * @return 0xFF if operation cannot be + * performed now (nor enough memory, resources, etc.) + * + * See zdo_binding sample + */ +zb_uint8_t zb_zdo_mgmt_bind_req(zb_uint8_t param, zb_callback_t cb); + +/** + @brief Sends 2.4.4.3.4 Mgmt_Bind_rsp + @param param - index of buffer with Mgmt_Bind request + */ +void zdo_mgmt_bind_resp(zb_uint8_t param); + + + + +/** @brief Parameters for Bind_req API call + * @see ZB spec, subclause 2.4.3.2.2. + */ +typedef struct zb_zdo_bind_req_param_s +{ + zb_ieee_addr_t src_address; /*!< The IEEE address for the source. */ + zb_uint8_t src_endp; /*!< The source endpoint for the binding entry. */ + zb_uint16_t cluster_id; /*!< The identifier of the cluster on the + * source device that is bound to the destination. */ + zb_uint8_t dst_addr_mode; /*!< Destination address mode @ref zb_bind_dst_addr_mode_t */ + zb_addr_u dst_address; /*!< The destination address for the + * binding entry. */ + zb_uint8_t dst_endp; /*!< This field shall be present only if the + * DstAddrMode field has a value of + * @ref ZB_BIND_DST_ADDR_MODE_64_BIT_EXTENDED @ref zb_bind_dst_addr_mode_t + * and, if present, shall be the + * destination endpoint for the binding + * entry. */ + zb_uint16_t req_dst_addr; /*!< Destination address of the request */ +} +zb_zdo_bind_req_param_t; + + +/** @brief Bind_req request head send to the remote. + * @see ZB spec, subclause 2.4.3.2.2. + */ +typedef ZB_PACKED_PRE struct zb_zdo_bind_req_head_s +{ + zb_ieee_addr_t src_address; /*!< The IEEE address for the source. */ + zb_uint8_t src_endp; /*!< The source endpoint for the binding entry. */ + zb_uint16_t cluster_id; /*!< The identifier of the cluster on the + * source device that is bound to the destination. */ + zb_uint8_t dst_addr_mode; /*!< Destination address mode @ref zb_bind_dst_addr_mode_t */ +} +ZB_PACKED_STRUCT +zb_zdo_bind_req_head_t; + +/** @brief Bind_req request tail 1st variant send to the remote. + * @see ZB spec, subclause 2.4.3.2.2. + */ +typedef ZB_PACKED_PRE struct zb_zdo_bind_req_tail_1_s +{ + zb_uint16_t dst_addr; /*!< The destination address for the + * binding entry. */ +} +ZB_PACKED_STRUCT +zb_zdo_bind_req_tail_1_t; + +/** @brief Bind_req request tail 2nd variant send to the remote. + * @see ZB spec, subclause 2.4.3.2.2. + */ +typedef ZB_PACKED_PRE struct zb_zdo_bind_req_tail_2_s +{ + zb_ieee_addr_t dst_addr; /*!< The destination address for the + * binding entry. */ + zb_uint8_t dst_endp; /*!< The destination address for the + * binding entry. */ +} +ZB_PACKED_STRUCT +zb_zdo_bind_req_tail_2_t; + +/** @brief Response by BibdReq. */ +typedef ZB_PACKED_PRE struct zb_zdo_bind_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /**< Operation status. */ +} +ZB_PACKED_STRUCT +zb_zdo_bind_resp_t; + + +/** @brief Bind_req request. + + @param param - index of buffer with request. \ref zb_apsme_binding_req_s + @param cb - user's function to call when got response from the + remote. \ref zb_zdo_bind_resp_s + @return ZDP transaction sequence number + @return 0xFF if operation cannot be performed now (nor enough memory, resources, etc.) + + @b Example: +@code +{ + zb_apsme_binding_req_t *req; + + req = ZB_BUF_GET_PARAM(buf, zb_apsme_binding_req_t); + ZB_MEMCPY(&req->src_addr, &g_ieee_addr, sizeof(zb_ieee_addr_t)); + req->src_endpoint = i; + req->clusterid = 1; + req->addr_mode = ZB_APS_ADDR_MODE_64_ENDP_PRESENT; + ZB_MEMCPY(&req->dst_addr.addr_long, &g_ieee_addr_d, sizeof(zb_ieee_addr_t)); + req->dst_endpoint = 240; + + zb_zdo_bind_req(ZB_REF_FROM_BUF(buf), zb_bind_callback); + ret = buf->u.hdr.status; + if (ret == RET_TABLE_FULL) + { + TRACE_MSG(TRACE_ERROR, "TABLE FULL %d", (FMT__D, ret)); + } +} + +void zb_bind_callback(zb_uint8_t param) +{ + zb_ret_t ret = RET_OK; + zb_bufid_t buf = (zb_bufid_t )ZB_BUF_FROM_REF(param); + zb_uint8_t *aps_body = NULL; + + aps_body = zb_buf_begin(buf); + ZB_MEMCPY(&ret, aps_body, sizeof(ret)); + + TRACE_MSG(TRACE_INFO1, "zb_bind_callback %hd", (FMT__H, ret)); + if (ret == RET_OK) + { + // bind ok + } +} +@endcode + +See tp_zdo_bv-12 sample + */ +zb_uint8_t zb_zdo_bind_req(zb_uint8_t param, zb_callback_t cb); + + +/** @brief Unbind_req request. + + @param param - index of buffer with request. @ref zb_zdo_bind_req_param_s + @param cb - user's function to call when got response from the + remote. @ref zb_zdo_bind_resp_s + @return ZDP transaction sequence number + @return 0xFF if operation cannot be performed now (nor enough memory, resources, etc.) + + @b Example: +@code +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_zdo_bind_req_param_t *bind_param; + + TRACE_MSG(TRACE_COMMON1, "unbind_device_1", (FMT__0)); + + zb_buf_initial_alloc(buf, 0); + bind_param = ZB_BUF_GET_PARAM(buf, zb_zdo_bind_req_param_t); + ZB_MEMCPY(bind_param->src_address, g_ieee_addr_ed1, sizeof(zb_ieee_addr_t)); + bind_param->src_endp = TEST_ED1_EP; + bind_param->cluster_id = TP_BUFFER_TEST_REQUEST_CLID; + bind_param->dst_addr_mode = ZB_APS_ADDR_MODE_64_ENDP_PRESENT; + ZB_MEMCPY(bind_param->dst_address.addr_long, g_ieee_addr_ed2, sizeof(zb_ieee_addr_t)); + bind_param->dst_endp = TEST_ED2_EP; + bind_param->req_dst_addr = zb_address_short_by_ieee(g_ieee_addr_ed1); + TRACE_MSG(TRACE_COMMON1, "dst addr %d", (FMT__D, bind_param->req_dst_addr)); + + zb_zdo_unbind_req(param, unbind_device1_cb); +} + + +void unbind_device1_cb(zb_uint8_t param) +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_zdo_bind_resp_t *bind_resp = (zb_zdo_bind_resp_t*)zb_buf_begin(buf); + + TRACE_MSG(TRACE_COMMON1, "unbind_device1_cb resp status %hd", (FMT__H, bind_resp->status)); + if (bind_resp->status != ZB_ZDP_STATUS_SUCCESS) + { + TRACE_MSG(TRACE_COMMON1, "Error bind device 1. Test status failed", (FMT__0)); + } + zb_free_buf(buf); + +} +@endcode + + See tp_aps_bv-23-i, tp_zdo_bv-12 samples + */ +zb_uint8_t zb_zdo_unbind_req(zb_uint8_t param, zb_callback_t cb); + +/** + * @brief Checks existence of bind table entries with selected endpoint and cluster ID. + * + * @param src_end - source endpoint + * @param cluster_id - source cluster ID + * + * @return ZB_TRUE if binding is found on given endpoint, ZB_FALSE otherwise + */ +zb_bool_t zb_zdo_find_bind_src(zb_uint8_t src_end, zb_uint16_t cluster_id); + +/** @} */ + +/** @addtogroup zdo_mgmt + @{ +*/ + +/** @brief Request for Mgmt_Leave_req + @see ZB spec, subclause 2.4.3.3.5. + + Problem in the specification: + in 2.4.3.3.5 Mgmt_Leave_req only one DeviceAddress exists. + But, in such case it is impossible to satisfy 2.4.3.3.5.1: + "The Mgmt_Leave_req is generated from a Local Device requesting that a Remote + Device leave the network or to request that another device leave the network." + Also, in the PRO TC document, 14.2TP/NWK/BV-04 ZR-ZDO-APL RX Join/Leave is + following note: + "gZC sends Mgmt_Leave.request with DevAddr=all zero, DstAddr=ZR" + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_leave_param_s +{ + zb_ieee_addr_t device_address; /*!< 64-bit IEEE address */ + zb_uint16_t dst_addr; /*!< Destination address. Not defined in + * the spac - let's it be short address */ + zb_bitfield_t reserved:6; /*!< Reserve */ + zb_bitfield_t remove_children:1; /*!< Remove children */ + zb_bitfield_t rejoin:1; /*!< Rejoin */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_leave_param_t; + +/** Request for Mgmt_Leave_req. + * @see ZB spec, subclause 2.4.3.3.5. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_leave_req_s +{ + zb_ieee_addr_t device_address; /*!< 64-bit IEEE address */ + zb_bitfield_t reserved:6; /*!< Reserve */ + zb_bitfield_t remove_children:1; /*!< Remove children */ + zb_bitfield_t rejoin:1; /*!< Rejoin */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_leave_req_t; + +/** @brief Response for Mgmt_Leave_rsp. + * @see ZB spec, subclause 2.4.4.3.5. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_leave_res_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /**< Operation status. */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_leave_res_t; + +/** @brief Sends Mgmt_Leave_req + @see ZB spec, subclause 2.4.3.3.2. + + @param param - index of buffer with Lqi request parameters. @ref zb_zdo_mgmt_leave_param_s + @param cb - user's function to call when got response from the remote. + @return - transaction sequence number of request or 0xFF if operation not be + performed right now (in case if not exist free slot for registering callback) + + @b Example: +@code +{ + zb_bufid_t buf = ZB_BUF_FROM_REF(param); + zb_zdo_mgmt_leave_param_t *req = NULL; + zb_ret_t ret = RET_OK; + zb_uint8_t tsn; + + TRACE_MSG(TRACE_ERROR, "zb_leave_req", (FMT__0)); + + req = ZB_BUF_GET_PARAM(buf, zb_zdo_mgmt_leave_param_t); + + ZB_MEMSET(req->device_address, 0, sizeof(zb_ieee_addr_t)); + req->remove_children = ZB_FALSE; + req->rejoin = ZB_FALSE; + req->dst_addr = 1; + tsn = zdo_mgmt_leave_req(param, leave_callback); +} + +void leave_callback(zb_uint8_t param) +{ + zb_zdo_mgmt_leave_res_t *resp = (zb_zdo_mgmt_leave_res_t *)zb_buf_begin(ZB_BUF_FROM_REF(param)); + + TRACE_MSG(TRACE_ERROR, "LEAVE CALLBACK status %hd", (FMT__H, resp->status)); +} +@endcode + +See nwk_leave sample +*/ +zb_uint8_t zdo_mgmt_leave_req(zb_uint8_t param, zb_callback_t cb); + +/** @} */ +/** @addtogroup zdo_bind + @{ +*/ + + +/** @brief End_Device_Bind_req command head. + * @see ZB spec, subclause 2.4.3.2.1. + */ +typedef ZB_PACKED_PRE struct zb_zdo_end_device_bind_req_head_s +{ + zb_uint16_t binding_target; /*!< The address of the target for the + * binding. This can be either the + * primary binding cache device or the + * short address of the local device. */ + zb_ieee_addr_t src_ieee_addr; /*!< IEEE address of the device generating the request */ + zb_uint8_t src_endp; /*!< The endpoint on the device generating the request */ + zb_uint16_t profile_id; /*!< ProfileID which is to be matched + * between two End_Device_Bind_req + * received at the Zigbee Coordinator */ + zb_uint8_t num_in_cluster; /*!< The number of Input Clusters + * provided for end device binding + * within the InClusterList. */ +} +ZB_PACKED_STRUCT +zb_zdo_end_device_bind_req_head_t; + +/** @brief End_Device_Bind_req command head. + * @see ZB spec, subclause 2.4.3.2.1. + */ +typedef ZB_PACKED_PRE struct zb_zdo_end_device_bind_req_tail_s +{ + zb_uint8_t num_out_cluster; /*!< The number of Output Clusters + * provided for matching within OutClusterList */ +} +ZB_PACKED_STRUCT +zb_zdo_end_device_bind_req_tail_t; + +/** @brief Parameters for End_Device_Bind_req. + * @see ZB spec, subclause 2.4.3.2.1. + */ +typedef ZB_PACKED_PRE struct zb_end_device_bind_req_param_s +{ + zb_uint16_t dst_addr; /*!< Destination address */ + zb_zdo_end_device_bind_req_head_t head_param; /*!< Parameters for command head */ + zb_zdo_end_device_bind_req_tail_t tail_param; /*!< Parameters for command tail */ + zb_uint16_t cluster_list[1]; /*!< List of Input and Output + * ClusterIDs to be used for matching */ +} ZB_PACKED_STRUCT +zb_end_device_bind_req_param_t; + +/** + sends 2.4.3.2.1 End_Device_Bind_req command + @param param - index of buffer with request + @param cb - user's function to call when got response from the remote. + @return ZDP transaction sequence number or + @return 0xFF if operation cannot be performed now (nor enough memory, resources, etc.) +*/ +zb_uint8_t zb_end_device_bind_req(zb_uint8_t param, zb_callback_t cb); + + +/** @brief Response from End_Device_Bind_req. + * @see ZB spec, subclause 2.4.3.2.1. + */ +typedef ZB_PACKED_PRE struct zb_zdo_end_device_bind_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /**< Operation status. */ +} +ZB_PACKED_STRUCT +zb_zdo_end_device_bind_resp_t; + +/** @} */ +/** @addtogroup zdo_mgmt + @{ +*/ + +/** @brief Parameters for Mgmt_Permit_Joining_req. + * @see ZB spec, subclause 2.4.3.3.7. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_permit_joining_req_s +{ + zb_uint8_t permit_duration; /**< The length of time in seconds. 0x00 and 0xff indicate that + * permission is disabled or enabled + */ + zb_uint8_t tc_significance; /**< If this is set to 0x01 and the remote device is the Trust + * Center, the command affects the + * Trust Center authentication policy as described in the + * sub-clauses below; According to + * r21, should be always set to 0x01. + */ +} ZB_PACKED_STRUCT +zb_zdo_mgmt_permit_joining_req_t; + +/** @brief Parameters for zb_zdo_mgmt_permit_joining_req. */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_permit_joining_req_param_s +{ + zb_uint16_t dest_addr; /**< Destination address */ + zb_uint8_t permit_duration; /**< The length of time in seconds. 0x00 and 0xff indicate that + * permission is disabled or enabled + */ + zb_uint8_t tc_significance; /**< If this is set to 0x01 and the remote device is the Trust + * Center, the command affects the Trust Center authentication + * policy as described in the sub-clauses below; If this is set to + * 0x00, there is no effect on the Trust + * Center. + * Ignored for r21. + */ +} ZB_PACKED_STRUCT +zb_zdo_mgmt_permit_joining_req_param_t; + +/** + @brief sends Mgmt_Permit_Joining_req (See Zigbee spec 2.4.3.3.7) + @param param - Index of buffer with request + @param cb - user's function to call when got response from the remote. + @return ZDP transaction sequence number + @return 0xFF if operation cannot be performed now (nor enough memory, resources, etc.) + + @snippet onoff_server/on_off_switch_zed.c zdo_mgmt_permit_joining_req + + See onoff_server sample + */ +zb_uint8_t zb_zdo_mgmt_permit_joining_req(zb_uint8_t param, zb_callback_t cb); + +/** @} */ +/** @addtogroup zdo_groups + @{ +*/ + + +/** @brief Response from zb_zdo_mgmt_permit_joining_req. */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_permit_joining_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /**< Operation status. */ +} +ZB_PACKED_STRUCT +zb_zdo_mgmt_permit_joining_resp_t; + +/** @brief Not Supported Response */ +typedef ZB_PACKED_PRE struct zb_zdo_not_supported_resp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + zb_uint8_t status; /**< Operation status. */ +} +ZB_PACKED_STRUCT +zb_zdo_not_supported_resp_t; + +/** + * @brief Parameters for Mgmt_NWK_IEEE_Joining_List_req. + * @see ZB r22 spec, subclause 2.4.3.3.11. + */ +typedef struct zb_zdo_mgmt_nwk_ieee_joining_list_param_s +{ + zb_uint8_t start_index; /*!< Starting Index for nwkIeeeJoiningList to be returned */ + zb_uint16_t dst_addr; /*!< destination address */ +} +zb_zdo_mgmt_nwk_ieee_joining_list_param_t; + +/** + * @brief Request for Mgmt_NWK_IEEE_Joining_List_req. + * @see ZB r22 spec, subclause 2.4.3.3.11. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_ieee_joining_list_req_s +{ + zb_uint8_t start_index; /*!< Starting Index for nwkIeeeJoiningList to be returned */ +} +ZB_PACKED_STRUCT zb_zdo_mgmt_nwk_ieee_joining_list_req_t; + + +/** + * @brief Response for Mgmt_NWK_IEEE_Joining_List_rsp. + * @see ZB spec, subclause 2.4.4.4.11. + */ +typedef ZB_PACKED_PRE struct zb_zdo_mgmt_nwk_ieee_joining_list_rsp_s +{ + zb_uint8_t tsn; /*!< ZDP transaction sequence number */ + + zb_uint8_t status; /*!< The status of the Mgmt_NWK_IEEE_Joining_List_req command. */ + + zb_uint8_t ieee_joining_list_update_id; + + zb_uint8_t joining_policy; /*profileid == TEST_CUSTOM_PROFILE_ID) + * { + * ptr = ZB_APS_HDR_CUT(asdu); + * + * TRACE_MSG(TRACE_APS3, "apsde_data_indication: packet %p len %hd status 0x%hx from %d", + * (FMT__P_D_D_D, asdu, ZB_BUF_LEN(asdu), asdu->u.hdr.status, ind->src_addr)); + * + * for (i = 0 ; i < ZB_BUF_LEN(asdu) ; ++i) + * { + * TRACE_MSG(TRACE_APS3, "%x %c", (FMT__D_C, (int)ptr[i], ptr[i])); + * } + * zb_free_buf(apsdu); + * return ZB_TRUE; + * } + * return ZB_FALSE; + * } + * @endcode + */ +void zb_af_set_data_indication(zb_device_handler_t cb); + +/** + * @brief Perform "Reset with a Local Action" procedure (as described in BDB spec, chapter 9.5). + * The device will perform the NLME leave and clean all ZigBee persistent data except the outgoing NWK + * frame counter and application datasets (if any). + * The reset can be performed at any time once the device is started (see @ref zboss_start). + * After the reset, the application will receive the @ref ZB_ZDO_SIGNAL_LEAVE signal. + * + * @param param - buffer reference (if 0, buffer will be allocated automatically) + */ +void zb_bdb_reset_via_local_action(zb_uint8_t param); +/** @} */ /* af_management_service */ +/*! @} */ + +#endif /*ZB_ZBOSS_API_ZDO_H*/ diff --git a/zboss/include/zboss_api_zgp.h b/zboss/include/zboss_api_zgp.h new file mode 100644 index 0000000000..08fecf2f46 --- /dev/null +++ b/zboss/include/zboss_api_zgp.h @@ -0,0 +1,1737 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: common definitions for ZGP profile +*/ + +#ifndef ZBOSS_API_ZGP_H +#define ZBOSS_API_ZGP_H 1 + +#include "zb_config.h" +#include "zb_address.h" +#include "zboss_api_buf.h" +#include "zb_types.h" + +/********************************************************************/ +/********* Type declarations specific to ZGP profile ****************/ +/********************************************************************/ + +/** + @addtogroup zgp_common + @{ +*/ + +#define ZGP_ENDPOINT 242 + +/** @brief ZGPD application ID */ +typedef enum zb_zgp_app_id_e +{ + ZB_ZGP_APP_ID_0000 = 0x00, /**< ApplicationID value 0b000 - usage of the SrcID */ + ZB_ZGP_APP_ID_0001 = 0x01, /**< ApplicationID value 0b001 - LPED */ + ZB_ZGP_APP_ID_0010 = 0x02, /**< ApplicationID value 0b010 - usage of the GPD IEEE address.*/ + ZB_ZGP_APP_ID_INVALID = 0x07, /**< Invalid ApplicationID */ +} +zb_zgp_app_id_t; + +/** + * @brief ZGPD address + * + * ZGPD is identified in network whether by SrcId or its IEEE address. */ +typedef ZB_PACKED_PRE union zb_zgpd_addr_u +{ + zb_uint32_t src_id; /**< ZGPD SrcId @see ZGP spec, A.1.4.1.4 */ + zb_ieee_addr_t ieee_addr; /**< ZGPD IEEE address */ +} ZB_PACKED_STRUCT +zb_zgpd_addr_t; + +enum zb_zgp_endpoint_e +{ + ZB_ZGP_COMMUNICATION_ENDPOINT, + ZB_ZGP_ALL_ENDPOINTS = 255 +}; + +/** + * @brief ZGPD identification info (ZGPD ID) + * + * ZGPD is identified by SrcId if ApplicationID is @ref ZB_ZGP_APP_ID_0000. + * Otherwise, ZGPD is identified by its IEEE address. */ +typedef ZB_PACKED_PRE struct zb_zgpd_id_s +{ + zb_uint8_t app_id; /**< One of the @ref zb_zgp_app_id_t values */ + zb_uint8_t endpoint;/**< Identifier of the GPD endpoint, which jointly with the GPD IEEE address identifies a unique logical GPD device.*/ + zb_zgpd_addr_t addr; /**< ZGPD SrcId or IEEE address */ +} ZB_PACKED_STRUCT +zb_zgpd_id_t; + +#define SIZE_BY_APP_ID(app_id) (((app_id) == ZB_ZGP_APP_ID_0000) ? 4 : 8) +#define ZGPD_ID_SIZE(zgpd_id) SIZE_BY_APP_ID((zgpd_id)->app_id) + +#define ZB_ZGPD_IDS_ARE_EQUAL(id1, id2) \ + (((id1)->app_id == (id2)->app_id) && \ + (((id1)->app_id == ZB_ZGP_APP_ID_0000) ? \ + ((id1)->addr.src_id == (id2)->addr.src_id) : \ + (!ZB_MEMCMP(&(id1)->addr.ieee_addr, &(id2)->addr.ieee_addr, sizeof(zb_ieee_addr_t)) &&\ + ((id1)->endpoint == (id2)->endpoint)))) + +/* From ZGP spec, A. 1.4.1.4: + * ZGPD ID value of 0x00000000 indicates unspecified. + * ... 0xffffffff indicates all. + */ +#define ZB_ZGP_SRC_ID_UNSPECIFIED 0x00000000 +#define ZB_ZGP_SRC_ID_ALL 0xffffffff + +#define ZB_INIT_ZGPD_ID(zgpd_id) \ +{ \ + (zgpd_id)->app_id = ZB_ZGP_APP_ID_0000; \ + (zgpd_id)->addr.src_id = ZB_ZGP_SRC_ID_UNSPECIFIED; \ +} + +#define ZB_ZGPD_IS_SPECIFIED(zgpd_id) \ + (((zgpd_id)->app_id != ZB_ZGP_APP_ID_0000) \ + || ((zgpd_id)->addr.src_id != ZB_ZGP_SRC_ID_UNSPECIFIED)) + +#define ZB_MAKE_ZGPD_ID(zgpd_id, s_app_id, s_endpoint, s_addr)\ + {\ + (zgpd_id).app_id = (s_app_id);\ + (zgpd_id).endpoint = (s_endpoint);\ + (zgpd_id).addr = (s_addr);\ + } + +/** + * @brief ZGP security level type + * @see ZGP spec, A.1.5.3.2 */ +enum zb_zgp_security_level_e +{ + ZB_ZGP_SEC_LEVEL_NO_SECURITY = 0x00, /**< No security */ + ZB_ZGP_SEC_LEVEL_REDUCED = 0x01, /**< 1LSB of frame counter and short (2B) MIC */ + ZB_ZGP_SEC_LEVEL_FULL_NO_ENC = 0x02, /**< Full (4B) frame counter and full (4B) MIC */ + ZB_ZGP_SEC_LEVEL_FULL_WITH_ENC = 0x03, /**< Encryption & full (4B) frame counter and + full (4B) MIC */ +}; + +/** +The gpSharedSecurityKeyType attribute can take the following values from Table 48: +Table 48 - Values of gpSecurityKeyType + +See also Table 12 - Mapping between the gpSecurityKeyType and the SecurityKey +sub-field of the Extended NWK Frame Control field +*/ +enum zb_zgp_security_key_type_e +{ + ZB_ZGP_SEC_KEY_TYPE_NO_KEY = 0x00, /**< No key */ + ZB_ZGP_SEC_KEY_TYPE_NWK = 0x01, /**< Zigbee NWK key */ + ZB_ZGP_SEC_KEY_TYPE_GROUP = 0x02, /**< ZGPD group key */ + ZB_ZGP_SEC_KEY_TYPE_GROUP_NWK_DERIVED = 0x03, /**< NWK-key derived ZGPD group key */ + ZB_ZGP_SEC_KEY_TYPE_ZGPD_INDIVIDUAL = 0x04, /**< (Individual) out-of-the-box ZGPD key */ + ZB_ZGP_SEC_KEY_TYPE_DERIVED_INDIVIDUAL = 0x07, /**< Derived individual ZGPD key */ +}; + +/********************************************************************/ +/******** ZGP Device Type declarations and configuration ************/ +/********************************************************************/ + +/** + * @brief Possible ZGPD device identifiers + * @see ZGP spec, A.4.3 */ +typedef enum zb_zgpd_dev_id_e +{ + ZB_ZGP_SIMPLE_GEN_1_STATE_SWITCH_DEV_ID = 0x00, /**< Simple Generic 1-state ZGP switch */ + ZB_ZGP_ON_OFF_SWITCH_DEV_ID = 0x02, /**< ZGP On/Off switch */ + ZB_ZGP_LEVEL_CONTROL_SWITCH_DEV_ID = 0x03, /**< ZGP Level Control Switch */ +#define ZB_ZGP_LVL_CTRL_SWITCH_DEV_ID ZB_ZGP_LEVEL_CONTROL_SWITCH_DEV_ID + ZB_ZGP_TEMPERATURE_SENSOR_DEV_ID = 0x30, /**< ZGP temperature sensor */ + ZB_ZGP_ENVIRONMENT_SENSOR_DEV_ID = 0x33, /**< ZGP Temperature + Humidity sensor */ + ZB_ZGP_MANUF_SPECIFIC_DEV_ID = 0xfe, /**< Manufactures-specific; 2 + * more fields in the + * Commissioning frame. See 4.1 + * Manufacturer Specific Green + * Power Device Type Use case + * in Green Power Device + * Manufacturer Specific Device & Command + * Definition Proposal + */ + ZB_ZGP_UNDEFINED_DEV_ID = 0xff, /**< Undefined device type */ +} +zb_zgpd_dev_id_t; + +/** + * @brief Manufacturer-specific device identifiers for GreanPeak + * @see ZGP spec, A.4.3 */ +typedef enum zb_zgpd_manuf_specific_dev_id_e +{ + /* TODO: ZB_ZGP_MS_DOOR_SENSOR_DEV_ID is deprecated. Remove it when there will be + * no testing devices using this type. GreanPeak door sensors use + * ZB_ZGP_MS_DOOR_WINDOW_SENSOR_DEV_ID now. */ + ZB_ZGP_MS_DOOR_SENSOR_DEV_ID = 0x00, /**< IAS Zone - Door Sensor*/ + ZB_ZGP_MS_DOOR_WINDOW_SENSOR_DEV_ID = 0x01, /**< IAS Zone - Door/Window Sensor*/ + ZB_ZGP_MS_LEAKAGE_SENSOR_DEV_ID = 0x02, /**< IAS Zone - Leakage Sensor */ + ZB_ZGP_MS_HUMIDITY_SENSOR_DEV_ID = 0x03, /**< Relative Humidity Sensor */ + ZB_ZGP_MS_MOTION_SENSOR_DEV_ID = 0x05, /**< IAS Zone - Motion sensor */ + ZB_ZGP_MS_MOVEMENT_SENSOR_DEV_ID = 0x07, /**< IAS Zone - Movement sensor */ + ZB_ZGP_MS_SMART_PLUG_DEV_ID = 0X08, /**< GreenPeak Greenpower smart plug */ + ZB_ZGP_MS_KEY_FOB_DEV_ID = 0x0A, /**< GreenPeak Greenpower IAS Zone - Key fob */ + ZB_ZGP_MS_SMOKE_DETECTOR_DEV_ID = 0x0b, /**< IAS Zone - Smoke Detector */ + ZB_ZGP_MS_BED_SENSOR_DEV_ID = 0x0c, /**< IAS Zone - Bed Sensor */ + ZB_ZGP_MS_PARKING_SENSOR_DEV_ID = 0xc0, /**< Occupancy - Parking sensor */ +} +zb_zgpd_manuf_specific_dev_id_t; + +/** + @} +*/ + +#ifdef ZB_ENABLE_ZGP_SINK +/********************************************************************/ +/*********************** Sink definitions ***************************/ +/********************************************************************/ + +/** + * @brief Mapping of ZGPD command ID to Zigbee ZCL command ID + */ +typedef struct zgp_to_zb_cmd_mapping_s +{ + zb_uint8_t zgp_cmd_id; /**< ZGPD command ID */ + zb_uint8_t zb_cmd_id; /**< Zigbee ZCL command ID */ +} +zgp_to_zb_cmd_mapping_t; + +typedef struct zgps_cluster_rec_s +{ + zb_uint16_t cluster_id; /** Cluster ID to which specified ZGPD commands are translated + (see @ref zb_zcl_cluster_id_t) */ +/** + * Options field of cluster table entry + * + * [0-1] role mask client/server/both + * + */ + zb_uint8_t options; + zb_uint8_t cmd_ids[ZB_ZGP_MATCH_TBL_MAX_CMDS_FOR_MATCH]; /**< Supported commands by sink */ +} +zgps_dev_cluster_rec_t; + +#define GET_CLUSTER_ROLE(cluster) \ + (cluster->options & 0x03) + +typedef ZB_PACKED_PRE union zgps_device_id_u +{ + zb_uint8_t zgpd_dev_id; + zb_uint16_t zgpd_manuf_model; +} +zgps_device_id_t; + +typedef ZB_PACKED_PRE struct zgps_dev_match_rec_s +{ + zb_uint16_t clusters[ZB_ZGP_TBL_MAX_CLUSTERS]; + zb_uint16_t manuf_id; + zgps_device_id_t dev_id; +} +ZB_PACKED_STRUCT zgps_dev_match_rec_t; + +#define IS_STANDART_ZGPS_DEVICE(dev_match_rec) \ + (dev_match_rec->manuf_id == ZB_ZGPD_MANUF_ID_UNSPEC) + +/** + * @brief Necessary information for filling translation table for any ZGPD + * during commissioning + * + * Includes matching table and command ID mappings. Given some ZGPD device ID it is + * possible to fill translation table entry with help of this structure. + */ +typedef struct zb_zgps_match_info_s +{ + const zb_uint8_t match_tbl_size; + const ZB_CODE zgps_dev_match_rec_t *match_tbl; + const zb_uint8_t cmd_mappings_count; + const ZB_CODE zgp_to_zb_cmd_mapping_t *cmd_mapping; + const zb_uint8_t clusters_tbl_size; + const ZB_CODE zgps_dev_cluster_rec_t *clusters_tbl; +} +zb_zgps_match_info_t; +#endif /* ZB_ENABLE_ZGP_SINK */ + +#ifdef ZB_ENABLE_ZGP_DIRECT +enum zb_zgp_data_handle_e +{ + ZB_ZGP_HANDLE_DEFAULT_HANDLE, + ZB_ZGP_HANDLE_REMOVE_CHANNEL_CONFIG, + ZB_ZGP_HANDLE_REMOVE_COMMISSIONING_REPLY, + ZB_ZGP_HANDLE_ADD_COMMISSIONING_REPLY, + ZB_ZGP_HANDLE_ADD_CHANNEL_CONFIG, + ZB_ZGP_HANDLE_REMOVE_AFTER_FAILED_COMM, + ZB_ZGP_HANDLE_REMOVE_BY_USER_REQ, + +/** + * The first handle that can be used by application for gp-data.req primitives. + * Application may use any greater or equal handle value to match request with + * confirmation. + * + * @see zb_zgps_send_data(). + */ + ZB_ZGP_HANDLE_APP_DATA, +}; + +#define ZB_GP_TX_QUEUE_ENTRY_LIFETIME_NONE ZB_MIN_TIME_VAL +#define ZB_GP_TX_QUEUE_ENTRY_LIFETIME_INF ZB_MAX_TIME_VAL + +#define ZB_GP_DATA_REQ_USE_GP_TX_QUEUE 0x01 +#define ZB_GP_DATA_REQ_USE_CSMA_CA_BIT 0x02 +#define ZB_GP_DATA_REQ_USE_MAC_ACK_BIT 0x04 +#define ZB_GP_DATA_REQ_MAINT_FRAME_TYPE 0x08 + +#define ZB_GP_DATA_REQ_FRAME_TYPE(tx_opt) \ + ((tx_opt >> 3) & 0x03) + +#define ZB_GP_DATA_REQ_ACTION_REMOVE_GPDF ZB_FALSE +#define ZB_GP_DATA_REQ_ACTION_ADD_GPDF ZB_TRUE + +#define ZB_CGP_DATA_REQ_USE_CSMA_CA_BIT 0x01 +#define ZB_CGP_DATA_REQ_USE_MAC_ACK_BIT 0X02 + +#endif /* ZB_ENABLE_ZGP_DIRECT */ +/*! @} */ +/*! @endcond */ + +/********************************************************************/ +/*********************** Proxy definitions **************************/ +/********************************************************************/ + +/** + @addtogroup zgp_common + @{ +*/ + +/** Values of gpsCommunicationMode attribute + * Table 27 +*/ +typedef enum zgp_communication_mode_e +{ + ZGP_COMMUNICATION_MODE_FULL_UNICAST = 0, + /*Groupcast - one of the communication modes used for tunneling GPD commands between the + proxies and sinks. In Zigbee terms, it is the APS level multicast, with NWK level broadcast to the + RxOnWhenIdle=TRUE (0xfffd) broadcast address.*/ + ZGP_COMMUNICATION_MODE_GROUPCAST_DERIVED = 1, + ZGP_COMMUNICATION_MODE_GROUPCAST_PRECOMMISSIONED = 2, + ZGP_COMMUNICATION_MODE_LIGHTWEIGHT_UNICAST = 3 +} zgp_communication_mode_t; + +/* A.3.3.2.4 gpsCommissioningExitMode attribute */ +typedef enum zgp_commissioning_exit_mode_e +{ + ZGP_COMMISSIONING_EXIT_MODE_ON_COMMISSIONING_WINDOW_EXPIRATION = (1<<0), + ZGP_COMMISSIONING_EXIT_MODE_ON_PAIRING_SUCCESS = (1<<1), + ZGP_COMMISSIONING_EXIT_MODE_ON_GP_PROXY_COMMISSIONING_MODE_EXIT = (1<<2), + ZGP_COMMISSIONING_EXIT_MODE_ON_CWE_OR_PS = (ZGP_COMMISSIONING_EXIT_MODE_ON_COMMISSIONING_WINDOW_EXPIRATION | + ZGP_COMMISSIONING_EXIT_MODE_ON_PAIRING_SUCCESS), + ZGP_COMMISSIONING_EXIT_MODE_ON_CWE_OR_PCM = (ZGP_COMMISSIONING_EXIT_MODE_ON_COMMISSIONING_WINDOW_EXPIRATION | + ZGP_COMMISSIONING_EXIT_MODE_ON_GP_PROXY_COMMISSIONING_MODE_EXIT), + ZGP_COMMISSIONING_EXIT_MODE_ALL = (ZGP_COMMISSIONING_EXIT_MODE_ON_COMMISSIONING_WINDOW_EXPIRATION | + ZGP_COMMISSIONING_EXIT_MODE_ON_PAIRING_SUCCESS | + ZGP_COMMISSIONING_EXIT_MODE_ON_GP_PROXY_COMMISSIONING_MODE_EXIT) +} zgp_commissioning_exit_mode_t; + +/*! @} + * @endcond*/ + +/********************************************************************/ +/******************** Commissioning definitions *********************/ +/********************************************************************/ + +/** + @addtogroup zgp_common + @{ +*/ + +/** + * @brief Possible commissioning result + */ +typedef enum zb_zgp_comm_status_e +{ + /** Commissioning with some device completed successfully */ + ZB_ZGP_COMMISSIONING_COMPLETED, + /** Commissioning failed. The reason can be: + * - parameters of connection can't be negotiated + * - ZGPD device behaves incorrectly + * - Maximum number of connected ZGPDs is reached */ + ZB_ZGP_COMMISSIONING_FAILED, + /** Commissioning failed, because of timeout */ + ZB_ZGP_COMMISSIONING_TIMED_OUT, + /** No functionality match with commissioning device is found. + * Maybe matching table is not provided by user application */ + ZB_ZGP_COMMISSIONING_NO_MATCH_ERROR, + /** Commissioning failed, because some internal error occured in stack. + * This type of error is recoverable, so next commissioning attempt can + * be successful */ + ZB_ZGP_COMMISSIONING_INTERNAL_ERROR, + /** Commissioning failed, because some critical error has occured. + * Normal functioning of ZGP subsystem is not possible + * (e.g. physical operational channel can't be changed) */ + ZB_ZGP_COMMISSIONING_CRITICAL_ERROR, + /** User cancelled commissioning by calling zb_zgps_stop_commissioning() */ + ZB_ZGP_COMMISSIONING_CANCELLED_BY_USER, + /** ZGPD sent Decommissioning command */ + ZB_ZGP_ZGPD_DECOMMISSIONED, +} +zb_zgp_comm_status_t; + +#ifdef ZB_ENABLE_ZGP_SINK +/** + * @brief Commissioning callback type + * + * @note this is legacy API. Use ZB_ZGP_SIGNAL_COMMISSIONING signal passed to + * zboss_signal_handler instead! + * + * Commissioning callback notifies user about commissioning complete. So, ZGP + * device is in the operational mode at the time of calling this callback. + * Result variable carries the status of commissioning: whether some device + * successfully commissioned or not. + */ +typedef void (ZB_CODE * zb_zgp_comm_completed_cb_t)( + zb_zgpd_id_t *zgpd_id, + zb_zgp_comm_status_t result); + +/** + * @brief Commissioning request callback type + * + * Commissioning request callback notifies application about commissioning + * attempt from ZGPD. Callback is called when ZGPD sends commissioning frame. + * Callback provides to user ZGPD ID and ZGPD Device ID. Based on these + * parameters user application should decide whether commissioning procedure + * should be continued or not. + * + * Commissioning request callback should be set during ZGP initialization using + * @ref ZB_ZGP_REGISTER_COMM_REQ_CB macro. If callback is not registered, then + * ZBOSS accepts all incoming commissioning attempts. + * + * @param zgpd_id [in] ZGPD ID + * @param device_id [in] ZGPD device ID + * @param manuf_id [in] Manufacturer ID (meaningful if device_id = 0xFE or 0xFF) + * @param manuf_model_id [in] Manufacturer model ID (meaningful if device_id = 0xFE or 0xFF) + * @param ieee_addr [in] ZGPD long IEEE address if available, otherwise filled with zeroes + * + * @see zb_zgps_accept_commissioning + * @see ZB_IS_64BIT_ADDR_ZERO + */ +typedef void (ZB_CODE * zb_zgp_comm_req_cb_t)( + zb_zgpd_id_t *zgpd_id, + zb_uint8_t device_id, + zb_uint16_t manuf_id, + zb_uint16_t manuf_model_id, + zb_ieee_addr_t ieee_addr); + +/*! @} */ + +/** + @cond internals_doc + @addtogroup zgp_internal + @{ +*/ + +/** + * @brief Application confirm callback type + * + * Application confirm callback notifies application about data + * request attempt to ZGPD. Callback is called when data frame is sent + * to ZGPD. Callback provides to command ID and its status. Based on these + * parameters user application should decide further actions. + * + * Application confirm callback should be set during ZGP initialization using + * @ref ZB_ZGP_REGISTER_APP_CFM_CB macro. + * + * @param cmd_id [in] Command ID + * @param status [in] Confirmation status + * @param data_ptr [in] Pointer to data payload + * @param zgpd_id [in] ZGPD ID + * @param handle [in] ZGP handle + */ +typedef void (ZB_CODE * zb_zgp_app_cfm_cb_t)( + zb_uint8_t cmd_id, + zb_int16_t status, + zb_uint8_t *data_ptr, + zb_zgpd_id_t *zgpd_id, + zb_uint8_t handle); + +/*! @} */ +/*! @endcond */ + + +/** + @addtogroup zgp_sink + @{ +*/ + + /** + * @brief Application callback, indication of the attempted commissioning in GPS operational mode. + * + * Application commissioning indication callback notifies application about commissioning + * attempt from ZGPD. Callback is called when commissioning frame or notification is received + * from ZGPD. Callback provides to zgpd_id and full incoming packet's data. Based on these + * parameters user application should decide further actions. + * + * Application commissioning indication callback should be set during ZGP initialization using + * @ref ZB_ZGP_REGISTER_APP_CIC_CB macro. + * + * @param zgpd_id [in] ZGPD ID + * @param param [in] buffer index, containing GPDF + */ +typedef void (ZB_CODE * zb_zgp_app_comm_ind_cb_t)( + zb_zgpd_id_t *zgpd_id, + zb_uint8_t param); + + +/*! @} */ + +/** + @cond internal + @addtogroup zgp_internal + @{ +*/ + +#ifdef ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET +/** + * @brief Application search ZGP manufactured specific device callback + * + * Callback is called when sink table entry data is restored from old NVRAM version. + * + * Application search ZGP manufactured specific device callback + * should be set during ZGP initialization using + * @ref ZB_ZGP_REGISTER_APP_SEARCH_ZGP_DEVICE_CB macro. + * + * @param zgpd_id [in] ZGPD ID + * @param manuf_model_id [out] Manufacturer model ID + * @return RET_OK on success, RET_NOT_FOUND otherwise + */ +typedef zb_ret_t (ZB_CODE * zb_zgp_app_search_zgp_device_cb_t)( + zb_zgpd_id_t *zgpd_id, + zb_uint16_t *manuf_model_id); +#endif /* ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET */ + +/*! @} */ +/*! @endcond */ + +/** + @addtogroup zgp_sink + @{ +*/ + +/** + * @ingroup zgp_sink + * @brief Set matching information that is used to fill ZGP command - ZCL + * cluster translation table. + * @param [in] info Matching information of type @ref zb_zgps_match_info_t + */ +void zb_zgps_set_match_info(const zb_zgps_match_info_t *info); +#define ZB_ZGP_SET_MATCH_INFO(info) \ +{ \ + zb_zgps_set_match_info((info)); \ +} + +/** + * @ingroup zgp_sink + * @brief Register commissioning callback + * + * @note this is legacy API. Use ZB_ZGP_SIGNAL_COMMISSIONING signal passed to + * zboss_signal_handler instead! + * + * @param cb [in] Commissioning callback (@ref zb_zgp_comm_completed_cb_t) + * #define ZB_ZGP_REGISTER_COMM_COMPLETED_CB(cb) + */ + +/** + * @ingroup zgp_sink + * @brief Register commissioning request callback + * + * @param cb [in] Commissioning request callback (@ref zb_zgp_comm_req_cb_t) + * + * @snippet doxygen_snippets.dox accept_comm + */ +void zb_zgps_register_comm_req_cb(zb_zgp_comm_req_cb_t cb); +#define ZB_ZGP_REGISTER_COMM_REQ_CB(cb) \ +{ \ + zb_zgps_register_comm_req_cb((cb)); \ +} + +/** + * @ingroup zgp_sink + * @brief Register application commissioning indication callback + * + * @param cb [in] Application commissioning indication callback (@ref zb_zgp_app_comm_ind_cb_t) + */ +void zb_zgps_register_app_cic_cb(zb_zgp_app_comm_ind_cb_t cb); +#define ZB_ZGP_REGISTER_APP_CIC_CB(cb) \ +{ \ + zb_zgps_register_app_cic_cb((cb)); \ +} + +/*! @} */ +/** + @cond internals_doc + @addtogroup zgp_internal + @{ +*/ + +/** + * @brief Register application confirm callback + * + * @param cb [in] Application confirm callback (@ref zb_zgp_app_cfm_cb_t) + */ +void zb_zgps_register_app_cfm_cb(zb_zgp_app_cfm_cb_t cb); +#define ZB_ZGP_REGISTER_APP_CFM_CB(cb) \ +{ \ + zb_zgps_register_app_cfm_cb((cb)); \ +} + +#ifdef ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET +/** + * @brief Register application search ZGP manufactured specific device callback + * + * @param cb [in] Application search ZGP manufactured specific device callback (@ref zb_zgp_app_search_zgp_device_cb_t) + */ +void zb_zgps_register_app_search_zgp_device_cb(zb_zgp_app_search_zgp_device_cb_t cb); +#define ZB_ZGP_REGISTER_APP_SEARCH_ZGP_DEVICE_CB(cb) \ +{ \ + zb_zgps_register_app_search_zgp_device_cb((cb)); \ +} +#endif /* ZB_ENABLE_ZGP_MIGRATE_OLD_SINK_DATASET */ + +/*! @} */ +/*! @endcond */ + +/** + @addtogroup zgp_common + @{ +*/ +#endif /* ZB_ENABLE_ZGP_SINK */ + +/********************************************************************/ +/********************* GPDF command IDs *****************************/ +/********************************************************************/ + +/** + * @brief Command identifiers sent from or to ZGPD */ +enum zb_zgpd_cmd_id_e +{ + ZB_GPDF_CMD_RECALL_SCENE0 = 0x10, + ZB_GPDF_CMD_RECALL_SCENE1 = 0x11, + ZB_GPDF_CMD_RECALL_SCENE2 = 0x12, + ZB_GPDF_CMD_RECALL_SCENE3 = 0x13, + ZB_GPDF_CMD_RECALL_SCENE4 = 0x14, + ZB_GPDF_CMD_RECALL_SCENE5 = 0x15, + ZB_GPDF_CMD_RECALL_SCENE6 = 0x16, + ZB_GPDF_CMD_RECALL_SCENE7 = 0x17, + /* @note recall scene 8-11 are got from LCGW. But GPPB specification + * does not define recall scenes 8-11. Only 8 scenes are + * supported. See Table 49 Payloadless GPDF commands 6236 sent by + * GPD */ + ZB_GPDF_CMD_RECALL_SCENE8 = 0x18, + ZB_GPDF_CMD_RECALL_SCENE9 = 0x19, + ZB_GPDF_CMD_RECALL_SCENE10 = 0x1A, + ZB_GPDF_CMD_RECALL_SCENE11 = 0x1B, +#define ZB_GPDF_CMD_STORE_SCENE0 ZB_GPDF_CMD_RECALL_SCENE8 +#define ZB_GPDF_CMD_STORE_SCENE1 ZB_GPDF_CMD_RECALL_SCENE9 +#define ZB_GPDF_CMD_STORE_SCENE2 ZB_GPDF_CMD_RECALL_SCENE10 +#define ZB_GPDF_CMD_STORE_SCENE3 ZB_GPDF_CMD_RECALL_SCENE11 + ZB_GPDF_CMD_STORE_SCENE4 = 0x1C, + ZB_GPDF_CMD_STORE_SCENE5 = 0x1D, + ZB_GPDF_CMD_STORE_SCENE6 = 0x1E, + ZB_GPDF_CMD_STORE_SCENE7 = 0x1F, + /* on/off */ + ZB_GPDF_CMD_OFF = 0x20, + ZB_GPDF_CMD_ON = 0x21, + ZB_GPDF_CMD_TOGGLE = 0x22, + /* level control */ + ZB_GPDF_CMD_MOVE_UP = 0x30, + ZB_GPDF_CMD_MOVE_DOWN = 0x31, + ZB_GPDF_CMD_STEP_UP = 0x32, + ZB_GPDF_CMD_STEP_DOWN = 0x33, + ZB_GPDF_CMD_LC_STOP = 0x34, +#define ZB_GPDF_CMD_LVL_CTRL_STOP ZB_GPDF_CMD_LC_STOP + ZB_GPDF_CMD_MOVE_UP_W_ONOFF = 0x35, +#define ZB_GPDF_CMD_MOVE_UP_WITH_ON_OFF ZB_GPDF_CMD_MOVE_UP_W_ONOFF + ZB_GPDF_CMD_MOVE_DOWN_W_ONOFF = 0x36, +#define ZB_GPDF_CMD_MOVE_DOWN_WITH_ON_OFF ZB_GPDF_CMD_MOVE_DOWN_W_ONOFF + ZB_GPDF_CMD_STEP_UP_W_ONOFF = 0x37, +#define ZB_GPDF_CMD_MOVE_STEP_ON ZB_GPDF_CMD_STEP_UP_W_ONOFF + ZB_GPDF_CMD_STEP_DOWN_W_ONOFF = 0x38, +#define ZB_GPDF_CMD_MOVE_STEP_OFF ZB_GPDF_CMD_STEP_DOWN_W_ONOFF + /* Color Control */ + ZB_GPDF_CMD_MOVE_HUE_STOP = 0x40, + ZB_GPDF_CMD_MOVE_HUE_UP = 0x41, + ZB_GPDF_CMD_MOVE_HUE_DOWN = 0x42, + ZB_GPDF_CMD_STEP_HUE_UP = 0x43, + ZB_GPDF_CMD_STEP_HUE_DOWN = 0x44, + ZB_GPDF_CMD_MOVE_SATURATION_STOP = 0x45, + ZB_GPDF_CMD_MOVE_SATURATION_UP = 0x46, + ZB_GPDF_CMD_MOVE_SATURATION_DOWN = 0x47, + ZB_GPDF_CMD_STEP_SATURATION_UP = 0x48, + ZB_GPDF_CMD_STEP_SATURATION_DOWN = 0x49, + ZB_GPDF_CMD_MOVE_COLOR = 0x4A, + ZB_GPDF_CMD_STEP_COLOR = 0x4B, + /* Simple Generic Switch */ + ZB_GPDF_CMD_PRESS_1_OF_1 = 0x60, + ZB_GPDF_CMD_RELEASE_1_OF_1 = 0x61, + ZB_GPDF_CMD_PRESS_1_OF_2 = 0x62, + ZB_GPDF_CMD_RELEASE_1_OF_2 = 0X63, + + ZB_GPDF_CMD_ATTR_REPORT = 0xA0, + ZB_GPDF_CMD_MANUF_SPEC_ATTR_REPORT = 0xA1, + ZB_GPDF_CMD_MULTI_CLUSTER_ATTR_REPORT = 0xA2, + ZB_GPDF_CMD_MANUF_SPEC_MULTI_CLUSTER_ATTR_REPORT = 0xA3, + ZB_GPDF_CMD_REQUEST_ATTRIBUTES = 0xA4, + ZB_GPDF_CMD_READ_ATTR_RESP = 0xA5, + + ZB_GPDF_CMD_ZCL_TUNNELING_FROM_ZGPD = 0xA6, + + /* Manufacturer-defined GPD commands (payload is manufacturer-specific) */ + ZB_GPDF_CMD_MANUF_DEFINED_B0 = 0xB0, + ZB_GPDF_CMD_MANUF_DEFINED_BF = 0xBF, + /* commissioning from ZGPD */ + ZB_GPDF_CMD_COMMISSIONING = 0xE0, + ZB_GPDF_CMD_DECOMMISSIONING = 0xE1, + ZB_GPDF_CMD_SUCCESS = 0xE2, + ZB_GPDF_CMD_CHANNEL_REQUEST = 0xE3, + + /* GPDF commands sent to GPD */ + ZB_GPDF_CMD_COMMISSIONING_REPLY = 0xF0, + ZB_GPDF_CMD_WRITE_ATTRIBUTES = 0xF1, + ZB_GPDF_CMD_READ_ATTRIBUTES = 0xF2, + ZB_GPDF_CMD_CHANNEL_CONFIGURATION = 0xF3, + + ZB_GPDF_CMD_ZCL_TUNNELING_TO_ZGPD = 0xF6, +}; + +/*! @} */ + +/********************************************************************/ +/**************** Macros for sending GPDF packets *******************/ +/********************************************************************/ + +/** + @cond internal + @addtogroup zgp_internal + @{ +*/ + + +/** + * @brief Start constructing GPDF packet + * + * @param [in] zbbuf Buffer for GPDF packet + */ +#define ZB_START_GPDF_PACKET(zbbuf) \ + zb_buf_reuse(zbbuf) + +/** + * @brief Put 1 byte into GPDF packet + * + * @param ptr [in] Destination memory address, where val should be copied + * @param val [in] Pointer to 1-byte value to be put in packet + */ +#define ZB_GPDF_PUT_UINT8(ptr, val) \ + ( *(ptr) = (val), (ptr)++ ) + +/** + * @brief Put 2 bytes into GPDF packet + * + * @param ptr [in] Destination memory address, where val should be copied + * @param val [in] Pointer to 2-byte value to be put in packet + */ +#define ZB_GPDF_PUT_UINT16(ptr, val) \ + ( ZB_HTOLE16((ptr), (val)), (ptr) += 2 ) + + +/** + * @brief Put 4 bytes into GPDF packet + * + * @param ptr [in] Destination memory address, where val should be copied + * @param val [in] Pointer to 4-byte value to be put in packet + */ +#define ZB_GPDF_PUT_UINT32(ptr, val) \ + ( ZB_HTOLE32((ptr), (val)), (ptr) += 4 ) + + +/** + * @brief Finish constructing GPDF frame + * + * @param zbbuf [in] Buffer with GPDF + * @param ptr [in] Pointer to the GPDF tail + */ +void zb_finish_gpdf_packet(zb_bufid_t buf_ref, zb_uint8_t** ptr); +#define ZB_FINISH_GPDF_PACKET(zbbuf, ptr) zb_finish_gpdf_packet(zbbuf, &ptr) + + +/** + * @brief RX channel in the next attempt parameter of ZGPD Channel request command + * @see ZGP spec, A.4.2.1.4 + */ +#define ZB_GPDF_CHANNEL_REQ_NEXT_RX_CHANNEL(par) \ + ((par) & 0x0F) + +/** + * @brief ZGPD Commissioning command parameters + * @see ZGP spec, A.4.2.1.1 + */ +typedef struct zb_gpdf_comm_params_s +{ + zb_uint8_t zgpd_device_id; /**< ZGPD Device ID */ + zb_uint8_t options; /**< Options */ + zb_uint8_t ext_options; /**< Extended options */ + zb_uint8_t ms_extensions; /**< MS extensions */ + zb_uint16_t manuf_model_id; /**< Manufacturer model ID */ + zb_uint16_t manuf_id; /**< Manufacturer ID */ + /* TODO: Add fields "Number of GP commands", "GP command ID list", + * "Number of cluster reports", "ClusterReportN" */ +} +zb_gpdf_comm_params_t; + +/** + * @brief ZGPD Commissioning reply parameters + * @see ZGP spec, A.4.2.1.1 + */ +typedef struct zb_gpdf_comm_reply_s +{ + zb_uint8_t options; /**< Options */ + zb_uint16_t pan_id; /**< Pan ID if requested */ + zb_uint8_t security_key[ZB_CCM_KEY_SIZE]; /**< ZGPD key */ + zb_uint8_t key_mic[ZB_CCM_M]; /**< ZGPD key MIC */ + zb_uint32_t frame_counter; /**< ZGPD key encryption counter */ +} +zb_gpdf_comm_reply_t; + +#define ZB_GPDF_COMM_REPLY_PAN_ID_PRESENT(options) ((options) & 0x01) +#define ZB_GPDF_COMM_REPLY_SEC_KEY_PRESENT(options) (((options) >> 1) & 0x01) +#define ZB_GPDF_COMM_REPLY_SEC_KEY_ENCRYPTED(options) (((options) >> 2) & 0x01) +#define ZB_GPDF_COMM_REPLY_SEC_LEVEL(options) (((options) >> 3) & 0x03) +#define ZB_GPDF_COMM_REPLY_SEC_KEY_TYPE(options) (((options) >> 5) & 0x07) + +/** + * @brief Construct options field of commissioning command from given values + * @see ZGP spec, A.4.2.1.1.2 + */ +#define ZB_GPDF_COMM_OPT_FLD(sn_cap, rx_cap, ms_ext, pan_id_req, \ + sec_key_req, fixed_loc, ext_opt) \ + ( (sn_cap) \ + | ((rx_cap) << 1) \ + | ((ms_ext) << 2) \ + | ((pan_id_req) << 4) \ + | ((sec_key_req) << 5) \ + | ((fixed_loc) << 6) \ + | ((ext_opt) << 7) ) + +/** + * @brief Value of Extended Options bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_EXT_OPT_PRESENT(options) \ + ((options) >> 7) + +/** + * @brief Value of GP security Key request bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_SEC_KEY_REQ(options) \ + (((options) >> 5) & 0x01) + +/** + * @brief Value of Pan ID request bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_PAN_ID_REQ(options) \ + (((options) >> 4) & 0x01) + +/** + * @brief Value of MAC sequence number capability bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_SEQ_NUM_CAPS(options) \ + ((options) & 0x01) + +/** + * @brief Value of RxOnCapability bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_RX_CAPABILITY(options) \ + (((options) >> 1) & 0x01) + +/** + * @brief Value of Fixed location bit in + * options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_FIX_LOC(options) \ + (((options) >> 6) & 0x01) + +/** + * @brief Value of GPD MS extensions present bit in + * Options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_MS_EXT_PRESENT(options) \ + (((options) >> 2) & 0x01) + +/** + * @brief Construct Extended Options field of commissioning command + * @see ZGP spec, A.4.2.1.1.3 + */ +#define ZB_GPDF_COMM_EXT_OPT_FLD(sec_cap, key_type, key_present, \ + key_enc, out_counter) \ + ( (sec_cap) \ + | ((key_type) << 2) \ + | ((key_present) << 5) \ + | ((key_enc) << 6) \ + | ((out_counter) << 7)) + +/** + * @brief Value of GPD Key present bit in + * Extended options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_ZGPD_KEY_PRESENT(ext_options) \ + (((ext_options) >> 5) & 0x01) + +/** + * @brief Value of GPD Key encryption bit in + * Extended options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_ZGPD_KEY_ENCRYPTED(ext_options) \ + (((ext_options) >> 6) & 0x01) + +/** + * @brief Value of GPD outgoing counter present bit in + * Extended options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_ZGPD_OUT_COUNTER_PRESENT(ext_options) \ + ((ext_options) >> 7) + +/** + * @brief Value of SecurityLevel capabilities bits in + * Extended options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_SEC_LEVEL_CAPS(ext_options) \ + ((ext_options) & 0x03) + +/** + * @brief Value of SecurityKey type bits in + * Extended options field of commissioning command + */ +#define ZB_GPDF_COMM_OPT_SEC_KEY_TYPE(ext_options) \ + ((ext_options >> 2) & 0x07) + +/** + * @brief Construct MS extensions field of commissioning command + * @see docs-13-0146-04-batt-green-powermanufacturer-specific-device-type-command.docx + */ +#define ZB_GPDF_COMM_MS_EXT_FLD(_manuf_id, _manuf_model_id, _gp_cmd_list, _clstr_reports) \ + ( (_manuf_id) \ + | ((_manuf_model_id) << 1) \ + | ((_gp_cmd_list) << 2) \ + | ((_clstr_reports) << 3)) + +/** + * @brief Value of "ManufacturerID present" bit in + * MS extensions field of commissioning command + */ +#define ZB_GPDF_COMM_MSEXT_MANUF_ID_PRESENT(ms_ext) \ + ((ms_ext) & 0x01) + +/** + * @brief Value of "Manufacturer ModelID present" bit in + * MS extensions field of commissioning command + */ +#define ZB_GPDF_COMM_MSEXT_MODEL_ID_PRESENT(ms_ext) \ + ((ms_ext >> 1) & 0x01) + +/** + * @brief Construct Options field of commissioning reply command + * @see ZGP spec, A.4.2.1.2.1 + */ +#define ZB_GPDF_COMM_REPLY_OPT_FLD(pan_id_present, key_present, \ + key_enc, sec_level, key_type) \ + ( (pan_id_present) \ + | ((key_present) << 1) \ + | ((key_enc) << 2) \ + | ((sec_level) << 3) \ + | ((key_type) << 5)) + +/** @} */ +/*! @endcond */ + + +/** + @cond internals_doc + @addtogroup zgp_internal + @{ +*/ + +/** + * @brief Send commissioning GPDF with ZGPD securityLevel capabilities set to 0 + */ +#define ZB_SEND_COMMISSIONING_GPDF_WITHOUT_SEC(buf, device_id, sn_cap, rx_cap) \ +{ \ + zb_uint8_t* ptr = (zb_uint8_t*)ZB_START_GPDF_PACKET(buf); \ + (void)zb_buf_alloc_left(buf, 3, ptr); \ + ZB_GPDF_PUT_UINT8(ptr, ZB_GPDF_CMD_COMMISSIONING); \ + ZB_GPDF_PUT_UINT8(ptr, device_id); \ + ZB_GPDF_PUT_UINT8(ptr, ZB_GPDF_COMM_OPT_FLD(sn_cap, rx_cap, 0, 0, 0, 0, 0)); \ + ZB_SEND_GPDF_CMD(ZB_REF_FROM_BUF(buf)); \ +} + +/** + * @brief Attribute report field of attribute reporting command + * @see ZGP spec, A.4.2.3.1 + */ +typedef struct zb_gpdf_attr_report_fld_s +{ + zb_uint16_t attr_id; /**< Attribute ID specific to cluster */ + zb_uint8_t attr_type; /**< Attribute type (see @ref zb_zcl_attr_type_t) */ + zb_voidp_t data_p; /**< Attribute data */ +} +zb_gpdf_attr_report_fld_t; + +/** + * @brief Start constructing ZGPD attribute reporting command + * + * @param buf [in] Buffer for GPDF command + * @param cluster_id [in] Cluster ID of attributes being reported + * @param ptr [out] Pointer to the current tail of GPDF + */ +#define ZB_ZGPD_ATTR_REPORTING_CMD_INIT(buf, cluster_id, ptr) \ +{ \ + ptr = ZB_START_GPDF_PACKET(buf); \ + ZB_GPDF_PUT_UINT8(ptr, ZB_GPDF_CMD_ATTR_REPORT); \ + ZB_GPDF_PUT_UINT16(ptr, &cluster_id); \ +} + +/** + * @brief Put attribute report field into attribute reporting command + * + * Macro should be called only after attribute reporting command is + * initialized with @ref ZB_ZGPD_ATTR_REPORTING_CMD_INIT + * @param ptr [in,out] Pointer to the tail of attribute reporting command + * @param attr [in] Attribute report field (see @zb_gpdf_attr_report_fld_t) + */ +#define ZB_ZGPD_ATTR_REPORTING_CMD_NEXT(ptr, attr) \ +{ \ + ZB_GPDF_PUT_UINT16(ptr, &attr.attr_id); \ + ZB_GPDF_PUT_UINT8(ptr, attr.attr_type); \ + ptr = zb_zcl_put_value_to_packet(ptr, attr.attr_type, (zb_uint8_t *)attr.data_p); \ +} + +/** + * @brief Finish constructing ZGPD attribute reporting command + * + * @param buf [in] Buffer for GPDF command + * @param ptr [in] Pointer to the tail of GPDF + */ +#define ZB_ZGPD_ATTR_REPORTING_CMD_FINISH(buf, ptr) \ +{ \ + ZB_FINISH_GPDF_PACKET(buf, ptr); \ +} + +/** + * @brief Value of multi-record bit of options field + * in ZGPD Request attributes or Write attributes command + * (ZGP spec, rev. 26 A.4.2.6.1) + */ +#define ZB_GPDF_REQUEST_ATTR_IS_MULTI_RECORD(opts) \ + (opts & 0x01) + +/** + * @brief Value of multi-record bit of options field + * in ZGPD Write attributes command + * (ZGP spec, rev. 26 A.4.2.6.1) + */ +#define ZB_GPDF_WRITE_ATTR_IS_MULTI_RECORD \ + ZB_GPDF_REQUEST_ATTR_IS_MULTI_RECORD + +/** + * @brief Value of "manufacturer field present" bit of options field + * in ZGPD Request attributes command + * (ZGP spec, rev. 26 A.4.2.6.1) + */ +#define ZB_GPDF_REQUEST_ATTR_MANUF_FIELD_PRESENT(opts) \ + ((opts >> 1) & 0x01) + +/** + * @brief Value of "manufacturer field present" bit of options field + * in ZGPD Write attributes command + * (ZGP spec, rev. 26 A.4.2.6.1) + */ +#define ZB_GPDF_WRITE_ATTR_MANUF_FIELD_PRESENT \ + ZB_GPDF_REQUEST_ATTR_MANUF_FIELD_PRESENT + +/** + * @brief Construct value of options field + * in ZGPD Request attributes or Write attributes command + * (ZGP spec, rev. 26 A.4.2.6.1) + */ +#define ZB_GPDF_REQUEST_ATTR_OPTIONS_FLD(multi_record, manuf_present) \ + ((multi_record) | (manuf_present << 1)) + +/** + * @brief Construct value of options field + * in ZGPD Write attributes command + * (ZGP spec, rev. 26 A.4.2.6.3) + */ +#define ZB_GPDF_WRITE_ATTR_OPTIONS_FLD \ + ZB_GPDF_REQUEST_ATTR_OPTIONS_FLD + +/** + * @brief Parse one Cluster Record request field of + * ZGPD Request attributes command + * @param rec pointer to record to parse of type zb_uint8_t* + * @param cluster_id Cluster ID (out) + * @param attr_count Attribute count (out) + * @param attrs Pointer to attributes list (out) + */ +#define ZB_GPDF_REQUEST_ATTR_PARSE_RECORD(rec, cluster_id, attr_count, attrs) \ +{ \ + ZB_LETOH16((cluster_id), (rec)); \ + *(attr_count) = (rec)[2]/sizeof(zb_uint16_t); \ + *(attrs) = (zb_uint16_t *)ZB_SAFE_PTR_CAST(&(rec)[3]); \ +} + +/** + * @brief Start constructing ZGP write attribute command + * + * @param buf [in] Buffer for GPDF command + * @param cluster_id [in] Cluster ID of attributes being reported + * @param ptr [out] Pointer to the current tail of GPDF + */ +#define ZB_ZGPD_WRITE_ATTR_CMD_INIT(buf, ptr) \ +{ \ + ptr = ZB_START_GPDF_PACKET(buf); \ + ZB_GPDF_PUT_UINT8(ptr, ZB_GPDF_WRITE_ATTR_OPTIONS_FLD(0,0)); \ +} + +/** + * @brief Start constructing ZGP write attribute command + * + * @param buf [in] Buffer for GPDF command + * @param manuf_id [in] Manufacturer ID + * @param ptr [out] Pointer to the current tail of GPDF + */ +#define ZB_ZGPD_WRITE_ATTR_MANUF_CMD_INIT(buf, manuf_id, ptr) \ +{ \ + ptr = ZB_START_GPDF_PACKET(buf); \ + ZB_GPDF_PUT_UINT8(ptr, ZB_GPDF_WRITE_ATTR_OPTIONS_FLD(0,1)); \ + ZB_GPDF_PUT_UINT16(ptr, &(manuf_id)); \ +} + +/** + * @brief Start cluster record field in write attributes command + * + * Macro should be called only after write attributes command is + * initialized with @ref ZB_ZGPD_WRITE_ATTR_MANUF_CMD_INIT or + * @ref ZB_ZGPD_WRITE_ATTR_CMD_INIT + * @param ptr [in,out] Pointer to the tail of write attributes command + * @param cluster_id [in] Cluster ID + * @param record_list_len [in] Length in bytes of following Write Attribute Records list + */ +#define ZB_ZGPD_WRITE_ATTR_NEW_CLUSTER_RECORD(ptr, cluster_id, record_list_len) \ +{ \ + ZB_GPDF_PUT_UINT16(ptr, &cluster_id); \ + ZB_GPDF_PUT_UINT8(ptr, (record_list_len)); \ +} + +/** + * @brief Put write attribute record into write attributes command + * + * Macro should be called only after new cluster record is + * initialized with @ref ZB_ZGPD_WRITE_ATTR_NEXT_CLUSTER_RECORD + * @param ptr [in,out] Pointer to the tail of write attributes command + * @param attr_id [in] Attribute ID + * @param attr_type [in] Attribute type + * @param value [in] Pointer to attribute value + */ +#define ZB_ZGPD_WRITE_ATTR_CMD_NEXT_ATTR(ptr, attr_id, attr_type, value) \ +{ \ + ZB_GPDF_PUT_UINT16(ptr, &attr_id); \ + ZB_GPDF_PUT_UINT8(ptr, attr_type); \ + ptr = zb_zcl_put_value_to_packet(ptr, attr_type, (zb_uint8_t *)(value)); \ +} + +/** + * @brief Finish constructing ZGPD write attributes command + * + * @param buf [in] Buffer for GPDF command + * @param ptr [in] Pointer to the tail of GPDF + */ +#define ZB_ZGPD_WRITE_ATTR_CMD_FINISH(buf, ptr) \ +{ \ + ZB_FINISH_GPDF_PACKET(buf, ptr); \ +} + +/* [AV] tmm it'll be better to name macros like this once + and don't rename them like #def macro_write_init(...) macro_read_init(...), + because there is no difference +*/ +#define ZB_ZGPD_CLUSTER_CMD_INIT(_buf, _ptr) \ + ZB_ZGPD_WRITE_ATTR_CMD_INIT(_buf, _ptr) +#define ZB_ZGPD_CLUSTER_CMD_MANUF_INIT(_buf, _manuf_id, _ptr) \ + ZB_ZGPD_WRITE_ATTR_MANUF_CMD_INIT(_buf, _manuf_id, _ptr) +#define ZB_ZGPD_NEW_CLUSTER_RECORD(_ptr, _cluster_id, _record_list_len) \ + ZB_ZGPD_WRITE_ATTR_NEW_CLUSTER_RECORD(_ptr, _cluster_id, _record_list_len) +#define ZB_ZGPD_READ_ATTR_CMD_NEXT_ATTR(_ptr, _attr_id) \ +{ \ + ZB_GPDF_PUT_UINT16(_ptr, &_attr_id); \ +} +#define ZB_ZGPD_CLUSTER_CMD_FINISH(_buf, _ptr) \ +{ \ + ZB_FINISH_GPDF_PACKET(_buf, _ptr); \ +} + +#ifdef ZB_ENABLE_ZGP_DIRECT +typedef struct zb_zgps_send_cmd_params_s +{ + zb_uint8_t cmd_id; + zb_zgpd_id_t zgpd_id; + zb_ieee_addr_t ieee_addr; + zb_time_t lifetime; + zb_uint8_t tx_options; + zb_uint8_t handle; +} +zb_zgps_send_cmd_params_t; + +/** + * @brief Send provided packet to ZGPD + * + * Buffer data is command payload to send. + * Other parameters are in the buffer tail (see @ref zb_zgps_send_cmd_params_t). + * + * @param param[in, out] Reference to buffer. + * + * @note maximum length of data payload is @ref ZB_ZGP_TX_CMD_PLD_MAX_SIZE + * + * @note zb_gp_data_cfm is called from: + * - gp_data_req_send_cnf to notify about status of adding data to tx_packet_info_queue; + * - notify_about_expired_entry to notify about expired entry; + * - zb_cgp_data_cfm to notify about status from MAC layer. + * + * @note Status of confirm (ZGP TX queue is used) can be: + * ZB_ZGP_STATUS_ENTRY_REPLACED + * ZB_ZGP_STATUS_ENTRY_ADDED + * ZB_ZGP_STATUS_ENTRY_EXPIRED + * ZB_ZGP_STATUS_ENTRY_REMOVED + * ZB_ZGP_STATUS_TX_QUEUE_FULL + * + * MAC_SUCCESS + * + * @note Status of confirm (ZGP TX queue is not used) can be: + * ZB_ZGP_STATUS_TX_QUEUE_FULL + * + * MAC_SUCCESS + * MAC_NO_ACK + * + */ +void zb_zgps_send_data(zb_uint8_t param); +#endif /* ZB_ENABLE_ZGP_DIRECT */ +/*! @} + * @endcond */ + +/** + @addtogroup zgp_sink + @{ +*/ + +/** + * @brief Put ZGPS into commissioning mode + * + * It is safe to call this function when device is already in + * commissioning mode. In this case function does nothing. + * + * @param timeout [in] Maximum commissioning time in beacon intervals. \n + * 0 means no timeout. \n + * If timeout occurs, then result of commissioning is + * @ref ZB_ZGP_COMMISSIONING_TIMED_OUT + * + * @snippet light_sample/light_coordinator_combo/light_zc.c zgps_start_comm + */ +void zb_zgps_start_commissioning(zb_time_t timeout); + +/** + * @brief Switch ZGPS back to operational mode from commissioning + * + * After commissioning is cancelled, user is notified with + * @ref zb_zgp_comm_completed_cb_t with ZB_ZGP_COMMISSIONING_CANCELLED_BY_USER + * status. + * + * @snippet light_sample/light_coordinator_combo/light_zc.c zgps_stop_comm + */ +void zb_zgps_stop_commissioning(void); + +/** + * @brief Accept/reject ZGPD commissioning attempt + * + * This function should be called as an answer to commissioning request made by + * stack via @ref zb_zgp_comm_req_cb_t. Also, it can be called from @ref + * zb_zgp_comm_req_cb_t callback as well as outside it. + * + * @param[in] accept - If ZB_TRUE, then stack will continue ongoing commissioning + * process with ZGPD \n + * Otherwise ongoing commissioning process will be + * terminated + * @snippet tests/zgp/gppb/test_gps_decommissioning/dut_gps.c accept_comm + */ +void zb_zgps_accept_commissioning(zb_bool_t accept); + +/** + * @brief Remove all the information about ZGPD from stack + * + * In ZGP there is no way to say ZGPD to leave the network. + * ZGPD can leave network by itself using "Decommissioning" command, + * but ZGPS can miss this command if it was not in commissioning state. + * + * This function removes all the information related to specified ZGPD + * from stack. + * + * @param buf_ref reference to the free buffer + * @param zgpd_id identifier of ZGPD to be removed + * + * @note It is safe to free or overwrite memory pointed by zgpd_id + * after call + */ +void zb_zgps_delete_zgpd(zb_uint8_t buf_ref, zb_zgpd_id_t *zgpd_id); + +/** + * @brief Remove all the information about ALL ZGPD from stack + * + */ +void zb_zgps_delete_all_zgpd(void); + +/** + Get LQI and RSSI last time received from that ZGPD. + */ +void zb_zgps_get_diag_data(zb_zgpd_id_t *zgpd_id, zb_uint8_t *lqi, zb_int8_t *rssi); + +/*! @} */ + +/** + @addtogroup zgp_sink + @{ +*/ + +/** + Fill security level constant to be passed to zb_zgps_set_security_level() + + Described in A.3.3.2.6 gpsSecurityLevel attribute. + + @param sec_lvl @ref zb_zgp_security_level_e Minimal GPD Security Level sub-field contains the minimum gpdSecurityLevel this sink accepts + @param with_link_key 1 bit - Protection with the gpLinkKey sub-field, indicates if + the GPDs attempting the pairing are required to support protecting the + over-the-air exchange of the GPD Key + @param involve_tc always zero for the current GPPB specification + + @snippet light_sample/light_coordinator_combo/light_zc.c zgps_set_secur_level + */ +#define ZB_ZGP_FILL_GPS_SECURITY_LEVEL(sec_lvl, with_link_key, involve_tc)\ + (((sec_lvl) & 3) | ((!!(with_link_key)) << 2) | ((!!(involve_tc)) << 3)) + + +/** + Set gpsSecurityLevel GP cluster attribute of gpcb + + Described in A.3.3.2.6 gpsSecurityLevel attribute. + + @param level Security level to set + + @snippet light_sample/light_coordinator_combo/light_zc.c zgps_set_secur_level + */ +void zb_zgps_set_security_level(zb_uint_t level); + +/** + Set gpSharedSecurityKeyType GP cluster attribute + + Described in A.3.3.3.1 gpSharedSecurityKeyType attribute. + + @param key_type Security key type to set (@see zb_zgp_security_key_type_e) + */ +void zb_zgp_set_shared_security_key_type(zb_uint_t key_type); + +/** + Set gpSharedSecurityKey GP cluster attribute + + Described in A.3.3.3.1 gpSharedSecurityKey attribute. + + @param key Security key to set + */ +void zb_zgp_set_shared_security_key(zb_uint8_t *key); + +/** + Set gpsCommissioningExitMode GP cluster attribute + + Described in A.3.3.2.4 gpsCommissioningExitMode attribute. + + @param cem Commissioning exit mode to set (@see zgp_commissioning_exit_mode_t) + */ +void zb_zgps_set_commissioning_exit_mode(zb_uint_t cem); + +/** + Set gpsCommunicationMode GP cluster attribute of gpcb + + Described in A.3.3.2.3 gpsCommunicationMode attribute + + @param mode @ref zgp_communication_mode_t communication mode + + @snippet light_sample/light_coordinator_combo/light_zc.c set_comm_mode + */ +void zb_zgps_set_communication_mode(zgp_communication_mode_t mode); + +#ifdef ZB_ENABLE_ZGP_DIRECT +/** + Set ZBOSS to skip all incoming GPDF. + + To be used for testing only. + Use that function with ZB_TRUE parameter to prevent Combo device from + receiving GPDFS thus always working thru Proxy device. + + @param skip if ZB_TRUE, skip incoming GP frames + */ +void zb_zgp_set_skip_gpfd(zb_bool_t skip); + +#endif /* ZB_ENABLE_ZGP_DIRECT */ + +/*! @} */ + +#ifndef ZB_ZGPD_ROLE + +typedef enum zgp_proxy_comm_mode_action_e +{ + ZGP_PROXY_COMM_MODE_LEAVE, + ZGP_PROXY_COMM_MODE_ENTER +} zgp_proxy_comm_mode_action_t; + +typedef enum zgp_proxy_comm_mode_ch_present_e +{ + ZGP_PROXY_COMM_MODE_CHANNEL_PRESENT, + ZGP_PROXY_COMM_MODE_CHANNEL_NOT_PRESENT +} zgp_proxy_comm_mode_ch_present_t; + +typedef enum zgp_proxy_comm_mode_communication_e +{ + ZGP_PROXY_COMM_MODE_BROADCAST, + ZGP_PROXY_COMM_MODE_UNICAST +} zgp_proxy_comm_mode_communication_t; + +/** + * @brief Setup options for zb_zgp_cluster_proxy_commissioning_mode_req() + * + * @param action [in] enter/exit (see @ref zgp_proxy_comm_mode_action_t) + * @param exit_mode [in] exit mode (see @ref zgp_commissioning_exit_mode_t) + * @param ch_present [in] is channel present (see @ref zgp_proxy_comm_mode_ch_present_t) + * @param communication [in] communication type (see @ref zgp_proxy_comm_mode_communication_t) + */ +#define ZB_ZGP_FILL_PROXY_COMM_MODE_OPTIONS(action, exit_mode, ch_present, communication) \ + ((!!(action)) | (((exit_mode) & 7) << 1) | ((!!(ch_present)) << 4) | (((communication)&3) << 5)) + +/** + * @brief Perform Proxy Commissioning mode request + * + * @param param [in] Buffer reference + * @param options [in] Request options (see @ref ZB_ZGP_FILL_PROXY_COMM_MODE_OPTIONS) + * @param comm_wind [in] Commissioning window + * @param channel [in] Channel where perform commissioning (0x0b for channel 11) + * @param cb [in] Callback call if needed after send request + * + * @see ZGP spec, A.3.3.5.3 +*/ +void zb_zgp_cluster_proxy_commissioning_mode_req(zb_uint8_t param, + zb_uint8_t options, + zb_uint16_t comm_wind, + zb_uint8_t channel, + zb_callback_t cb); + +/** + * @brief Perform Proxy Commissioning mode enter request + * + * @param param [in] Buffer reference + * @param exit_mode [in] exit mode (see @ref zgp_commissioning_exit_mode_t) + * @param comm_wind [in] Commissioning window + * @param cb [in] Callback call if needed after send request + * + * @see ZGP spec, A.3.3.5.3 + */ +void zgp_cluster_send_proxy_commissioning_mode_enter_req(zb_uint8_t param, + zb_uint8_t exit_mode, + zb_uint16_t comm_window, + zb_callback_t cb); + +/** + * @brief Perform Proxy Commissioning mode leave request + * + * @param param [in] Buffer reference + * @param cb [in] Callback call if needed after send request + * + * @see ZGP spec, A.3.3.5.3 + */ +void zgp_cluster_send_proxy_commissioning_mode_leave_req(zb_uint8_t param, zb_callback_t cb); + +/** + * @brief Setup options for zb_zgp_cluster_gp_pairing_req() + * + * @param app_id [in] ZGPD application id (@see zb_zgp_app_id_t) + * @param add_sink [in] Add sink flag + * @param remove_gpd [in] Remove GPD flag + * @param comm_mode [in] Communication mode (@see zgp_communication_mode_t) + * @param gpd_fixed [in] ZGPD is fixed + * @param gpd_mac_sec_num_cap [in] MAC sequence number capability + * @param sec_lvl [in] SecurityLevel (@see zb_zgp_security_level_e) + * @param sec_key_type [in] SecurityKeyType (@see zb_zgp_security_key_type_e) + * @param gpd_sec_key_prsnt [in] Is key presented + * @param assigned_alias_prsnt [in] Is assigned alias presented + * @param frwrd_radius_prsnt [in] Is radius in the groupcast forwarding presented + * + * @see ZGP spec, A.3.3.5.2 + */ +#define ZB_ZGP_FILL_GP_PAIRING_OPTIONS(app_id, add_sink, remove_gpd, comm_mode,\ + gpd_fixed, gpd_mac_sec_num_cap, sec_lvl,\ + sec_key_type, frame_cnt_prsnt,\ + gpd_sec_key_prsnt, assigned_alias_prsnt, \ + frwrd_radius_prsnt)\ + (((app_id) & 7) | ((!!(add_sink)) << 3) | ((!!(remove_gpd)) << 4) | (((comm_mode) & 3) << 5) | (((!!(add_sink)) ? (!!(gpd_fixed)) : 0) << 7) | (((!!(add_sink)) ? (!!(gpd_mac_sec_num_cap)) : 0) << 8) | (((!!(add_sink)) ? ((sec_lvl) & 3) : 0) << 9) | (((!!(add_sink)) ? ((sec_key_type) & 7) : 0) << 11) | ((!!(frame_cnt_prsnt)) << 14) | (((!!(add_sink)) ? (!!(gpd_sec_key_prsnt)) : 0) << 15) | (((!!(add_sink)) ? (!!(assigned_alias_prsnt)) : 0) << 16) | (((!!(add_sink)) ? (!!(frwrd_radius_prsnt)) : 0) << 17)) + +/** + * @brief Perform GP Pairing request + * + * @param param [in] Buffer reference + * @param dst_addr [in] Destination address + * @param dst_addr_mode [in] Destination address mode + * @param options [in] Request options + * @param gpd_id [in] ZGPD ID + * @param endpoint [in] Endpoint of ZGPD if APP_ID eq 0010 + * @param dev_id [in] Device ID + * @param sec_frame_counter [in] Security frame counter of ZGPD + * @param key [in] Pointer to the security key + * @param assigned_alias [in] Assigned alias in the groupcast forwarding of the GPDF packet + * @param frwd_radius [in] Radius in the groupcast forwarding of the GPDF packet + * @param cb [in] Callback call if needed after send request + * + * @see ZGP spec, A.3.3.5.2 + */ +void zb_zgp_cluster_gp_pairing_req(zb_uint8_t param, + zb_uint16_t dst_addr, + zb_uint8_t dst_addr_mode, + zb_uint32_t options, + zb_zgpd_addr_t gpd_id, + zb_uint8_t endpoint, + zb_uint8_t dev_id, + zb_uint32_t sec_frame_counter, + zb_uint8_t *key, + zb_uint16_t assigned_alias, + zb_uint8_t frwd_radius, + zb_uint16_t group_id, + zb_callback_t cb); + +/** + * @brief Perform send zcl gp sink table request for ZGP clister + * + * @param buf_ref [in] Buffer reference + * @param dst_addr [in] Destination address + * @param dst_addr_mode [in] Destination address mode + * @param options [in] Request options + * @param zgpd_id [in] Pointer to ZGPD ID + * @param index [in] The Index field carries the index value of the Sink Table entry is requested + * @param cb [in] Call callback if needed after sending request + * + * @see ZGP spec, A.3.3.4.7 + * + */ +void zgp_cluster_send_gp_sink_table_request(zb_uint8_t buf_ref, + zb_uint16_t dst_addr, + zb_uint8_t dst_addr_mode, + zb_uint8_t options, + zb_zgpd_id_t *zgpd_id, + zb_uint8_t index, + zb_callback_t cb); + +/** + * @brief Perform send zcl gp proxy table request for ZGP clister + * + * @param buf_ref [in] Buffer reference + * @param dst_addr [in] Destination address + * @param dst_addr_mode [in] Destination address mode + * @param options [in] Request options + * @param zgpd_id [in] Pointer to ZGPD ID + * @param index [in] The Index field carries the index value of the Proxy Table entry is requested + * @param cb [in] Call callback if needed after sending request + * + * @see ZGP spec, A.3.4.3.1 + * + */ +void zgp_cluster_send_gp_proxy_table_request(zb_uint8_t buf_ref, + zb_uint16_t dst_addr, + zb_uint8_t dst_addr_mode, + zb_uint8_t options, + zb_zgpd_id_t *zgpd_id, + zb_uint8_t index, + zb_callback_t cb); + +typedef ZB_PACKED_PRE struct zb_zgp_cluster_list_s +{ + zb_uint8_t server_cl_num; + zb_uint8_t client_cl_num; + zb_uint16_t server_clusters[ZB_ZGP_MAX_PAIRED_CONF_CLUSTERS]; + zb_uint16_t client_clusters[ZB_ZGP_MAX_PAIRED_CONF_CLUSTERS]; +} +ZB_PACKED_STRUCT zb_zgp_cluster_list_t; + +typedef ZB_PACKED_PRE struct zgp_pair_group_list_s +{ + zb_uint16_t sink_group; + zb_uint16_t alias; +} +ZB_PACKED_STRUCT zgp_pair_group_list_t; + +typedef struct zgp_tbl_ent_s +{ + zb_zgpd_addr_t zgpd_id; /**< ID of the paired ZGPD */ + zb_uint16_t options; /**< The options for the reception from ZGPD */ + zb_uint16_t zgpd_assigned_alias; /**< The commissioned 16-bit ID to be used + as alias for ZGPD */ + + zb_uint32_t security_counter; /**< The incoming security frame counter for ZGPD */ + zb_uint8_t zgpd_key[ZB_CCM_KEY_SIZE]; /**< Security key for the GPD */ + zb_uint8_t endpoint; + zb_uint8_t sec_options; /**< Security options */ + zb_uint8_t groupcast_radius; /**< To limit the range of the groupcast */ + + zb_uint8_t is_sink; + + union + { + struct zgp_proxy_tbl_ent_s + { + zb_uint16_t ext_options; + struct zgp_lwsink_addr_list_s + { + zb_address_ieee_ref_t addr_ref; + } lwsaddr[ZB_ZGP_MAX_LW_UNICAST_ADDR_PER_GPD]; + zgp_pair_group_list_t sgrp[ZB_ZGP_MAX_SINK_GROUP_PER_GPD]; + } proxy; + struct zgp_sink_tbl_ent_s + { + zb_uint8_t device_id; /**< ZGPD Device ID @see zb_zgpd_dev_id_t */ + zgp_pair_group_list_t sgrp[ZB_ZGP_MAX_SINK_GROUP_PER_GPD]; + zb_uint8_t match_dev_tbl_idx; + /** + * Extension to the table (field is not presented in specification). + * + * Dest IEEE address to use in GPT to GPD packets even if GPD is identified by SrcID + */ + zb_ieee_addr_t ieee_addr; + } sink; + } u; +} zgp_tbl_ent_t; + +#if defined ZB_ENABLE_ZGP_SINK || defined ZGP_COMMISSIONING_TOOL +typedef zgp_tbl_ent_t zb_zgp_sink_tbl_ent_t; +#endif /* defined ZB_ENABLE_ZGP_SINK || defined ZGP_COMMISSIONING_TOOL */ +#ifdef ZB_ENABLE_ZGP_PROXY +typedef zgp_tbl_ent_t zb_zgp_proxy_tbl_ent_t; +#endif /* ZB_ENABLE_ZGP_PROXY */ + +#if defined ZB_ENABLE_ZGP_SINK || defined ZGP_COMMISSIONING_TOOL +/* TODO: update description */ +/** + * @brief Perform send zcl gp pairing configuration command for ZGP cluster + * + * @param buf_ref [in] Buffer reference + * @param dst_addr [in] Destination address + * @param dst_addr_mode [in] Destination address mode + * @param actions [in] Actions + * @param ent [in] Sink table entry + * @param def_resp [in] Enable ZCL default response if TRUE + * @param cb [in] Call callback if needed after sending request + * + * @see ZGP spec, A.3.3.4.6 + * + */ +void zgp_cluster_send_pairing_configuration(zb_uint8_t buf_ref, + zb_uint16_t dst_addr, + zb_uint8_t dst_addr_mode, + zb_uint8_t actions, + zb_zgp_sink_tbl_ent_t *ent, + zb_uint8_t num_paired_endpoints, + zb_uint8_t *paired_endpoints, + zb_uint8_t app_info, + zb_uint16_t manuf_id, + zb_uint16_t model_id, + zb_uint8_t num_gpd_commands, + zb_uint8_t *gpd_commands, + zb_zgp_cluster_list_t *cluster_list, + zb_callback_t cb); +#endif /* defined ZB_ENABLE_ZGP_SINK || defined ZGP_COMMISSIONING_TOOL */ + +#ifdef ZGP_COMMISSIONING_TOOL +/** + * @brief Perform send zcl gp sink commissioning mode command for ZGP cluster + * + * @param buf_ref [in] Buffer reference + * @param dst_addr [in] Destination address + * @param dst_addr_mode [in] Destination address mode + * @param options [in] Options + * @param endpoint [in] Endpoint + * @param cb [in] Call callback if needed after sending request + * + * @see ZGP spec, A.3.3.4.8 + * + */ +void zgp_cluster_send_gp_sink_commissioning_mode(zb_uint8_t buf_ref, + zb_uint16_t dst_addr, + zb_uint8_t dst_addr_mode, + zb_uint8_t options, + zb_uint8_t endpoint, + zb_callback_t cb); +#endif /* ZGP_COMMISSIONING_TOOL */ + +void zgp_gp_set_shared_security_key_type(enum zb_zgp_security_key_type_e type); +#define ZGP_GP_SET_SHARED_SECURITY_KEY_TYPE(type) zgp_gp_set_shared_security_key_type(type) + +#ifdef ZGP_CLUSTER_TEST +/* Application specific zcl command handler for test purposes */ +typedef zb_uint8_t (*zgp_cluster_app_zcl_cmd_handler_t)(zb_uint8_t buf_ref); + +/** + * @brief Setup specific application zcl command handler for test purpose + * + * @param handler [in] Specific application zcl command handler pointer + */ +void zgp_cluster_set_app_zcl_cmd_handler(zgp_cluster_app_zcl_cmd_handler_t handler); +#endif /* ZGP_CLUSTER_TEST */ +#endif /* !ZB_ZGPD_ROLE */ + +#endif /* ZBOSS_API_ZGP_H */ diff --git a/zboss/include/zcl/zb_zcl_alarms.h b/zboss/include/zcl/zb_zcl_alarms.h new file mode 100644 index 0000000000..ad61a931df --- /dev/null +++ b/zboss/include/zcl/zb_zcl_alarms.h @@ -0,0 +1,361 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Alarms cluster defintions +*/ + +#if ! defined ZB_ZCL_ALARMS_H +#define ZB_ZCL_ALARMS_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_ALARMS + * @{ + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_ALARMS */ + +/*! @name Alarms cluster attributes + @{ +*/ + +/*! @brief Alarms cluster attribute identifiers + @see ZCL spec, subclause 3.11.2.2 +*/ +enum zb_zcl_alarms_attr_e +{ + /*! @brief AlarmCount attribute */ + ZB_ZCL_ATTR_ALARMS_ALARM_COUNT_ID = 0x0000 +}; + +/*! @} */ /* Alarms cluster attributes */ + +/*! @name Alarms cluster commands + @{ +*/ + +/*! @brief Alarms cluster command identifiers + @see ZCL spec, subclause 3.11.2.4 +*/ +enum zb_zcl_alarms_cmd_e +{ + ZB_ZCL_CMD_ALARMS_RESET_ALARM_ID = 0x00, /**< "Reset alarm" command. */ + ZB_ZCL_CMD_ALARMS_RESET_ALL_ALARMS_ID = 0x01, /**< "Reset all alarms" command. */ + ZB_ZCL_CMD_ALARMS_GET_ALARM_ID = 0x02, /**< "Get alarms" command. */ + ZB_ZCL_CMD_ALARMS_RESET_ALARM_LOG_ID = 0x03 /**< "Reset alarm log" command. */ +}; + +/*! @brief Structured representsation of Reset alarm command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_alarms_reset_alarm_req_s +{ + /** Alarm Code field */ + zb_uint8_t alarm_code; + /** Cluster ID field */ + zb_uint16_t cluster_id; +} ZB_PACKED_STRUCT zb_zcl_alarms_reset_alarm_req_t; + +/** @brief Reset alarm payload length macro */ +#define ZB_ZCL_ALARMS_RESET_ALARM_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_alarms_reset_alarm_req_t) + +/*! @brief Send Reset alarm command + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param dis_default_resp - "Disable default response" flag + @param cb - callback to call to report send status + @param alarm_code - Alarm Code field + @param cluster_id - Cluster ID field +*/ +#define ZB_ZCL_ALARMS_SEND_RESET_ALARM_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, cb, alarm_code, cluster_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ALARMS_RESET_ALARM_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (alarm_code)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (cluster_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ALARMS, cb); \ +} + +/** @brief Parses Reset alarm command and fills in data request + structure. If request contains invlid data, status will set to ZB_FALSE. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param reset_alarm_req - variable to save command request + @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_ALARMS_GET_RESET_ALARM_REQ(data_buf, reset_alarm_req, status) \ +{ \ + zb_zcl_alarms_reset_alarm_req_t *reset_alarm_req_ptr; \ + (reset_alarm_req_ptr) = zb_buf_len(data_buf) >= \ + ZB_ZCL_ALARMS_RESET_ALARM_REQ_PAYLOAD_LEN ? \ + (zb_zcl_alarms_reset_alarm_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (reset_alarm_req_ptr) \ + { \ + reset_alarm_req.alarm_code = reset_alarm_req_ptr->alarm_code; \ + ZB_HTOLE16(&(reset_alarm_req).cluster_id, &(reset_alarm_req_ptr->cluster_id)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/*! @brief Send Reset all alarms command + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param dis_default_resp - "Disable default response" flag + @param cb - callback to call to report send status +*/ +#define ZB_ZCL_ALARMS_SEND_RESET_ALL_ALARMS_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ALARMS_RESET_ALL_ALARMS_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ALARMS, cb); \ +} + +/*! @brief Send Get alarm command + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param dis_default_resp - "Disable default response" flag + @param cb - callback to call to report send status +*/ +#define ZB_ZCL_ALARMS_SEND_GET_ALARM_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ALARMS_GET_ALARM_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ALARMS, cb); \ +} + +/*! @brief Send Reset alarm log command + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param dis_default_resp - "Disable default response" flag + @param cb - callback to call to report send status +*/ +#define ZB_ZCL_ALARMS_SEND_RESET_ALARM_LOG_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ALARMS_RESET_ALARM_LOG_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ALARMS, cb); \ +} + +/********************************** Responses *******************/ + +/** @brief Alarms cluster response command identifiers + @see ZCL spec, subclause 3.6.2.3 +*/ +enum zb_zcl_alarms_cmd_resp_e +{ + ZB_ZCL_CMD_ALARMS_ALARM_ID = 0x00, /**< Alarm command identifier. */ + ZB_ZCL_CMD_ALARMS_GET_ALARM_RES_ID = 0x01 /**< Get alarm response command identifier. */ +}; + +/** @cond internals_doc */ +/* Alarms cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_ALARMS_SERVER_ROLE_GENERATED_CMD_LIST ZB_ZCL_CMD_ALARMS_ALARM_ID + +#define ZB_ZCL_CLUSTER_ID_ALARMS_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_ALARMS_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_ALARMS_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_ALARMS_RESET_ALARM_ID, \ + ZB_ZCL_CMD_ALARMS_RESET_ALL_ALARMS_ID + +#define ZB_ZCL_CLUSTER_ID_ALARMS_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_ALARMS_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/*! @brief Structured representsation of Alarm command payload */ +typedef zb_zcl_alarms_reset_alarm_req_t zb_zcl_alarms_alarm_res_t; + +typedef ZB_PACKED_PRE struct zb_zcl_alarm_get_alarm_hdr_res_s +{ + zb_uint8_t status; /**< Status field */ +} ZB_PACKED_STRUCT zb_zcl_alarm_get_alarm_hdr_res_t; + +/** @brief Get alarm response command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_alarm_get_alarm_res_s +{ + zb_uint8_t status; /**< Status field */ + zb_uint8_t alarm_code; /**< Alarm code field */ + zb_uint16_t cluster_id; /**< Cluster ID field */ + zb_uint32_t timestamp; /**< TimeStamp field */ +} ZB_PACKED_STRUCT zb_zcl_alarm_get_alarm_res_t; + +/** @internal Get alarm response size */ +#define ZB_ZCL_ALARM_GET_ALARM_RES_SIZE \ + sizeof(zb_zcl_alarm_get_alarm_res_t) + +/** @internal Get alarm response header size */ +#define ZB_ZCL_ALARM_GET_ALARM_HDR_RES_SIZE \ + sizeof(zb_zcl_alarm_get_alarm_hdr_res_t) + +/*! @brief Send Alarm command (to client) + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param cb - callback to call to report send status + @param alarm_code - Alarm Code + @param cluster_id - Cluster Id +*/ +#define ZB_ZCL_ALARMS_SEND_ALARM_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cb, alarm_code, cluster_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_ALARMS_ALARM_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (alarm_code)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (cluster_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_ALARMS, cb); \ +} + +/** @brief Parses Reset alarm command and fills in data request + structure. If request contains invalid data, status will set to ZB_FALSE. + @param data_ptr - pointer to a variable of type @ref zb_zcl_alarms_alarm_res_t. + @param buffer containing the packet (by pointer). + @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_ALARMS_GET_ALARM_RES(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_alarms_alarm_res_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_alarms_alarm_res_t *src_ptr = \ + (zb_zcl_alarms_alarm_res_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->alarm_code = src_ptr->alarm_code; \ + ZB_HTOLE16(&((data_ptr)->cluster_id), &(src_ptr->cluster_id)); \ + } \ +} + + +/** @brief Parses Get alarm response command and returns response data + structure or status = ZB_FALSE if request contains invlid data. + @param data_buf - pointer to zb_buf_t buffer containing command response data + @param get_alarm_res - command response record + @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t) + @note data_buf buffer should contain response command payload without ZCL header + */ +#define ZB_ZCL_ALARMS_GET_GET_ALARM_RES(data_buf, get_alarm_res, status) \ +{ \ + zb_zcl_alarm_get_alarm_res_t *get_alarm_res_ptr; \ + if (zb_buf_len(data_buf) >= ZB_ZCL_ALARM_GET_ALARM_HDR_RES_SIZE) \ + { \ + (get_alarm_res_ptr) = zb_buf_begin(data_buf); \ + get_alarm_res.status = get_alarm_res_ptr->status; \ + if (zb_buf_len(data_buf) >= ZB_ZCL_ALARM_GET_ALARM_RES_SIZE) \ + { \ + get_alarm_res.alarms_code = get_alarm_res_ptr->alarm_code; \ + ZB_HTOLE16(&(get_alarm_res).cluster_id, &(get_alarm_res_ptr->cluster_id)); \ + ZB_HTOLE32(&(get_alarm_res).timestamp, &(get_alarm_res_ptr->timestamp)); \ + } \ + status = ZB_TRUE; \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/*! @} */ /* Alarms cluster commands */ + +/*! @internal @name Alarms cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +/*! @internal Number of attributes mandatory for reporting in Alarms cluster */ +#define ZB_ZCL_ALARMS_REPORT_ATTR_COUNT 0 + + +/*! @} */ /* Alarms cluster internals */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_alarms_init_server(void); +void zb_zcl_alarms_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_ALARMS_SERVER_ROLE_INIT zb_zcl_alarms_init_server +#define ZB_ZCL_CLUSTER_ID_ALARMS_CLIENT_ROLE_INIT zb_zcl_alarms_init_client + +#endif /* ! defined ZB_ZCL_ALARMS_H */ diff --git a/zboss/include/zcl/zb_zcl_basic.h b/zboss/include/zcl/zb_zcl_basic.h new file mode 100644 index 0000000000..ab2e79a963 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_basic.h @@ -0,0 +1,515 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZCL Basic Cluster definitions +*/ +#if ! defined ZB_ZCL_BASIC_H +#define ZB_ZCL_BASIC_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_BASIC + * @{ + * @details + * According to ZCL spec, clause 3.2, Basic cluster contains attributes only. These attributes + * could be queried with @ref ZB_ZCL_COMMANDS "general ZCL commands". + */ + +/** @name Basic cluster attributes + * @{ + */ + +/** @brief Basic cluster information attribute set identifiers + @see ZCL spec, subclauses 3.2.2.2.1 to 3.2.2.2.9 +*/ +enum zb_zcl_basic_info_attr_e +{ + /** ZCL version attribute */ + ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID = 0x0000, + /** Application version attribute */ + ZB_ZCL_ATTR_BASIC_APPLICATION_VERSION_ID = 0x0001, + /** Stack version attribute */ + ZB_ZCL_ATTR_BASIC_STACK_VERSION_ID = 0x0002, + /** Hardware version attribute */ + ZB_ZCL_ATTR_BASIC_HW_VERSION_ID = 0x0003, + /** Manufacturer name attribute */ + ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID = 0x0004, + /** Model identifier attribute */ + ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID = 0x0005, + /** Date code attribute */ + ZB_ZCL_ATTR_BASIC_DATE_CODE_ID = 0x0006, + /** Power source attribute */ + ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID = 0x0007, + /** The GenericDeviceClass attribute defines the field of application of the + * GenericDeviceType attribute. */ + ZB_ZCL_ATTR_BASIC_GENERIC_DEVICE_CLASS_ID = 0x0008, + /** The GenericDeviceType attribute allows an application to show an icon on + * a rich user interface (e.g. smartphone app). */ + ZB_ZCL_ATTR_BASIC_GENERIC_DEVICE_TYPE_ID = 0x0009, + /** The ProductCode attribute allows an application to specify a code for + * the product. */ + ZB_ZCL_ATTR_BASIC_PRODUCT_CODE_ID = 0x000a, + /** The ProductURL attribute specifies a link to a web page containing specific + * product information. */ + ZB_ZCL_ATTR_BASIC_PRODUCT_URL_ID = 0x000b, + /** Vendor specific human readable (displayable) string representing the versions + * of one of more program images supported on the device. */ + ZB_ZCL_ATTR_BASIC_MANUFACTURER_VERSION_DETAILS_ID = 0x000c, + /** Vendor specific human readable (displayable) serial number. */ + ZB_ZCL_ATTR_BASIC_SERIAL_NUMBER_ID = 0x000d, + /** Vendor specific human readable (displayable) product label. */ + ZB_ZCL_ATTR_BASIC_PRODUCT_LABEL_ID = 0x000e, + /** Manufacturer-specific reference to the version of the software. */ + ZB_ZCL_ATTR_BASIC_SW_BUILD_ID = 0x4000, +}; + +/** @brief Basic cluster settings attribute set identifiers + @see ZCL spec, subclauses 3.2.2.2.10 to 3.2.2.2.15 +*/ +enum zb_zcl_basic_settings_attr_e +{ + /*! Location description attribute */ + ZB_ZCL_ATTR_BASIC_LOCATION_DESCRIPTION_ID = 0x0010, + /*! Physical environment attribute */ + ZB_ZCL_ATTR_BASIC_PHYSICAL_ENVIRONMENT_ID = 0x0011, + /*! Device enabled attribute */ + ZB_ZCL_ATTR_BASIC_DEVICE_ENABLED_ID = 0x0012, + /*! Alarm mask attribute */ + ZB_ZCL_ATTR_BASIC_ALARM_MASK_ID = 0x0013, + /*! Disable local config attribute */ + ZB_ZCL_ATTR_BASIC_DISABLE_LOCAL_CONFIG_ID = 0x0014 +}; + +/** + * @brief Permitted values for "Power source" attribute. + * @see ZCL spec, subclauses 3.2.2.2.9. + */ +enum zb_zcl_basic_power_source_e +{ + ZB_ZCL_BASIC_POWER_SOURCE_UNKNOWN = 0x00, /**< Power source unknown. */ + ZB_ZCL_BASIC_POWER_SOURCE_MAINS_SINGLE_PHASE = 0x01, /**< Single-phase mains. */ + ZB_ZCL_BASIC_POWER_SOURCE_MAINS_THREE_PHASE = 0x02, /**< 3-phase mains. */ + ZB_ZCL_BASIC_POWER_SOURCE_BATTERY = 0x03, /**< Battery source. */ + ZB_ZCL_BASIC_POWER_SOURCE_DC_SOURCE = 0x04, /**< DC source. */ + ZB_ZCL_BASIC_POWER_SOURCE_EMERGENCY_MAINS_CONST = 0x05, /**< Emergency mains constantly + powered. */ + ZB_ZCL_BASIC_POWER_SOURCE_EMERGENCY_MAINS_TRANSF = 0x06 /**< Emergency mains and transfer + switch. */ +}; + +/** @brief Basic permitted values for "Physical environment" attribute. + @note most of values are profile-specific. + @see ZCL spec, subclause 3.2.2.2.12 +*/ +enum zb_zcl_basic_physical_env_e +{ + /*! Environment unspecified */ + ZB_ZCL_BASIC_ENV_UNSPECIFIED = 0, + /*! Environment unknown */ + ZB_ZCL_BASIC_ENV_UNKNOWN = 0xff +}; + +/** @brief Permitted bits for "Alarm mask" attribute + @see ZCL spec, subclause 3.2.2.2.14 +*/ +enum zb_zcl_basic_alarm_mask_e +{ + /*! General hardware fault */ + ZB_ZCL_BASIC_ALARM_MASK_HW_FAULT = 0, + /*! General software fault */ + ZB_ZCL_BASIC_ALARM_MASK_SW_FAULT = 1 +}; + +/** @brief Value structure for "Disable local config" attribute + @see ZCL spec, subclause 3.2.2.2.15 +*/ +typedef struct zb_zcl_basic_disable_local_conf_s +{ + /*! Reset to factry defaults disabled */ + zb_bitfield_t reset_disabled : 1; + /*! Device configuration enabled */ + zb_bitfield_t config_enabled : 1; + /*! Reserved bits */ + zb_bitfield_t reserved : 6; +} zb_zcl_basic_disable_local_conf_t; + +/** @brief Default value for ZCL version attribute */ +#define ZB_ZCL_BASIC_ZCL_VERSION_DEFAULT_VALUE ((zb_uint8_t)ZB_ZCL_VERSION) + +/** @brief Default value for Application version attribute */ +#define ZB_ZCL_BASIC_APPLICATION_VERSION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for Stack version attribute */ +#define ZB_ZCL_BASIC_STACK_VERSION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for Hardware version attribute */ +#define ZB_ZCL_BASIC_HW_VERSION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for Manufacturer name attribute */ +#define ZB_ZCL_BASIC_MANUFACTURER_NAME_DEFAULT_VALUE {0} + +/** @brief Default value for Model identifier attribute */ +#define ZB_ZCL_BASIC_MODEL_IDENTIFIER_DEFAULT_VALUE {0} + +/** @brief Default value for Date code attribute */ +#define ZB_ZCL_BASIC_DATE_CODE_DEFAULT_VALUE {0} + +/** @brief Default value for Power source attribute */ +#define ZB_ZCL_BASIC_POWER_SOURCE_DEFAULT_VALUE (ZB_ZCL_BASIC_POWER_SOURCE_UNKNOWN) + +/** @brief Default value for GenericDeviceClass attribute */ +#define ZB_ZCL_BASIC_GENERIC_DEVICE_CLASS_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for GenericDeviceType attribute */ +#define ZB_ZCL_BASIC_GENERIC_DEVICE_TYPE_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for ProductCode attribute */ +#define ZB_ZCL_BASIC_PRODUCT_CODE_DEFAULT_VALUE {0} + +/** @brief Default value for ProductURL attribute */ +#define ZB_ZCL_BASIC_PRODUCT_URL_DEFAULT_VALUE {0} +/** @brief Default value for ManufacturerVersionDetails attribute */ + +#define ZB_ZCL_BASIC_MANUFACTURER_VERSION_DETAILS_DEFAULT_VALUE {0} +/** @brief Default value for SerialNumber attribute */ + +#define ZB_ZCL_BASIC_SERIAL_NUMBER_DEFAULT_VALUE {0} +/** @brief Default value for ProductLabel attribute */ + +#define ZB_ZCL_BASIC_PRODUCT_LABEL_DEFAULT_VALUE {0} + +/** @brief Default value for location description attribute */ +#define ZB_ZCL_BASIC_LOCATION_DESCRIPTION_DEFAULT_VALUE {0} + +/** @brief Default value for Physical environment attribute */ +#define ZB_ZCL_BASIC_PHYSICAL_ENVIRONMENT_DEFAULT_VALUE (ZB_ZCL_BASIC_ENV_UNSPECIFIED) + +/** @brief Default value for Device enabled attribute */ +#define ZB_ZCL_BASIC_DEVICE_ENABLED_DEFAULT_VALUE ((zb_uint8_t)0x01) + +/** @brief Default value for Alarm mask attribute */ +#define ZB_ZCL_BASIC_ALARM_MASK_DEFAULT_VALUE (ZB_ZCL_BASIC_ALARM_MASK_HW_FAULT) + +/** @brief Default value for Disable local config attribute */ +#define ZB_ZCL_BASIC_DISABLE_LOCAL_CONFIG_DEFAULT_VALUE ((zb_zcl_basic_disable_local_conf_t){0,0,0}) + +/** + * @brief Default value for SWBuildId attribute. + * @note Default value supposes that attribute will be stored as Pascal-style string (i. e. + * length-byte, then content). + */ +#define ZB_ZCL_BASIC_SW_BUILD_ID_DEFAULT_VALUE {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} + + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_APPLICATION_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_APPLICATION_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_STACK_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_STACK_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_HW_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_HW_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_DATE_CODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_DATE_CODE_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_LOCATION_DESCRIPTION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_LOCATION_DESCRIPTION_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_PHYSICAL_ENVIRONMENT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_PHYSICAL_ENVIRONMENT_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_DEVICE_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_DEVICE_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BASIC_SW_BUILD_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BASIC_SW_BUILD_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#if defined ZB_ZCL_SUPPORT_CLUSTER_SCENES +/*! Scenes fieldset length for Basic cluster */ +#define ZB_ZCL_CLUSTER_ID_BASIC_SCENE_FIELD_SETS_LENGTH 0 +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_SCENES */ + +/** @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Basic cluster + @param attr_list - attribute list name + @param zcl_version - pointer to variable to store zcl version attribute value + @param power_source - pointer to variable to store power source attribute value + + @snippet lighting/dimmable_light_tl/light_device_zr.c BASIC_CLUSTER_DECLARE +*/ +#define ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST(attr_list, zcl_version, power_source) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, (zcl_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (power_source)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** + * @brief Declare attribute list for Basic cluster (extended attribute set). + * @param attr_list [IN] - attribute list name. + * @param zcl_version [IN] - pointer to variable storing ZCL version attribute value. + * @param app_version [IN] - pointer to the variable storing application version. + * @param stack_version [IN] - pointer to the variable storing stack version. + * @param hardware_version [IN] - pointer to the variable storing hardware version. + * @param manufacturer_name [IN] - pointer to the variable storing manufacturer name. + * @param model_id [IN] - pointer to the variable storing model identifier. + * @param date_code [IN] - pointer to the variable storing date code. + * @param power_source [IN] - pointer to variable storing power source attribute value. + * @param location_id [IN] - pointer to variable storing location description attribute value. + * @param ph_env [IN] - pointer to variable storing physical environment attribute value. + * @param sw_build_id [IN] - pointer to the variable storing software version reference. + */ +#define ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST_EXT( \ + attr_list, \ + zcl_version, \ + app_version, \ + stack_version, \ + hardware_version, \ + manufacturer_name, \ + model_id, \ + date_code, \ + power_source, \ + location_id, \ + ph_env, \ + sw_build_id) \ + zb_bool_t device_enable_##attr_list = ZB_TRUE; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID, (zcl_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_APPLICATION_VERSION_ID, (app_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_STACK_VERSION_ID, (stack_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_HW_VERSION_ID, (hardware_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_MANUFACTURER_NAME_ID, (manufacturer_name))\ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_MODEL_IDENTIFIER_ID, (model_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_DATE_CODE_ID, (date_code)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID, (power_source)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_SW_BUILD_ID, (sw_build_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_DEVICE_ENABLED_ID, \ + &(device_enable_##attr_list)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_LOCATION_DESCRIPTION_ID, (location_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BASIC_PHYSICAL_ENVIRONMENT_ID, (ph_env)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! Maximum length of ManufacturerName string field */ +#define ZB_ZCL_CLUSTER_ID_BASIC_MANUFACTURER_NAME_MAX_LEN 32 + +/*! Maximum length of ModelIdentifier string field */ +#define ZB_ZCL_CLUSTER_ID_BASIC_MODEL_IDENTIFIER_MAX_LEN 32 + +/** + * @brief Basic cluster attributes + */ +typedef struct zb_zcl_basic_attrs_s +{ + /** @copydoc ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID + * @see ZB_ZCL_ATTR_BASIC_ZCL_VERSION_ID + */ + zb_uint8_t zcl_version; + + /** @copydoc ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID + * @see ZB_ZCL_ATTR_BASIC_POWER_SOURCE_ID + */ + zb_uint8_t power_source; +} zb_zcl_basic_attrs_t; + + +/** @brief Declare attribute list for Basic cluster cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - variable of @ref zb_zcl_basic_attrs_t type (containing Basic cluster attributes) + */ +#define ZB_ZCL_DECLARE_BASIC_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_BASIC_ATTRIB_LIST(attr_list, &attrs.zcl_version, &attrs.power_source) + +/** @} */ /* Basic cluster attributes */ + +/*! @name Alarms cluster commands + @{ +*/ + +/*! @brief Basic cluster command identifiers + @see ZCL spec, subclause 3.2.2.3 +*/ +enum zb_zcl_basic_cmd_e +{ + ZB_ZCL_CMD_BASIC_RESET_ID = 0x00, /**< "Reset to Factory Defaults" command. */ +}; + +/** @cond internals_doc */ +/* Basic cluster commands lists : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_BASIC_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CMD_BASIC_RESET_ID + +#define ZB_ZCL_CLUSTER_ID_BASIC_CLIENT_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_BASIC_SERVER_ROLE_RECEIVED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +//////////////////////////////////////// + +/*! @brief Send Reset to Factory Defaults command + @param buffer to put data to + @param addr - address of the device to send command to + @param dst_addr_mode - addressing mode + @param dst_ep destination endpoint + @param ep - current endpoint + @param prof_id - profile identifier + @param dis_default_resp - "Disable default response" flag + @param cb - callback to call to report send status +*/ +#define ZB_ZCL_BASIC_SEND_RESET_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, dis_default_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_BASIC_RESET_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_BASIC, cb); \ +} + + +/** Call device callback in user application to reset application settings to defaults. + * @param[in] buffer - pointer to buffer for callback + * @param[in] ep - current endpoint + * @param[out] result - callback status + */ +#define ZB_ZCL_RESET_TO_FACTORY_DEFAULTS_USER_APP(buffer, ep, result) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_RESET_TO_FACTORY_DEFAULTS_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + user_app_data->device_cb_id = ZB_ZCL_BASIC_RESET_CB_ID; \ + user_app_data->endpoint = (ep); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + result = user_app_data->status; \ + } \ +} + +/** @} */ /* Basic cluster commands */ + +/*! @} */ /* ZCL Basic cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_basic_init_server(void); +void zb_zcl_basic_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_BASIC_SERVER_ROLE_INIT zb_zcl_basic_init_server +#define ZB_ZCL_CLUSTER_ID_BASIC_CLIENT_ROLE_INIT zb_zcl_basic_init_client + +#endif /* ! defined ZB_ZCL_BASIC_H */ diff --git a/zboss/include/zcl/zb_zcl_binary_input.h b/zboss/include/zcl/zb_zcl_binary_input.h new file mode 100644 index 0000000000..c7fd8be35c --- /dev/null +++ b/zboss/include/zcl/zb_zcl_binary_input.h @@ -0,0 +1,296 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Binary Input cluster +*/ + +#if !defined ZB_ZCL_BINARY_INPUT_H +#define ZB_ZCL_BINARY_INPUT_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_BINARY_INPUT + * @{ + * @details + * According to ZCL spec, subclause 3.14.4, Binary Input (Basic) cluster has no cluster-specific + * commands. Cluster attributes could be queried with + * @ref ZB_ZCL_COMMANDS "general ZCL commands". + * + * @par Example + * @code + * #define DUT_ENDPOINT 5 + * @endcode + * @snippet doxygen_snippets.dox Binary input_snippet_binary_input_dut_c + * @par + * + * For more information see 544_binary_input sample + */ + +/* ZB_ZCL_CLUSTER_ID_BINARY_INPUT = 0x000f defined in zb_zcl_common.h ZCL spec 3.14.4 */ + +/*! @name Binary Input cluster attributes + @{ +*/ + +/** @brief Binary Input cluster attribute identifiers. */ +enum zb_zcl_binary_input_attr_e +{ + /** This attribute, of type Character string, MAY be used to hold a human readable + * description of the ACTIVE state of a binary PresentValue. */ + ZB_ZCL_ATTR_BINARY_INPUT_ACTIVE_TEXT_ID = 0x0004, + /** The Description attribute, of type Character string, MAY be used to hold a + * description of the usage of the input, output or value, as appropriate + * to the cluster. */ + ZB_ZCL_ATTR_BINARY_INPUT_DESCRIPTION_ID = 0x001C, + /** This attribute, of type Character string, MAY be used to hold a human readable + * description of the INACTIVE state of a binary PresentValue. */ + ZB_ZCL_ATTR_BINARY_INPUT_INACTIVE_TEXT_ID = 0x002E, + + /** @brief OutOfService attribute */ + ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID = 0x0051, + /** This attribute, of type enumeration, indicates the relationship between + * the physical state of the input (or output as appropriate for the cluster) + * and the logical state represented by a binary PresentValue attribute, + * when OutOfService is FALSE. */ + ZB_ZCL_ATTR_BINARY_INPUT_POLARITY_ID = 0x0054, + + /** @brief PresentValue attribute */ + ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID = 0x0055, + +// adding GP specific attributes + ZB_ZCL_ATTR_GP_ATTR_BINARY_INPUT_BATTERY_VALUE_ID = 0x0056, + ZB_ZCL_ATTR_GP_ATTR_BINARY_INPUT_TEMPERATURE_VALUE_ID = 0x0057, + ZB_ZCL_ATTR_GP_ATTR_BINARY_INPUT_TAMPER_VALUE_ID = 0x0058, +// end GP specific attributes + /** The Reliability attribute, of type 8-bit enumeration, provides an indication + * of whether the PresentValue or the operation of the physical input, + * output or value in question (as appropriate for the cluster) is reliable + * as far as can be determined and, if not, why not. */ + ZB_ZCL_ATTR_BINARY_INPUT_RELIABILITY_ID = 0x0067, + + /** @brief StatusFlag attribute */ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID = 0x006F, + /** The ApplicationType attribute is an unsigned 32-bit integer that indicates + * the specific application usage for this cluster. */ + ZB_ZCL_ATTR_BINARY_INPUT_APPLICATION_TYPE_ID = 0x0100, +}; + +/** + * @brief StatusFlag attribute values. + * @see ZCL spec 3.14.10.3. + */ +enum zb_zcl_binary_input_status_flag_value_e +{ + ZB_ZCL_BINARY_INPUT_STATUS_FLAG_NORMAL = 0x00, /**< Normal (default) state. */ + ZB_ZCL_BINARY_INPUT_STATUS_FLAG_IN_ALARM = 0x01, /**< In alarm bit. */ + ZB_ZCL_BINARY_INPUT_STATUS_FLAG_FAULT = 0x02, /**< Fault bit. */ + ZB_ZCL_BINARY_INPUT_STATUS_FLAG_OVERRIDEN = 0x04, /**< Overriden bit. */ + ZB_ZCL_BINARY_INPUT_STATUS_FLAG_OUT_OF_SERVICE = 0x08, /**< Out of service bit. */ +}; + +/** @brief Default value for ActiveText attribute */ +#define ZB_ZCL_BINARY_INPUT_ACTIVE_TEXT_DEFAULT_VALUE {0} + +/** @brief Default value for Description attribute */ +#define ZB_ZCL_BINARY_INPUT_DESCRIPTION_DEFAULT_VALUE {0} + +/** @brief Default value for InactiveText attribute */ +#define ZB_ZCL_BINARY_INPUT_INACTIVE_TEXT_DEFAULT_VALUE {0} + +/*! @brief OutOfService attribute default value */ +#define ZB_ZCL_BINARY_INPUT_OUT_OF_SERVICE_DEFAULT_VALUE ZB_FALSE + +/** @brief Default value for Polarity attribute */ +#define ZB_ZCL_BINARY_INPUT_POLARITY_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for Reliability attribute */ +#define ZB_ZCL_BINARY_INPUT_RELIABILITY_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/*! @brief StatusFlag attribute default value */ +#define ZB_ZCL_BINARY_INPUT_STATUS_FLAG_DEFAULT_VALUE ZB_ZCL_BINARY_INPUT_STATUS_FLAG_NORMAL + +/*! @brief StatusFlag attribute minimum value */ +#define ZB_ZCL_BINARY_INPUT_STATUS_FLAG_MIN_VALUE 0 + +/*! @brief StatusFlag attribute maximum value */ +#define ZB_ZCL_BINARY_INPUT_STATUS_FLAG_MAX_VALUE 0x0F + +/** @brief Declare attribute list for Binary Input cluster + @param attr_list - attribute list name + @param out_of_service - pointer to variable to store OutOfService attribute value + @param present_value - pointer to variable to store PresentValue attribute value + @param status_flag - pointer to variable to store StatusFlag attribute value +*/ +#define ZB_ZCL_DECLARE_BINARY_INPUT_ATTRIB_LIST( \ + attr_list, out_of_service, present_value, status_flag) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID, (out_of_service)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, (present_value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID, (status_flag)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Binary Input cluster attributes */ + +/*! @name Binary input attribute value manipulation API + @{ +*/ + +/** @brief Set normal operating mode + @param ep - endpoint number +*/ +#define ZB_ZCL_BINARY_INPUT_SET_NORMAL_MODE(ep) \ +{ \ + zb_uint8_t val; \ + \ + val = ZB_FALSE; \ + ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID, \ + &val, ZB_FALSE); \ + \ + val = ZB_ZCL_BINARY_INPUT_STATUS_FLAG_NORMAL; \ + ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID, \ + &val, ZB_FALSE); \ +} + +/** @brief Set Out of service operating mode + @param ep - endpoint number +*/ +#define ZB_ZCL_BINARY_INPUT_SET_OUT_OF_SERVICE(ep) \ +{ \ + zb_zcl_attr_t *attr_desc; \ + zb_uint8_t val; \ + \ + val = ZB_TRUE; \ + ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID, \ + &val, ZB_FALSE); \ + \ + attr_desc = zb_zcl_get_attr_desc_a(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID); \ + if (attr_desc) \ + { \ + val = *(zb_uint8_t*)attr_desc->data_p | ZB_ZCL_BINARY_INPUT_STATUS_FLAG_OUT_OF_SERVICE; \ + ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID, \ + &val, ZB_FALSE); \ + } \ +} + +/** @brief Set overriden operating mode + @param ep - endpoint number +*/ +#define ZB_ZCL_BINARY_INPUT_SET_OVERRIDEN_MODE(ep) \ +{ \ + zb_zcl_attr_t *attr_desc; \ + zb_uint8_t val; \ + \ + attr_desc = zb_zcl_get_attr_desc_a(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID); \ + if (attr_desc) \ + { \ + val = *(zb_uint8_t*)attr_desc->data_p | ZB_ZCL_BINARY_INPUT_STATUS_FLAG_OVERRIDEN; \ + ZB_ZCL_SET_ATTRIBUTE(ep, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID, \ + &val, ZB_FALSE); \ + } \ +} + +/*! @} */ /* Binary input cluster commands */ + +/** @cond internals_doc */ +/** @name Binary Input cluster internals + Internal structures for Binary Input cluster + @{ +*/ + +/* Optionally, access to this attribute may be changed to READ_WRITE */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BINARY_INPUT_OUT_OF_SERVICE_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL, \ + (zb_voidp_t) data_ptr \ +} + +/* Optionally, access to this attribute may be changed to READ_WRITE */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_BINARY_INPUT_STATUS_FLAG_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +/*! Number of attributes mandatory for reporting in Binary Input cluster */ +#define ZB_ZCL_BINARY_INPUT_REPORT_ATTR_COUNT 2 + +/*! @} + * @endcond */ /* Binary Input cluster internals */ + + +/*! @} */ /* ZCL Binary Input cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_binary_input_init_server(void); +zb_void_t zb_zcl_binary_input_init_client(void); +#define ZB_ZCL_CLUSTER_ID_BINARY_INPUT_SERVER_ROLE_INIT zb_zcl_binary_input_init_server +#define ZB_ZCL_CLUSTER_ID_BINARY_INPUT_CLIENT_ROLE_INIT zb_zcl_binary_input_init_client + +#endif /* ZB_ZCL_BINARY_INPUT_H */ diff --git a/zboss/include/zcl/zb_zcl_color_control.h b/zboss/include/zcl/zb_zcl_color_control.h new file mode 100644 index 0000000000..5cce127fc6 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_color_control.h @@ -0,0 +1,2672 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Color control cluster definitions +*/ + +#if !defined ZB_ZCL_COLOR_CONTROL_H +#define ZB_ZCL_COLOR_CONTROL_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_COLOR_CONTROL + @{ +*/ + +/* ZB_ZCL_CLUSTER_ID_COLOR_CONTROL = 0x0300 defined in zb_zcl_common.h */ + +/*! @name Color Control cluster attributes + @{ +*/ + +/** @brief Color Control cluster information attribute identifiers + @see ZCL spec, subclause 5.2.2.2.3 +*/ + +/** + * @brief Color control attribute list + */ +enum zb_zcl_color_control_attr_e +{ + /** @internal Current_HUE attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID = 0x0000, + /** @internal Current Saturation attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID = 0x0001, + /** @internal Remaining Time attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_REMAINING_TIME_ID = 0x0002, + /** @internal CurrentX attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID = 0x0003, + /** @internal CurrentY attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID = 0x0004, + /** The DriftCompensation attribute indicates what mechanism, if any, is in use for + * compensation for color/intensity drift over time. */ + ZB_ZCL_ATTR_COLOR_CONTROL_DRIFT_COMPENSATION_ID = 0x0005, + /** The CompensationText attribute holds a textual indication of what mechanism, + * if any, is in use to compensate for color/intensity drift over time. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COMPENSATION_TEXT_ID = 0x0006, + /** @internal Color Temperature Mireds attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID = 0x0007, + /** @internal Color Mode attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_MODE_ID = 0x0008, + /** The Options attribute is a bitmap that determines the default behavior of some + * cluster commands. */ + ZB_ZCL_ATTR_COLOR_CONTROL_OPTIONS_ID = 0x000f, + /** The EnhancedCurrentHue attribute represents non-equidistant steps along the + * CIE 1931 color triangle, and it provides 16-bits precision. */ + ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ID = 0x4000, + /** The EnhancedColorMode attribute specifies which attributes are currently + * determining the color of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_COLOR_MODE_ID = 0x4001, + /** The ColorLoopActive attribute specifies the current active status of the color + * loop. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ID = 0x4002, + /** The ColorLoopDirection attribute specifies the current direction of the color + * loop. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ID = 0x4003, + /** The ColorLoopTime attribute specifies the number of seconds it SHALL take to + * perform a full color loop, i.e., to cycle all values of the EnhancedCurrentHue + * attribute (between 0x0000 and 0xffff). */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_TIME_ID = 0x4004, + /** The ColorLoopStartEnhancedHue attribute specifies the value of the + * EnhancedCurrentHue attribute from which the color loop SHALL be started. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_START_ENHANCED_HUE_ID = 0x4005, + /** The ColorLoopStoredEnhancedHue attribute specifies the value of the + * EnhancedCurrentHue attribute before the color loop was started. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_STORED_ENHANCED_HUE_ID = 0x4006, + /** The ColorCapabilities attribute specifies the color capabilities of the device + * supporting the color control cluster. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID = 0x400a, + /** The ColorTempPhysicalMinMireds attribute indicates the minimum mired value + * supported by the hardware. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_ID = 0x400b, + /** The ColorTempPhysicalMaxMireds attribute indicates the maximum mired value + * supported by the hardware. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_ID = 0x400c, + /** The CoupleColorTempToLevelMinMireds attribute specifies a lower bound on the + * value of the ColorTemperatureMireds attribute for the purposes of coupling + * the ColorTemperatureMireds attribute to the CurrentLevel attribute when the + * CoupleColorTempToLevel bit of the Options attribute of the Level Control cluster + * is equal to 1. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COUPLE_COLOR_TEMP_TO_LEVEL_MIN_MIREDS_ID = 0x400d, + /** The StartUpColorTemperatureMireds attribute SHALL define the desired startup color + * temperature value a lamp SHALL use when it is supplied with power and this value + * SHALL be reflected in the ColorTemperatureMireds attribute. */ + ZB_ZCL_ATTR_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_MIREDS_ID = 0x4010, + /** @internal Number Of Primaries attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_NUMBER_OF_PRIMARIES_ID = 0x0010, + /** @internal Primary 1 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_X_ID = 0x0011, + /** @internal Primary 1 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_Y_ID = 0x0012, + /** @internal Primary 1 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_INTENSITY_ID = 0x0013, + /** @internal Primary 2 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_X_ID = 0x0015, + /** @internal Primary 2 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_Y_ID = 0x0016, + /** @internal Primary 2 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_INTENSITY_ID = 0x0017, + /** @internal Primary 3 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_X_ID = 0x0019, + /** @internal Primary 3 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_Y_ID = 0x001a, + /** @internal Primary 3 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_INTENSITY_ID = 0x001b, + /** @internal Primary 4 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_X_ID = 0x0020, + /** @internal Primary 4 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_Y_ID = 0x0021, + /** @internal Primary 4 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_INTENSITY_ID = 0x0022, + /** @internal Primary 5 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_X_ID = 0x0024, + /** @internal Primary 5 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_Y_ID = 0x0025, + /** @internal Primary 5 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_INTENSITY_ID = 0x0026, + /** @internal Primary 6 X attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_X_ID = 0x0028, + /** @internal Primary 6 Y attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_Y_ID = 0x0029, + /** @internal Primary 6 Intensity attribute */ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_INTENSITY_ID = 0x002a, + /** The WhitePointX attribute contains the normalized chromaticity value x, as defined + * in the CIE xyY Color Space, of the current white point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_WHITE_POINT_X_ID = 0x0030, + /** The WhitePointY attribute contains the normalized chromaticity value y, as defined + * in the CIE xyY Color Space, of the current white point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_WHITE_POINT_Y_ID = 0x0031, + /** The ColorPointRX attribute contains the normalized chromaticity value x, as defined + * in the CIE xyY Color Space, of the red color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_RX_ID = 0x0032, + /** The ColorPointRY attribute contains the normalized chromaticity value y, as defined + * in the CIE xyY Color Space, of the red color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_RY_ID = 0x0033, + /** The ColorPointRIntensity attribute contains a representation of the relative + * intensity of the red color point as defined in the Dimming Light Curve in the + * Ballast Configuration cluster. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_R_INTENSITY_ID = 0x0034, + /** The ColorPointGX attribute contains the normalized chromaticity value x, as defined + * in the CIE xyY Color Space, of the green color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_GX_ID = 0x0036, + /** The ColorPointGY attribute contains the normalized chromaticity value y, as defined + * in the CIE xyY Color Space, of the green color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_GY_ID = 0x0037, + /** The ColorPointGIntensity attribute contains a representation of the relative + * intensity of the green color point as defined in the Dimming Light Curve in the + * Ballast Configuration cluster. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_G_INTENSITY_ID = 0x0038, + /** The ColorPointBX attribute contains the normalized chromaticity value x, as defined + * in the CIE xyY Color Space, of the blue color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_BX_ID = 0x003a, + /** The ColorPointBY attribute contains the normalized chromaticity value y, as defined + * in the CIE xyY Color Space, of the blue color point of the device. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_BY_ID = 0x003b, + /** The ColorPointBIntensity attribute contains a representation of the relative + * intensity of the blue color point as defined in the Dimming Light Curve in the + * Ballast Configuration cluster. */ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_POINT_B_INTENSITY_ID = 0x003c, +}; + +/** @brief Current Hue attribute minimum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_HUE_MIN_VALUE 0 + +/** @brief Current Hue attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_HUE_MAX_VALUE 0xfe + +/** + * @brief Color control Hue value + */ +enum zb_zcl_color_control_hue_e +{ +/** @brief Current Hue attribute red value */ + ZB_ZCL_COLOR_CONTROL_HUE_RED = 0, + +/** @brief Current Hue attribute green value */ + ZB_ZCL_COLOR_CONTROL_HUE_GREEN = 85 /*254 / 3*/, + +/** @brief Current Hue attribute blue value */ + ZB_ZCL_COLOR_CONTROL_HUE_BLUE = 169/*2*254 / 3*/ +}; + +/** @brief Current Saturation attribute minimum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_SATURATION_MIN_VALUE 0 + +/** @brief Current Saturation attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_SATURATION_MAX_VALUE 0xfe + +/** @brief Remaining Time attribute minimum value */ +#define ZB_ZCL_COLOR_CONTROL_REMAINING_TIME_MIN_VALUE 0 + +/** @brief Remaining Time attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_REMAINING_TIME_MAX_VALUE 0xfffe + + +/** @brief Current X attribute default value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_X_DEF_VALUE 0x616b + +/** @brief Default value for CurrentHue attribute */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_HUE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for CurrentSaturation attribute */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_SATURATION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for RemainingTime attribute */ +#define ZB_ZCL_COLOR_CONTROL_REMAINING_TIME_DEFAULT_VALUE ((zb_uint16_t)0x00) + +/** @brief Current X attribute minimum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_X_MIN_VALUE 0 + +/** @brief Current X attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_X_MAX_VALUE 0xfeff + +/** @brief Current Y attribute default value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_Y_DEF_VALUE 0x607d + +/** @brief Current Y attribute minimum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_Y_MIN_VALUE 0 + +/** @brief Current Y attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_CURRENT_Y_MAX_VALUE 0xfeff + +/** @brief Current Hue attribute red value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_X_RED (zb_uint16_t)(0.735484*ZB_ZCL_COLOR_CONTROL_CURRENT_X_MAX_VALUE) + +/** @brief Current Hue attribute green value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_X_GREEN (zb_uint16_t)(0.0138702*ZB_ZCL_COLOR_CONTROL_CURRENT_X_MAX_VALUE) + +/** @brief Current Hue attribute blue value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_X_BLUE (zb_uint16_t)(0.0995467*ZB_ZCL_COLOR_CONTROL_CURRENT_X_MAX_VALUE) + + +/** @brief Current Hue attribute red value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_Y_RED (zb_uint16_t)(0.264516*ZB_ZCL_COLOR_CONTROL_CURRENT_Y_MAX_VALUE) + +/** @brief Current Hue attribute green value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_Y_GREEN (zb_uint16_t)(0.750186*ZB_ZCL_COLOR_CONTROL_CURRENT_Y_MAX_VALUE) + +/** @brief Current Hue attribute blue value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_Y_BLUE (zb_uint16_t)(0.11196*ZB_ZCL_COLOR_CONTROL_CURRENT_Y_MAX_VALUE) + + +/** @brief Color Temperature default value (4000K) */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_DEF_VALUE 0x00fa + +/** @brief Color Temperature minimum value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_MIN_VALUE 0 + +/** @brief Color Temperature maximum value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_MAX_VALUE 0xfeff + +/** @brief Default value for ColorMode attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_MODE_DEFAULT_VALUE ((zb_uint8_t)0x01) + +/** @brief Default value for Options attribute */ +#define ZB_ZCL_COLOR_CONTROL_OPTIONS_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for EnhancedCurrentHue attribute */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_CURRENT_HUE_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for EnhancedColorMode attribute */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_COLOR_MODE_DEFAULT_VALUE ((zb_uint8_t)0x01) + +/** @brief Default value for ColorLoopActive attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOP_ACTIVE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for ColorLoopDirection attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOP_DIRECTION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Invalid value for Physical Mireds attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIREDS_INVALID_VALUE ((zb_uint16_t)0xffff) + +/*! @brief Color Mode attribute enumeration + @see ZCL spec, subclause 5.2.2.2.1.9 +*/ +enum zb_zcl_color_control_color_mode_e +{ + /** CurrentHue and CurrentSaturation */ + ZB_ZCL_COLOR_CONTROL_COLOR_MODE_HUE_SATURATION = 0x00, + /** CurrentX and CurrentY */ + ZB_ZCL_COLOR_CONTROL_COLOR_MODE_CURRENT_X_Y = 0x01, + /** ColorTemperature */ + ZB_ZCL_COLOR_CONTROL_COLOR_MODE_TEMPERATURE = 0x02, +}; + + +/** @brief Number Of Primaries attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_NUMBER_OF_PRIMARIES_MAX_VALUE 6 + +/** @brief Primary X attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_PRIMARY_X_MAX_VALUE 0xfeff + +/** @brief Primary Y attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_PRIMARY_Y_MAX_VALUE 0xfeff + +/** @brief Primary Intensity attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_PRIMARY_INTENSITY_MAX_VALUE 0xfe + +/** @brief Primary Intensity attribute not used value */ +#define ZB_ZCL_COLOR_CONTROL_PRIMARY_INTENSITY_NON_USED_VALUE 0xff + + +/** @brief Enhanced Hue Max attribute default value */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_HUE_MAX_DEF_VALUE 0xffff + +/** @brief Current Hue attribute red value */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_HUE_RED (zb_uint16_t)(ZB_ZCL_COLOR_CONTROL_HUE_RED << 8) + +/** @brief Current Hue attribute green value */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_GREEN (zb_uint16_t)(ZB_ZCL_COLOR_CONTROL_HUE_GREEN << 8) + +/** @brief Current Hue attribute blue value */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_BLUE (zb_uint16_t)(ZB_ZCL_COLOR_CONTROL_HUE_BLUE << 8) + +/** @brief Color Loop Time attribute default value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOP_TIME_DEF_VALUE 0x0019 + +/** @brief Color Loop Start Enhanced Hue attribute default value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOP_START_DEF_VALUE 0x2300 + +/** @brief Default value for ColorLoopStoredEnhancedHue attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOP_STORED_ENHANCED_HUE_DEFAULT_VALUE ((zb_uint16_t)0x0000) +/** @brief Default value for ColorCapabilities attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_CAPABILITIES_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for ColorTempPhysicalMinMireds attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for ColorTempPhysicalMaxMireds attribute */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_DEFAULT_VALUE ((zb_uint16_t)0xFEFF) + +/** @brief Color Capabilities attribute maximum value */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_CAPABILITIES_MAX_VALUE 0x001f + +/** @brief Start Up Color Temperature Mireds Max value */ +#define ZB_ZCL_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_MAX_VALUE ZB_ZCL_COLOR_CONTROL_COLOR_TEMPERATURE_MAX_VALUE + +/** @brief Start Up Color Temperature Mireds Use Previous value */ +#define ZB_ZCL_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_USE_PREVIOUS_VALUE 0xffff + +/*! @brief Options attribute flags + @see ZCL spec, subclause 5.2.2.1.1.10 +*/ +enum zb_zcl_color_control_options_e +{ + /** Execute command if the On/Off cluster, OnOff attribute is 0x00 (FALSE) */ + ZB_ZCL_COLOR_CONTROL_OPTIONS_EXECUTE_IF_OFF = 0, +}; + +/*! @brief Enhanced Color Mode attribute enumeration + @see ZCL spec, subclause 5.2.2.2.1.2 +*/ +enum zb_zcl_color_control_enhanced_color_mode_e +{ + /** CurrentHue and CurrentSaturation */ + ZB_ZCL_COLOR_CONTROL_COLOR_EX_MODE_HUE_SATURATION = 0x00, + /** CurrentX and CurrentY */ + ZB_ZCL_COLOR_CONTROL_COLOR_EX_MODE_CURRENT_X_Y = 0x01, + /** ColorTemperature */ + ZB_ZCL_COLOR_CONTROL_COLOR_EX_MODE_TEMPERATURE = 0x02, + /** EnhancedCurrentHue and EnhancedCurrentSaturation */ + ZB_ZCL_COLOR_CONTROL_COLOR_EX_MODE_HUE_SATURATION_EX = 0x03, +}; + +/*! @brief Enhanced Color Capabilities attribute flags + @see ZCL spec, subclause 5.2.2.2.1.8 +*/ +enum zb_zcl_color_control_color_capabilities_e +{ + /** Hue/saturation supported*/ + ZB_ZCL_COLOR_CONTROL_CAPABILITIES_HUE_SATURATION = 1 << 0, + /** Enhanced hue supported*/ + ZB_ZCL_COLOR_CONTROL_CAPABILITIES_EX_HUE = 1 << 1, + /** Color loop supported*/ + ZB_ZCL_COLOR_CONTROL_CAPABILITIES_COLOR_LOOP = 1 << 2, + /** XY supported*/ + ZB_ZCL_COLOR_CONTROL_CAPABILITIES_X_Y = 1 << 3, + /** Color temperature supported*/ + ZB_ZCL_COLOR_CONTROL_CAPABILITIES_COLOR_TEMP = 1 << 4, +}; + +/*! + @brief Declare attribute list for Color Control cluster (extended attribute set) + @param attr_list - attribute list name + @param current_hue - pointer to variable to store current_hue attribute value + @param current_saturation - pointer to variable to store current_saturation attribute value + @param remaining_time - pointer to variable to store remaining_time attribute value + @param current_X - pointer to variable to store current_X attribute value + @param current_Y - pointer to variable to store current_Y attribute value + @param color_temperature - pointer to variable to store color_temperature attribute value + @param color_mode - pointer to variable to store color_mode attribute value + @param options - pointer to variable to store options attribute value + @param number_primaries - pointer to variable to store number_primaries attribute value + @param primary_1_X - pointer to variable to store primary_1_X attribute value + @param primary_1_Y - pointer to variable to store primary_1_Y attribute value + @param primary_1_intensity - pointer to variable to store primary_1_intensity attribute value + @param primary_2_X - pointer to variable to store primary_2_X attribute value + @param primary_2_Y - pointer to variable to store primary_2_Y attribute value + @param primary_2_intensity - pointer to variable to store primary_2_intensity attribute value + @param primary_3_X - pointer to variable to store primary_3_X attribute value + @param primary_3_Y - pointer to variable to store primary_3_Y attribute value + @param primary_3_intensity - pointer to variable to store primary_3_intensity attribute value + @param primary_4_X - pointer to variable to store primary_4_X attribute value + @param primary_4_Y - pointer to variable to store primary_4_Y attribute value + @param primary_4_intensity - pointer to variable to store primary_4_intensity attribute value + @param primary_5_X - pointer to variable to store primary_5_X attribute value + @param primary_5_Y - pointer to variable to store primary_5_Y attribute value + @param primary_5_intensity - pointer to variable to store primary_5_intensity attribute value + @param primary_6_X - pointer to variable to store primary_6_X attribute value + @param primary_6_Y - pointer to variable to store primary_6_Y attribute value + @param primary_6_intensity - pointer to variable to store primary_6_intensity attribute value + @param enhanced_current_hue - pointer to variable to store Enhanced Current Hue attribute value + @param enhanced_color_mode - pointer to variable to store Enhanced Color Mode attribute value + @param color_loop_active - pointer to variable to store Color Loop Active attribute value + @param color_loop_direction - pointer to variable to store Color Loop Direction attribute value + @param color_loop_time - pointer to variable to store Color Loop Time attribute value + @param color_loop_start - pointer to variable to store Color Loop Start Enhanced Hue attribute value + @param color_loop_stored - pointer to variable to store Color Loop Stored Enhanced Hue attribute value + @param color_capabilities - pointer to variable to store Color Capabilities attribute value + @param color_temp_physical_min - pointer to variable to store Color Temp Physical Min attribute value + @param color_temp_physical_max - pointer to variable to store Color Temp Physical Max attribute value + @param couple_color_temp_to_level_min - pointer to variable to store Couple Color Temp To Level Min Mireds attribute value + @param start_up_color_temp - pointer to variable to store Start Up Color Temperature Mireds attribute value +*/ +#define ZB_ZCL_DECLARE_COLOR_CONTROL_ATTRIB_LIST_EXT(attr_list, current_hue, \ + current_saturation, remaining_time, current_X, current_Y, color_temperature, \ + color_mode, options, number_primaries, primary_1_X, primary_1_Y, primary_1_intensity, \ + primary_2_X, primary_2_Y, primary_2_intensity, primary_3_X, primary_3_Y, \ + primary_3_intensity, primary_4_X, primary_4_Y, primary_4_intensity, primary_5_X, \ + primary_5_Y, primary_5_intensity, primary_6_X, primary_6_Y, primary_6_intensity, \ + enhanced_current_hue, enhanced_color_mode, color_loop_active, color_loop_direction, \ + color_loop_time, color_loop_start, color_loop_stored, color_capabilities, \ + color_temp_physical_min, color_temp_physical_max, \ + couple_color_temp_to_level_min, start_up_color_temp) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, (current_hue)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, (current_saturation)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_REMAINING_TIME_ID, (remaining_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID, (current_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID, (current_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID, (color_temperature)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_MODE_ID, (color_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_OPTIONS_ID, (options)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_NUMBER_OF_PRIMARIES_ID, (number_primaries)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_X_ID, (primary_1_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_Y_ID, (primary_1_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_INTENSITY_ID, (primary_1_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_X_ID, (primary_2_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_Y_ID, (primary_2_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_INTENSITY_ID, (primary_2_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_X_ID, (primary_3_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_Y_ID, (primary_3_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_INTENSITY_ID, (primary_3_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_X_ID, (primary_4_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_Y_ID, (primary_4_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_INTENSITY_ID, (primary_4_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_X_ID, (primary_5_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_Y_ID, (primary_5_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_INTENSITY_ID, (primary_5_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_X_ID, (primary_6_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_Y_ID, (primary_6_Y)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_INTENSITY_ID, (primary_6_intensity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ID, (enhanced_current_hue)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_COLOR_MODE_ID, (enhanced_color_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ID, (color_loop_active)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ID, (color_loop_direction)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_TIME_ID, (color_loop_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_START_ENHANCED_HUE_ID, (color_loop_start)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_STORED_ENHANCED_HUE_ID, (color_loop_stored)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID, (color_capabilities)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_ID, (color_temp_physical_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_ID, (color_temp_physical_max)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_COUPLE_COLOR_TEMP_TO_LEVEL_MIN_MIREDS_ID, (couple_color_temp_to_level_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_MIREDS_ID, (start_up_color_temp)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! + @brief Declare attribute list for Color Control cluster (mandatory attribute set) + @param attr_list - attribute list name + @param current_X - pointer to variable to store current_X attribute value + @param current_Y - pointer to variable to store current_Y attribute value +*/ +#define ZB_ZCL_DECLARE_COLOR_CONTROL_ATTRIB_LIST(attr_list, current_X, current_Y) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID, (current_X)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID, (current_Y)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Color Control cluster attributes */ + +/** @cond internals_doc */ +/*! @name Color Control cluster internals + Internal structures for Color Control cluster + @internal + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_HUE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_SATURATION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_REMAINING_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_REMAINING_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_CURRENT_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_DRIFT_COMPENSATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_DRIFT_COMPENSATION_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COMPENSATION_TEXT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COMPENSATION_TEXT_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMPERATURE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_OPTIONS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_OPTIONS_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_CURRENT_HUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_COLOR_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_ENHANCED_COLOR_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_ACTIVE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_DIRECTION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_START_ENHANCED_HUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_START_ENHANCED_HUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_STORED_ENHANCED_HUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_LOOP_STORED_ENHANCED_HUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_CAPABILITIES_ID, \ + ZB_ZCL_ATTR_TYPE_16BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MIN_MIREDS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COLOR_TEMP_PHYSICAL_MAX_MIREDS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_COUPLE_COLOR_TEMP_TO_LEVEL_MIN_MIREDS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_COUPLE_COLOR_TEMP_TO_LEVEL_MIN_MIREDS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_MIREDS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_START_UP_COLOR_TEMPERATURE_MIREDS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_NUMBER_OF_PRIMARIES_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_NUMBER_OF_PRIMARIES_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_1_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_2_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_3_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_4_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_5_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_X_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_X_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_Y_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_Y_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_INTENSITY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_COLOR_CONTROL_PRIMARY_6_INTENSITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/** @internal Structure of Move variables for Move alarm + */ +typedef struct zb_zcl_color_control_move_loop_s +{ + /** Command header */ + zb_zcl_parsed_hdr_t cmd_info; + + /** @brief Time for last process move loop command */ + zb_time_t time_last; + + /** @brief attribute id */ + zb_uint16_t attr_id; + /** @brief rate */ + zb_int16_t rate; + /** @brief limit */ + zb_uint16_t limit; + /** @brief time mod - different last time - process time*/ + zb_uint16_t time_mod; + + /** @brief attribute id2 */ + zb_uint16_t attr_id2; + /** @brief rate2 */ + zb_int16_t rate2; + /** @brief limit2 */ + zb_uint16_t limit2; + /** @brief time mod - different last time - process time*/ + zb_uint16_t time_mod2; + +} zb_zcl_color_control_move_loop_t; + +#define ZB_ZCL_COLOR_CONTROL_FILL_MOVE_DATA(buf, cmd_info_, \ + attr_id_, rate_, limit_) \ +{ \ + zb_zcl_color_control_move_loop_t *loop_data = \ + ZB_BUF_GET_PARAM((buf), zb_zcl_color_control_move_loop_t); \ + ZB_MEMMOVE(&(loop_data->cmd_info), (cmd_info_), sizeof(zb_zcl_parsed_hdr_t)); \ + loop_data->time_last = ZB_TIMER_GET(); \ + loop_data->attr_id = (attr_id_); \ + loop_data->rate = (rate_); \ + loop_data->limit = (limit_); \ + loop_data->time_mod = 0; \ + loop_data->attr_id2 = 0; \ + loop_data->time_mod2 = 0; \ +} + +/*! @internal + * @brief Structure for loop of move to command */ +typedef struct zb_zcl_color_control_move_to_loop_s +{ + /** Command header */ + zb_zcl_parsed_hdr_t cmd_info; + + /** Attribute_ID */ + zb_uint16_t attr_id; + /** Start value */ + zb_uint16_t start_value; + /** Finish value */ + zb_uint16_t finish_value; + /** Is increment direction */ + zb_bool_t incr_direction; + + /** Attribute_ID */ + zb_uint16_t attr_id2; + /** Start value */ + zb_uint16_t start_value2; + /** Finish value */ + zb_uint16_t finish_value2; + + /** Start time - beacon interval */ + zb_time_t start_time; + /** transition time - time unit = 1/10sec */ + zb_time_t transition_time; +} zb_zcl_color_control_move_to_loop_t; + +#define ZB_ZCL_COLOR_CONTROL_FILL_MOVE_TO_DATA(buf, cmd_info_, \ + attr_id_, start_, finish_, incr_direction_, transition_time_) \ +{ \ + zb_zcl_color_control_move_to_loop_t *loop_data = \ + ZB_BUF_GET_PARAM((buf), zb_zcl_color_control_move_to_loop_t); \ + ZB_MEMMOVE(&(loop_data->cmd_info), (cmd_info_), sizeof(zb_zcl_parsed_hdr_t)); \ + loop_data->attr_id = (attr_id_); \ + loop_data->start_value = start_; \ + loop_data->finish_value = finish_; \ + loop_data->attr_id2 = 0; \ + loop_data->incr_direction = (zb_bool_t)(incr_direction_); \ + loop_data->start_time = ZB_TIMER_GET(); \ + loop_data->transition_time = transition_time_; \ +} + +/*! @internal + * @brief Structure for loop of step command */ +typedef struct zb_zcl_color_control_step_loop_s +{ + /** Command header */ + zb_zcl_parsed_hdr_t cmd_info; + + /** Attribute_ID */ + zb_uint16_t attr_id; + /** Rate value */ + zb_uint16_t rate; + /** @brief limit */ + zb_uint16_t limit; + + /** last time - beacon interval */ + zb_time_t last_time; + /** time bitween two steps - beacon interval */ + zb_time_t step_time; + + /** Attribute_ID second */ + zb_uint16_t attr_id2; + /** Rate value second */ + zb_uint16_t rate2; + /** @brief limit2 */ + zb_uint16_t limit2; + +} zb_zcl_color_control_step_loop_t; + +#define ZB_ZCL_COLOR_CONTROL_FILL_STEP_DATA(buf, cmd_info_, attr_id_, rate_, \ + transition_time, limit_) \ +{ \ + zb_zcl_color_control_step_loop_t *loop_data = \ + ZB_BUF_GET_PARAM((buf), zb_zcl_color_control_step_loop_t); \ + ZB_MEMMOVE(&(loop_data->cmd_info), (cmd_info_), sizeof(zb_zcl_parsed_hdr_t)); \ + loop_data->attr_id = (attr_id_); \ + loop_data->attr_id2 = 0; \ + loop_data->rate = (rate_); \ + loop_data->last_time = ZB_TIMER_GET(); \ + loop_data->step_time = ZB_TIME_UNITS_TO_BEACON_INTERVAL(transition_time); \ + loop_data->limit = (limit_); \ +} + +/*! Number of attributes mandatory for reporting in Color Control cluster + * Attribute: CurrentX, CurrentY, CurrentHue, CurrentSaturation, ColorTemperature + * */ +#define ZB_ZCL_COLOR_CONTROL_REPORT_ATTR_COUNT 5 + +/*! @} */ /* Color Control cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/*! @name Color Control cluster commands + @{ +*/ + +/************************** Color Control cluster command definitions ****************************/ + +/*! @brief Color control cluster command identifiers + @see ZCL spec, subclause 5.2.2.3 +*/ +enum zb_zcl_color_control_cmd_e +{ + /** Move To Hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE = 0x00, + /** Move Hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_HUE = 0x01, + /** Step Hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_HUE = 0x02, + /** Move To Saturation command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_SATURATION = 0x03, + /** Move Saturation command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_SATURATION = 0x04, + /** Step Saturation command */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_SATURATION = 0x05, + /** Move To Hue and Saturation command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_SATURATION = 0x06, + /** Move To Color command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR = 0x07, + /** Move Color command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR = 0x08, + /** Step Color command */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR = 0x09, + /** Move to color temperature command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR_TEMPERATURE = 0x0a, + /** Enhanced move to hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE = 0x40, + /** Enhanced move hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_HUE = 0x41, + /** Enhanced step hue command */ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_STEP_HUE = 0x42, + /** Enhanced move to hue and saturation command */ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION = 0x43, + /** Color loop set command */ + ZB_ZCL_CMD_COLOR_CONTROL_COLOR_LOOP_SET = 0x44, + /** Stop move step command */ + ZB_ZCL_CMD_COLOR_CONTROL_STOP_MOVE_STEP = 0x47, + /** Move color temperature command */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR_TEMPERATURE = 0x4b, + /** Step color temperature command */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR_TEMPERATURE = 0x4c, +}; + +/** @cond internals_doc */ +/* Color control cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_SATURATION, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_SATURATION, \ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_SATURATION, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_SATURATION, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR, \ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR_TEMPERATURE, \ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_STEP_HUE, \ + ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION, \ + ZB_ZCL_CMD_COLOR_CONTROL_COLOR_LOOP_SET, \ + ZB_ZCL_CMD_COLOR_CONTROL_STOP_MOVE_STEP, \ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR_TEMPERATURE, \ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR_TEMPERATURE + +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + + +/* command parameters enumerates */ + +/** @brief Direction of Move Hue command. + * See specs 5.2.2.3.3.2, 5.2.2.3.6.2 */ +enum zb_zcl_color_control_move_direction_e +{ + /** Stop */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_STOP = 0x00, + /** Up */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_UP = 0x01, + /** Down */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_DOWN = 0x03 +}; + +/** @brief Direction of Step command. + * See specs 5.2.2.3.4.2, 5.2.2.3.7.2 */ +enum zb_zcl_color_control_step_mode_e +{ + /** Up */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_UP = 0x01, + /** Down */ + ZB_ZCL_CMD_COLOR_CONTROL_STEP_DOWN = 0x03 +}; + + +/* command request structure */ + +/*! @brief Structured representsation of Level Control command payload (optional part) + @see ZCL spec, subclause 3.10.2.3.1.1*/ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_req_options_s +{ + /** OptionsMask field */ + zb_uint8_t options_mask; + /** OptionsOverride field */ + zb_uint8_t options_override; +} ZB_PACKED_STRUCT zb_zcl_color_control_req_options_t; + +/** @brief Move to Level payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_REQ_OPTIONS_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_req_options_t) + +/** @internal Macro for getting Move to Color command */ +#define ZB_ZCL_COLOR_CONTROL_GET_CMD_OPTIONS(data_buf, req_options, status) \ +{ \ + zb_zcl_color_control_req_options_t *req_options_ptr; \ + (req_options_ptr) = zb_buf_len(data_buf) >= \ + ZB_ZCL_COLOR_CONTROL_REQ_OPTIONS_PAYLOAD_LEN ? \ + (zb_zcl_color_control_req_options_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_options_ptr) \ + { \ + req_options.options_mask = req_options_ptr->options_mask; \ + req_options.options_override = req_options_ptr->options_override; \ + status = ZB_TRUE; \ + (void)zb_buf_cut_left(data_buf, sizeof(zb_zcl_color_control_req_options_t)); \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/******************************* MOVE_TO_HUE ******************************/ + +/** @brief Direction of Move to Hue command. + * See spec 5.2.2.3.2.3 */ +enum zb_zcl_color_control_move_to_hue_direction_e +{ + /** Shortest distance */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_SHORTEST = 0x00, + /** Longest distance */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_LONGEST = 0x01, + /** Up */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_UP = 0x02, + /** Down */ + ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_DOWN = 0x03 +}; + +/*! @brief Structure representsation of Move To Hue command payload + @see ZCL spec, subclause 5.2.2.3.2 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_to_hue_req_s +{ + /** Hue */ + zb_uint8_t hue; + /** Direction, see @ref zb_zcl_color_control_move_to_hue_direction_e */ + zb_uint8_t direction; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_to_hue_req_t; + +/** @brief Move Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_to_hue_req_t) + +/*! @brief Send Move to Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param hue - Hue value + @param direction - Direction value, see @ref zb_zcl_color_control_move_to_hue_direction_e + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, hue, direction, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (hue)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (direction)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move to Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_to_hue_req - pointer to a variable of type @ref + * zb_zcl_color_control_move_to_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_TO_HUE_REQ(buffer, move_to_hue_req, status) \ +{ \ + zb_zcl_color_control_move_to_hue_req_t *move_to_hue_req_ptr; \ + (move_to_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_to_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_to_hue_req_ptr) \ + { \ + move_to_hue_req.hue = move_to_hue_req_ptr->hue; \ + move_to_hue_req.direction = move_to_hue_req_ptr->direction; \ + ZB_HTOLE16(&(move_to_hue_req).transition_time, &(move_to_hue_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} +/******************************* MOVE_HUE ******************************/ + +/*! @brief Structure representsation of Move Hue command payload + @see ZCL spec, subclause 5.2.2.3.3 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_hue_req_s +{ + /** Move mode, see @ref zb_zcl_color_control_move_direction_e */ + zb_uint8_t move_mode; + /** Rate */ + zb_uint8_t rate; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_hue_req_t; + +/** @brief Move Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_hue_req_t) + +/*! @brief Send Move Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - Move mode, see @ref zb_zcl_color_control_move_direction_e + @param rate - Rate +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_HUE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (move_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (rate)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_hue_req - variable of type @ref + * zb_zcl_color_control_move_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_HUE_REQ(buffer, move_hue_req, status) \ +{ \ + zb_zcl_color_control_move_hue_req_t *move_hue_req_ptr; \ + (move_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_hue_req_ptr) \ + { \ + move_hue_req.move_mode = move_hue_req_ptr->move_mode; \ + move_hue_req.rate = move_hue_req_ptr->rate; \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* STEP_HUE ******************************/ + +/*! @brief Structure representsation of Step Hue command payload + @see ZCL spec, subclause 5.2.2.3.4 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_step_hue_req_s +{ + /** Step mode, see @ref zb_zcl_color_control_step_mode_e */ + zb_uint8_t step_mode; + /** Step size */ + zb_uint8_t step_size; + /** Transition time field */ + zb_uint8_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_step_hue_req_t; + +/** @brief Step Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_STEP_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_step_hue_req_t) + +/*! @brief Send Step Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - step mode value, see @ref zb_zcl_color_control_step_mode_e + @param step_size - step size value + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_STEP_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, step_mode, step_size, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_STEP_HUE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Step Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param step_hue_req - pointer to a variable of type @ref + * zb_zcl_color_control_step_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_STEP_HUE_REQ(buffer, step_hue_req, status) \ +{ \ + zb_zcl_color_control_step_hue_req_t *step_hue_req_ptr; \ + (step_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_STEP_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_step_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (step_hue_req_ptr) \ + { \ + step_hue_req.step_mode = step_hue_req_ptr->step_mode; \ + step_hue_req.step_size = step_hue_req_ptr->step_size; \ + ZB_HTOLE16(&(step_hue_req).transition_time, &(step_hue_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_STEP_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Move to Saturation ******************************/ + +/*! @brief Structure representsation of Move To Saturation command payload + @see ZCL spec, subclause 5.2.2.3.5 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_to_saturation_req_s +{ + /** Saturation */ + zb_uint8_t saturation; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_to_saturation_req_t; + +/** @brief Move To Saturation payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_TO_SATURATION_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_to_saturation_req_t) + +/*! @brief Send Move to Saturation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param saturation - saturation + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_SATURATION_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, saturation, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (saturation)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move To Saturation command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_to_saturation_req - variable of type @ref + * zb_zcl_color_control_move_to_saturation_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_TO_SATURATION_REQ(buffer, move_to_saturation_req, status) \ +{ \ + zb_zcl_color_control_move_to_saturation_req_t *move_to_saturation_req_ptr; \ + (move_to_saturation_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_TO_SATURATION_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_to_saturation_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_to_saturation_req_ptr) \ + { \ + move_to_saturation_req.saturation = move_to_saturation_req_ptr->saturation; \ + ZB_HTOLE16(&(move_to_saturation_req).transition_time, &(move_to_saturation_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_TO_SATURATION_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} +/******************************* Move Saturation ******************************/ + +/*! @brief Structure representsation of Move Saturation command payload + @see ZCL spec, subclause 5.2.2.3.6 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_saturation_req_s +{ + /** Move mode, see @ref zb_zcl_color_control_move_direction_e */ + zb_uint8_t move_mode; + /** Rate */ + zb_uint8_t rate; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_saturation_req_t; + +/** @brief Move Saturation payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_SATURATION_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_saturation_req_t) + +/*! @brief Send Move Saturation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - Move mode, see @ref zb_zcl_color_control_move_direction_e + @param rate - Rate +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_SATURATION_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (move_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (rate)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move Saturation command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_saturation_req - variable of type @ref + * zb_zcl_color_control_move_saturation_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_SATURATION_REQ(buffer, move_saturation_req, status) \ +{ \ + zb_zcl_color_control_move_saturation_req_t *move_saturation_req_ptr; \ + (move_saturation_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_SATURATION_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_saturation_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_saturation_req_ptr) \ + { \ + move_saturation_req.move_mode = move_saturation_req_ptr->move_mode; \ + move_saturation_req.rate = move_saturation_req_ptr->rate; \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_SATURATION_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* STEP_SATURATION ******************************/ + +/*! @brief Structure representsation of Step Saturation command payload + @see ZCL spec, subclause 5.2.2.3.7 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_step_saturation_req_s +{ + /** Step mode, see @ref zb_zcl_color_control_step_mode_e */ + zb_uint8_t step_mode; + /** Step size */ + zb_uint8_t step_size; + /** Transition time field */ + zb_uint8_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_step_saturation_req_t; + +/** @brief Move Saturation payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_STEP_SATURATION_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_step_saturation_req_t) + +/*! @brief Send Step Saturation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - step mode value, see @ref zb_zcl_color_control_step_mode_e + @param step_size - step size value + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_STEP_SATURATION_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, step_mode, step_size, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_STEP_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Step Saturation command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param step_saturation_req - variable of type @ref + * zb_zcl_color_control_step_saturation_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_STEP_SATURATION_REQ(buffer, step_saturation_req, status) \ +{ \ + zb_zcl_color_control_step_saturation_req_t *step_saturation_req_ptr; \ + (step_saturation_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_STEP_SATURATION_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_step_saturation_req_t*)zb_buf_begin(buffer) : NULL; \ + if (step_saturation_req_ptr) \ + { \ + step_saturation_req.step_mode = step_saturation_req_ptr->step_mode; \ + step_saturation_req.step_size = step_saturation_req_ptr->step_size; \ + step_saturation_req.transition_time = step_saturation_req_ptr->transition_time; \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_STEP_SATURATION_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Move to Hue and Saturation ******************************/ + +/*! @brief Structure representsation of Move To Hue and Saturation command payload + @see ZCL spec, subclause 5.2.2.3.8 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_to_hue_saturation_req_s +{ + /** Hue */ + zb_uint8_t hue; + /** Saturation */ + zb_uint8_t saturation; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_to_hue_saturation_req_t; + +/** @brief Move to Hue and Saturation payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_to_hue_saturation_req_t) + +/*! @brief Send Move to Hue and Saturation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param hue - hue + @param saturation - saturation + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_HUE_SATURATION_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, hue, saturation, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_HUE_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (hue)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (saturation)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move To Hue and Saturation command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_to_hue_saturation_req - pointer to a variable of type @ref + * zb_zcl_color_control_move_to_hue_saturation_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_TO_HUE_SATURATION_REQ(buffer, move_to_hue_saturation_req, status) \ +{ \ + zb_zcl_color_control_move_to_hue_saturation_req_t *move_to_hue_saturation_req_ptr; \ + (move_to_hue_saturation_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_to_hue_saturation_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_to_hue_saturation_req_ptr) \ + { \ + move_to_hue_saturation_req.hue = move_to_hue_saturation_req_ptr->hue; \ + move_to_hue_saturation_req.saturation = move_to_hue_saturation_req_ptr->saturation; \ + ZB_HTOLE16(&(move_to_hue_saturation_req).transition_time, &(move_to_hue_saturation_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Move to Color ******************************/ + +/*! @brief Structure representsation of Move To Color command payload + @see ZCL spec, subclause 5.2.2.3.9 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_to_color_req_s +{ + /** ColorX */ + zb_uint16_t color_x; + /** ColorY */ + zb_uint16_t color_y; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_to_color_req_t; + +/** @brief Move to Color payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_to_color_req_t) + +/*! @brief Send Move to Color command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param color_x - colorX + @param color_y - colorY + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_COLOR_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, color_x, color_y, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_x)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_y)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + + +/** @brief Macro for getting Move To Color command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * zb_zcl_color_control_move_to_color_req_s. + * @param move_to_color_req containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_TO_COLOR_REQ(buffer, move_to_color_req, status) \ +{ \ + zb_zcl_color_control_move_to_color_req_t *move_to_color_req_ptr; \ + (move_to_color_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_to_color_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_to_color_req_ptr) \ + { \ + ZB_HTOLE16(&(move_to_color_req).color_x, &(move_to_color_req_ptr->color_x)); \ + ZB_HTOLE16(&(move_to_color_req).color_y, &(move_to_color_req_ptr->color_y)); \ + ZB_HTOLE16(&(move_to_color_req).transition_time, &(move_to_color_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Move Color ******************************/ + +/*! @brief Structure representsation of Move Color command payload + @see ZCL spec, subclause 5.2.2.3.10 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_color_req_s +{ + /** RateX */ + zb_int16_t rate_x; + /** RateY */ + zb_int16_t rate_y; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_color_req_t; + +/** @brief Move Color payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_color_req_t) + +/*! @brief Send Move Color command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param rate_x - RateX + @param rate_y - RateY +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_COLOR_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, rate_x, rate_y) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (rate_x)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (rate_y)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move Color command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_color_req - variable of type @ref + * zb_zcl_color_control_move_color_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_COLOR_REQ(buffer, move_color_req, status) \ +{ \ + zb_zcl_color_control_move_color_req_t *move_color_req_ptr; \ + (move_color_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_color_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_color_req_ptr) \ + { \ + ZB_HTOLE16(&(move_color_req).rate_x, &(move_color_req_ptr->rate_x)); \ + ZB_HTOLE16(&(move_color_req).rate_y, &(move_color_req_ptr->rate_y)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Step Color ******************************/ + +/*! @brief Structure representsation of Step Color command payload + @see ZCL spec, subclause 5.2.2.3.11 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_step_color_req_s +{ + /** StepX */ + zb_uint16_t step_x; + /** StepY */ + zb_uint16_t step_y; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_step_color_req_t; + +/** @brief Step Color payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_STEP_COLOR_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_step_color_req_t) + +/*! @brief Send Step Color command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_x - StepX + @param step_y - StepY + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_STEP_COLOR_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, step_x, step_y, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (step_x)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (step_y)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move Color command + * @attention Assumes that ZCL header already cut. + * @param buffer Buffer containing the packet. + * @param step_color_req - variable of type @ref zb_zcl_color_control_step_color_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_STEP_COLOR_REQ(buffer, step_color_req, status) \ +{ \ + zb_zcl_color_control_step_color_req_t *step_color_req_ptr; \ + (step_color_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_STEP_COLOR_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_step_color_req_t*)zb_buf_begin(buffer) : NULL; \ + if (step_color_req_ptr) \ + { \ + ZB_HTOLE16(&(step_color_req).step_x, &(step_color_req_ptr->step_x)); \ + ZB_HTOLE16(&(step_color_req).step_y, &(step_color_req_ptr->step_y)); \ + ZB_HTOLE16(&(step_color_req).transition_time, &(step_color_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_STEP_COLOR_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Move to Color Temperature ******************************/ + +/*! @brief Structure representsation of Move To Color Temperature command payload + @see ZCL spec, subclause 5.2.2.3.12 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_to_color_temperature_req_s +{ + /** Color Temperature */ + zb_uint16_t color_temperature; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_to_color_temperature_req_t; + +/** @brief Move to Color Temperature payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_TEMP_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_to_color_temperature_req_t) + + +/*! @brief Send Move To Color Temperature command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param color_temperature - Color Temperature + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_TO_COLOR_TEMPERATURE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, color_temperature, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_TO_COLOR_TEMPERATURE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_temperature)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move to Color Temperature command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_to_color_temperature_req - variable of type @ref + * zb_zcl_color_control_move_to_color_temperature_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_TO_COLOR_TEMPERATURE_REQ(buffer, move_to_color_temperature_req, status) \ +{ \ + zb_zcl_color_control_move_to_color_temperature_req_t *move_to_color_temp_req_ptr; \ + (move_to_color_temp_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_TEMP_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_to_color_temperature_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_to_color_temp_req_ptr) \ + { \ + ZB_HTOLE16(&(move_to_color_temperature_req).color_temperature, &(move_to_color_temp_req_ptr->color_temperature)); \ + ZB_HTOLE16(&(move_to_color_temperature_req).transition_time, &(move_to_color_temp_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_TO_COLOR_TEMP_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* ENHANCED_MOVE_TO_HUE ******************************/ + +/*! @brief Structure representsation of Enhanced Move To Hue command payload + @see ZCL spec, subclause 5.2.2.3.14 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_enhanced_move_to_hue_req_s +{ + /** Enhanced Hue */ + zb_uint16_t enhanced_hue; + /** Direction, see @ref zb_zcl_color_control_move_to_hue_direction_e */ + zb_uint8_t direction; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_enhanced_move_to_hue_req_t; + +/** @brief Enhanced Move to Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_enhanced_move_to_hue_req_t) + +/*! @brief Send Enhanced Move to Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param ex_hue - Enhanced Hue value + @param direction - Direction value, see @ref zb_zcl_color_control_move_to_hue_direction_e + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_ENHANCED_MOVE_TO_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, ex_hue, direction, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (ex_hue)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (direction)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Enhanced Move to Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param enhanced_move_to_hue_req - variable of type @ref + * zb_zcl_color_control_enhanced_move_to_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_ENHANCED_MOVE_TO_HUE_REQ(buffer, enhanced_move_to_hue_req, status) \ +{ \ + zb_zcl_color_control_enhanced_move_to_hue_req_t *enhanced_move_to_hue_req_ptr; \ + (enhanced_move_to_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_enhanced_move_to_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (enhanced_move_to_hue_req_ptr) \ + { \ + ZB_HTOLE16(&(enhanced_move_to_hue_req).enhanced_hue, &(enhanced_move_to_hue_req_ptr->enhanced_hue)); \ + enhanced_move_to_hue_req.direction = enhanced_move_to_hue_req_ptr->direction; \ + ZB_HTOLE16(&(enhanced_move_to_hue_req).transition_time, &(enhanced_move_to_hue_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* ENHANCED_MOVE_HUE ******************************/ + +/*! @brief Structure representsation of Enhanced Move Hue command payload + @see ZCL spec, subclause 5.2.2.3.15 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_enhanced_move_hue_req_s +{ + /** Move mode, see @ref zb_zcl_color_control_move_direction_e */ + zb_uint8_t move_mode; + /** Rate */ + zb_uint16_t rate; +} ZB_PACKED_STRUCT zb_zcl_color_control_enhanced_move_hue_req_t; + +/** @brief Enhanced Move to Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_enhanced_move_hue_req_t) + +/*! @brief Send Enhanced Move Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - Move mode, see @ref zb_zcl_color_control_move_direction_e + @param rate - Rate +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_ENHANCED_MOVE_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_HUE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (move_mode)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (rate)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Enhanced Move Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param enhanced_move_hue_req - variable of type @ref + * zb_zcl_color_control_enhanced_move_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_ENHANCED_MOVE_HUE_REQ(buffer, enhanced_move_hue_req, status) \ +{ \ + zb_zcl_color_control_enhanced_move_hue_req_t *enhanced_move_hue_req_ptr; \ + (enhanced_move_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_enhanced_move_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (enhanced_move_hue_req_ptr) \ + { \ + enhanced_move_hue_req.move_mode = enhanced_move_hue_req_ptr->move_mode; \ + ZB_HTOLE16(&(enhanced_move_hue_req).rate, &(enhanced_move_hue_req_ptr->rate)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* ENHANCED_STEP_HUE ******************************/ + +/*! @brief Structure representsation of Enhanced Step Hue command payload + @see ZCL spec, subclause 5.2.2.3.16 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_enhanced_step_hue_req_s +{ + /** Step mode, see @ref zb_zcl_color_control_step_mode_e */ + zb_uint8_t step_mode; + /** Step size */ + zb_uint16_t step_size; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_enhanced_step_hue_req_t; + +/** @brief Enhanced Move to Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_STEP_HUE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_enhanced_step_hue_req_t) + +/*! @brief Send Enhanced Step Hue command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - step mode value, see @ref zb_zcl_color_control_step_mode_e + @param step_size - step size value + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_ENHANCED_STEP_HUE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, step_mode, step_size, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_STEP_HUE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Enhanced Step Hue command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param enhanced_step_hue_req - variable of type @ref + * zb_zcl_color_control_enhanced_step_hue_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_ENHANCED_STEP_HUE_REQ(buffer, enhanced_step_hue_req, status) \ +{ \ + zb_zcl_color_control_enhanced_step_hue_req_t *enhanced_step_hue_req_ptr; \ + (enhanced_step_hue_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_ENHANCED_STEP_HUE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_enhanced_step_hue_req_t*)zb_buf_begin(buffer) : NULL; \ + if (enhanced_step_hue_req_ptr) \ + { \ + enhanced_step_hue_req.step_mode = enhanced_step_hue_req_ptr->step_mode; \ + ZB_HTOLE16(&(enhanced_step_hue_req).step_size, &(enhanced_step_hue_req_ptr->step_size)); \ + ZB_HTOLE16(&(enhanced_step_hue_req).transition_time, &(enhanced_step_hue_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_ENHANCED_STEP_HUE_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Enhanced Move to Hue and Saturation ******************************/ + +/*! @brief Structure representsation of Move To Hue and Saturation command payload + @see ZCL spec, subclause 5.2.2.3.17 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_enhanced_move_to_hue_saturation_req_s +{ + /** Enhanced Hue */ + zb_uint16_t enhanced_hue; + /** Saturation */ + zb_uint8_t saturation; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_color_control_enhanced_move_to_hue_saturation_req_t; + +/** @brief Enhanced Move to Hue payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_enhanced_move_to_hue_saturation_req_t) + +/*! @brief Send Enhanced Move to Hue and Saturation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param enhanced_hue - enhanced hue + @param saturation - saturation + @param transition_time - Transition Time value +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_ENHANCED_MOVE_TO_HUE_SATURATION_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, enhanced_hue, saturation, transition_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (enhanced_hue)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (saturation)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Enhanced Move To Hue and Saturation command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param enhanced_move_to_hue_saturation_req - variable of type @ref + * zb_zcl_color_control_enhanced_move_to_hue_saturation_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_ENHANCED_MOVE_TO_HUE_SATURATION_REQ(buffer, enhanced_move_to_hue_saturation_req, status) \ +{ \ + zb_zcl_color_control_enhanced_move_to_hue_saturation_req_t *enhanced_move_to_hue_saturation_req_ptr; \ + (enhanced_move_to_hue_saturation_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_enhanced_move_to_hue_saturation_req_t*)zb_buf_begin(buffer) : NULL; \ + if (enhanced_move_to_hue_saturation_req_ptr) \ + { \ + ZB_HTOLE16(&(enhanced_move_to_hue_saturation_req).enhanced_hue, &(enhanced_move_to_hue_saturation_req_ptr->enhanced_hue)); \ + enhanced_move_to_hue_saturation_req.saturation = enhanced_move_to_hue_saturation_req_ptr->saturation; \ + ZB_HTOLE16(&(enhanced_move_to_hue_saturation_req).transition_time, &(enhanced_move_to_hue_saturation_req_ptr->transition_time)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_ENHANCED_MOVE_TO_HUE_SATURATION_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Color Loop Set ******************************/ + +/*! @brief Structure representsation of Color Loop Set command payload + @see ZCL spec, subclause 5.2.2.3.18 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_color_loop_set_req_s +{ + /** Update flags, see @ref zb_zcl_color_control_color_loop_update_e */ + zb_uint8_t update_flags; + /** Action, see @ref zb_zcl_color_control_color_loop_action_e */ + zb_uint8_t action; + /** Direction, see @ref zb_zcl_color_control_color_loop_direction_e */ + zb_uint8_t direction; + /** Time */ + zb_uint16_t time; + /** Start hue */ + zb_uint16_t start_hue; +} ZB_PACKED_STRUCT zb_zcl_color_control_color_loop_set_req_t; + +/** @brief Enhanced Color Loop Set payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_COLOR_LOOR_SET_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_color_loop_set_req_t) + +/** @brief Update flag for Color Loop Set command + * See ZCL specs 5.2.2.3.18.1 */ +enum zb_zcl_color_control_color_loop_update_e +{ + /** Update action */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_UPDATE_ACTION = 1 << 0, + /** Update direction */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_UPDATE_DIRECTION = 1 << 1, + /** Update time */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_UPDATE_TIME = 1 << 2, + /** Update start hue */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_UPDATE_START_HUE = 1 << 3, +}; + +/** @brief Action enumerate for Color Loop Set command + * See ZCL specs 5.2.2.3.18.2 */ +enum zb_zcl_color_control_color_loop_action_e +{ + /** De-activate the color loop */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_ACTION_DEACTIVATE = 0, + /** Activate the color loop from the value in the Color Loop Start Enhanced Hue field*/ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_ACTION_START_HUE = 1, + /** Activate the color loop from the value of the Enhanced Current Hue attribute*/ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_ACTION_CURRENT_HUE = 2, +}; + +/** @brief Direction enumerate for Color Loop Set command + * See ZCL specs 5.2.2.3.18.3 */ +enum zb_zcl_color_control_color_loop_direction_e +{ + /** Decrement the hue in the color loop */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_DIRECTION_DECREMENT = 0, + /** Increment the hue in the color loop */ + ZB_ZCL_CMD_COLOR_CONTROL_LOOP_DIRECTION_INCREMENT = 1, +}; + +/*! @internal + * @brief Structure for loop of Color Loop Set command */ +typedef struct zb_zcl_color_control_color_loop_set_s +{ + /** Command header */ + zb_zcl_parsed_hdr_t cmd_info; + + /** Last time - beacon interval */ + zb_time_t last_time; + +} zb_zcl_color_control_color_loop_set_t; + +#define ZB_ZCL_COLOR_CONTROL_FILL_COLOR_LOOP_SET_DATA(buf, cmd_info_) \ +{ \ + zb_zcl_color_control_color_loop_set_t *loop_data = \ + ZB_BUF_GET_PARAM((buf), zb_zcl_color_control_color_loop_set_t); \ + ZB_MEMMOVE(&(loop_data->cmd_info), (cmd_info_), sizeof(zb_zcl_parsed_hdr_t)); \ + loop_data->last_time = ZB_TIMER_GET(); \ +} + +/*! @brief Send Color Loop Set command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param update_flags - update flags, see @ref zb_zcl_color_control_color_loop_update_e + @param action - action, see @ref zb_zcl_color_control_color_loop_action_e + @param direction - direction, see @ref zb_zcl_color_control_color_loop_direction_e + @param time - time + @param start_hue - start hue +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_COLOR_LOOP_SET_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, update_flags, action, direction, time, start_hue) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_COLOR_LOOP_SET); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (update_flags)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (action)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (direction)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (time)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (start_hue)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Color Loop Set command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param color_loop_set_req - pointer to a variable of + * type @ref zb_zcl_color_control_color_loop_set_req_t + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_COLOR_LOOP_SET_REQ(buffer, color_loop_set_req, status) \ +{ \ + zb_zcl_color_control_color_loop_set_req_t *color_loop_set_req_ptr; \ + (color_loop_set_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_COLOR_LOOR_SET_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_color_loop_set_req_t*)zb_buf_begin(buffer) : NULL; \ + if (color_loop_set_req_ptr) \ + { \ + color_loop_set_req.update_flags = color_loop_set_req_ptr->update_flags; \ + color_loop_set_req.action = color_loop_set_req_ptr->action; \ + color_loop_set_req.direction = color_loop_set_req_ptr->direction; \ + ZB_HTOLE16(&(color_loop_set_req).time, &(color_loop_set_req_ptr->time)); \ + ZB_HTOLE16(&(color_loop_set_req).start_hue, &(color_loop_set_req_ptr->start_hue)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_COLOR_LOOR_SET_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Stop move step ******************************/ + +/*! @brief Stop move step command, see ZCL spec 5.2.2.3.19 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_STOP_MOVE_STEP_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_STOP_MOVE_STEP); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/******************************* Move color temperature command ******************************/ + +/*! @brief Structure representsation of Move color temperature command payload + @see ZCL spec, subclause 5.2.2.3.20 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_move_color_temp_req_s +{ + /** Move mode, see @ref zb_zcl_color_control_move_direction_e */ + zb_uint8_t move_mode; + /** Rate */ + zb_uint16_t rate; + /** Color temperature minimum */ + zb_uint16_t color_temp_min; + /** Color temperature maximum */ + zb_uint16_t color_temp_max; +} ZB_PACKED_STRUCT zb_zcl_color_control_move_color_temp_req_t; + +/** @brief Enhanced Move Color Temperature payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_TEMP_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_move_color_temp_req_t) + +/*! @brief Send Move color temperature command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - move mode, see @ref zb_zcl_color_control_move_direction_e + @param rate - rate + @param color_temp_min - color temperature minimum + @param color_temp_max - color temperature maximum +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_MOVE_COLOR_TEMP_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate, color_temp_min, color_temp_max) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_MOVE_COLOR_TEMPERATURE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (move_mode)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (rate)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_temp_min)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_temp_max)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move color temperature command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_color_temp_req - variable of type @ref + * zb_zcl_color_control_move_color_temp_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_COLOR_TEMP_REQ(buffer, move_color_temp_req, status) \ +{ \ + zb_zcl_color_control_move_color_temp_req_t *move_color_temp_req_ptr; \ + (move_color_temp_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_TEMP_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_color_temp_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_color_temp_req_ptr) \ + { \ + move_color_temp_req.move_mode = move_color_temp_req_ptr->move_mode; \ + ZB_HTOLE16(&(move_color_temp_req).rate, &(move_color_temp_req_ptr->rate)); \ + ZB_HTOLE16(&(move_color_temp_req).color_temp_min, &(move_color_temp_req_ptr->color_temp_min)); \ + ZB_HTOLE16(&(move_color_temp_req).color_temp_max, &(move_color_temp_req_ptr->color_temp_max)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_TEMP_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/******************************* Step color temperature command ******************************/ + +/*! @brief Structure representsation of Step color temperature command command payload + @see ZCL spec, subclause 5.2.2.3.21 */ +typedef ZB_PACKED_PRE struct zb_zcl_color_control_step_color_temp_req_s +{ + /** Step mode, see @ref zb_zcl_color_control_step_mode_e */ + zb_uint8_t step_mode; + /** Step size */ + zb_uint16_t step_size; + /** Transition time field */ + zb_uint16_t transition_time; + /** Color temperature minimum */ + zb_uint16_t color_temp_min; + /** Color temperature maximum */ + zb_uint16_t color_temp_max; +} ZB_PACKED_STRUCT zb_zcl_color_control_step_color_temp_req_t; + +/** @brief Enhanced Move Color Temperature payload length macro */ +#define ZB_ZCL_COLOR_CONTROL_STEP_COLOR_TEMP_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_color_control_step_color_temp_req_t) + +/*! @brief Step color temperature command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - move mode, see @ref zb_zcl_color_control_step_mode_e + @param step_size - step size + @param transition_time - Transition Time value + @param color_temp_min - color temperature minimum + @param color_temp_max - color temperature maximum +*/ +#define ZB_ZCL_COLOR_CONTROL_SEND_STEP_COLOR_TEMP_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, step_mode, step_size, transition_time, color_temp_min, color_temp_max) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_COLOR_CONTROL_STEP_COLOR_TEMPERATURE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_temp_min)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (color_temp_max)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, cb); \ +} + +/** @brief Macro for getting Move color temperature command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param move_color_temp_req - variable of type @ref + * zb_zcl_color_control_move_color_temp_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_MOVE_COLOR_TEMP_REQ(buffer, move_color_temp_req, status) \ +{ \ + zb_zcl_color_control_move_color_temp_req_t *move_color_temp_req_ptr; \ + (move_color_temp_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_TEMP_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_move_color_temp_req_t*)zb_buf_begin(buffer) : NULL; \ + if (move_color_temp_req_ptr) \ + { \ + move_color_temp_req.move_mode = move_color_temp_req_ptr->move_mode; \ + ZB_HTOLE16(&(move_color_temp_req).rate, &(move_color_temp_req_ptr->rate)); \ + ZB_HTOLE16(&(move_color_temp_req).color_temp_min, &(move_color_temp_req_ptr->color_temp_min)); \ + ZB_HTOLE16(&(move_color_temp_req).color_temp_max, &(move_color_temp_req_ptr->color_temp_max)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_MOVE_COLOR_TEMP_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Macro for getting Move color temperature command + * @attention Assumes that ZCL header already cut. + * @param buffer containing the packet (by pointer). + * @param step_color_temp_req - variable of type @ref + * zb_zcl_color_control_step_color_temp_req_s. + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_COLOR_CONTROL_GET_STEP_COLOR_TEMP_REQ(buffer, step_color_temp_req, status) \ +{ \ + zb_zcl_color_control_step_color_temp_req_t *step_color_temp_req_ptr; \ + (step_color_temp_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_COLOR_CONTROL_STEP_COLOR_TEMP_REQ_PAYLOAD_LEN ? \ + (zb_zcl_color_control_step_color_temp_req_t*)zb_buf_begin(buffer) : NULL; \ + if (step_color_temp_req_ptr) \ + { \ + step_color_temp_req.step_mode = step_color_temp_req_ptr->step_mode; \ + ZB_HTOLE16(&(step_color_temp_req).step_size, &(step_color_temp_req_ptr->step_size)); \ + ZB_HTOLE16(&(step_color_temp_req).transition_time, &(step_color_temp_req_ptr->transition_time)); \ + ZB_HTOLE16(&(step_color_temp_req).color_temp_min, &(step_color_temp_req_ptr->color_temp_min)); \ + ZB_HTOLE16(&(step_color_temp_req).color_temp_max, &(step_color_temp_req_ptr->color_temp_max)); \ + (void)zb_buf_cut_left(buffer, ZB_ZCL_COLOR_CONTROL_STEP_COLOR_TEMP_REQ_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/*! @} */ /* Color Control cluster commands */ + +/** @cond internals_doc + * + @name Added struct and define for specific Color Control cluster commands + @{ +*/ + +#define ZB_ZCL_COLOR_CONTROL_SEC_TO_MSEC 1000 + +/** Standard Color Control time uint = 1/10 sec */ +#define ZB_ZCL_COLOR_CONTROL_TIMER_INTERVAL 100 + +/** Standard Color Control time uint = 1/10 sec, beacon */ +#define ZB_ZCL_COLOR_CONTROL_TIMER_BEACON_INTERVAL \ + ZB_MILLISECONDS_TO_BEACON_INTERVAL(ZB_ZCL_COLOR_CONTROL_TIMER_INTERVAL) + +/** + * @brief Struct for process one interation of move command for one attribute + */ +typedef struct zb_zcl_color_control_loop_element_s +{ + zb_uint8_t endpoint; /** Device endpoint */ + zb_uint8_t buffer_id; /** buffer for invoke User App */ + + zb_uint16_t attr_id; /** Attribute ID */ + zb_int16_t value; /** delta value */ + zb_bool_t is_continue; /** If ZB_TRUE attribute when is already limit value, command + continious from another limit. If ZB_FALSE attribute when + is already limit value, command stop */ + zb_uint16_t limit; /** limit of attribute value */ + +} zb_zcl_color_control_loop_element_t; + +/** + * @brief Define for fill struct process step command for one attribute, + * see @ref zb_zcl_color_control_loop_element_s + * + * @param el_data - struct see @ref zb_zcl_color_control_loop_element_s 'zb_zcl_color_control_loop_element_t' + * @param endp - endpoint + * @param param - buffer for invoke User App + * @param attr - attribute ID + * @param value_ - value + * @param is_continue_ - continue if limit dest + * @param limit_ - limit of attribute value, min or max - depend of sing of rate field + */ +#define ZB_ZCL_COLOR_CONTROL_FILL_LOOP_ELEMENT(el_data, endp, \ + param, attr, value_, is_continue_, limit_) \ + (el_data).endpoint = (endp); \ + (el_data).buffer_id = (param); \ + (el_data).attr_id = (attr); \ + (el_data).value = (value_); \ + (el_data).is_continue = (is_continue_); \ + (el_data).limit = (limit_); + + +/** + * @brief Copy 16bit attribute value for Color Control cluster + * + * @param endpoint - device endpoint + * @param attr_id_to - destination attribute ID + * @param attr_id_from - source attribute ID + */ +#define ZB_ZCL_COLOR_CONTROL_COPY_ATTRIBUTE_16(endpoint, attr_id_to, attr_id_from) \ +{ \ + zb_uint16_t value; \ + zb_zcl_attr_t * attr_desc = zb_zcl_get_attr_desc_a((endpoint), \ + ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ZB_ZCL_CLUSTER_SERVER_ROLE, (attr_id_from)); \ + ZB_ASSERT(attr_desc); \ + value = ZB_ZCL_GET_ATTRIBUTE_VAL_16(attr_desc); \ + \ + attr_desc = zb_zcl_get_attr_desc_a((endpoint), \ + ZB_ZCL_CLUSTER_ID_COLOR_CONTROL, ZB_ZCL_CLUSTER_SERVER_ROLE, (attr_id_to)); \ + ZB_ASSERT(attr_desc); \ + ZB_ZCL_SET_DIRECTLY_ATTR_VAL16(attr_desc, value); \ +} + +/** + * @brief Struct invoke User App and set attribute value + */ +typedef struct zb_zcl_color_control_invoke_user_s +{ + zb_uint8_t endpoint; + zb_uint16_t attr_id; + zb_uint16_t new_value; /** New value attribute */ +} zb_zcl_color_control_invoke_user_t; + +/** @} + * + * @endcond */ /* internals_doc */ + + +/*! @} */ /* ZCL Color Control cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_color_control_init_server(void); +void zb_zcl_color_control_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_SERVER_ROLE_INIT zb_zcl_color_control_init_server +#define ZB_ZCL_CLUSTER_ID_COLOR_CONTROL_CLIENT_ROLE_INIT zb_zcl_color_control_init_client + +#endif /* ZB_ZCL_COLOR_CONTROL_H */ diff --git a/zboss/include/zcl/zb_zcl_commands.h b/zboss/include/zcl/zb_zcl_commands.h new file mode 100644 index 0000000000..c298d47c92 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_commands.h @@ -0,0 +1,2407 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Zigbee cluster library commands common for all clusters +*/ +#if ! defined ZB_ZCL_COMMANDS_H +#define ZB_ZCL_COMMANDS_H + +#include "zcl/zb_zcl_common.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +struct zb_zcl_reporting_info_s; /* Forward declaration */ + +/* Debug functions */ +#ifdef DEBUG + +#define ZB_ZCL_DEBUG_DUMP_COMMAND(buf) zb_zcl_dump_cmd(buf) +#define ZB_ZCL_DEBUG_DUMP_HEADER(header) dump_zcl_header(header) + +void zb_zcl_dump_cmd(zb_bufid_t buf); +void dump_zcl_header(zb_zcl_parsed_hdr_t *header); +void dump_zcl_default_resp(zb_bufid_t buffer); + +#else +#define ZB_ZCL_DEBUG_DUMP_COMMAND(buf) while(0); +#define ZB_ZCL_DEBUG_DUMP_HEADER(header) while(0); +#endif + +/** @addtogroup ZB_ZCL_COMMANDS + * @{ + * @details + * This section describes data structures representing command payloads shared by all clusters, + * and APIs for sending these commands and parsing their payloads. + */ + +/** @brief ZCL common command IDs + @see ZCL spec, clause 2.4 + @note The enumeration does not contain commands not unused in ZB HA profile +*/ +typedef enum zb_zcl_cmd_e +{ + ZB_ZCL_CMD_READ_ATTRIB = 0x00, /*!< Read attributes command */ + ZB_ZCL_CMD_READ_ATTRIB_RESP = 0x01, /*!< Read attributes response command */ + ZB_ZCL_CMD_WRITE_ATTRIB = 0x02, /*!< Write attributes foundation command */ + ZB_ZCL_CMD_WRITE_ATTRIB_UNDIV = 0x03, /*!< Write attributes undivided command */ + ZB_ZCL_CMD_WRITE_ATTRIB_RESP = 0x04, /*!< Write attributes response command */ + ZB_ZCL_CMD_WRITE_ATTRIB_NO_RESP = 0x05, /*!< Write attributes no response command */ + ZB_ZCL_CMD_CONFIG_REPORT = 0x06, /*!< Configure reporting command */ + ZB_ZCL_CMD_CONFIG_REPORT_RESP = 0x07, /*!< Configure reporting response command */ + ZB_ZCL_CMD_READ_REPORT_CFG = 0x08, /*!< Read reporting config command */ + ZB_ZCL_CMD_READ_REPORT_CFG_RESP = 0x09, /*!< Read reporting config response command */ + ZB_ZCL_CMD_REPORT_ATTRIB = 0x0a, /*!< Report attribute command */ + ZB_ZCL_CMD_DEFAULT_RESP = 0x0b, /*!< Default response command */ + ZB_ZCL_CMD_DISC_ATTRIB = 0x0c, /*!< Discover attributes command */ + ZB_ZCL_CMD_DISC_ATTRIB_RESP = 0x0d, /*!< Discover attributes response command */ + /*Not release yet*/ + ZB_ZCL_CMD_READ_ATTRIB_STRUCT = 0x0e, /*!< Read attributes structured */ + ZB_ZCL_CMD_WRITE_ATTRIB_STRUCT = 0x0f, /*!< Write attributes structured */ + ZB_ZCL_CMD_WRITE_ATTRIB_STRUCT_RESP = 0x10, /*!< Write attributes structured response */ + + ZB_ZCL_CMD_DISCOVER_COMMANDS_RECEIVED = 0x11, /*!< Discover Commands Received command */ + ZB_ZCL_CMD_DISCOVER_COMMANDS_RECEIVED_RES = 0x12, /*!< Discover Commands Received response command */ + ZB_ZCL_CMD_DISCOVER_COMMANDS_GENERATED = 0x13, /*!< Discover Commands Generated command */ + ZB_ZCL_CMD_DISCOVER_COMMANDS_GENERATED_RES = 0x14, /*!< Discover Commands Generated response command */ + + /* Discover attr ext is HA1.2 specific, but as soon as this command + * handling is done together with ZCL Dosciver attr cmd, declare it + * unconditianaly */ + ZB_ZCL_CMD_DISCOVER_ATTR_EXT = 0x15, /*!< Discover attributes extended command */ + ZB_ZCL_CMD_DISCOVER_ATTR_EXT_RES = 0x16 /*!< Discover attributes extended response command */ +} zb_zcl_cmd_t; + +/** @brief ZCL broadcast endpoint */ +#define ZB_ZCL_BROADCAST_ENDPOINT 0xFF + +/** @brief Minimum time delay between responses to ZCL command sent to broadcast endpoint */ +#define ZB_ZCL_BROADCAST_ENDPOINT_CMD_RESP_JITTER (ZB_MILLISECONDS_TO_BEACON_INTERVAL(500)) + +/** @cond internals_doc */ + +/** @brief Start to declare cluster descriptors list */ +#define ZB_ZCL_START_DECLARE_CLUSTER_LIST(_cluster_list_name) \ + zb_zcl_cluster_desc_t _cluster_list_name[] = { + + +/** @brief Declare general cluster descriptor */ +#define ZB_ZCL_DECLARE_CLUSTER_DESC(_cluster_id, _attrib_list, _role) \ + { \ + (_cluster_id), \ + ZB_ZCL_ARRAY_SIZE((_attrib_list), zb_zcl_attr_t), \ + (_attrib_list), \ + (_role), \ + ZB_ZCL_MANUF_CODE_INVALID, \ + } + + +/** @brief Declare manufacturer specific cluster descriptor */ +#define ZB_ZCL_DECLARE_MANUF_CLUSTER_DESC(_cluster_id, _attrib_list, _role, _code) \ + { \ + (_cluster_id), \ + ZB_ZCL_ARRAY_SIZE((_attrib_list), zb_zcl_attr_t), \ + (_attrib_list), \ + (_role), \ + (_code) \ + } + + +/** @brief Finish cluster descriptors list */ +#define ZB_ZCL_FINISH_DECLARE_CLUSTER_LIST } + + +/** @internal @brief Send ZCL request command + + Sends ZCL request command (with direction @ref ZB_ZCL_FRAME_DIRECTION_TO_SRV) to the device + with 16-bit address. + @param buffer - ID zb_bufid_t of a buffer with payload + @param addr - short destination address + @param dst_addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and + @ref ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + @param dst_ep - destination end point + @param ep - our end point + @param prof_id - profile identifier + @param cluster_id - cluster identifier + @param cmd_id - command identifier +*/ +#define ZB_ZCL_SEND_GENERAL_COMMAND_REQ_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cmd_id) \ +{ \ + zb_uint8_t * ptr = NULL; \ + (void)zb_buf_alloc_left((buffer), sizeof(zb_zcl_frame_hdr_short_t), ptr); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), (cmd_id)); \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, NULL) \ +} + +/** @internal @brief Send ZCL response command + + Sends ZCL response command (with direction @ref ZB_ZCL_FRAME_DIRECTION_TO_CLI) to the device + with 16-bit address. + @param buffer - ID zb_bufid_t of a buffer with payload + @param addr - short destination address + @param dst_addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and + @ref ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + @param dst_ep - destination end point + @param ep - our end point + @param prof_id - profile identifier + @param cluster_id - cluster identifier + @param seq_num - sequence number + @param cmd_id - command identifier +*/ +#define ZB_ZCL_SEND_GENERAL_COMMAND_RESP_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd_id) \ +{ \ + zb_uint8_t * ptr = NULL; \ + (void)zb_buf_alloc_left((buffer), sizeof(zb_zcl_frame_hdr_short_t), ptr); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL(ptr); \ + TRACE_MSG( \ + TRACE_APS1, \ + "fc: 0x%x, seq num: %i, cmd: 0x%hx", \ + (FMT__D_D_D, *(zb_uint8_t*)zb_buf_begin(buffer), seq_num, cmd_id)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, (seq_num), (cmd_id)); \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, NULL) \ +} + +#define ZB_ZCL_SCHEDULE_STATUS_ABORT(buffer, addr, dst_addr_mode, dst_ep, ep, cb) \ + zb_zcl_schedule_status_abort(buffer, addr, dst_addr_mode, dst_ep, ep, cb) + +#ifdef ZB_USEALIAS +void zb_zcl_send_command_short_alias(zb_bufid_t buffer, + zb_addr_u *addr, zb_uint8_t dst_addr_mode, + zb_uint8_t dst_ep, zb_uint8_t ep, + zb_uint16_t prof_id, zb_uint16_t cluster_id, + zb_uint8_t radius, zb_callback_t cb, zb_uint8_t use_alias, + zb_uint16_t alias_addr, zb_uint8_t alias_seq); + +/** @internal @brief Send ZCL request command + Aliases + + Sends ZCL request command (with direction @ref ZB_ZCL_FRAME_DIRECTION_TO_SRV) to the device + with 16-bit address. + All parameters are the same as in ZB_ZCL_SEND_COMMAND_SHORT but with Aliases support + + + @param alias_addr - alias address + @param alias_seq - alias sequence number + */ +#define ZB_ZCL_SEND_COMMAND_SHORT_ALIAS( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, rd, cb, _use_alias, alias_addr, alias_seq) \ + zb_zcl_send_command_short_alias(buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, rd, cb, _use_alias, alias_addr, alias_seq) +#endif /* ZB_USEALIAS */ + +/** @internal @brief Send ZCL request command without ACK TX + + Sends ZCL request command (with direction @ref ZB_ZCL_FRAME_DIRECTION_TO_SRV) to the device + with 16-bit address. + @param buffer - ID zb_bufid_t of a buffer with payload + @param ptr - pointer to @ref zb_uint8_t start of ZCL command header + @param addr - short destination address + @param dst_addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and + @ref ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + @param dst_ep - destination end point + @param ep - our end point + @param prof_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for make next sequence number + @param random_delay - for a random delay before running the command + */ +#define ZB_ZCL_SEND_COMMAND_SHORT_WITHOUT_ACK( \ + buffer, ptr, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, random_delay) \ + (void) zb_zcl_finish_and_send_packet_new((buffer), (ptr), (zb_addr_u *)(&(addr)), dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, ZB_FALSE, ZB_TRUE, ZB_RANDOM_VALUE(random_delay)) + + +void zb_zcl_send_command_short_schedule(zb_bufid_t buffer, + zb_uint16_t addr, zb_uint8_t dst_addr_mode, + zb_uint8_t dst_ep, zb_uint8_t ep, + zb_uint16_t prof_id, zb_uint16_t cluster_id, + zb_callback_t cb, zb_uint16_t delay); + +/** @internal @brief Send ZCL request command with delay (ms) + + Sends ZCL request command (with direction @ref ZB_ZCL_FRAME_DIRECTION_TO_SRV) to the device + with 16-bit address. + @param buffer - ID zb_bufid_t of a buffer with payload + @param addr - short destination address + @param dst_addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and + @ref ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + @param dst_ep - destination end point + @param ep - our end point + @param prof_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for make next sequence number + @param delay - Delay current send + */ +#define ZB_ZCL_SEND_COMMAND_SHORT_SCHEDULE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, delay) \ + zb_zcl_send_command_short_schedule(buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, delay) + +/** @endcond */ /* internals_doc */ + +/** + * @defgroup zcl_def_resp Default response command sending and parsing. + * @{ + * @details + * Default response command is defined in ZCL spec, subclause 2.4.12. + * + * @par Example + * Command can be sent like in the following snippet: + * @snippet custom_cluster/custom_cluster_zr/custom_cluster_zr.c ZCL_SEND_DEFAULT_RESP + * Incoming default response can be barsed as following: + * @code + * zb_zcl_default_resp_payload_t* payload = ZB_ZCL_READ_DEFAULT_RESP(zcl_cmd_buf); + * @endcode + * @par + * + * For more information see any HA sample + */ + +/** + * @brief Send default response command with custom Direction + * + * If you don't want to specify direction explicitly, use @ref ZB_ZCL_SEND_DEFAULT_RESP() + * + * @param buffer - ID zb_bufid_t of a buffer with payload + * @param addr - short destination address + * @param addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and @ref + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + * @param dst_ep - destination end point + * @param ep - our end point + * @param prof_id - profile identifier + * @param cluster_id - cluster identifier + * @param seq_num - sequence number + * @param cmd - dentifier of the command the response is dedicated to + * @param status_code - status field for received command + * @param direction - direction of the command (see @ref zb_zcl_frame_direction_t) + */ +#define ZB_ZCL_SEND_DEFAULT_RESP_DIRECTION(buffer, \ + addr, addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd, status_code, direction) \ +{ \ + zb_uint8_t * ptr = NULL; \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + (direction), ZB_ZCL_NOT_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_DEFAULT_RESP); \ + *(ptr++) = cmd; \ + *(ptr++) = status_code; \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, NULL); \ +} + +/** + * @brief Send default response command and execute callback when it is acknowledged or expired + * + * If no callback is needed, use @ref ZB_ZCL_SEND_DEFAULT_RESP() + * + * @param buffer - ID zb_bufid_t of a buffer with payload + * @param addr - short destination address + * @param addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and @ref + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + * @param dst_ep - destination end point + * @param ep - our end point + * @param prof_id - profile identifier + * @param cluster_id - cluster identifier + * @param seq_num - sequence number + * @param cmd - dentifier of the command the response is dedicated to + * @param status_code - status field for received command + * @param callback - callback to be executed when command is acknowledged or expired (of type @ref zb_callback_t) + */ +#define ZB_ZCL_SEND_DEFAULT_RESP_WITH_CB(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd, status_code, callback) \ +{ \ + zb_uint8_t * ptr = NULL; \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_DEFAULT_RESP); \ + *(ptr++) = cmd; \ + *(ptr++) = status_code; \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, (callback)); \ +} + +#define ZB_ZCL_SEND_DEFAULT_RESP_WITH_CB_NEW(buffer, addr, addr_mode, dst_ep, ep, \ + prof_id, cluster_id, seq_num, cmd, status_code, callback, aps_secured) \ +{ \ + zb_uint8_t * ptr = NULL; \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_DEFAULT_RESP); \ + *(ptr++) = cmd; \ + *(ptr++) = status_code; \ + ZB_ZCL_FINISH_N_SEND_PACKET_NEW(buffer, ptr, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, (callback), aps_secured, ZB_FALSE, 0); \ +} + +/** + * @brief Send default response command and execute callback when it's acknowledged or expired + * + * If no callback is needed, use @ref ZB_ZCL_SEND_DEFAULT_RESP() + * + * @param buffer - ID zb_bufid_t of a buffer with payload + * @param addr - short destination address + * @param addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and @ref + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + * @param dst_ep - destination end point + * @param ep - our end point + * @param prof_id - profile identifier + * @param cluster_id - cluster identifier + * @param seq_num - sequence number + * @param cmd - dentifier of the command the response is dedicated to + * @param status_code - status field for received command + * @param manuf_code - manufacturer code + * @param direction - direction of the command (see @ref zb_zcl_frame_direction_t) + * @param callback - callback to be executed when command is acknowledged or expired (of type @ref zb_callback_t) + */ +#define ZB_ZCL_SEND_DEFAULT_RESP_MANUF_WITH_CB(buffer, addr, addr_mode, dst_ep, ep, prof_id, \ + cluster_id, seq_num, cmd, status_code, manuf_code, direction, callback) \ +{ \ + zb_uint8_t * ptr = NULL; \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_EXT(ptr, ZB_TRUE, direction); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, seq_num, ZB_TRUE, manuf_code, ZB_ZCL_CMD_DEFAULT_RESP); \ + *(ptr++) = cmd; \ + *(ptr++) = status_code; \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, (callback)); \ +} + +/** + * @brief check whether command requires default response to be sent + * + * Default response is sent if: + * - particular response is not sent yet + * - original command is NOT broadcat + * - disable_default_response is set to FALSE or command status is not Success + * - command itself is NOT default response + * + * This is a helper method, use @ref ZB_ZCL_CHECK_IF_SEND_DEFAULT_RESP instead + * + * @param _is_broadcast - broadcast bit from NWK header + * @param _delivery_mode - delivery mode from APS header + * @param _disable_def_resp - Disable Default Response bit from ZCL header + * @param _status - status of the handled command + * @param _is_def_resp_frame - check for command type + */ +#define ZB_ZCL_CHECK_IF_SEND_DEFAULT_RESP_EXT( \ + _is_broadcast, _delivery_mode, _disable_def_resp, _status, _is_def_resp_frame) \ + (!(_is_broadcast) && ((_delivery_mode) == ZB_APS_DELIVERY_UNICAST) && \ + (!(_disable_def_resp) || (_status) != ZB_ZCL_STATUS_SUCCESS) \ + && !(_is_def_resp_frame)) + + +/** + @brief API call that is used to check if it is needed to send + Default response for the command + @param _cmd_info - variable of zb_zcl_parsed_hdr_t type, containg + received command header data + @param _status - status of the handled command + */ +#define ZB_ZCL_CHECK_IF_SEND_DEFAULT_RESP(_cmd_info, _status) \ + ZB_ZCL_CHECK_IF_SEND_DEFAULT_RESP_EXT( \ + ZB_NWK_IS_ADDRESS_BROADCAST((_cmd_info).addr_data.common_data.dst_addr), \ + ZB_APS_FC_GET_DELIVERY_MODE((_cmd_info).addr_data.common_data.fc), \ + (_cmd_info).disable_default_response, _status, \ + ((_cmd_info).is_common_command && (_cmd_info).cmd_id == ZB_ZCL_CMD_DEFAULT_RESP)) + +/** + * @brief General API for sending Default response command + * + * @param _buffer - zb_bufid_t buffer + * @param _dst_addr - 16-bit destinition address + * @param _dst_addr_mode - destinition adress mode. Possible values + * ZB_APS_ADDR_MODE_DST_ADDR_ENDP_NOT_PRESENT, ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT, + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT + * @param _dst_ep - destinition Endpoint number + * @param _src_ep - source Endpoint number + * @param _prof_id - profile ID + * @param _cluster_id - cluster ID + * @param _seq_num - transaction sequense number + * @param _cmd - command ID + * @param _status_code - command status (enum zb_zcl_status_e) + * @param _direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param _is_manuf_specific - flag, equal to 1 if command is + * manufacturer specific + * @param _manuf_code - manufacturer specific code, is taken unto + * account only if _is_manuf_specific is equal to 1 + * @param _callback - pointer to the callback function that will be + * called when the command is sent + */ +#define ZB_ZCL_SEND_DEFAULT_RESP_EXT( \ + _buffer, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, \ + _prof_id, _cluster_id, _seq_num, _cmd, _status_code, \ + _direction, _is_manuf_specific, _manuf_code, _callback) \ +{ \ + zb_uint8_t * _ptr = NULL; \ + _ptr = ZB_ZCL_START_PACKET(_buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A(_ptr, \ + (_direction), \ + (zb_zcl_manufacturer_specific_t)((_is_manuf_specific)!=ZB_FALSE ? \ + ZB_ZCL_MANUFACTURER_SPECIFIC : ZB_ZCL_NOT_MANUFACTURER_SPECIFIC)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(_ptr, _seq_num, \ + _is_manuf_specific, _manuf_code, ZB_ZCL_CMD_DEFAULT_RESP); \ + *(_ptr++) = (_cmd); \ + *(_ptr++) = (_status_code); \ + ZB_ZCL_FINISH_PACKET(_buffer, _ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(_buffer, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _prof_id, _cluster_id, _callback); \ +} + + +/** @brief Send default response command. + * @param buffer - ID zb_bufid_t of a buffer with payload + * @param addr - short destination address + * @param addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and @ref + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + * @param dst_ep - destination end point + * @param ep - our end point + * @param prof_id - profile identifier + * @param cluster_id - cluster identifier + * @param seq_num - sequence number + * @param cmd - dentifier of the command the response is dedicated to + * @param status_code - status field for received command + */ +#define ZB_ZCL_SEND_DEFAULT_RESP( \ + buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd, status_code) \ + ZB_ZCL_SEND_DEFAULT_RESP_WITH_CB(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, \ + seq_num, cmd, status_code, NULL) + +#define ZB_ZCL_SEND_DEFAULT_RESP_NEW( \ + buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd, status_code, aps_secured) \ + ZB_ZCL_SEND_DEFAULT_RESP_WITH_CB_NEW(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, \ + seq_num, cmd, status_code, NULL, aps_secured) + +/** + * @brief Send default response command. + * + * @param buffer - ID zb_bufid_t of a buffer with payload + * @param addr - short destination address + * @param addr_mode - address mode, only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and @ref + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported + * @param dst_ep - destination end point + * @param ep - our end point + * @param prof_id - profile identifier + * @param cluster_id - cluster identifier + * @param seq_num - sequence number + * @param cmd - dentifier of the command the response is dedicated to + * @param status_code - status field for received command + * @param manuf_code - manufacturer code + * @param direction - direction of command (see @ref zb_zcl_frame_direction_t) + */ +#define ZB_ZCL_SEND_DEFAULT_RESP_MANUF( \ + buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, seq_num, cmd, status_code, manuf_code, direction) \ + ZB_ZCL_SEND_DEFAULT_RESP_MANUF_WITH_CB(buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, \ + seq_num, cmd, status_code, manuf_code, direction, NULL) + + + +/** @brief Default response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_default_resp_payload_s +{ + zb_uint8_t command_id; /*!< Command identifier */ + zb_uint8_t status; /*!< Command execution status */ +} ZB_PACKED_STRUCT zb_zcl_default_resp_payload_t; + +/** @brief Default response structured reading + @param buffer - pointer to the message buffer (of type zb_bufid_t) + containing payload + @return pointer to @ref zb_zcl_default_resp_payload_s structure + @attention returned pointer will point to the same data in the buffer thus + being valid until buffer data will be overwritten. +*/ +#define ZB_ZCL_READ_DEFAULT_RESP(buffer) \ + ( (zb_buf_len((buffer)) != sizeof(zb_zcl_default_resp_payload_t)) ? \ + NULL : \ + (zb_zcl_default_resp_payload_t*)zb_buf_begin((buffer))) + +/** @} */ /* Default response command sending and parsing. */ + +/*************** Read attribute command definitions ************************/ + +/** + * @defgroup read_attr_command Read attributes request and response sending and parsing. + * @{ + * @details + * Read attributes command described in ZCL spec, subclauses 2.4.1 and 2.4.2. + * + * Read attributes request command can be formed and sent as in following snippet: + * @code + * ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ(zcl_cmd_buf, cmd_ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE); + * ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ(cmd_ptr, ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID); + * ZB_ZCL_GENRAL_SEND_READ_ATTR_REQ(zcl_cmd_buf, cmd_ptr, DUT_ADDR, DUT_ADDR_MODE, DUT_ENDPOINT, + * TH_ENDPOINT, ZB_AF_HA_PROFILE_ID, + * ZB_ZCL_CLUSTER_ID_BINARY_INPUT, NULL); + * @endcode + * Read attributes response can be parsed as: + * @code + * ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES(buf, read_attr_resp); + * @endcode + * until allocated buffer space exceeds. + * + * Read attributes request parsing and response filling and sending is implemented in ZCL + * library internal functions. + * + * For more information see any HA sample + */ + +/*! @brief ZCL Read Attribute Command frame + @see ZCL spec, zb_zcl_read_attr 2.4.1 Read Attributes Command + @note Command frame contains variable number of parameters +*/ +typedef ZB_PACKED_PRE struct zb_zcl_read_attr_req_s +{ + zb_uint16_t attr_id[1]; /*!< Attribute ID list */ +} ZB_PACKED_STRUCT +zb_zcl_read_attr_req_t; + +/** @cond internals_doc */ + +/** @brief Minimal size of Read attribute response, it should contain attribute id and status */ +#define ZB_ZCL_READ_ATTR_RESP_SIZE (sizeof(zb_uint16_t) + sizeof(zb_uint8_t)) + +/** @endcond */ /* internals_doc */ + +/*! @brief ZCL Read Attribute Response Command frame + @see ZCL spec, zb_zcl_read_attr 2.4.2 Read Attributes Response Command + @note Command frame contains variable number of parameters. Also, based on status value + attr_type and attr_value maybe absent. +*/ +typedef ZB_PACKED_PRE struct zb_zcl_read_attr_res_s +{ + zb_uint16_t attr_id; /*!< Attribute ID */ + zb_uint8_t status; /*!< Attribute status */ + zb_uint8_t attr_type; /*!< Attribute type */ + zb_uint8_t attr_value[1]; /*!< Attribute value */ +} ZB_PACKED_STRUCT zb_zcl_read_attr_res_t; + +/** @brief Parses Read attribute response and returns next Read attribute status record or NULL if + there is no more data. + + If response contains invalid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing read attribute response data + @param read_attr_resp - out pointer to zb_zcl_read_attr_res_t, containing Read attribute status + record + @note data_buf buffer should contain Read attribute response payload, without ZCL header. Each + parsed Read attribute status record is exctracted from initial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_READ_ATTR_RES(data_buf, read_attr_resp) \ +{ \ + zb_uint8_t resp_size = 0xff; \ + (read_attr_resp) = zb_buf_len(data_buf) >= ZB_ZCL_READ_ATTR_RESP_SIZE ? \ + (zb_zcl_read_attr_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (read_attr_resp) \ + { \ + resp_size = ZB_ZCL_READ_ATTR_RESP_SIZE; \ + ZB_ZCL_HTOLE16_INPLACE(&(read_attr_resp)->attr_id); \ + if ((read_attr_resp)->status == ZB_ZCL_STATUS_SUCCESS) \ + { \ + resp_size += \ + sizeof(zb_uint8_t) + \ + zb_zcl_get_attribute_size((read_attr_resp)->attr_type, (read_attr_resp)->attr_value); \ + if (resp_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_FIX_ENDIAN((read_attr_resp)->attr_value, (read_attr_resp)->attr_type); \ + } \ + } \ + \ + if (resp_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), resp_size); \ + } \ + else \ + { \ + (read_attr_resp) = NULL; \ + } \ + } \ +} + +/** @brief Initialize Read attribute command + @param buffer to put packet to + @param cmd_ptr - command buffer pointer + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ(buffer, cmd_ptr, def_resp) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(cmd_ptr, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_READ_ATTRIB); \ +} + +/** + * @brief Initialize Read Attribute Request command + * + * @param buffer - buffer to store command data + * @param cmd_ptr - pointer to a command data memory + * @param direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param def_resp - enable/disable default response + */ +#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_A(buffer, cmd_ptr, direction, def_resp) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_READ_ATTRIB); \ +} + +/** + * @brief Initialize Read Attribute Request command with manufacturer code + * + * @param buffer - buffer to store command data + * @param cmd_ptr - pointer to a command data memory + * @param direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param def_resp - enable/disable default response + * @param manuf_code - manufacturer specific code + */ +#define ZB_ZCL_GENERAL_INIT_READ_ATTR_REQ_MANUF(buffer, cmd_ptr, direction, def_resp, manuf_code) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_TRUE, manuf_code, ZB_ZCL_CMD_READ_ATTRIB); \ +} + +/** @brief Add attribute id to command payload + @param cmd_ptr - command buffer pointer + @param attr_id - attribute ID +*/ +#define ZB_ZCL_GENERAL_ADD_ID_READ_ATTR_REQ(cmd_ptr, attr_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (attr_id)); \ +} + +/** @brief Sends Read attribute command + @param buffer to place data to + @param cmd_ptr - pointer to the memory area after the command data end + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_SEND_READ_ATTR_REQ(buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb) \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb); + +/** @brief Parses Read attribute request and returns next Read attribute record or NULL if there + * is no more data. + + If request contains invalid data, NULL is returned. + @param _data_buf - ID zb_bufid_t of a buffer containing write attribute request data + @param _read_attr_req - out pointer to zb_zcl_read_attr_req_t, containing Read attribute record + out value direct into data_buf. Do not change data_buf before finish work with read_attr_req + @note data_buf buffer should contain Read attribute request payload, without ZCL header. Each + parsed Read attribute record is exctracted from initial data_buf buffer + + */ +#define ZB_ZCL_GENERAL_GET_READ_ATTR_REQ(_data_buf, _read_attr_req) \ +{ \ + (_read_attr_req) = zb_buf_len((_data_buf)) >= sizeof(zb_zcl_read_attr_req_t) ? \ + (zb_zcl_read_attr_req_t*)zb_buf_begin((_data_buf)) : NULL; \ + \ + if ((_read_attr_req)) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(_read_attr_req)->attr_id); \ + (void)zb_buf_cut_left((_data_buf), sizeof(zb_zcl_read_attr_req_t)); \ + } \ +} + +/** @brief Initialize Read Attribute Response command + @param _buffer - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _seq - command sequence +*/ +#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP(_buffer, _cmd_ptr, _seq) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL((_cmd_ptr)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER((_cmd_ptr), (_seq), ZB_ZCL_CMD_READ_ATTRIB_RESP); \ +} + +/** + * @brief Initialize Read Attribute Response command + * + * @param _buffer - buffer to store command data + * @param _cmd_ptr - pointer to a command data memory + * @param _direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param _seq - command sequence + * @param _is_manuf - whether command is manufacturer specific + * @param _manuf_id - manufacturer ID (needed if _is_manuf is set) + */ +#define ZB_ZCL_GENERAL_INIT_READ_ATTR_RESP_EXT(_buffer, _cmd_ptr, _direction, _seq, _is_manuf, _manuf_id) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A((_cmd_ptr), (_direction), (_is_manuf)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT((_cmd_ptr), (_seq), (_is_manuf), (_manuf_id), ZB_ZCL_CMD_READ_ATTRIB_RESP); \ +} + +/** @brief Add attribute value to command payload + @param _buf - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _attr_desc - attribute descriptor +*/ +#define ZB_ZCL_GENERAL_ADD_READ_ATTR_RESP(_buf, _cmd_ptr, _attr_desc) \ +{ \ + zb_uint8_t bytes_avail = ZB_ZCL_GET_BYTES_AVAILABLE((_buf), (_cmd_ptr)); \ + zb_uint8_t attr_size = zb_zcl_get_attribute_size((_attr_desc)->type, (_attr_desc)->data_p); \ + if (bytes_avail >= (sizeof(zb_zcl_read_attr_res_t) - sizeof(zb_uint8_t) + attr_size)) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL((_cmd_ptr), (_attr_desc)->id); \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), ZB_ZCL_STATUS_SUCCESS); \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), (_attr_desc)->type); \ + (_cmd_ptr) = zb_zcl_put_value_to_packet((_cmd_ptr), (_attr_desc)->type, \ + (zb_uint8_t *)(_attr_desc)->data_p); \ + } \ + else \ + { \ + TRACE_MSG(TRACE_ZCL1, "ERROR, buffer is full", (FMT__0)); \ + } \ +} + +/** @brief Add attribute value to command payload + @param _buf - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _attr_id - attribute identifier +*/ +#define ZB_ZCL_GENERAL_ADD_NO_SUPPORT_READ_ATTR_RESP(_buf, _cmd_ptr, _attr_id) \ +{ \ + zb_uint8_t bytes_avail = ZB_ZCL_GET_BYTES_AVAILABLE((_buf), (_cmd_ptr)); \ + if (bytes_avail >= (sizeof(zb_uint16_t) + sizeof(zb_uint8_t))) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL((_cmd_ptr), (_attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), ZB_ZCL_STATUS_UNSUP_ATTRIB); \ + } \ + else \ + { \ + TRACE_MSG(TRACE_ZCL1, "ERROR, buffer is full", (FMT__0)); \ + } \ +} + +/** @brief Send Read attribute response command + @param _buffer - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _addr - address to send packet to + @param _dst_addr_mode - addressing mode + @param _dst_ep - destination endpoint + @param _ep - sending endpoint + @param _profile_id - profile identifier + @param _cluster_id - cluster identifier + @param _cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_SEND_READ_ATTR_RESP( \ + _buffer, _cmd_ptr, _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb) \ +{ \ + ZB_ZCL_FINISH_PACKET((_buffer), (_cmd_ptr)) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), \ + (_profile_id), (_cluster_id), (_cb)); \ +} + +/** @} */ /* Read attribute request and response sending and parsing. */ + +/********************** Write attribute command definitions ***************************/ + +/** + * @defgroup write_attr_cmd Write attributes command sending and parsing. + * @{ + * @details + * Both write attributes request and response commands have variable-length payload. + * + * Write attributes request can be filled as following: + * @code + * ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ(data_buf, ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE); + * ZB_ZCL_GENERAL_ADD_VALUE_WRITE_ATTR_REQ(ptr, attr_id, attr_type, attr_val); + * ZB_ZCL_GENERAL_SEND_WRITE_ATTR_REQ( + * data_buf, + * ptr, + * dst_addr, + * ZB_APS_ADDR_MODE_16_ENDP_PRESENT, + * dst_ep, + * src_ep, + * ZB_AF_HA_PROFILE_ID, + * ZB_ZCL_CLUSTER_ID_ON_OFF, + * NULL); + * @endcode + * On the server side, this packet could be parsed in the following manner: + * @code + * zb_zcl_write_attr_req_t *write_attr_req; + * ... + * do + * { + * ZB_ZCL_GENERAL_GET_NEXT_WRITE_ATTR_REQ(data_buf, write_attr_req); + * if (write_attr_req) + * { + * process write attribute request record + * } + * } + * while(write_attr_req); + * @endcode + * + * Response sending and parsing could be done in the same manner. + * + * For more information see any HA sample + */ + +/*! @brief ZCL Write Attribute Command frame + @see ZCL spec, 2.4.3 Write Attributes Command +*/ +typedef ZB_PACKED_PRE struct zb_zcl_write_attr_req_s +{ + zb_uint16_t attr_id; /*!< Attribute ID */ + zb_uint8_t attr_type; /*!< Attribute type */ + zb_uint8_t attr_value[1]; /*!< Attribute value */ +} ZB_PACKED_STRUCT +zb_zcl_write_attr_req_t; + +/** @cond internals_doc */ + +/** @brief Minimal size of Write attribute request, it will be more if attr_value size is more + * than 1 byte + */ +#define ZB_ZCL_WRITE_ATTR_REQ_SIZE sizeof(zb_zcl_write_attr_req_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Write attribute request and returns next Write attribute record or NULL if there + * is no more data. + + If request contains invlid data, NULL is returned. + @param data_ptr - pointer to the data of a zb_bufid_t buffer containing write attribute request data + @param data_len - variable containing length of a zb_bufid_t buffer + @param write_attr_req - out pointer to zb_zcl_write_attr_req_t, containing Write attribute record + @note buffer data by data_ptr should contain Write attribute request payload, without ZCL header. + */ +#define ZB_ZCL_GENERAL_GET_NEXT_WRITE_ATTR_REQ(data_ptr, data_len, write_attr_req) \ +{ \ + zb_uint8_t req_size = 0xff; \ + (write_attr_req) = (data_len) >= ZB_ZCL_WRITE_ATTR_REQ_SIZE ? \ + (zb_zcl_write_attr_req_t*)(data_ptr) : NULL; \ + \ + if (write_attr_req) \ + { \ + /* substruct sizeof(zb_uint8_t) because its size */ \ + /* is already included into ZB_ZCL_WRITE_ATTR_REQ_SIZE */ \ + req_size = ZB_ZCL_WRITE_ATTR_REQ_SIZE - sizeof(zb_uint8_t) + \ + zb_zcl_get_attribute_size((write_attr_req)->attr_type, (write_attr_req)->attr_value); \ + if (req_size <= (data_len)) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(write_attr_req)->attr_id); \ + ZB_ZCL_FIX_ENDIAN((write_attr_req)->attr_value, (write_attr_req)->attr_type); \ + } \ + } \ + \ + if (req_size <= (data_len)) \ + { \ + (data_ptr) = (data_ptr) + req_size; \ + (data_len) = (data_len) - req_size; \ + } \ + else \ + { \ + (write_attr_req) = NULL; \ + } \ +} + +/*! @brief ZCL Write Attribute Command frame + @see ZCL spec, 2.4.3 Write Attributes Command +*/ +typedef ZB_PACKED_PRE struct zb_zcl_write_attr_res_s +{ + zb_uint8_t status; /*!< Write attribute status */ + zb_uint16_t attr_id; /*!< Attribute ID */ +} ZB_PACKED_STRUCT +zb_zcl_write_attr_res_t; + +/** @cond internals_doc */ + +/** Minimal size of write attribute response */ +#define ZB_ZCL_WRITE_ATTR_RES_SIZE sizeof(zb_uint8_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Write attribute response and returns next Write attribute status or NULL if there + is no more data. + + If response contains invlid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing write attribute response data + @param write_attr_res - out pointer to zb_zcl_write_attr_res_t, containing Write attribute status + @note data_buf buffer should contain Write attribute response payload, without ZCL header. Each + parsed Write attribute response is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GET_NEXT_WRITE_ATTR_RES(data_buf, write_attr_res) \ +{ \ + zb_uint8_t res_size; \ + (write_attr_res) = zb_buf_len(data_buf) >= ZB_ZCL_WRITE_ATTR_RES_SIZE ? \ + (zb_zcl_write_attr_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (write_attr_res) \ + { \ + if ((write_attr_res)->status != ZB_ZCL_STATUS_SUCCESS) \ + { \ + /* In case of error, attribute id is reported */ \ + res_size = sizeof(zb_zcl_write_attr_res_t); \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(write_attr_res)->attr_id); \ + } \ + } \ + else \ + { \ + res_size = ZB_ZCL_WRITE_ATTR_RES_SIZE; \ + } \ + \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), res_size); \ + } \ + else \ + { \ + (write_attr_res) = NULL; \ + } \ + } \ +} + +/** @brief Initialize Write attribute command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param def_resp - enable/disable default response + @param write_attr_type - type of 'Write Attribute' command: + default - @see ZB_ZCL_CMD_WRITE_ATTRIB; + no response - @see ZB_ZCL_CMD_WRITE_ATTRIB_NO_RESP; + undivided - @see ZB_ZCL_CMD_WRITE_ATTRIB_UNDIV; +*/ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_BY_TYPE(buffer, cmd_ptr, def_resp, write_attr_type) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(cmd_ptr, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), write_attr_type); \ +} + +/** @brief Initialize Write attribute command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ(buffer, cmd_ptr, def_resp) \ + ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_BY_TYPE( \ + (buffer), (cmd_ptr), (def_resp), ZB_ZCL_CMD_WRITE_ATTRIB); + +/** @brief Initialize Write Attribute No Response command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_NO_RESP(buffer, cmd_ptr, def_resp) \ + ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_BY_TYPE( \ + (buffer), (cmd_ptr), (def_resp), ZB_ZCL_CMD_WRITE_ATTRIB_NO_RESP); + +/** @brief Initialize Write Attribute Undivided command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_UNDIV(buffer, cmd_ptr, def_resp) \ + ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_BY_TYPE( \ + (buffer), (cmd_ptr), (def_resp), ZB_ZCL_CMD_WRITE_ATTRIB_UNDIV); + +/** + * @brief Initialize Write attribute command + * + * @param buffer - buffer to store command data + * @param cmd_ptr - pointer to a command data memory + * @param direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param def_resp - enable/disable default response + */ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_REQ_A(buffer, cmd_ptr, direction, def_resp) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_WRITE_ATTRIB); \ +} + +/** @brief Add attribute value to command payload + @param cmd_ptr - pointer to a command data memory + @param attr_id - attribute identifier + @param attr_type - attribute type + @param attr_val - pointer to attribute data value +*/ +#define ZB_ZCL_GENERAL_ADD_VALUE_WRITE_ATTR_REQ(cmd_ptr, attr_id, attr_type, attr_val) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (attr_type)); \ + (cmd_ptr) = zb_zcl_put_value_to_packet(cmd_ptr, attr_type, attr_val); \ +} + +/** @brief Send Write attribute command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_SEND_WRITE_ATTR_REQ( \ + buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb); \ +} + + +/** @brief Send "write attributes" request. + * depricate */ +#define ZB_ZCL_GENERAL_SEND_WRITE_ATTRS_REQ( \ + buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id) \ + ZB_ZCL_SEND_GENERAL_COMMAND_REQ_SHORT( \ + buffer, addr, addr_mode, dst_ep, ep, prof_id, cluster_id, ZB_ZCL_CMD_WRITE_ATTRIB) + + +/** @brief Initialize Write attribute response command + @param _buffer - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _seq - command sequence +*/ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_RESP(_buffer, _cmd_ptr, _seq) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL((_cmd_ptr)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER((_cmd_ptr), (_seq), ZB_ZCL_CMD_WRITE_ATTRIB_RESP); \ +} + +/** + * @brief Initialize Write attribute response command + * + * @param _buffer - buffer to store command data + * @param _cmd_ptr - pointer to a command data memory + * @param _direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param _seq - command sequence + * @param _is_manuf - whether command is manufacturer specific + * @param _manuf_id - manufacturer ID (needed if _is_manuf is set) + */ +#define ZB_ZCL_GENERAL_INIT_WRITE_ATTR_RESP_EXT(_buffer, _cmd_ptr, _direction, _seq, _is_manuf, _manuf_id) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A((_cmd_ptr), (_direction), (_is_manuf)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT((_cmd_ptr), (_seq), (_is_manuf), (_manuf_id), ZB_ZCL_CMD_WRITE_ATTRIB_RESP); \ +} + +/** @brief Add Success status value to Write attribute response command payload + @param _cmd_ptr - pointer to a command data memory +*/ +#define ZB_ZCL_GENERAL_SUCCESS_WRITE_ATTR_RESP(_cmd_ptr) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), ZB_ZCL_STATUS_SUCCESS); \ +} + +/** @brief Add Fail status value to Write attribute response command payload + @param _buf - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _attr_id - attribute ID + @param _status - status +*/ +#define ZB_ZCL_GENERAL_ADD_STATUS_WRITE_ATTR_RESP(_buf, _cmd_ptr, _attr_id, _status) \ +{ \ + zb_uint8_t bytes_avail = ZB_ZCL_GET_BYTES_AVAILABLE((_buf), (_cmd_ptr)); \ + if (bytes_avail >= sizeof(zb_zcl_write_attr_res_t)) \ + { \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), (_status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL((_cmd_ptr), (_attr_id)); \ + } \ + else \ + { \ + TRACE_MSG(TRACE_ZCL1, "ERROR, buffer is full", (FMT__0)); \ + } \ +} + +/** @brief Send Write attribute response command + @param _buffer - buffer to store command data + @param _cmd_ptr - pointer to a command data memory + @param _addr - address to send packet to + @param _dst_addr_mode - addressing mode + @param _dst_ep - destination endpoint + @param _ep - sending endpoint + @param _profile_id - profile identifier + @param _cluster_id - cluster identifier + @param _cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_SEND_WRITE_ATTR_RESP( \ + _buffer, _cmd_ptr, _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb) \ +{ \ + ZB_ZCL_FINISH_PACKET((_buffer), (_cmd_ptr)) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), \ + (_profile_id), (_cluster_id), (_cb)); \ +} + + +/** @} */ /* Write attributes command sending and parsing. */ + +/*************** Discover attribute command definitions ************************/ + +/** + * @defgroup disc_attr_command Discover attributes request and response sending and parsing. + * @{ + * @details + * Discover attributes command described in ZCL spec, subclauses 2.4.13 and 2.4.14. + * + * Read attributes request command can be formed and sent as in following snippet: + * @code + * ZB_ZCL_GENERAL_DISC_ATTR_REQ(zcl_cmd_buf, cmd_ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE, + * ZB_ZCL_ATTR_BINARY_INPUT_PRESENT_VALUE_ID, 5, + * DUT_ADDR, DUT_ADDR_MODE, DUT_ENDPOINT, + * TH_ENDPOINT, ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_BINARY_INPUT, NULL); + * @endcode + * Discover attributes response can be parsed as: + * @code + * ZB_ZCL_GENERAL_GET_COMPLETE_DISC_RES(buf, complete); + * ZB_ZCL_GENERAL_GET_NEXT_DISC_ATTR_RES(buf, disc_attr_info); + * @endcode + * until allocated buffer space exceeds. + * + * Discover attributes request parsing and response filling and sending is implemented in ZCL + * library internal functions. + * + * For more information see any HA sample + */ + +/*! @brief ZCL Discover Attribute Command frame + @see ZCL spec, zb_zcl_disc_attr 2.4.13 Discover Attributes Command +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_attr_req_s +{ + zb_uint16_t start_attr_id; /*!< Start attribute identifier */ + zb_uint8_t maximum; /*!< Maximum attribute identifiers */ +} ZB_PACKED_STRUCT +zb_zcl_disc_attr_req_t; + +/*! @brief ZCL Description for Discover Attribute Response frame + @see ZCL spec, zb_zcl_read_attr 2.4.14 Discover Attribute Response +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_attr_info_s +{ + zb_uint16_t attr_id; /*!< Attribute identifier */ + zb_uint8_t data_type; /*!< Attribute data type */ +} ZB_PACKED_STRUCT +zb_zcl_disc_attr_info_t; + + +/*! @brief ZCL Discover Attribute Response frame + @see ZCL spec, zb_zcl_read_attr 2.4.15 Discover Attribute Response + @note Command frame contains variable number of parameters +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_attr_res_s +{ + zb_uint8_t complete; /*!< Discovery complete */ + zb_zcl_disc_attr_info_t info[1]; /*!< Attribute desc list */ +} ZB_PACKED_STRUCT +zb_zcl_disc_attr_res_t; + +/** @brief ZCL Discover Attribute Response - complete field + @see ZCL spec, clause 2.4.14 +*/ +typedef enum zb_zcl_disc_complete_e +{ + ZB_ZCL_DISC_NON_COMPLETE = 0x00, /*!< more attributes to be discovered */ + ZB_ZCL_DISC_COMPLETE = 0x01, /*!< no more attributes to be discovered */ + +} zb_zcl_disc_complete_t; + +/** @cond internals_doc */ + +#define ZB_ZCL_DISC_ATTR_RESP_SIZE sizeof(zb_zcl_disc_attr_info_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Discovery attribute response and returns next Read attribute status record or NULL if + there is no more data. + + If response contains invalid data, 0 is returned. + @param data_buf - ID zb_bufid_t of a buffer containing discover attribute response data + @param complete - variable to store Complete field + @note data_buf buffer should contain Discover attribute response payload, without ZCL header. + */ +#define ZB_ZCL_GENERAL_GET_COMPLETE_DISC_RES(data_buf, complete) \ +{ \ + if (zb_buf_len(data_buf) > 0) \ + { \ + complete = *(zb_uint8_t*)zb_buf_begin(data_buf); \ + (void)zb_buf_cut_left((data_buf), sizeof(zb_uint8_t)); \ + } \ + else \ + { \ + (complete) = 0; \ + } \ +} + +/** @brief Discovery attribute response and returns next Discovery attribute status record or NULL if + there is no more data. + + If response contains invalid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing part of Discover attribute response data + @param disc_attr_info - out pointer to zb_zcl_disc_attr_info_t, containing Discover attribute status + record + @note data_buf buffer should contain Discover attribute response payload, without ZCL header. Each + parsed Discover attribute status record is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_DISC_ATTR_RES(data_buf, disc_attr_info) \ +{ \ + (disc_attr_info) = zb_buf_len(data_buf) >= ZB_ZCL_DISC_ATTR_RESP_SIZE ? \ + (zb_zcl_disc_attr_info_t*)zb_buf_begin(data_buf) : (zb_zcl_disc_attr_info_t*)0; \ + \ + if (disc_attr_info) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(disc_attr_info)->attr_id); \ + \ + (void)zb_buf_cut_left((data_buf), ZB_ZCL_DISC_ATTR_RESP_SIZE); \ + } \ +} + +/** @brief Discover attribute command + @param buffer - reference to buffer to put packet into + @param def_resp - enable/disable default response + @param start_attr_id - start attribute ID + @param max_len - max count + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_DISC_READ_ATTR_REQ(buffer, def_resp, start_attr_id, max_len, \ + addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(cmd_ptr, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_DISC_ATTRIB); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (start_attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (max_len)); \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb); \ +} + +/** + * @brief Discover Attribute Request + * @param buffer - reference to buffer to put packet into + * @param cmd_ptr - pointer to command (not used) + * @param direction - direction of command (see @ref zb_zcl_frame_direction_t) + * @param def_resp - enable/disable default response + * @param start_attr_id - start attribute ID + * @param max_len - max count + * @param addr - address to send packet to + * @param dst_addr_mode - addressing mode + * @param dst_ep - destination endpoint + * @param ep - sending endpoint + * @param profile_id - profile identifier + * @param cluster_id - cluster identifier + * @param cb - callback for getting command send status + */ +#define ZB_ZCL_GENERAL_DISC_ATTR_REQ_A(buffer, cmd_ptr, direction, def_resp, \ + start_attr_id, max_len, \ + addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(cmd_ptr, direction, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_DISC_ATTRIB); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (start_attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (max_len)); \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, cluster_id, cb); \ +} + +/** @} */ /* Discover attribute request and response sending and parsing. */ + + + +/********************** Configure reporting command definitions ***************************/ + +#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) + +/** + * @defgroup cfg_reporting_cmd Configure reporting command sending and parsing + * @{ + * @details + * Most of actions related to the attribute reporting configuration are implemented in ZCL + * internals. + * + * As described in ZCL spec, subclause 2.4.7, Configure Reporting command has two forms: + * @li client to server - instructs server to configure for attribute reporting. + * @li server to client - notifies client that server has configured for attribute reporting, + * and will report attribute values to the client. + * + * Request to configure server for attribute reporting can be filled like in the snippet below: + * @snippet simple_gw/simple_gw.c zcl_general_fill_configure_report + * Other variant of the command can be filled in a similar way with @ref + * ZB_ZCL_GENERAL_INIT_CONFIGURE_REPORTING_CLI_REQ() and @ref + * ZB_ZCL_GENERAL_ADD_RECV_REPORT_CONFIGURE_REPORTING_REQ() macros, and scheduled for sending + * with ZB_ZCL_GENERAL_SEND_CONFIGURE_REPORTING_REQ() macro. + * + * Configure reporting request record can be parsed as: + * @code + * zb_bufid_t buffer = pointer_to_the_packet_buffer; + * zb_zcl_configure_reporting_req_t* req_record; + * ... + * do + * { + * ZB_ZCL_GENERAL_GET_NEXT_CONFIGURE_REPORTING_REQ(buffer, req_record); + * if (! req_record) + * { + * break; + * } + * process_request_record(req_record); + * } while (1); + * @endcode + * + * Configure Reporting response command will be generated automatically by ZCL internals. + * Response record to the Configure Reporting command can be parsed as: + * @code + * ZB_ZCL_GENERAL_GET_NEXT_CONFIGURE_REPORTING_RES(buf, config_res); + * @endcode + * If there are several Configure Reporting response records, they could be processed cyclically + * in the same manner as Configure Reporting request ones. + * + * For more information see HA samples + */ + + /** u.clnt: as usual, cluster with client role sends this request + to a server to configure reporting: how attribute should be reprted by a server */ +typedef ZB_PACKED_PRE struct zb_zcl_configure_reporting_req_clnt_s + { + zb_uint8_t attr_type; /*!< Attribute data type */ + zb_uint16_t min_interval; /*!< Minimum reporting interval */ + zb_uint16_t max_interval; /*!< Maximum reporting interval */ + zb_uint8_t delta[1]; /*!< Reportable change */ + } ZB_PACKED_STRUCT +zb_zcl_configure_reporting_req_clnt_t; + + /** u.srv: as usual, cluster with server role sends this request + to a client, to inform him how an attribute will be reported by a server */ +typedef ZB_PACKED_PRE struct zb_zcl_configure_reporting_req_srv_s + { + zb_uint16_t timeout; /*!< Timeout period */ + } ZB_PACKED_STRUCT +zb_zcl_configure_reporting_req_srv_t; + +/** + * @brief General type for Configure Reporting Request command. + + * see @ref zb_zcl_configure_reporting_req_srv_t + * see @ref zb_zcl_configure_reporting_req_clnt_t + */ +typedef ZB_PACKED_PRE union zb_zcl_configure_reporting_req_u_s +{ + zb_zcl_configure_reporting_req_clnt_t clnt; /*!< Parameters for client */ + zb_zcl_configure_reporting_req_srv_t srv; /*!< Parameters for server */ +} ZB_PACKED_STRUCT +zb_zcl_configure_reporting_req_u_t; + +/** @brief One chunk of Configure reporting command request + * + * Attribute reporting configuration record + */ +/* WARNING: Do not put directly packed_struct declaration inside another packet_struct - some + * compilators does not handle it correctly! */ +typedef ZB_PACKED_PRE struct zb_zcl_configure_reporting_req_s +{ + zb_uint8_t direction; /*!< Direction */ + zb_uint16_t attr_id; /*!< Attribute ID */ + zb_zcl_configure_reporting_req_u_t u; /*!< Request fields */ +} ZB_PACKED_STRUCT zb_zcl_configure_reporting_req_t; + +/*! Configure reporting command, direction field values */ +typedef enum zb_zcl_configure_reporting_direction_value_e +{ + ZB_ZCL_CONFIGURE_REPORTING_SEND_REPORT = 0x00, /**< Report should be send by a cluster. */ + ZB_ZCL_CONFIGURE_REPORTING_RECV_REPORT = 0x01 /**< Report should be received by a cluster. */ +} +zb_zcl_configure_reporting_direction_value_t; + +/** @cond internals_doc */ + +/* client configuration size is larger then srv version, can take + * sizeof(struct); reduce by sizeof(zb_uint8_t) because delta maybe ommited */ +#define ZB_ZCL_CONFIGURE_REPORTING_FOR_SEND_SIZE \ + (sizeof(zb_zcl_configure_reporting_req_t) - sizeof(zb_uint8_t)) + +/* calculate size for srv command version: direction, attr_id, timeout */ +#define ZB_ZCL_CONFIGURE_REPORTING_FOR_RECV_SIZE sizeof(zb_uint8_t) + sizeof(zb_uint16_t)*2 + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Configure reporting command request and returns next Attribute reporting + configuration record or NULL if there is no more data. + + If request contains invlid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing Parses Configure reporting command data + @param config_rep_req - out pointer to zb_zcl_configure_reporting_req_t, containing Attribute + reporting configuration record + @note data_buf buffer should contain Configure reporting command payload, without ZCL header. + Each parsed Attribute reporting configuration record is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_CONFIGURE_REPORTING_REQ(data_buf, config_rep_req) \ +{ \ + zb_uint8_t res_size = 0xff; \ + /* ZB_ZCL_CONFIGURE_REPORTING_FOR_SEND_SIZE - is minimum payload length */ \ + (config_rep_req) = zb_buf_len(data_buf) >= ZB_ZCL_CONFIGURE_REPORTING_FOR_RECV_SIZE ? \ + (zb_zcl_configure_reporting_req_t *)zb_buf_begin(data_buf) : NULL; \ + \ + if (config_rep_req) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(config_rep_req)->attr_id); \ + if ((config_rep_req)->direction == ZB_ZCL_CONFIGURE_REPORTING_RECV_REPORT) \ + { \ + res_size = ZB_ZCL_CONFIGURE_REPORTING_FOR_RECV_SIZE; \ + ZB_ZCL_HTOLE16_INPLACE(&(config_rep_req)->u.srv.timeout); \ + } \ + else /* ZB_ZCL_CONFIGURE_REPORTING_SEND_REPORT */ \ + { \ + res_size = ZB_ZCL_CONFIGURE_REPORTING_FOR_SEND_SIZE; \ + ZB_ZCL_HTOLE16_INPLACE(&(config_rep_req)->u.clnt.min_interval); \ + ZB_ZCL_HTOLE16_INPLACE(&(config_rep_req)->u.clnt.max_interval); \ + if (zb_zcl_is_analog_data_type((config_rep_req)->u.clnt.attr_type)) \ + { \ + res_size += zb_zcl_get_analog_attribute_size((config_rep_req)->u.clnt.attr_type); \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_FIX_ENDIAN((config_rep_req)->u.clnt.delta, (config_rep_req)->u.clnt.attr_type); \ + } \ + } \ + } /* if ZB_ZCL_CONFIGURE_REPORTING_SEND_REPORT */ \ + } /* if config_rep_req */ \ + \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), res_size); \ + } \ + else \ + { \ + (config_rep_req) = NULL; \ + } \ +} + +/** One chunk of Configure reporting response command + * + * Attribute status record + */ +typedef ZB_PACKED_PRE struct zb_zcl_configure_reporting_res_s +{ + zb_uint8_t status; /*!< Configure reporting status */ + zb_uint8_t direction; /*!< Direction */ + zb_uint16_t attr_id; /*!< Attribute ID */ +} ZB_PACKED_STRUCT +zb_zcl_configure_reporting_res_t; + +/** @cond internals_doc */ + +/*! Minimum size of zb_zcl_configure_reporting_res_t */ +#define ZB_ZCL_CONFIGURE_REPORTING_RES_SIZE sizeof(zb_uint8_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Configure reporting response and returns next + configure attribute status record or NULL if there is no more data. + + If response contains invlid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing Configure reporting response data + @param config_rep_res - out pointer to zb_zcl_configure_reporting_res_t, containing Configure + attribute status record + @note data_buf buffer should contain Configure reporting response payload, without ZCL header. + Each parsed Configure attribute status record is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_CONFIGURE_REPORTING_RES(data_buf, config_rep_res) \ +{ \ + zb_uint8_t res_size = 0; \ + (config_rep_res) = zb_buf_len(data_buf) >= ZB_ZCL_CONFIGURE_REPORTING_RES_SIZE ? \ + (zb_zcl_configure_reporting_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (config_rep_res) \ + { \ + if ((config_rep_res)->status != ZB_ZCL_STATUS_SUCCESS \ + && (config_rep_res)->status != ZB_ZCL_STATUS_MALFORMED_CMD) \ + { \ + /* In case of error, direction and attribute id is reported */ \ + res_size = sizeof(zb_zcl_configure_reporting_res_t); \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(config_rep_res)->attr_id); \ + } \ + } \ + else \ + { \ + res_size = ZB_ZCL_CONFIGURE_REPORTING_RES_SIZE; \ + } \ + \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), res_size); \ + } \ + else \ + { \ + (config_rep_res) = NULL; \ + } \ + } \ +} + +/*! @brief Initialize Configure reporting command (report send case) + @param buffer to put packet to + @param ptr - command buffer pointer + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_CONFIGURE_REPORTING_SRV_REQ(buffer, ptr, def_resp) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A( \ + ptr, ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_CONFIG_REPORT); \ +} + +/*! @brief Initialize Configure reporting command (report receive case) + @param buffer to put packet to + @param ptr - command buffer pointer + @param def_resp - enable/disable default response +*/ +#define ZB_ZCL_GENERAL_INIT_CONFIGURE_REPORTING_CLI_REQ(buffer, ptr, def_resp) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A( \ + ptr, ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_CONFIG_REPORT); \ +} + +/*! @brief Add attribute reporting configuration record to command payload (report send case) + @param ptr - command buffer pointer + @param attr_id - attribute identifier + @param attr_type - type of the attribute + @param min_interval - reporting minimum interval + @param max_interval - reporting maximum interval + @param report_change - reportable value change +*/ +#define ZB_ZCL_GENERAL_ADD_SEND_REPORT_CONFIGURE_REPORTING_REQ( \ + ptr, attr_id, attr_type, min_interval, max_interval, report_change) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_CONFIGURE_REPORTING_SEND_REPORT); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (attr_type)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (min_interval)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (max_interval)); \ + if (zb_zcl_is_analog_data_type(attr_type)) \ + { \ + (ptr) = zb_zcl_put_value_to_packet((ptr), (attr_type), report_change); \ + } \ +} + +/*! @brief Add attribute reporting configuration record to command payload (report receive case) + @param ptr - command buffer pointer + @param attr_id - attribute identifier + @param timeout - reporting timeout +*/ +#define ZB_ZCL_GENERAL_ADD_RECV_REPORT_CONFIGURE_REPORTING_REQ(ptr, attr_id, timeout) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_CONFIGURE_REPORTING_RECV_REPORT); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (timeout)); \ +} + +/** @brief Sends Configure reporting command + @param buffer to put data to + @param ptr - pointer to the memory area to put data to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GENERAL_SEND_CONFIGURE_REPORTING_REQ( \ + buffer, ptr, addr, dst_addr_mode, dst_ep, ep, prfl_id, cluster_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cluster_id, cb); \ +} + +/** @} */ /* Configure reporting command sending and parsing. */ + +/************************** Report attribute command definitions **********************************/ + +/** + * @defgroup report_attr_cmd Report attribute command parsing + * @{ + * @details + * Report attributes command originates from ZCL internals as a packet constructed according to + * ZCL spec, subclause 2.4.11. This command can be parsed by cyclical application of @ref + * ZB_ZCL_GENERAL_GET_NEXT_REPORT_ATTR_REQ() macro. + * + * For more information see any HA sample + */ + +/** @cond internals_doc */ + +/** @brief Minimal size of Read attribute response, it should contain attribute id and status */ +#define ZB_ZCL_REPORT_ATTR_CMD_SIZE sizeof(zb_zcl_report_attr_req_t) + +/** @endcond */ /* internals_doc */ + +/*! @brief ZCL Report Attribute Command frame + @see ZCL spec, 2.4.11.1 Report Attributes Command + @note Report attribute command contains variable number of attribute reports, + zb_zcl_report_attr_req_t defines one attribute report +*/ +typedef ZB_PACKED_PRE struct zb_zcl_report_attr_req_s +{ + zb_uint16_t attr_id; /*!< Attribute ID */ + zb_uint8_t attr_type; /*!< Attribute type */ + zb_uint8_t attr_value[1]; /*!< Attribute value */ +} ZB_PACKED_STRUCT +zb_zcl_report_attr_req_t; + +/** @cond internals_doc */ + +/** @brief Minimum size of report attribute command */ +#define ZB_ZCL_REPORT_ATTR_REQ_SIZE sizeof(zb_zcl_report_attr_req_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Report attribute command and returns next Attribute + report or NULL if there is no more data. + + If command contains invlid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing Report attribute command data + @param rep_attr_req - out pointer to zb_zcl_report_attr_req_t, containing Attribute report + @note data_buf buffer should contain Report attribute command payload, without ZCL header. + Each parsed Attribute report attribute is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_REPORT_ATTR_REQ(data_buf, rep_attr_req) \ +{ \ + zb_uint8_t req_size = 0xff; \ + (rep_attr_req) = zb_buf_len(data_buf) >= ZB_ZCL_REPORT_ATTR_REQ_SIZE ? \ + (zb_zcl_report_attr_req_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (rep_attr_req) \ + { \ + req_size = ZB_ZCL_REPORT_ATTR_REQ_SIZE; \ + ZB_ZCL_HTOLE16_INPLACE(&(rep_attr_req)->attr_id); \ + /* Reduce req_size value by sizeof(zb_uint8_t) because it is \ + * already included into zb_zcl_report_attr_req_t */ \ + req_size += \ + zb_zcl_get_attribute_size((rep_attr_req)->attr_type, (rep_attr_req)->attr_value) - \ + sizeof(zb_uint8_t); \ + if (req_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_FIX_ENDIAN((rep_attr_req)->attr_value, (rep_attr_req)->attr_type); \ + } \ + \ + if (req_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), req_size); \ + } \ + else \ + { \ + (rep_attr_req) = NULL; \ + } \ + } \ +} + +/** @} */ /* Report attribute command parsing. */ + +/************************** Read Reporting Configuration command definitions **********************************/ + +/** + * @defgroup read_reporting_cfg_cmd Read reporting configuration command sending and parsing + * @{ + * @details + * Most of actions related to the read attribute reporting configuration are implemented in ZCL + * internals. + * Read reportung configuration command is described in ZCL spec, subclause 2.4.9. + */ + + + +/**Format of the Attribute Status Record Field + *Figure 2.20 in ZCL spec. + *NOTE: it can be variouse number of attribute status record fields in Read + *reporting configuration request + */ +typedef ZB_PACKED_PRE struct zb_zcl_read_reporting_cfg_req_s +{ + zb_uint8_t direction; /*!< The direction field specifies whether + * values of the attribute are reported (0x00), or + *whether reports of the attribute are received (0x01). + */ + zb_uint16_t attr_id; /*!< The attribute identifier field shall + *contain the identifier of the attribute whose + *reporting configuration details are to be read. + */ +} ZB_PACKED_STRUCT + zb_zcl_read_reporting_cfg_req_t; + +/** @brief Minimal size of Write attribute request, it will be more if attr_value size is more + * than 1 byte + */ +#define ZB_ZCL_READ_REP_CFG_REQ_SIZE sizeof(zb_zcl_read_reporting_cfg_req_t) + +/** @brief Parses read reporting configuration request and returns + * next Read reporting configuration attribute record or NULL if there + * is no more data. + + If request contains invlid data, NULL is returned. + @param data_buf - ID zb_bufid_t of a buffer containing read reporting configuration request data + @param rep_cfg_req - out pointer to @ref zb_zcl_read_attr_req_t, containing read reporting configuration request + @param rslt - returns TRUE if record exist and FALSE if not + @note data_buf buffer should contain read reporting configuration request payload, without ZCL header. Each + parsed read reporting configuration request is exctracted from intial data_buf buffer + */ +#define ZB_ZCL_GENERAL_GET_NEXT_READ_REP_CFG_REQ(data_buf, rep_cfg_req, rslt) \ + { \ +zb_zcl_read_reporting_cfg_req_t *cfg_req; \ + (cfg_req) = zb_buf_len(data_buf) >= ZB_ZCL_READ_REP_CFG_REQ_SIZE ? \ + (zb_zcl_read_reporting_cfg_req_t *) zb_buf_begin(data_buf) : NULL; \ + if (cfg_req) \ + { \ + rep_cfg_req.direction = cfg_req -> direction; \ + rep_cfg_req.attr_id = cfg_req -> attr_id; \ + ZB_ZCL_HTOLE16_INPLACE(&(read_rep_cfg_req).attr_id); \ + (void)zb_buf_cut_left((data_buf), ZB_ZCL_READ_REP_CFG_REQ_SIZE); \ + rslt = ZB_TRUE; \ + } \ + else \ + { \ + rslt = ZB_FALSE; \ + } \ +} + + +/**Format of the Attribute Reporting Configuration Record Field + *Figure 2.22 in ZCL spec. + *NOTE: it can be variouse number of attribute recording configuration + *record fields in Read reporting configuration responce + */ +typedef ZB_PACKED_PRE struct zb_zcl_read_reporting_cfg_rsp_s +{ + zb_uint8_t status; /*!direction == ZB_ZCL_CONFIGURE_REPORTING_SEND_REPORT) \ + { \ + min_resp_size = zb_zcl_is_analog_data_type((read_rep_conf_res)->u.clnt.attr_type)? \ + ZB_ZCL_READ_REPORTING_CFG_RES_SIZE: \ + ZB_ZCL_READ_REPORTING_CFG_RES_SIZE - sizeof(zb_uint8_t); \ + } \ + else \ + { \ + min_resp_size += sizeof(zb_uint16_t); /* timeout value */ \ + } \ + \ + if (zb_buf_len(data_buf) < min_resp_size) \ + { \ + (read_rep_conf_res) = NULL; \ + } \ + } \ + \ + if (read_rep_conf_res) \ + { \ + if ((read_rep_conf_res)->status != ZB_ZCL_STATUS_SUCCESS \ + && (read_rep_conf_res)->status != ZB_ZCL_STATUS_MALFORMED_CMD) \ + { \ + /* In case of error, direction and attribute id is reported */ \ + res_size = sizeof(zb_uint16_t) + 2*sizeof(zb_uint8_t); \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(read_rep_conf_res)->attr_id); \ + } \ + } \ + else \ + { \ + res_size = min_resp_size; \ + } \ + } \ + \ + if (res_size <= zb_buf_len(data_buf)) \ + { \ + (void)zb_buf_cut_left((data_buf), res_size); \ + } \ + else \ + { \ + (read_rep_conf_res) = NULL; \ + } \ +} + + +/** @} */ /* Configure read reporting configuration command sending and parsing. */ + +/** @cond internals_doc */ + +#endif + + +/******************** HA extentions: discovery commands ***************************/ +/********************* HA extention: discovery commands *****************************/ + +#if defined ZB_ENABLE_HA || defined DOXYGEN + +/** + * @defgroup disc_cmd Discovery commands command sending and parsing. + * @{ + * @details + * Discovery commands request has fixed length payload. + * Discovery commands response has variable-length payload. + * + * For more information see any HA sample + */ + +/********* request commands ************/ + +/*! @brief ZCL Discovery Commands Command frame + @see HA spec, 12.1.1 Discovery Commands Command + @see HA spec, 12.1.3 Discovery Commands Command +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_cmd_req_s +{ + zb_uint8_t start_cmd_id; /*!< Start command identifier */ + zb_uint8_t maximum; /*!< Maximum command identifiers */ +} ZB_PACKED_STRUCT +zb_zcl_disc_cmd_req_t; + +/** @brief Discover commands Generated command + @param buffer to put packet to + @param direction - direction client-to-server or server-to-client + @param def_resp - enable/disable default response + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status + @param _is_manuf - is discovery manufacturer attributes + @param _manuf_id - manufacturer ID + @param start_attr_id - start command ID + @param max_len - max count +*/ +#define ZB_ZCL_GENERAL_DISC_COMMAND_GENERATED_REQ(_buffer, _direction, _def_resp, \ + _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb, \ + _is_manuf, _manuf_id, _start_cmd_id, _max_len) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_EXT(cmd_ptr, \ + ((_is_manuf) ? ZB_ZCL_MANUFACTURER_SPECIFIC : ZB_ZCL_NOT_MANUFACTURER_SPECIFIC), \ + (_direction), (_def_resp)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), (_is_manuf), \ + (_manuf_id), ZB_ZCL_CMD_DISCOVER_COMMANDS_GENERATED); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (_start_cmd_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (_max_len)); \ + ZB_ZCL_FINISH_PACKET((_buffer), cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), \ + (_profile_id), (_cluster_id), (_cb)); \ +} + +/** @brief Discover commands Received command + @param buffer to put packet to + @param direction - direction client-to-server or server-to-client + @param def_resp - enable/disable default response + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cluster_id - cluster identifier + @param cb - callback for getting command send status + @param _is_manuf - is discovery manufacturer attributes + @param _manuf_id - manufacturer ID + @param start_attr_id - start command ID + @param max_len - max count +*/ +#define ZB_ZCL_GENERAL_DISC_COMMAND_RECEIVED_REQ(_buffer, _direction, _def_resp, \ + _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb, \ + _is_manuf, _manuf_id, _start_cmd_id, _max_len) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_EXT(cmd_ptr, \ + ((_is_manuf) ? ZB_ZCL_MANUFACTURER_SPECIFIC : ZB_ZCL_NOT_MANUFACTURER_SPECIFIC), \ + (_direction), (_def_resp)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), (_is_manuf), \ + (_manuf_id), ZB_ZCL_CMD_DISCOVER_COMMANDS_RECEIVED); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (_start_cmd_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (_max_len)); \ + ZB_ZCL_FINISH_PACKET((_buffer), cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), \ + (_profile_id), (_cluster_id), (_cb)); \ +} + +/** @brief Get parameter of Discovery command request. + + @param data_buf - ID zb_bufid_t of a buffer containing part of Discover command request data + @param data_ptr - out pointer to zb_zcl_disc_cmd_req_t, containing Discover command data + @status - result parse, see @ref zb_zcl_parse_status_t + */ +#define ZB_ZCL_GENERAL_GET_DISC_COMMAND(_data_ptr, _buffer, _status) \ +{ \ + if (zb_buf_len((_buffer)) != sizeof(zb_zcl_disc_cmd_req_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_disc_cmd_req_t *src_ptr = \ + (zb_zcl_disc_cmd_req_t*)zb_buf_begin((_buffer)); \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (_data_ptr)->start_cmd_id = src_ptr->start_cmd_id; \ + (_data_ptr)->maximum = src_ptr->maximum; \ + } \ +} + +/********* response commands ************/ + +/*! @brief ZCL Discover command complete enum + @see HA spec, subclause 12.1.2.1.2. +*/ +typedef enum zb_zcl_disc_cmd_complete_e +{ + /*! Are more commands to be discovered */ + ZB_ZCL_DISC_CMD_NOT_COMPLETE = 0x00, + /*! No more commands to be discovered */ + ZB_ZCL_DISC_CMD_COMPLETE = 0x01, +} zb_zcl_disc_cmd_complete_t; + +/*! @brief ZCL Discovery Commands Command frame + @see HA spec, 12.1.2 Discovery Commands Command + @see HA spec, 12.1.4 Discovery Commands Command +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_cmd_resp_s +{ + zb_uint8_t complete; /*!< Discovery complete */ +} ZB_PACKED_STRUCT +zb_zcl_disc_cmd_resp_t; + +/** @brief Init Discover commands response manufacture specific and not specific + @param _cmd_ptr - pointer of current part command + @param _buffer to put packet to + @param _direction - direction client-to-server or server-to-client + @param _seq - sequence of request + @param _cmd - command Id + @param _is_manuf - is manufacturer specific + @param _manuf_id - manufacturer ID + @param _complete - The discovery complete field is a boolean field +*/ +#define ZB_ZCL_GENERAL_INIT_DISC_COMMAND_RESP(_cmd_ptr, _buffer, \ + _direction, _seq, _cmd, _is_manuf, _manuf_id, _complete) \ +{ \ + (_cmd_ptr) = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_EXT((_cmd_ptr), \ + ((zb_zcl_manufacturer_specific_t)((_is_manuf)!=ZB_FALSE ? \ + ZB_ZCL_MANUFACTURER_SPECIFIC : ZB_ZCL_NOT_MANUFACTURER_SPECIFIC)), \ + (_direction)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT((_cmd_ptr), (_seq), (_is_manuf), \ + (_manuf_id), (_cmd)); \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), (_complete)); \ +} + +/** @brief Add command Id to Discover commands response + @param _cmd_ptr - pointer of current part command + @param _cmd_id - The discovery complete field is a boolean field +*/ +#define ZB_ZCL_GENERAL_ADD_DISC_COMMAND_RESP(_cmd_ptr, _cmd_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8((_cmd_ptr), (_cmd_id)); \ +} + +/** @brief Finish command Id to Discover commands response + @param _buffer to put packet to + @param _cmd_ptr - pointer of current part command + @param _addr - address to send packet to + @param _dst_addr_mode - addressing mode + @param _dst_ep - destination endpoint + @param _ep - sending endpoint + @param _profile_id - profile identifier + @param _cluster_id - cluster identifier +*/ +#define ZB_ZCL_GENERAL_FINISH_DISC_COMMAND_RESP(_buffer, _cmd_ptr, \ + _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id) \ +{ \ + ZB_ZCL_FINISH_PACKET((_buffer), (_cmd_ptr)) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), (_dst_ep), \ + (_ep), (_profile_id), (_cluster_id), NULL); \ +} + + +/** @brief Get parameter of Discovery command response. + + @param _buffer - ID zb_bufid_t of a buffer containing part of Discover command response data + @param _data_ptr - out pointer to zb_zcl_disc_cmd_res_t, containing Discover command response + @param _status - result parse, see @ref zb_zcl_parse_status_t + */ +#define ZB_ZCL_GENERAL_GET_DISC_COMMAND_RESP(_data_ptr, _buffer, _status) \ +{ \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_disc_cmd_resp_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_disc_cmd_resp_t *src_ptr = \ + (zb_zcl_disc_cmd_resp_t*)zb_buf_begin((_buffer)); \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (_data_ptr)->complete = src_ptr->complete; \ + (void)zb_buf_cut_left(()buffer), sizeof(zb_zcl_disc_cmd_resp_t)); \ + } \ +} + +/** @brief Get next command ID from Discovery command response. + + @param _buffer - ID zb_bufid_t of a buffer containing part of Discover command response data + @param _cmd_id - out next command ID + @param _status - result parse, see @ref zb_zcl_parse_status_t + */ +/* sizeof(cmd_id) == sizeof(zb_uint8_t), + command ID has not special struct */ +#define ZB_ZCL_GENERAL_GET_NEXT_CMD_ID_DISC_COMMAND_RESP(_cmd_id, _buffer, _status) \ +{ \ + if (zb_buf_len((_buffer)) < sizeof(zb_uint8_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_uint8_t *cmd_id_list = (zb_uint8_t*)zb_buf_begin((_buffer)); \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (_cmd_id) = cmd_id_list[0]; \ + (void)zb_buf_cut_left((_buffer), sizeof(zb_uint8_t)); \ + } \ +} + +/** @} */ /* Discovery commands command sending and parsing */ + +#endif /* defined ZB_ENABLE_HA || defined DOXYGEN */ + +/***** HA extention: discovery attribute extended ************************/ + +/*! @brief ZCL Discover Attribute Extended Command frame + @see HA1.2 spec, zb_zcl_disc_attr_ext 12.1.5 Discover Attributes Extended Command +*/ +/* command frames are identical for Discover attr and Discover attr ext */ +typedef zb_zcl_disc_attr_req_t zb_zcl_disc_attr_ext_req_t; + +/** @brief Discover Attributes Extended command + @param _buffer to put packet to + @param _direction - direction client-to-server or server-to-client + @param _def_resp - enable/disable default response + @param _addr - address to send packet to + @param _dst_addr_mode - addressing mode + @param _dst_ep - destination endpoint + @param _ep - sending endpoint + @param _profile_id - profile identifier + @param _cluster_id - cluster identifier + @param _cb - callback for getting command send status + @param _is_manuf - is discovery manufacturer attributes + @param _manuf_id - manufacturer ID + @param _start_attr_id - start attribute ID + @param _max_len - max count +*/ +#define ZB_ZCL_GENERAL_DISC_ATTRIBUTE_EXT_REQ(_buffer, _direction, _def_resp, \ + _addr, _dst_addr_mode, _dst_ep, _ep, _profile_id, _cluster_id, _cb, \ + _is_manuf, _manuf_id, _start_attr_id, _max_len) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_EXT(cmd_ptr, \ + ((_is_manuf) ? ZB_ZCL_MANUFACTURER_SPECIFIC : ZB_ZCL_NOT_MANUFACTURER_SPECIFIC), \ + (_direction), (_def_resp)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), (_is_manuf), \ + (_manuf_id), ZB_ZCL_CMD_DISCOVER_ATTR_EXT); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (_start_attr_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (_max_len)); \ + ZB_ZCL_FINISH_PACKET((_buffer), cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((_buffer), (_addr), (_dst_addr_mode), \ + (_dst_ep), (_ep), (_profile_id), (_cluster_id), (_cb)); \ +} + +/*! @brief HA1.2 Description for Discover Attribute Response frame + @see ZCL spec, zb_zcl_read_attr 2.4.14 Discover Attribute Response +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_attr_ext_info_s +{ + zb_uint16_t attr_id; /*!< Attribute identifier */ + zb_uint8_t data_type; /*!< Attribute data type */ + zb_uint8_t attr_access; /*!< Attribute access control */ +} ZB_PACKED_STRUCT +zb_zcl_disc_attr_ext_info_t; + +#define ZB_ZCL_DISC_ATTR_EXT_RESP_SIZE sizeof(zb_zcl_disc_attr_ext_info_t) + +/*! @brief ZCL Discover Attribute Response frame + @see ZCL spec, zb_zcl_read_attr 2.4.15 Discover Attribute Response + @note Command frame contains variable number of parameters +*/ +typedef ZB_PACKED_PRE struct zb_zcl_disc_attr_ext_res_s +{ + zb_uint8_t complete; /*!< Discovery complete */ + zb_zcl_disc_attr_ext_info_t info[1]; /*!< Attribute desc list */ +} ZB_PACKED_STRUCT +zb_zcl_disc_attr_ext_res_t; + +/** @brief Get parameter of Discovery Attribute Extended response. + + @param _buffer - ID zb_bufid_t of a buffer containing part of Discover Attribute Extended response data + @param _complete - out variable to complete field Discover command response, see @ref zb_zcl_disc_complete_t + @param _status - result parse, see @ref zb_zcl_parse_status_t + */ +#define ZB_ZCL_GENERAL_GET_COMPLETE_DISC_ATTR_RESP(_complete, _buffer, _status) \ +{ \ + if (zb_buf_len((_buffer)) < sizeof(zb_uint8_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + zb_uint8_t *complete_ptr = (zb_uint8_t*)zb_buf_begin((_buffer)); \ + (_complete) = *complete_ptr; \ + (void)zb_buf_cut_left((_buffer), sizeof(zb_uint8_t)); \ + } \ +} + +/** @brief Get next command ID from Discovery command response. + + @param _buffer - ID zb_bufid_t of a buffer containing part of Discover command response data + @param _data_ptr - out Description for Discover Attribute Response frame, see @ref zb_zcl_disc_attr_ext_info_t + @param _status - result parse, see @ref zb_zcl_parse_status_t + */ +#define ZB_ZCL_GENERAL_GET_NEXT_ATTR_DISC_COMMAND_RESP(_data_ptr, _buffer, _status) \ +{ \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_disc_attr_ext_info_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_disc_attr_ext_info_t *src_ptr = \ + (zb_zcl_disc_attr_ext_info_t*)zb_buf_begin((_buffer)); \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((_data_ptr)->attr_id), &(src_ptr->attr_id)); \ + (_data_ptr)->data_type = src_ptr->data_type; \ + (_data_ptr)->data_access = src_ptr->data_access; \ + (void)zb_buf_cut_left((_buffer), sizeof(zb_zcl_disc_attr_ext_info_t)); \ + } \ +} + + /*! Convert internal attribute access bitmask into ZCL/HA1.2 bitmask + * value (actually, support 0 and 1 bits) */ +#define ZB_ZCL_CONVERT_ATTR_ACCESS_BITMASK(_access) ((_access) && 0x3) + +/******************** Command handlers ***************************/ + +/* ZCL handlers */ +void zb_zcl_read_attr_handler(zb_uint8_t param); +void zb_zcl_write_attr_handler(zb_uint8_t param); +void zb_zcl_discover_commands_res(zb_uint8_t param, zb_bool_t recv_cmd_type); +void zb_zcl_disc_attr_handler_ext(zb_uint8_t param); + +#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) + +void zb_zcl_configure_reporting_handler(zb_uint8_t param); + +/* ZCL commands */ +void zb_zcl_send_report_attr_command(struct zb_zcl_reporting_info_s *rep_info, zb_uint8_t param); + +#endif + +/** @endcond */ /* internals_doc */ + +/** @} */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* ! defined ZB_ZCL_COMMANDS_H */ diff --git a/zboss/include/zcl/zb_zcl_common.h b/zboss/include/zcl/zb_zcl_common.h new file mode 100644 index 0000000000..110684e431 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_common.h @@ -0,0 +1,2206 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Zigbee cluster library types and macros common for all clusters +*/ + +#if ! defined ZB_ZCL_COMMON_H +#define ZB_ZCL_COMMON_H + +#include /* int types, zb_bufid_t */ + +/** @cond DOXYGEN_ZCL_SECTION */ + +#ifdef DEBUG +/* If defined, samples included to zcl source files will be comiled - need for development only */ +#define ZB_COMPILE_ZCL_SAMPLE +#endif + + +/** @addtogroup ZB_ZCL_COMMON + * @{ + */ + +/** + * @defgroup zb_zcl_common_types ZCL common types + * @{ + * @details + * The section contains enumerations defining cluster identifiers and inter-device operation + * statuses, and a callback type usesd to notify application on attribute value change (see @ref + * write_attr_cmd "Write attributes" command description). + */ + +/*************************** ZCL cluster definitions ***********************************/ + +/*! ZCL payload maximum size; is used to calculate number of + * available bytes in variable-size commands */ +/* TODO: current max size is defined for the worst case (nwk security + * enabled, long address is specified). Possibly - recalculate this + * max size in run-time taking into account current parameters */ +/* TODO: check this value - calculate it correctly!!! */ +/* + Let's count: +- max PHY payload - 127 bytes +- MAC hdr (w/o Pan ID complession, short src/dest) - (FC 2, Seq 1, Pan ID 2, DST addr 2, SRC addr +2, FCS 2) = 11b MAC +- NWK HDR 8 + 8*2 (addresses). Note: not use source routing, else have more fields. +- NWK security 18b +- APS HDR (without security) 8b +Total 61 (45 without ieee addresses). +So, rest is 127-61 = 66b +So, rest is 127-45 = 82b + */ +/* #define ZB_ZCL_MAX_PAYLOAD_SIZE 55 */ +/*! Maximal payload size */ +#define ZB_ZCL_HI_MAX_PAYLOAD_SIZE 66 +/*! Maximal payload size without long adress sending */ +#define ZB_ZCL_HI_WO_IEEE_MAX_PAYLOAD_SIZE 82 + +struct zb_zcl_attr_s; /* Forward declaration */ + +/** @brief ZCL Cluster Init Handler. This handler is called on registering device context (@ref + ZB_AF_REGISTER_DEVICE_CTX). Initialization of the cluster should include @ref + zb_zcl_add_cluster_handlers call, if any of the cluster handlers are implemented. + + Cluster Init handler is bound to the cluster declaration via ZB_ZCL_CLUSTER_DESC macro. Every + cluster should implement "__INIT" macro, for example: + @code + #define ZB_ZCL_CLUSTER_ID_ON_OFF_SERVER_ROLE_INIT zb_zcl_on_off_init_server + #define ZB_ZCL_CLUSTER_ID_ON_OFF_CLIENT_ROLE_INIT zb_zcl_on_off_init_client + @endcode + + If cluster does not have any initialization steps and does not need any cluster handlers, + Cluster Init handler may be NULL, for example: + @code + #define ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING_SERVER_ROLE_INIT (zb_zcl_cluster_init_t)NULL + #define ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING_CLIENT_ROLE_INIT (zb_zcl_cluster_init_t)NULL + @endcode +*/ +typedef void (*zb_zcl_cluster_init_t)(void); +/** @brief ZCL Cluster Command Handler. This handler is called on incoming ZCL command for + corresponding cluster. + @param param - pointer to buffer with ZCL command + + @return ZB_TRUE if command was handled (no additional actions are needed), + ZB_FALSE otherwise +*/ +typedef zb_bool_t (*zb_zcl_cluster_handler_t)(zb_uint8_t param); +/** @brief ZCL Cluster Check Value Handler. This handler is called before attribute change (for + corresponding cluster) and checks if new value is in correct range and can be applied. + @param attr_id - ZCL Attribute ID + @param endpoint - Device Endpoint + @param value - pointer to the new Attribute Value + + @return RET_OK if check is passed successfully (attribute can be changed), + RET_OUT_OF_RANGE if the value is out of range (TODO: describe), + RET_ERROR otherwise +*/ +typedef zb_ret_t (*zb_zcl_cluster_check_value_t)(zb_uint16_t attr_id, zb_uint8_t endpoint, zb_uint8_t *value); +/** @brief ZCL Cluster Write Attribute Hook Handler. This handler is called before attribute change + (if any cluster-specific action needs to be bound to attribute change, it can be placed in this + handler). + @param endpoint - Device Endpoint + @param attr_id - ZCL Attribute ID + @param value - pointer to the new Attribute Value +*/ +typedef void (*zb_zcl_cluster_write_attr_hook_t)(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); + +/** @brief ZCL cluster description. */ +typedef ZB_PACKED_PRE struct zb_zcl_cluster_desc_s +{ + zb_uint16_t cluster_id; /**< ZCL 16-bit cluster id. @see zb_zcl_cluster_id_e */ + zb_uint16_t attr_count; /**< Attributes number supported by the cluster */ + struct zb_zcl_attr_s *attr_desc_list; /**< List of cluster attributes, + declared using ZB_ZCL_DECLARE__ATTRIB_LIST() macro */ + zb_uint8_t role_mask; /**< Cluster role, refer to zb_zcl_cluster_role_e */ + zb_uint16_t manuf_code; /**< Manufacturer code for cluster and its attributes */ + zb_zcl_cluster_init_t cluster_init; +} ZB_PACKED_STRUCT +zb_zcl_cluster_desc_t; + +/** + * @brief Add ZCL cluster handlers for Cluster ID and Cluster Role. + * + * @param cluster_id - ZCL Cluster ID + * @param cluster_role - ZCL Cluster Role, see @ref zb_zcl_cluster_role_e + * @param cluster_check_value - "Check Value" handler, see @ref zb_zcl_cluster_check_value_t; may + * be NULL if this handler is not needed + * @param cluster_write_attr_hook - "Write Attr Hook" handler, see @ref + * zb_zcl_cluster_write_attr_hook_t; may be NULL if this handler is not needed + * @param cluster_handler - "Cluster Commands" handler, see @ref zb_zcl_cluster_handler_t; may + * be NULL if this handler is not needed + * + * @return RET_OK if ZCL handlers were installed + * @return RET_ALREADY_EXISTS if ZCL handlers are already installed (for given Cluster ID and Role), + * new handlers will not be installed in that case + * @return RET_EMPTY if ZCL handlers were not installed + */ +zb_ret_t zb_zcl_add_cluster_handlers(zb_uint16_t cluster_id, zb_uint8_t cluster_role, + zb_zcl_cluster_check_value_t cluster_check_value, + zb_zcl_cluster_write_attr_hook_t cluster_write_attr_hook, + zb_zcl_cluster_handler_t cluster_handler); + +/** @cond internals_doc */ +zb_zcl_cluster_handler_t zb_zcl_get_cluster_handler(zb_uint16_t cluster_id, zb_uint8_t cluster_role); +zb_zcl_cluster_check_value_t zb_zcl_get_cluster_check_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role); +zb_zcl_cluster_write_attr_hook_t zb_zcl_get_cluster_write_attr_hook(zb_uint16_t cluster_id, zb_uint8_t cluster_role); + +#ifdef ZB_CONTROL4_NETWORK_SUPPORT +/** Functions for adding and getting Control4 Network cluster specific handlers */ +zb_ret_t zb_zcl_add_control4_cluster_handlers(zb_uint16_t cluster_id, zb_uint8_t cluster_role, + zb_zcl_cluster_check_value_t cluster_check_value, + zb_zcl_cluster_write_attr_hook_t cluster_write_attr_hook, + zb_zcl_cluster_handler_t cluster_handler); + +zb_zcl_cluster_handler_t zb_zcl_get_control4_cluster_handler(zb_uint16_t cluster_id, zb_uint8_t cluster_role); +zb_zcl_cluster_check_value_t zb_zcl_get_control4_cluster_check_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role); +zb_zcl_cluster_write_attr_hook_t zb_zcl_get_control4_cluster_write_attr_hook(zb_uint16_t cluster_id, zb_uint8_t cluster_role); +#endif /* ZB_CONTROL4_NETWORK_SUPPORT */ +/** @endcond */ /* internals_doc */ + +/** @brief Cluster roles in message exchange */ +enum zb_zcl_cluster_role_e +{ + /*! Server cluster role */ + ZB_ZCL_CLUSTER_SERVER_ROLE = 0x01, + /*! Client cluster role */ + ZB_ZCL_CLUSTER_CLIENT_ROLE = 0x02, + /*! Internal value - used for searching any role (on the moment when cluster role is not known + * yet). */ + ZB_ZCL_CLUSTER_ANY_ROLE = 0x03 +}; + +/** @brief ZCL cluster identifiers + * @see ZCL spec, subclause 2.2.2. + */ +typedef enum zb_zcl_cluster_id_e +{ + ZB_ZCL_CLUSTER_ID_BASIC = 0x0000, /**< Basic cluster identifier. */ + ZB_ZCL_CLUSTER_ID_POWER_CONFIG = 0x0001, /**< Power configuration cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DEVICE_TEMP_CONFIG = 0x0002, /**< Device temperature configuration cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_IDENTIFY = 0x0003, /**< Identify cluster identifier. */ + ZB_ZCL_CLUSTER_ID_GROUPS = 0x0004, /**< Groups cluster identifier. */ + ZB_ZCL_CLUSTER_ID_SCENES = 0x0005, /**< Scenes cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ON_OFF = 0x0006, /**< On/Off cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG = 0x0007, /**< On/Off switch configuration cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL = 0x0008, /**< Level control cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ALARMS = 0x0009, /**< Alarms cluster identifier. */ + ZB_ZCL_CLUSTER_ID_TIME = 0x000a, /**< Time cluster identifier. */ + ZB_ZCL_CLUSTER_ID_RSSI_LOCATION = 0x000b, /**< RSSI location cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ANALOG_INPUT = 0x000c, /**< Analog input (basic) cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ANALOG_OUTPUT = 0x000d, /**< Analog output (basic) cluster identifier. + */ + ZB_ZCL_CLUSTER_ID_ANALOG_VALUE = 0x000e, /**< Analog value (basic) cluster identifier. */ + ZB_ZCL_CLUSTER_ID_BINARY_INPUT = 0x000f, /**< Binary input (basic) cluster identifier. */ + ZB_ZCL_CLUSTER_ID_BINARY_OUTPUT = 0x0010, /**< Binary output (basic) cluster identifier. + */ + ZB_ZCL_CLUSTER_ID_BINARY_VALUE = 0x0011, /**< Binary value (basic) cluster identifier. */ + ZB_ZCL_CLUSTER_ID_MULTI_INPUT = 0x0012, /**< Multistate input (basic) cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_MULTI_OUTPUT = 0x0013, /**< Multistate output (basic) cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_MULTI_VALUE = 0x0014, /**< Multistate value (basic) cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_COMMISSIONING = 0x0015, /**< Commissioning cluster identifier. */ + + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE = 0x0019, /**< Over The Air cluster identifier. */ + + /* General clusters */ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL = 0x0020, /**< Poll control cluster identifier. */ + ZB_ZCL_CLUSTER_ID_GREEN_POWER = 0x0021, /**< Green Power cluster identifier. */ + + ZB_ZCL_CLUSTER_ID_KEEP_ALIVE = 0x0025, /**< Keep Alive cluster identifier. */ + + /* Closures clusters */ + ZB_ZCL_CLUSTER_ID_SHADE_CONFIG = 0x0100, /**< Shade configuration cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK = 0x0101, /**< Door lock cluster identifier. */ + ZB_ZCL_CLUSTER_ID_WINDOW_COVERING = 0x0102, /**< Window covering cluster identifier. */ + /* HVAC clusters */ + ZB_ZCL_CLUSTER_ID_PUMP_CONFIG_CONTROL = 0x200, /**< Pump configuration and control cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_THERMOSTAT = 0x201, /**< Thermostat cluster identifier. */ + ZB_ZCL_CLUSTER_ID_FAN_CONTROL = 0x202, /**< Fan control cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DEHUMID_CONTROL = 0x203, /**< Dehumidification control cluster + identifier. */ + ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG = 0x204, /**< Thermostat user interface configuration + cluster identifier. */ + + /* Lighting clusters */ + ZB_ZCL_CLUSTER_ID_COLOR_CONTROL = 0x0300, /**< Color control cluster identifier. */ + ZB_ZCL_CLUSTER_ID_BALLAST_CONFIG = 0x0301, /**< Ballast configuration cluster identifier. */ + + /* Measurement and Sensing */ + ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT = 0x0400, /**< Illuminance measurement */ + ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT = 0x0402, /**< Temperature measurement */ + ZB_ZCL_CLUSTER_ID_PRESSURE_MEASUREMENT = 0x0403, /**< Pressure measurement */ + ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT = 0x0405, /**< Relative humidity measurement */ + ZB_ZCL_CLUSTER_ID_OCCUPANCY_SENSING = 0x0406, /**< Occupancy sensing */ + + /* IAS clusters */ + ZB_ZCL_CLUSTER_ID_IAS_ZONE = 0x0500, /**< IAS Zone cluster identifier */ + ZB_ZCL_CLUSTER_ID_IAS_ACE = 0x0501, /**< IAS ACE cluster identifier */ + ZB_ZCL_CLUSTER_ID_IAS_WD = 0x0502, /**< IAS WD cluster identifier */ + + /* Smart Energy */ + ZB_ZCL_CLUSTER_ID_PRICE = 0x0700, /**< Price cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DRLC = 0x0701, /**< Demand-Response cluster identifier. */ + ZB_ZCL_CLUSTER_ID_METERING = 0x0702, /**< Metering cluster identifier. */ + ZB_ZCL_CLUSTER_ID_MESSAGING = 0x0703, /**< Messaging cluster identifier. */ + ZB_ZCL_CLUSTER_ID_TUNNELING = 0x0704, /**< Tunneling cluster identifier. */ + ZB_ZCL_CLUSTER_ID_PREPAYMENT = 0x0705, /**< Prepayment cluster identifier. */ + ZB_ZCL_CLUSTER_ID_ENERGY_MANAGEMENT = 0x0706, /**< Energy Management cluster identifier. */ + ZB_ZCL_CLUSTER_ID_CALENDAR = 0x0707, /**< Calendar cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DEVICE_MANAGEMENT = 0x0708, /**< Device Management cluster identifier. */ + ZB_ZCL_CLUSTER_ID_EVENTS = 0x0709, /**< Events cluster identifier. */ + ZB_ZCL_CLUSTER_ID_MDU_PAIRING = 0x070A, /**< MDU Pairing cluster identifier. */ + ZB_ZCL_CLUSTER_ID_SUB_GHZ = 0x070B, /**< Sub-GHz cluster identifier. */ + ZB_ZCL_CLUSTER_ID_KEY_ESTABLISHMENT = 0x0800, /**< Key Establishment cluster identifier. */ + + + /* Home Automation */ + ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS = 0x0b02, /**< Appliance events + and alerts cluster identifier */ + /* HA spec, rev. 29, ver. 1.2 - Electricity Measurement, not sure that its Electrical Measurement */ + ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT = 0x0b04, /**< Electrical Measurement cluster identifier. */ + ZB_ZCL_CLUSTER_ID_DIAGNOSTICS = 0x0b05, /**< Home Automation Diagnostics */ + + ZB_ZCL_CLUSTER_ID_WWAH = 0xFC57, /**< Works with All Hubs cluster identifier */ + /** @cond touchlink */ + ZB_ZCL_CLUSTER_ID_TOUCHLINK_COMMISSIONING = 0x1000, /**< Touchlink Commissioning cluster identifier */ + /** @endcond */ /* touchlink */ + + /************** Manufacturer specific clusters ****************/ + + ZB_ZCL_CLUSTER_ID_TUNNEL = 0xfc00, /**< Manufacturer specific Tunnel cluster */ + ZB_ZCL_CLUSTER_ID_IR_BLASTER = 0xfc01, /**< Manufacturer specific IR Blaster cluster */ + + ZB_ZCL_CLUSTER_ID_CUSTOM_ATTR = 0xffee, /**< Custom Attributes */ + + ZB_ZCL_CLUSTER_ID_METER_IDENTIFICATION = 0x0B01, /**< Meter Identification cluster identifier */ + /* TODO: define other clusters IDs */ + /* Measurements and sensing clusters */ + /* Security and safety clusters */ +} zb_zcl_cluster_id_t; + +#ifdef ZB_CONTROL4_NETWORK_SUPPORT +#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING ((zb_uint16_t)0x0001) +#endif + +/** @brief Check whether cluster is manufacturer specific. */ +#define ZB_ZCL_IS_CLUSTER_MANUF_SPEC(_cluster_id) ((_cluster_id) > 0xfbff) + +/** @brief Internal invalid manufacturer code value. */ +#define ZB_ZCL_MANUF_CODE_INVALID 0x0000 + + +/** @brief Parse frame operation status. */ +typedef enum zb_zcl_parse_status_e +{ + ZB_ZCL_PARSE_STATUS_SUCCESS, /**< Frame parsed successfully. */ + ZB_ZCL_PARSE_STATUS_FAILURE /**< Frame parse operation failed. */ +} zb_zcl_parse_status_t; + +/** @brief Attribute Reporting Status. */ +typedef enum zb_zcl_attribute_reporting_status_e +{ + ZB_ZCL_AR_STATUS_PENDING =0x00, /**< Pending. */ + ZB_ZCL_AR_STATUS_COMPLETE =0x01 /**< Attribute Reporting Complete. */ +} zb_zcl_attribute_reporting_status_t; + +/** @brief ZCL status values + @see ZCL spec, subclause 2.5.3 + @note The enumeration does not contain statuses not used in ZB HA profile +*/ +typedef enum zb_zcl_status_e +{ + ZB_ZCL_STATUS_SUCCESS = 0x00, /*!< ZCL Success */ + ZB_ZCL_STATUS_FAIL = 0x01, /*!< ZCL Fail */ + ZB_ZCL_STATUS_NOT_AUTHORIZED = 0x7E, /*!< Server is not authorized to upgrade the client */ + ZB_ZCL_STATUS_MALFORMED_CMD = 0x80, /*!< Malformed command */ + ZB_ZCL_STATUS_UNSUP_CLUST_CMD = 0x81, /*!< Unsupported cluster command */ + ZB_ZCL_STATUS_UNSUP_GEN_CMD = 0x82, /*!< Unsupported general command */ + ZB_ZCL_STATUS_UNSUP_MANUF_CLUST_CMD = 0x83, /*!< Unsupported manuf-specific clust command */ + ZB_ZCL_STATUS_UNSUP_MANUF_GEN_CMD = 0x84, /*!< Unsupported manuf-specific general command */ + ZB_ZCL_STATUS_INVALID_FIELD = 0x85, /*!< Invalid field */ + ZB_ZCL_STATUS_UNSUP_ATTRIB = 0x86, /*!< Unsupported attribute */ + ZB_ZCL_STATUS_INVALID_VALUE = 0x87, /*!< Invalid value */ + ZB_ZCL_STATUS_READ_ONLY = 0x88, /*!< Read only */ + ZB_ZCL_STATUS_INSUFF_SPACE = 0x89, /*!< Insufficient space */ + ZB_ZCL_STATUS_DUPE_EXISTS = 0x8a, /*!< Duplicate exists */ + ZB_ZCL_STATUS_NOT_FOUND = 0x8b, /*!< Not found */ + ZB_ZCL_STATUS_UNREPORTABLE_ATTRIB = 0x8c, /*!< Unreportable attribute */ + ZB_ZCL_STATUS_INVALID_TYPE = 0x8d, /*!< Invalid type */ + ZB_ZCL_STATUS_WRITE_ONLY = 0x8f, /*!< Write only */ + ZB_ZCL_STATUS_INCONSISTENT = 0x92, /*!< Supplied values are inconsistent */ + ZB_ZCL_STATUS_ACTION_DENIED = 0x93, /*!< The credentials presented by the device sending the + command are not sufficient to perform this action. */ + ZB_ZCL_STATUS_TIMEOUT = 0x94, /*!< Timeout */ + ZB_ZCL_STATUS_ABORT = 0x95, /*!< Abort */ + + ZB_ZCL_STATUS_INVALID_IMAGE = 0x96, /*!< Invalid OTA upgrade image */ + ZB_ZCL_STATUS_WAIT_FOR_DATA = 0x97, /*!< Server does not have data block available yet */ + ZB_ZCL_STATUS_NO_IMAGE_AVAILABLE = 0x98, /*!< No OTA upgrade image available for a particular client. */ + ZB_ZCL_STATUS_REQUIRE_MORE_IMAGE = 0x99, /*!< The client still requires more OTA upgrade image files + in order to successfully upgrade. */ + ZB_ZCL_STATUS_NOTIFICATION_PENDING = 0x9A, /*!< The command has been received and is being processed.*/ + ZB_ZCL_STATUS_HW_FAIL = 0xc0, /*!< Hardware failure */ + ZB_ZCL_STATUS_SW_FAIL = 0xc1, /*!< Software failure */ + ZB_ZCL_STATUS_CALIB_ERR = 0xc2, /*!< Calibration error */ + ZB_ZCL_STATUS_UNSUP_CLUST = 0xc3, /*!< Cluster is not found on the target endpoint */ + ZB_ZCL_STATUS_LIMIT_REACHED = 0xc4, /*!< Cluster is not found on the target endpoint */ +} zb_zcl_status_t; + +/** @brief ZCL global attibute: cluster version returned by default. + Used if the GLOBAL_CLUSTER_REVISION attribute is undefined for the cluster/role. +*/ +#define ZB_ZCL_GLOBAL_CLUSTER_VERSION_DEFAULT 1 + +#if defined ZB_ENABLE_HA + +/** @brief Discovery manufacture specific command + @param direction - direction 0 (client to server) or 1 (server to client) + @param ep - endpoint number + @param cluster_id - cluster ID + @param manuf_id - manufacture ID + @param recv_cmd_type - need list of received (ZB_TRUE) or generated (ZB_FALSE) command + @param value - (out) pointer to list command ID + + @return number of value elements +*/ +typedef zb_uint8_t (*zb_zcl_disc_manuf_cmd_cb_t)( + zb_uint8_t direction, zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t manuf_id, zb_bool_t recv_cmd_type, zb_uint8_t **value); + +#endif /* ZB_ENABLE_HA */ + +/********************************** ZCL attributes definitions ************************************/ + +/** @brief Informs application that some attribute value is being updated by Write attribute command + @param ep - endpoint number + @param cluster_id - cluster ID + @param attr_id - attribute ID of the attribute being updated + @param value - pointer to new data +*/ +typedef void (*zb_zcl_modify_attr_value_cb_t)( + zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t attr_id, zb_uint8_t *value); + +/*! @defgroup zb_zcl_common_attrs General attributes' description + Types and macros shared among all attributes' definitions. + @{ + Use @ref ZB_ZCL_SET_ATTRIBUTE + @par + For more information see HA samples +*/ + +/** @brief Sets correctly ZCL char string value */ +#define ZB_ZCL_SET_STRING_VAL(str, val, len) \ + (ZB_MEMCPY((zb_uint8_t*)(str) + 1, (val), (len)), *(zb_uint8_t*)(str) = (len)) + +/** @brief Get ZCL string length */ +#define ZB_ZCL_GET_STRING_LENGTH(str) ((str)[0]) + +#define ZB_ZCL_SET_STRING_LENGTH(str, _newlen) (((str))[0] = _newlen) + +/** @brief Returns size of a string constant */ +#define ZB_ZCL_STRING_CONST_SIZE(str) (zb_uint8_t)(sizeof(str) - 1) + +/** Get pointer to first char in the string. */ +#define ZB_ZCL_GET_STRING_BEGIN(_str) (&((_str)[1])) + +/** Get pointer to (begin + length) char in the string. */ +#define ZB_ZCL_GET_STRING_END(_str) (ZB_ZCL_GET_STRING_BEGIN(_str) + ZB_ZCL_GET_STRING_LENGTH(_str)) + +/** Get pointer to char in string at specified pos. */ +#define ZB_ZCL_GET_STRING_REF_AT(_str, _pos) (ZB_ZCL_GET_STRING_BEGIN(_str) + _pos) + +/** Get char by specified pos. */ +#define ZB_ZCL_GET_STRING_CHAR_AT(_str, _pos) *ZB_ZCL_GET_STRING_REF_AT(_str, _pos) + +/** Turn ZCL Octet string into string with null-term. */ +#define ZB_ZCL_STRING_TO_C_STRING(_str) \ +{ \ + zb_uint8_t _len = _str[0]; \ + ZB_MEMMOVE(_str, _str + 1, _len); \ + _str[_len] = 0; \ +} + +/** Set size of ZCL Octet String into 0 .*/ +#define ZB_ZCL_STRING_CLEAR(_str) (_str[0] = 0) + +/** Add some data to ZCL Octet String. */ +static ZB_INLINE zb_uint16_t zb_zcl_string_append_data(zb_uint8_t *zcl_str, + zb_uint8_t zcl_str_max_size, + const zb_uint8_t *c_str, + zb_uint8_t c_str_len) +{ + zb_uint16_t newlen = ZB_ZCL_GET_STRING_LENGTH(zcl_str) + c_str_len; + + if (newlen < (zb_uint16_t) zcl_str_max_size) + { + ZB_MEMCPY(ZB_ZCL_GET_STRING_END(zcl_str), c_str, c_str_len); + ZB_ZCL_SET_STRING_LENGTH(zcl_str, newlen); + } + else + { + newlen = 0; + } + + return newlen; +} + +/** Add signle byte to ZCL Octet String. */ +static ZB_INLINE zb_uint16_t zb_zcl_string_append_byte(zb_uint8_t *zcl_str, + zb_uint8_t zcl_str_max_size, + zb_uint8_t value) +{ + zb_uint16_t newlen = ZB_ZCL_GET_STRING_LENGTH(zcl_str) + 1; + + if (newlen < (zb_uint16_t) zcl_str_max_size) + { + *ZB_ZCL_GET_STRING_END(zcl_str) = value; + ZB_ZCL_SET_STRING_LENGTH(zcl_str, newlen); + } + else + { + newlen = 0; + } + + return newlen; +} + +/** Append C-string to ZCL string. */ +#define ZB_ZCL_STRING_APPEND_C_STR(_zcl_str, _zcl_str_max_size, _c_str) \ + zb_zcl_string_append_data(_zcl_str, _zcl_str_max_size, (const zb_uint8_t *) _c_str, strlen(_c_str)) + +/** Append C-string to ZCL static string. */ +#define ZB_ZCL_STATIC_STRING_APPEND_C_STR(_zcl_s_str, _c_str) \ + ZB_ZCL_STRING_APPEND_C_STR((zb_uint8_t *) _zcl_s_str, sizeof(_zcl_s_str), _c_str) + +/** Append char to ZCL static string. */ +#define ZB_ZCL_STATIC_STRING_APPEND_CHAR(_zcl_s_str, _char) \ + zb_zcl_string_append_byte(_zcl_s_str, sizeof(_zcl_s_str), (zb_uint8_t) _char) + + +/** @brief ZCL attribute data type values + @note The enumeration is not full, and does not contain ZCL types not used in HA profile. + @see ZCL spec., subclause 2.5.2, Table 2-10. Data Types +*/ +typedef enum zb_zcl_attr_type_e +{ + ZB_ZCL_ATTR_TYPE_NULL = 0x00, /*!< Null data type */ + ZB_ZCL_ATTR_TYPE_8BIT = 0x08, /*!< 8-bit value data type */ + ZB_ZCL_ATTR_TYPE_16BIT = 0x09, /*!< 16-bit value data type */ + ZB_ZCL_ATTR_TYPE_24BIT = 0x0a, /*!< 24-bit value data type */ + ZB_ZCL_ATTR_TYPE_32BIT = 0x0b, /*!< 32-bit value data type */ + ZB_ZCL_ATTR_TYPE_40BIT = 0x0c, /*!< 40-bit value data type */ + ZB_ZCL_ATTR_TYPE_48BIT = 0x0d, /*!< 48-bit value data type */ + ZB_ZCL_ATTR_TYPE_56BIT = 0x0e, /*!< 56-bit value data type */ + ZB_ZCL_ATTR_TYPE_64BIT = 0x0f, /*!< 64-bit value data type */ + ZB_ZCL_ATTR_TYPE_BOOL = 0x10, /*!< Boolean data type */ + ZB_ZCL_ATTR_TYPE_8BITMAP = 0x18, /*!< 8-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_16BITMAP = 0x19, /*!< 16-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_24BITMAP = 0x1a, /*!< 24-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_32BITMAP = 0x1b, /*!< 32-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_40BITMAP = 0x1c, /*!< 40-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_48BITMAP = 0x1d, /*!< 48-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_56BITMAP = 0x1e, /*!< 56-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_64BITMAP = 0x1f, /*!< 64-bit bitmap data type */ + ZB_ZCL_ATTR_TYPE_U8 = 0x20, /*!< Unsigned 8-bit value data type */ + ZB_ZCL_ATTR_TYPE_U16 = 0x21, /*!< Unsigned 16-bit value data type */ + ZB_ZCL_ATTR_TYPE_U24 = 0x22, /*!< Unsigned 24-bit value data type */ + ZB_ZCL_ATTR_TYPE_U32 = 0x23, /*!< Unsigned 32-bit value data type */ + ZB_ZCL_ATTR_TYPE_U40 = 0x24, /*!< Unsigned 40-bit value data type */ + ZB_ZCL_ATTR_TYPE_U48 = 0x25, /*!< Unsigned 48-bit value data type */ + ZB_ZCL_ATTR_TYPE_U56 = 0x26, /*!< Unsigned 56-bit value data type */ + ZB_ZCL_ATTR_TYPE_U64 = 0x27, /*!< Unsigned 64-bit value data type */ + ZB_ZCL_ATTR_TYPE_S8 = 0x28, /*!< Signed 8-bit value data type */ + ZB_ZCL_ATTR_TYPE_S16 = 0x29, /*!< Signed 16-bit value data type */ + ZB_ZCL_ATTR_TYPE_S24 = 0x2a, /*!< Signed 24-bit value data type */ + ZB_ZCL_ATTR_TYPE_S32 = 0x2b, /*!< Signed 32-bit value data type */ + ZB_ZCL_ATTR_TYPE_S40 = 0x2c, /*!< Signed 40-bit value data type */ + ZB_ZCL_ATTR_TYPE_S48 = 0x2d, /*!< Signed 48-bit value data type */ + ZB_ZCL_ATTR_TYPE_S56 = 0x2e, /*!< Signed 56-bit value data type */ + ZB_ZCL_ATTR_TYPE_S64 = 0x2f, /*!< Signed 64-bit value data type */ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM = 0x30, /*!< 8-bit enumeration (U8 discrete) data type */ + ZB_ZCL_ATTR_TYPE_16BIT_ENUM = 0x31, /*!< 16-bit enumeration (U16 discrete) data type */ + ZB_ZCL_ATTR_TYPE_SEMI = 0x38, /*!< 2 byte floating point */ + ZB_ZCL_ATTR_TYPE_SINGLE = 0x39, /*!< 4 byte floating point */ + ZB_ZCL_ATTR_TYPE_DOUBLE = 0x3a, /*!< 8 byte floating point */ + ZB_ZCL_ATTR_TYPE_OCTET_STRING = 0x41, /*!< Octet string data type, */ + ZB_ZCL_ATTR_TYPE_CHAR_STRING = 0x42, /*!< Charactery string (array) data type */ + ZB_ZCL_ATTR_TYPE_LONG_OCTET_STRING = 0x43, /*!< Long octet string */ + ZB_ZCL_ATTR_TYPE_LONG_CHAR_STRING = 0x44, /*!< Long character string */ + ZB_ZCL_ATTR_TYPE_ARRAY = 0x48, /*!< Array data type 2 + sum of content len */ + ZB_ZCL_ATTR_TYPE_STRUCTURE = 0x4c, /*!< Structure data type 2 + sum of content len */ + ZB_ZCL_ATTR_TYPE_SET = 0x50, /*!< Collection:set, size = sum of len of content */ + ZB_ZCL_ATTR_TYPE_BAG = 0x51, /*!< Collection:bag, size = sum of len of content */ + ZB_ZCL_ATTR_TYPE_TIME_OF_DAY = 0xe0, /*!< Time of day, 4 bytes */ + ZB_ZCL_ATTR_TYPE_DATE = 0xe1, /*!< Date, 4 bytes */ + ZB_ZCL_ATTR_TYPE_UTC_TIME = 0xe2, /*!< UTC Time, 4 bytes */ + ZB_ZCL_ATTR_TYPE_CLUSTER_ID = 0xe8, /*!< Cluster ID, 2 bytes */ + ZB_ZCL_ATTR_TYPE_ATTRIBUTE_ID = 0xe9, /*!< Attribute ID, 2 bytes */ + ZB_ZCL_ATTR_TYPE_BACNET_OID = 0xea, /*!< BACnet OID, 4 bytes */ + ZB_ZCL_ATTR_TYPE_IEEE_ADDR = 0xf0, /*!< IEEE address (U64) type */ + ZB_ZCL_ATTR_TYPE_128_BIT_KEY = 0xf1, /*!< 128-bit security key */ + + ZB_ZCL_ATTR_TYPE_CUSTOM_32ARRAY = 0x4a, /*!< Custom array of 32 elems data type (now is + * equal to ZB_ZCL_ATTR_TYPE_ARRAY) */ + + ZB_ZCL_ATTR_TYPE_INVALID = 0xff /*!< Invalid data type */ +} zb_zcl_attr_type_t; + +/*! @brief ZCL attribute access values */ +typedef enum zb_zcl_attr_access_e +{ + ZB_ZCL_ATTR_ACCESS_READ_ONLY = 0x01, + ZB_ZCL_ATTR_ACCESS_WRITE_ONLY = 0x02, /*!< Attribute is read/write */ + ZB_ZCL_ATTR_ACCESS_READ_WRITE = ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_WRITE_ONLY, /*!< Attribute is read/write */ + ZB_ZCL_ATTR_ACCESS_REPORTING = 0x04, /*!< Attribute is allowed for reporting */ + ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL = ZB_ZCL_ATTR_ACCESS_READ_ONLY, /*!< Attribute is read/write */ + ZB_ZCL_ATTR_ACCESS_SINGLETON = 0x08, /*!< Attribute is singleton */ + ZB_ZCL_ATTR_ACCESS_SCENE = 0x10, /*!< Attribute is accessed through scene */ + /* Use free bit in access attribute field to save RAM */ + ZB_ZCL_ATTR_MANUF_SPEC = 0x20, /*!< Attribute is manufacturer specific */ + ZB_ZCL_ATTR_ACCESS_INTERNAL = 0x40, /*!< ZBOSS Internal accsess only Attribute */ +} zb_zcl_attr_access_t; + +#define ZB_ZCL_ATTR_SET_WITH_ATTR_ID(_set, _id) ((_set << 8) | (_id & 0xFF)) + +/** @cond internals_doc */ + +/** + * @brief Sets attribute access type to WRITABLE, if it is optionally permitted. + * @param attr_desc - pointer to attribute descriptor + * @hideinitializer + */ +#define ZB_ZCL_SET_ATTR_WRITABLE(attr_desc) \ +{ \ + if (attr_desc->access & ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL) \ + { \ + attr_desc->access |= ZB_ZCL_ATTR_ACCESS_WRITE_ONLY; \ + } \ +} + +/** @endcond */ /* internals_doc */ + +/*! @brief ZCL attribute definiton structure */ +typedef ZB_PACKED_PRE struct zb_zcl_attr_s +{ + zb_uint16_t id; /*!< Attribute id */ + zb_uint8_t type; /*!< Attribute type see @ref zb_zcl_attr_type_t */ + zb_uint8_t access; /*!< Attribute access options according to @ref zb_zcl_attr_access_t */ + zb_voidp_t data_p; /*!< Pointer to data */ +} ZB_PACKED_STRUCT +zb_zcl_attr_t; + + +/*! @brief ZCL 6.0: Global attributes that are included to each cluster */ +enum zb_zcl_attr_global_e +{ + ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID = 0xfffd, /*!< Cluster revision */ + ZB_ZCL_ATTR_GLOBAL_ATTRIBUTE_REPORTING_STATUS_ID = 0xfffe, /*!< Attribute reporting status */ +}; + +/** @brief ZCL 6.0: Default value for cluster revision global attribute, + * see @ref zb_zcl_attr_global_e + */ +#define ZB_ZCL_CLUSTER_REVISION_DEFAULT 1 + +#define ZB_ZCL_ATTR_SET_WITH_ATTR_ID(_set, _id) ((_set << 8) | (_id & 0xFF)) + +/** @cond internals_doc */ + +/*! @internal @brief Set attribute description. + @param attr_id - attribute identifier (defined individually for any particular cluster). + @param data_ptr - pointer to attribute's value storage. + + Creates attribute description value (@ref zb_zcl_attr_s) initialized with provided pointer to + attribute's data. +*/ +#define ZB_ZCL_SET_ATTR_DESC(attr_id, data_ptr) ZB_SET_ATTR_DESCR_WITH_##attr_id(data_ptr), + + +/*! @internal @brief Set manufacturer specififc attribute description. + @param attr_id - attribute identifier (defined individually for any particular cluster). + @param attr_type - attribute data type @see zb_zcl_attr_type_e + @param attr_access - attribute access bitbask @see zb_zcl_attr_access_e + @param data_ptr - pointer to attribute's value storage. + + Creates attribute description value (@ref zb_zcl_attr_s) initialized with provided pointer to + attribute's data. +*/ +#define ZB_ZCL_SET_MANUF_SPEC_ATTR_DESC(attr_id, attr_type, attr_access, data_ptr) \ + { \ + attr_id, \ + attr_type, \ + attr_access | ZB_ZCL_ATTR_MANUF_SPEC, \ + (zb_voidp_t) data_ptr \ + }, + + +/*! @internal @brief Start declaration of attributes list */ +#define ZB_ZCL_START_DECLARE_ATTRIB_LIST(attrs_desc_name) \ + zb_uint16_t cluster_revision_##attrs_desc_name = ZB_ZCL_CLUSTER_REVISION_DEFAULT; \ + zb_zcl_attr_t attrs_desc_name [] = { \ + { \ + ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) &(cluster_revision_##attrs_desc_name) \ + }, + +/*! @internal @brief End declaration of attributes list */ +#define ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST \ + { \ + ZB_ZCL_NULL_ID, \ + 0, \ + 0, \ + NULL \ + } \ +} + +#define ZB_ZCL_SET_ATTR_DESC_M(id, data_ptr, type, attr) \ + { \ + (id), (type), (attr), (data_ptr) \ + }, + +#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) + +/*! @internal @brief Check, if attribute is reportable */ +#define ZB_ZCL_IS_ATTR_REPORTABLE(attr_desc) ((attr_desc)->access & ZB_ZCL_ATTR_ACCESS_REPORTING) + +#endif + +/*! @internal @brief Check, if attribute is singleton */ +#define ZB_ZCL_IS_ATTR_SINGLETON(attr_desc) ((attr_desc)->access & ZB_ZCL_ATTR_ACCESS_SINGLETON) + +/*! @internal @brief Check, if attribute is accessed through scene */ +#define ZB_ZCL_IS_ATTR_SCENE_ACCESSED(attr_desc) ((attr_desc)->access & ZB_ZCL_ATTR_ACCESS_SCENE) + +/*! @internal @brief Check, if attribute is manufacturer specific */ +#define ZB_ZCL_IS_ATTR_MANUF_SPEC(attr_desc) ((attr_desc)->access & ZB_ZCL_ATTR_MANUF_SPEC) + +/*! Mark attribute ID to distinguish if it is common/manufacturer + specific/internal attribute: + - set bit 15 (the highest) for internal attributes + - set bit 14 for manufacturer specific attributes +*/ +/*! @internal @brief Mark attribute Id as custom/manufacture specific attribute */ +#define ZB_ZCL_ATTR_INTERNAL_ID(_attr_id) ((_attr_id) | (1 << 15)) + +/*! @internal @brief Check if attribute Id is custom/manufacture specific */ +#define ZB_ZCL_ATTR_CHECK_INTERNAL_ID(_attr_id) ((_attr_id) & (1 << 15)) + + +/*! @internal @brief Mark attribute Id as custom/manufacture specific attribute */ +#define ZB_ZCL_ATTR_CUSTOM_ID(_attr_id) ((_attr_id) | (1 << 14)) + +/*! @internal @brief Check if attribute Id is custom/manufacture specific */ +#define ZB_ZCL_ATTR_CHECK_CUSTOM_ID(_attr_id) ((_attr_id) & (1 << 14)) + + +/*! @internal @brief Start number for custom attributes */ +#define ZB_ZCL_ATTR_CUSTOM_START_NUMBER 0xfff0 + + +/*! @internal @brief Check if attribute Id is custom/manufacture specific */ +#define ZB_ZCL_ATTR_CHECK_INTERNAL_ID(_attr_id) ((_attr_id) & (1 << 15)) + + +/*! @internal @brief Mark attribute Id as custom/manufacture specific attribute */ +#define ZB_ZCL_ATTR_CUSTOM_ID(_attr_id) ((_attr_id) | (1 << 14)) + +/*! @internal @brief Check if attribute Id is custom/manufacture specific */ +#define ZB_ZCL_ATTR_CHECK_CUSTOM_ID(_attr_id) ((_attr_id) & (1 << 14)) + +/*! @internal @brief Check boolean type attribute value */ +#define ZB_ZCL_CHECK_BOOL_VALUE(x) ((x) == ZB_FALSE || (x) == ZB_TRUE) + + +/** @endcond */ /* internals_doc */ + +/** + * @brief Sets attribute value, perform all needed checks before and after setting new value, + * including read-only check and marking for reporting. + * @param ep - end point number. + * @param cluster_id - cluster identifier. + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * @param attr_id - attribute identifier. + * @param value_ptr - pointer to new attribute value. + * @param check_access - boolean flag to specify if to perform access check or not. + * @hideinitializer + */ +#define ZB_ZCL_SET_ATTRIBUTE(ep, cluster_id, cluster_role, attr_id, value_ptr, check_access) \ + ZVUNUSED(zb_zcl_set_attr_val(ep, cluster_id, cluster_role, attr_id, value_ptr, check_access)) + + +/** + * @brief Set attribute 8-bit value without any check. Use this macro + * on your own risk, if and only if you are absolutely shure that no check for Access + * rights, Reporting and attribute type is needed. + * @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s. + * @param value - 8-bit value to be set. + * @hideinitializer + */ +#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL8(attr_desc, value) \ + (*(zb_uint8_t*)attr_desc->data_p = (zb_uint8_t)(value)) + +/** + * @brief Set attribute 16-bit value without any check. Use this macro + * on your own risk, if and only if you are absolutely shure that no check for Access + * rights, Reporting and attribute type is needed. + * @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s. + * @param value - 16-bit value to be set. + * @hideinitializer + */ +#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL16(attr_desc, value) \ + (*(zb_uint16_t*)attr_desc->data_p = (zb_uint16_t)(value)) + +/** + * @brief Set attribute 32-bit value without any check. Use this macro + * on your own risk, if and only if you are absolutely shure that no check for Access + * rights, Reporting and attribute type is needed. + * @param attr_desc - pointer to an attribute description structure @ref zb_zcl_attr_s. + * @param value - 32-bit value to be set. + * @hideinitializer + */ +#define ZB_ZCL_SET_DIRECTLY_ATTR_VAL32(attr_desc, value) \ + (*(zb_uint32_t*)attr_desc->data_p = (zb_uint32_t)(value)) + + +/*! Get 8-bit unsigned attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_8(attr_desc) \ + (*(zb_uint8_t*)attr_desc->data_p) + +/*! Get 8-bit signed attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_S8(attr_desc) \ + (*(zb_int8_t*)attr_desc->data_p) + +/*! Get 16-bit unsigned attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_16(attr_desc) \ + (*(zb_uint16_t*)attr_desc->data_p) + +/*! Get 16-bit signed attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_S16(attr_desc) \ + (*(zb_int16_t*)attr_desc->data_p) + +/*! Get 32-bit unsigned attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_32(attr_desc) \ + (*(zb_uint32_t*)attr_desc->data_p) + +/*! Get 32-bit unsigned attribute value (without any check) */ +#define ZB_ZCL_GET_ATTRIBUTE_VAL_S32(attr_desc) \ + (*(zb_int32_t*)attr_desc->data_p) + + +/*! @} */ /* General attributes' description */ + + +/************************************** ZCL frame definitions ************************************/ + +/*! @defgroup zb_zcl_common_frame General frame description + Types and macros required for ZCL frame manipulations + @{ + +*/ + +/** @cond internals_doc */ + +/*! @brief ZCL header size */ +#define ZB_ZCL_GET_HEADER_SIZE(frm_ctl) \ + ( (ZB_ZCL_GET_MANUF_SPECIFIC(frm_ctl)) \ + ? sizeof(zb_zcl_frame_hdr_full_t) \ + : sizeof(zb_zcl_frame_hdr_short_t)) + +/** @internal @brief Cuts ZCL header form a buffer. */ +#define ZB_ZCL_CUT_HEADER(buf) \ + zb_buf_cut_left(buf, ZB_ZCL_GET_HEADER_SIZE(*(zb_uint8_t*)zb_buf_begin(buf))) + +/** @endcond */ /* internals_doc */ + +/*! @brief ZCL frame type + + Defines Permitted values for Frame Type subfield of Frame Control field in ZCL frame. + @see ZCL spec, subclause 2.3.1.1.1. +*/ +typedef enum zb_zcl_frame_type_e +{ + ZB_ZCL_FRAME_TYPE_COMMON = 0x00, /*!< Command acts across the entire profile */ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC = 0x01 /*!< Command is specific to a cluster */ +} zb_zcl_frame_type_t; + +/*! @brief Values for Manufacturer-specific subfield of FCF in ZCL frame. + @see ZCL spec, subclause 2.3.1.1.2. +*/ +typedef enum zb_zcl_manufacturer_specific_e +{ + /** @brief Standard profile command + + Manufacturer code field shall @b not be included into ZCL frame header. + */ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC = 0x00, + /** @brief Command refers to manufacturer-specific profile extension + + Manufacturer code field shall be included into ZCL frame header. + */ + ZB_ZCL_MANUFACTURER_SPECIFIC = 0x01 +} zb_zcl_manufacturer_specific_t; + +#define ZB_ZCL_MANUFACTURER_WILDCARD_ID 0xffff + +/*! @brief Values for Disable default response subfield of FCF in ZCL frame. + @see ZCL spec, subclause 2.3.1.1.3. +*/ +typedef enum zb_zcl_disable_default_response_e +{ + /** @brief Enable default response */ + ZB_ZCL_ENABLE_DEFAULT_RESPONSE = 0x00, + /** @brief Disble default response */ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE = 0x01, +} zb_zcl_disable_default_response_t; + + +/*! @brief ZCL frame direction + @see ZCL spec, subclause 2.3.1.1.3. +*/ +typedef enum zb_zcl_frame_direction_e +{ + /*! Command sent from client to a server */ + ZB_ZCL_FRAME_DIRECTION_TO_SRV = 0x00, + /*! Command sent from server to a client */ + ZB_ZCL_FRAME_DIRECTION_TO_CLI = 0x01 +} zb_zcl_frame_direction_t; + +/*! @brief Reverts ZCL direction value */ +#define ZB_ZCL_REVERT_DIRECTION(_d) \ + (((zb_zcl_frame_direction_t)(_d) == ZB_ZCL_FRAME_DIRECTION_TO_SRV) ? ZB_ZCL_FRAME_DIRECTION_TO_CLI : ZB_ZCL_FRAME_DIRECTION_TO_SRV) + +/*! @brief ZCL frame control field + @see ZCL spec, subclause 2.3.1.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_frame_ctrl_s +{ + zb_bitfield_t frame_type :2; /*!< Frame type @ref zb_zcl_frame_type_t */ + zb_bitfield_t manufacturer :1; /*!< Manufacturer specific frame @ref + zb_zcl_manufacturer_specific_t*/ + zb_bitfield_t direction :1; /*!< Direction @ref zb_zcl_frame_direction_t*/ + zb_bitfield_t disable_def_resp :1; /*!< Disable default response */ + zb_bitfield_t reserved :3; +} ZB_PACKED_STRUCT +zb_zcl_frame_ctrl_t; + +/*! @brief ZCL frame header with manufacturer code + @see ZCL spec, subclause 2.3.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_frame_hdr_full_s +{ + zb_zcl_frame_ctrl_t frame_ctrl; /*!< Frame control filed see @ref zb_zcl_frame_ctrl_s */ + zb_uint16_t manufacturer_code; /*!< Manufacturer Code */ + zb_uint8_t seq_number; /*!< Transaction Sequence Number */ + zb_uint8_t command_id; /*!< Command Identifier Field */ +} ZB_PACKED_STRUCT +zb_zcl_frame_hdr_full_t; + +/*! @brief ZCL frame header without manufacturer code + @see ZCL spec, subclause 2.3.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_frame_hdr_short_s +{ + zb_zcl_frame_ctrl_t frame_ctrl; /*!< Frame control field see @ref zb_zcl_frame_ctrl_s */ + zb_uint8_t seq_number; /*!< Transaction Sequence Number */ + zb_uint8_t command_id; /*!< Command Identifier Field */ +} ZB_PACKED_STRUCT +zb_zcl_frame_hdr_short_t; + +/** + * @brief Possible address types of devices from which ZCL message is received. + */ +enum zb_zcl_addr_type_e +{ + ZB_ZCL_ADDR_TYPE_SHORT, + ZB_ZCL_ADDR_TYPE_IEEE_GPD, + ZB_ZCL_ADDR_TYPE_SRC_ID_GPD, + ZB_ZCL_ADDR_TYPE_IEEE, +}; + +/** + * @brief Type to represent source address of ZCL message + * + * It is needed if ZGP sink is enabled and therefore messages can + * be received from ZGPD devices which are identified by 32-bit + * source Id. + */ +typedef ZB_PACKED_PRE struct zb_zcl_addr_s +{ + zb_uint8_t addr_type; /**< address type (see @ref zb_zcl_addr_type_e) */ + ZB_PACKED_PRE union zb_zcl_addr_u + { + zb_uint16_t short_addr; /**< Zigbee short address */ + zb_uint32_t src_id; /**< Source ID of ZGPD */ + zb_ieee_addr_t ieee_addr; /**< Full IEEE-address of ZGPD */ + } u; +} ZB_PACKED_STRUCT +zb_zcl_addr_t; + +/*! Parsed ZCL header */ +typedef ZB_PACKED_PRE struct zb_zcl_parsed_hdr_s +{ + /* Values from APS data indication */ + ZB_PACKED_PRE union + { + ZB_PACKED_PRE struct + { + //zb_uint16_t src_addr; + zb_zcl_addr_t source; + zb_uint16_t dst_addr; + zb_uint8_t src_endpoint; + zb_uint8_t dst_endpoint; + zb_uint8_t fc; +#if (defined ZB_ENABLE_SE) || (defined ZB_ZCL_SUPPORT_CLUSTER_WWAH) + zb_uint8_t aps_key_source:1; + zb_uint8_t aps_key_attrs:2; + zb_uint8_t aps_key_from_tc:1; + zb_uint8_t reserved:4; +#endif + } ZB_PACKED_STRUCT common_data; + } addr_data; + zb_uint16_t cluster_id; + zb_uint16_t profile_id; + + /* ZCL specific fields */ + zb_uint8_t cmd_id; /**< Command identifier. */ + zb_uint8_t cmd_direction; /**< Command direction identifier. */ + zb_uint8_t seq_number; /**< ZCL transaction sequence number. */ + zb_uint8_t is_common_command; /**< "Common command" flag. */ + zb_uint8_t disable_default_response; /**< "Disable default response" flag. */ + zb_uint8_t is_manuf_specific; /**< "Has manufacturer-specific data" flag. */ + zb_uint16_t manuf_specific; /**< Manufacturer-specific data. */ +} ZB_PACKED_STRUCT +zb_zcl_parsed_hdr_t; + + +/*! Attribute address info structure */ +typedef struct zb_zcl_attr_addr_info_s +{ + zb_uint8_t src_ep; /**< Source endpoint */ + zb_uint8_t dst_ep; /**< Destination endpoint */ + zb_uint16_t dst_short_addr; /**< Destination short address */ + + zb_uint16_t profile_id; /**< Profile id */ + zb_uint16_t cluster_id; /**< Cluster id */ + zb_uint8_t cluster_role; /**< Cluster role */ + zb_uint16_t attr_id; /**< Attribute id */ +} +zb_zcl_attr_addr_info_t; + + +/** @brief Extract common addresing data from parsed ZCL structure. + * @param header - pointer to the parsed ZCL header structure (see @ref zb_zcl_parsed_hdr_s). + */ +#define ZB_ZCL_PARSED_HDR_SHORT_DATA(header) ((header)->addr_data.common_data) + +/** + * @brief Get ZCL frame type @ref zb_zcl_frame_type_e. + * @hideinitializer + */ +#define ZB_ZCL_GET_FRAME_TYPE(v) ((v) & 0x3) + +/** + * @brief Check is ZCL frame manufacturer specific @ref zb_zcl_manufacturer_specific_e. + * @hideinitializer + */ +#define ZB_ZCL_GET_MANUF_SPECIFIC(v) ((v >> 2) & 0x1) + +/** + * @brief Get ZCL frame direction @ref zb_zcl_frame_direction_e. + * @hideinitializer + */ +#define ZB_ZCL_GET_DIRECTION(v) ((v >> 3) & 0x1) + +/** + * @brief Get ZCL disable default response field @ref zb_zcl_disable_default_response_e. + * @hideinitializer + */ +#define ZB_ZCL_GET_DISABLE_DEFAULT_RESPONSE(v) ((v >> 4) & 0x1) + +/** + * @brief Set ZCL frame type @ref zb_zcl_frame_type_e. + * @hideinitializer + */ +#define ZB_ZCL_SET_FRAME_TYPE(v, val) ((v) |= (val)) + +/** + * @brief Set ZCL frame manufacturer specific @ref zb_zcl_manufacturer_specific_e. + * @hideinitializer + */ +#define ZB_ZCL_SET_MANUF_SPECIFIC(v, val) ((v) |= (val << 2)) + +/** + * @brief Set ZCL frame direction @ref zb_zcl_frame_direction_e. + * @hideinitializer + */ +#define ZB_ZCL_SET_DIRECTION(v, val) ((v) |= (val << 3)) + +/** + * @brief Set ZCL disable default response field @ref zb_zcl_disable_default_response_e. + * @hideinitializer + */ +#define ZB_ZCL_SET_DISABLE_DEFAULT_RESPONSE(v, val) ((v) |= (val << 4)) + +/** + * @brief Construct ZCL command header in the buffer + * @param zbbuf buffer ID + * @param frame_ctl Frame Control field for ZCL packet + * @param manuf_code manufacturer code, not used manufacturer-specific flag is not set + * @param cmd_id ZCL command id + * @param tsn pointer to variable (may be NULL) for TSN value of ZCL packet (generated by the function) + * + * Returns pointer to the buffer data begin after ZCL header (where command payload can be placed if needed). + */ +void *zb_zcl_start_command_header(zb_bufid_t zbbuf, zb_uint8_t frame_ctl, zb_uint16_t manuf_code, zb_uint8_t cmd_id, zb_uint8_t* tsn); + +/** @cond internals_doc */ + +/** @internal @brief Construct ZCL header frame control value */ +#define ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + frame_type, manuf_specific, direction, disable_default_resp) \ + (( (frame_type) \ + | ((manuf_specific) << 2) \ + | ((direction) << 3) \ + | ((disable_default_resp) << 4))) + +#define ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL( \ + frame_ctl, frame_type, manuf_specific, direction, disable_default_resp) \ + ((frame_ctl) = ZB_ZCL_CONSTRUCT_FRAME_CONTROL((frame_type), \ + (manuf_specific), \ + (direction), \ + (disable_default_resp))) + +/* NOTE: We suppose all general requests/responses currently are not manufacturer specific */ +/** @internal @brief Construct ZCL header frame control value for General command request */ +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL(buf_ptr, def_resp) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, \ + (def_resp)), \ + buf_ptr++) + +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_A(buf_ptr, \ + direction, is_manufacturer_specific, def_resp) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + (is_manufacturer_specific), \ + (direction), \ + (def_resp)), \ + buf_ptr++) + +/*! @internal Construct ZCL header frame control value for General + * command request, specifying extra parameters */ +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_REQ_FRAME_CONTROL_EXT(buf_ptr, \ + _is_manuf_specific, direction, def_resp) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + (_is_manuf_specific), \ + (direction), \ + (def_resp)), \ + buf_ptr++) + + +/* To do not change existing code too much: 3 consequent macro create single function call. */ +#define ZB_ZCL_START_PACKET_REQ(zbbuf) zb_zcl_start_command_header((zbbuf), +#define ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(buf_ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL(ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, (def_resp)), \ + 0, /* No manuf_code */ +#define ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(data_ptr, tsn, cmd_id) (cmd_id), NULL) + +/* TODO: Implement via zb_zcl_start_command_header() */ +#define ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_O(buf_ptr, def_resp) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, \ + def_resp), \ + buf_ptr++) + +#define ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(buf_ptr, \ + direction, is_manufacturer_specific, def_resp) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + (is_manufacturer_specific), \ + (direction), \ + (def_resp)), \ + buf_ptr++) + +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_A(buf_ptr, \ + direction, is_manufacturer_specific) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + (is_manufacturer_specific), \ + (direction), \ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE), \ + buf_ptr++) + +#define ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(buf_ptr, \ + direction, is_manufacturer_specific) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + (is_manufacturer_specific), \ + (direction), \ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE), \ + buf_ptr++) +/*! @internal Construct ZCL header frame control valueZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL for General command response */ +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL(buf_ptr) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE), \ + buf_ptr++) + + +/*! @internal Construct ZCL header frame control value for General + * command response, specifying extra parameters */ +#define ZB_ZCL_CONSTRUCT_GENERAL_COMMAND_RESP_FRAME_CONTROL_EXT(_buf_ptr, _is_manuf_specific, _direction) \ + (ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL( \ + *(_buf_ptr), \ + ZB_ZCL_FRAME_TYPE_COMMON, \ + (_is_manuf_specific), \ + (_direction), \ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE), \ + (_buf_ptr)++) + +/** @endcond */ /* internals_doc */ + +/*! @brief Construct ZCL header frame control value for cluster-specific command response + * + * @snippet wwah_door_lock/dl_device/dl_door_lock.c zcl_construct_specific_frame_header + * */ +#define ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(buf_ptr) \ + ( ZB_ZCL_CONSTRUCT_SET_FRAME_CONTROL(*buf_ptr, \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + ZB_ZCL_DISABLE_DEFAULT_RESPONSE), \ + buf_ptr++) + +/** + * @brief Construct ZCL header + * @note To add Manufacturer specific field, use ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(), macro. + * @hideinitializer + */ +#define ZB_ZCL_CONSTRUCT_COMMAND_HEADER(data_ptr, tsn, cmd_id) \ + (ZB_ZCL_PACKET_PUT_DATA8(data_ptr, tsn), ZB_ZCL_PACKET_PUT_DATA8(data_ptr, cmd_id)) + +/*! @brief Construct ZCL header, Manufacturer specific value is conditionally supported */ +#define ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(_data_ptr, _tsn, _is_manuf_spec, _manuf_specific, _cmd_id) \ + { \ + if (_is_manuf_spec) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL((_data_ptr), (_manuf_specific)); \ + } \ + ZB_ZCL_PACKET_PUT_DATA8((_data_ptr), (_tsn)); \ + ZB_ZCL_PACKET_PUT_DATA8((_data_ptr), (_cmd_id)); \ + } + +/** @cond internals_doc */ + +/*! @internal @brief Caclulate ZCL frame header size */ +#define ZB_ZCL_FRAME_HDR_GET_SIZE(p) ( ZB_ZCL_GET_MANUF_SPECIFIC(p) ? \ + 2*sizeof(zb_uint8_t)+sizeof(zb_uint16_t) : \ + 2*sizeof(zb_uint8_t) ) + +/*! @internal @brief Get ZCL frame manufacturer code from the packet */ +#define ZB_ZCL_FRAME_HDR_GET_MANUFACTURER_CODE(p) \ + ( *(zb_uint16_t *)((zb_uint8_t *)p + sizeof(zb_zcl_frame_ctrl_t)) ) + +/*! @internal Get ZCL frame sequence number from the packet. */ +#define ZB_ZCL_FRAME_HDR_GET_SEQ_NUM(p) \ + ( *((zb_uint8_t *)p \ + + sizeof(zb_zcl_frame_ctrl_t) \ + + (ZB_ZCL_GET_MANUF_SPECIFIC(p) ? sizeof(zb_uint16_t) : 0)) ) + +/*! @internal Get ZCL frame command identifier from the packet. */ +#define ZB_ZCL_FRAME_HDR_GET_COMMAND_ID(p) \ + ( *((zb_uint8_t *)p \ + + sizeof(zb_zcl_frame_ctrl_t) \ + + (ZB_ZCL_GET_MANUF_SPECIFIC(p) ? sizeof(zb_uint16_t) : 0) + sizeof(zb_uint8_t)) ) + +/** @endcond */ /* internals_doc */ + +/** + * @brief Return next sequence number for ZCL frame. + * @hideinitializer + */ +#define ZB_ZCL_GET_SEQ_NUM() (ZCL_CTX().seq_number++) + +/*! @brief Copy parsed ZCL header from buffer + @param buf - ID zb_bufid_t of buffer containing parsed ZCL header as parameter + @param dst - pointer to the memory area to copy header to +*/ +#define ZB_ZCL_COPY_PARSED_HEADER(buf, dst) \ + (ZB_MEMCPY( \ + (dst), \ + ZB_BUF_GET_PARAM((buf), zb_zcl_parsed_hdr_t), \ + sizeof(zb_zcl_parsed_hdr_t))) + + +/*! @brief General macro for sending a command with empty payload + @param buffer to put command payload and headers to + @param addr address to send to + @param dst_addr_mode destination address mode + @param dst_ep destination endpoint + @param ep source endpoint + @param prof_id profile the command belongs to + @param dis_default_resp "Disable default response" flag + @param cluster_id cluster identifier + @param command_id command identifier + @param cb command send status callback + + @code + #define ZB_ZCL_DOOR_LOCK_SEND_LOCK_DOOR_REQ(buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + dis_default_resp, \ + cb) \ + ZB_ZCL_SEND_CMD( buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + ZB_AF_HA_PROFILE_ID, \ + dis_default_resp, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR, \ + cb) + @endcode +*/ +#define ZB_ZCL_SEND_CMD( \ + buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + cluster_id, \ + command_id, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), command_id); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb); \ +} + +/*! @} */ /* General frame description */ + + +/******************************* ZCL frame basic manipulations *******************************/ + +/*! @defgroup zb_zcl_common_pckt_fill Fill ZCL packet low-level API + Types and macros shared fill Fill ZCL packet. + @{ + @par Example + @snippet HA_samples/write_attr_test/sample_zed.c ZB_ZCL_PACKET + @par + + For more information see HA samples +*/ + +/** + * @brief Initializes zb_buf_t buffer and returns pointer to the beginning of array. + * @hideinitializer + */ +#define ZB_ZCL_START_PACKET(zbbuf) \ + zb_buf_reuse(zbbuf) + +/** + * @brief Return number of bytes written to the buffer. + * @hideinitializer + */ +#define ZB_ZCL_GET_BYTES_WRITTEN(zbbuf, ptr) \ + zb_buf_get_ptr_off((zbbuf), (ptr)) + +/** + * @brief Return number of bytes available in a packet. + * @hideinitializer + */ +#ifdef APS_FRAGMENTATION +#define ZB_ZCL_GET_BYTES_AVAILABLE(zbbuf, ptr) \ + (ZB_ASDU_MAX_FRAG_LEN - ZB_ZCL_GET_BYTES_WRITTEN(zbbuf, ptr)) +#else +#define ZB_ZCL_GET_BYTES_AVAILABLE(zbbuf, ptr) \ + (ZB_ZCL_HI_WO_IEEE_MAX_PAYLOAD_SIZE - ZB_ZCL_GET_BYTES_WRITTEN(zbbuf, ptr)) +#endif + +/** + * @brief Put 8-bit value to packet. + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA8(ptr, val) (*(ptr) = (val), (ptr)++) + +/*! + Put 16-bit value to packet + @param ptr - pointer to the place to put value to + @param val - pointer to the value to put into packet +*/ +#define ZB_ZCL_PACKET_PUT_DATA16(ptr, val) \ + { \ + ZB_HTOLE16((ptr), (val)); \ + (ptr) += 2; \ +} + +/*! + Put 16-bit value to packet + @param ptr - pointer to the place to put value to + @param val - value to put into packet +*/ +//#define ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, val) ZB_PUT_NEXT_HTOLE16(ptr, val) +#define ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, val) (ptr) = zb_put_next_htole16((ptr), val) + +#define ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, val1, val2) (ptr) = zb_put_next_2_htole16((ptr),(val1),(val2)) + +#define ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, val1, val2) (ptr) = zb_put_next_2_htole32((ptr),(val1),(val2)) + +/** + * @brief Put 32-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - pointer to the value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, val) ZB_PUT_NEXT_HTOLE32((ptr),(val)) + +/** + * @brief Put 32-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - pointer to the value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA32(ptr, val) \ + (ZB_HTOLE32(ptr, val), (ptr) += 4) + +/** + * @brief Put 48-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA48_VAL(ptr, val) \ + (PUT_DATA48_VAL(ptr, val)) + +/** + * @brief Put 48-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - pointer to the value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA48(ptr, val) \ + (PUT_DATA48(ptr, val)) + +/** + * @brief Put 24-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA24_VAL(ptr, val) \ + (PUT_DATA24_VAL(ptr, val)) + +/** + * @brief Put 24-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - pointer to the value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA24(ptr, val) \ + (PUT_DATA24(ptr, val)) + + + +/** + * @brief Put 64-bit value to packet. + * @param ptr - pointer to the place to put value to + * @param val - pointer to the value to put into packet + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA64(ptr, val) (ZB_HTOLE64(ptr, val), (ptr) += 8) + +/** @brief Get 8-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented). + */ +#define ZB_ZCL_PACKET_GET_DATA8(dst_ptr, src_ptr) \ +{ \ + *(dst_ptr) = *((src_ptr)++); \ +} + +#define ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, val1, val2) (ptr) = zb_put_next_2_htole16((ptr),(val1),(val2)) + +#define ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, val1, val2) (ptr) = zb_put_next_2_htole32((ptr),(val1),(val2)) + +/** + * @brief Put N byte data to packet. + * @param ptr - pointer to the place to put value to. + * @param val - pointer to the value to put into packet. + * @param n - number of bytes to be copied. + * @hideinitializer + */ +#define ZB_ZCL_PACKET_PUT_DATA_N(ptr, val, n) (ZB_MEMCPY(ptr, val, n), (ptr) += (n)) + +/** @brief Get 16-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA16(dst_ptr, src_ptr) \ +{ \ + ZB_LETOH16((dst_ptr), (src_ptr)); \ + (src_ptr) += sizeof(zb_uint16_t); \ +} + +/** @brief Get 24-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA24(dst_ptr, src_ptr) \ +{ \ + ZB_LETOH24(dst_ptr, src_ptr); \ + (src_ptr) += ZB_24BIT_SIZE; \ +} + + +/** @brief Get 48-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA48(dst_ptr, src_ptr) \ +{ \ + ZB_LETOH48(dst_ptr, src_ptr); \ + (src_ptr) += ZB_48BIT_SIZE; \ +} + + +/** @brief Get 32-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA32(dst_ptr, src_ptr) \ +{ \ + ZB_LETOH32((dst_ptr), (src_ptr)); \ + (src_ptr) += sizeof(zb_uint32_t); \ +} + +/** @brief Get 64-bit value from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA64(dst_ptr, src_ptr) \ +{ \ + ZB_LETOH64((dst_ptr), (src_ptr)); \ + (src_ptr) += 8; \ +} + +/** @brief Get IEEE address from packet. + * @param dst_ptr - pointer to the memory to store value (pinter value preserved). + * @param src_ptr - pointer to the memory to get value from (will be incremented by value size). + */ +#define ZB_ZCL_PACKET_GET_DATA_IEEE(dst_ptr, src_ptr) \ +{ \ + ZB_IEEE_ADDR_COPY((dst_ptr), (src_ptr)); \ + (src_ptr) += sizeof(zb_ieee_addr_t); \ +} + +/** @brief Put IEEE address into packet. + * @param dst_ptr - pointer to the memory to store value (will be incremented by value size). + * @param src_ptr - pointer to the memory to get value from (pinter value preserved). + */ +#define ZB_ZCL_PACKET_PUT_DATA_IEEE(dst_ptr, src_ptr) \ +{ \ + ZB_IEEE_ADDR_COPY((dst_ptr), (src_ptr)); \ + (dst_ptr) += sizeof(zb_ieee_addr_t); \ +} + +/*! + Put N byte data to packet +*/ +#define ZB_ZCL_PACKET_PUT_DATA_N(ptr, val, n) \ + (ZB_MEMCPY(ptr, val, n), (ptr) += (n)) + +/** Put ZCL Octet String to packet */ +#define ZB_ZCL_PACKET_PUT_STRING(_ptr, _val) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8 (_ptr, ZB_ZCL_GET_STRING_LENGTH(_val)); \ + ZB_ZCL_PACKET_PUT_DATA_N(_ptr, ZB_ZCL_GET_STRING_BEGIN(_val), \ + ZB_ZCL_GET_STRING_LENGTH(_val)); \ +} + +/** Get ZCL String from packet. + * @note If string is invalid (cannot be stored in buffer) + * this macro sets data to NULL. + * + * @param _zcl_str - Destination buffer. + * @param data - Pointer to incomming data. + * @param _zcl_str_max_size - Size of destination buffer. + */ +#define ZB_ZCL_PACKET_GET_STRING(_zcl_str, data, _zcl_str_max_size) \ +{ \ + ZB_ZCL_PACKET_GET_DATA8(&_zcl_str[0], data); \ + if (_zcl_str_max_size > ZB_ZCL_GET_STRING_LENGTH(_zcl_str)) \ + { \ + ZB_ZCL_PACKET_GET_DATA_N(ZB_ZCL_GET_STRING_BEGIN(_zcl_str), \ + data, \ + ZB_ZCL_GET_STRING_LENGTH(_zcl_str)); \ + } \ + else \ + { \ + data = NULL; \ + } \ +} + +/** Get ZCL String from packet and put it into array with fixed size. */ +#define ZB_ZCL_PACKET_GET_STATIC_STRING(_zcl_str, data) \ + ZB_ZCL_PACKET_GET_STRING(_zcl_str, data, sizeof(_zcl_str)) + + +/** Put ZCL Octet String to packet */ +#define ZB_ZCL_PACKET_PUT_STRING(_ptr, _val) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8 (_ptr, ZB_ZCL_GET_STRING_LENGTH(_val)); \ + ZB_ZCL_PACKET_PUT_DATA_N(_ptr, ZB_ZCL_GET_STRING_BEGIN(_val), \ + ZB_ZCL_GET_STRING_LENGTH(_val)); \ +} + +/** Get ZCL String from packet. + * @note If string is invalid (cannot be stored in buffer) + * this macro sets data to NULL. + * + * @param _zcl_str - Destination buffer. + * @param data - Pointer to incomming data. + * @param _zcl_str_max_size - Size of destination buffer. + */ +#define ZB_ZCL_PACKET_GET_STRING(_zcl_str, data, _zcl_str_max_size) \ +{ \ + ZB_ZCL_PACKET_GET_DATA8(&_zcl_str[0], data); \ + if (_zcl_str_max_size > ZB_ZCL_GET_STRING_LENGTH(_zcl_str)) \ + { \ + ZB_ZCL_PACKET_GET_DATA_N(ZB_ZCL_GET_STRING_BEGIN(_zcl_str), \ + data, \ + ZB_ZCL_GET_STRING_LENGTH(_zcl_str)); \ + } \ + else \ + { \ + data = NULL; \ + } \ +} + +/** Get ZCL String from packet and put it into array with fixed size. */ +#define ZB_ZCL_PACKET_GET_STATIC_STRING(_zcl_str, data) \ + ZB_ZCL_PACKET_GET_STRING(_zcl_str, data, sizeof(_zcl_str)) + + +/** @brief Get N-byte value from packet. + * @param dst_ptr - pointer to the memory to store value (will be incremented by value size). + * @param src_ptr - pointer to the memory to get value from (pinter value preserved). + * @param n - data length. + */ +#define ZB_ZCL_PACKET_GET_DATA_N(dst_ptr, src_ptr, n) \ +{ \ + ZB_MEMCPY((dst_ptr), (src_ptr), (n)); \ + (src_ptr) += (n); \ +} + +/*! @brief ZCL finish and send packet + @param buffer pointer to the buffer where ZCL cmd is stored + @param ptr pointer to the end of ZCL cmd in buffer + @param dst_addr destination address (see zb_addr_u) + @param dst_addr_mode destination address mode (only @ref ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT and + @ref ZB_APS_ADDR_MODE_16_ENDP_PRESENT are supported) + @param dst_ep destination endpoint + @param ep source endpoint + @param prof_id profile the command belongs to + @param cluster_id cluster identifier + @param cb command send status callback + */ +zb_ret_t zb_zcl_finish_and_send_packet(zb_bufid_t buffer, zb_uint8_t *ptr, + zb_addr_u *dst_addr, zb_uint8_t dst_addr_mode, + zb_uint8_t dst_ep, zb_uint8_t ep, + zb_uint16_t prof_id, zb_uint16_t cluster_id, + zb_callback_t cb); + +zb_ret_t zb_zcl_finish_and_send_packet_new(zb_bufid_t buffer, zb_uint8_t *ptr, + zb_addr_u *dst_addr, zb_uint8_t dst_addr_mode, + zb_uint8_t dst_ep, zb_uint8_t ep, + zb_uint16_t prof_id, zb_uint16_t cluster_id, + zb_callback_t cb, zb_bool_t aps_secured, + zb_bool_t disable_aps_ack, zb_uint16_t delay); + + +/*! + Finish ZCL packet filling. Used bytes number are marked in a buffer. + @param zbbuf - pointer to zb_buf_t buffer. + @param ptr - pointer to the byte after the last written byte in the buffer. + @attention After ZB_ZCL_FINISH_PACKET() call, pointer ptr is set to the beginning of the buffer + data. + @note Please note that this macro does not return ret code, so if this macro is used without callback, + this may lead to buffer leaks (if function is failed to send the packet). + Please use @ref zb_zcl_finish_and_send_packet() function directly to be able to check ret code. + */ +/* Glue ZB_ZCL_FINISH_PACKET and ZB_ZCL_SEND_COMMAND_SHORT into one call */ +#define ZB_ZCL_FINISH_PACKET(zbbuf, ptr) (void) zb_zcl_finish_and_send_packet((zbbuf), (ptr), + +#define ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb) \ + (zb_addr_u *)(&(addr)), dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb) + + +#define ZB_ZCL_FINISH_N_SEND_PACKET(zbbuf, ptr, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb) \ + (void) zb_zcl_finish_and_send_packet((zbbuf), (ptr),(zb_addr_u *)(&(addr)), dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb) + +#define ZB_ZCL_FINISH_N_SEND_PACKET_NEW(zbbuf, ptr, addr, dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, aps_secured, disable_aps_ack, delay) \ + (void) zb_zcl_finish_and_send_packet_new((zbbuf), (ptr),(zb_addr_u *)(&(addr)), dst_addr_mode, dst_ep, ep, prof_id, cluster_id, cb, aps_secured, disable_aps_ack, delay) + +/* TODO: Implement via zb_zcl_finish_and_send_packet() */ +#define ZB_ZCL_FINISH_PACKET_O(zbbuf, ptr) \ + (ptr) = zb_buf_alloc_left((zbbuf), ZB_ZCL_GET_BYTES_WRITTEN((zbbuf), (ptr))); + +/*! @}*/ /* Fill ZCL packet */ + +/* align func */ +#ifdef ZB_NEED_ALIGN + +zb_uint16_t zb_zcl_attr_get16(zb_uint8_t *value); +zb_int16_t zb_zcl_attr_gets16(zb_uint8_t *value); +zb_uint32_t zb_zcl_attr_get32(zb_uint8_t *value); +zb_int32_t zb_zcl_attr_gets32(zb_uint8_t *value); +#define ZB_ZCL_ATTR_GET16(value) zb_zcl_attr_get16(value) +#define ZB_ZCL_ATTR_GETS16(value) zb_zcl_attr_gets16(value) +#define ZB_ZCL_ATTR_GET32(value) zb_zcl_attr_get32(value) +#define ZB_ZCL_ATTR_GETS32(value) zb_zcl_attr_gets32(value) + +zb_int24_t zb_zcl_attr_get24(zb_uint8_t *value); +zb_uint48_t zb_zcl_attr_get48(zb_uint8_t *value); +#define ZB_ZCL_ATTR_GET24(value) zb_zcl_attr_get24(value) +#define ZB_ZCL_ATTR_GET48(value) zb_zcl_attr_get48(value) + +#else + +#define ZB_ZCL_ATTR_GET16(value) (*((zb_uint16_t *)value)) +#define ZB_ZCL_ATTR_GETS16(value) (*((zb_int16_t *)value)) +#define ZB_ZCL_ATTR_GET32(value) (*((zb_uint32_t *)value)) +#define ZB_ZCL_ATTR_GETS32(value) (*((zb_int32_t *)value)) + +#define ZB_ZCL_ATTR_GET24(value) (*((zb_int24_t *)value)) +#define ZB_ZCL_ATTR_GET48(value) (*((zb_uint48_t *)value)) + +#endif + +/***************************** ZCL general functionality definitions ******************************/ + +/** @cond internals_doc */ +/** @internal @brief Calculates array size */ +#define ZB_ZCL_ARRAY_SIZE(ar, type) (sizeof(ar)/sizeof(type)) + +/** @internal @brief Calculates byte array size (add 2 bytes for full length). */ +#define ZB_ZCL_ARRAY_GET_SIZE(ar, val) ZB_LETOH16(ar, val) +#define ZB_ZCL_ARRAY_SET_SIZE(ar, val) ZB_HTOLE16_VAL(ar, val) + +/** @internal @brief Calculates 32-byte array size (add 2 bytes for full length). */ +#define ZB_BYTE_32ARRAY_GET_SIZE(ar, val) { ZB_ZCL_ARRAY_GET_SIZE(ar, val); *(zb_uint16_t*)(ar) *= 4; } +#define ZB_BYTE_32ARRAY_SET_SIZE(ar, val) { ZB_ZCL_ARRAY_SET_SIZE(ar, val); *(zb_uint16_t*)(ar) /= 4; } + +#define ZB_ZCL_NULL_EP_ID (zb_uint8_t)(-1) +#define ZB_ZCL_NULL_ID (zb_uint16_t)(-1) +#define ZB_ZCL_NULL_STRING (zb_uint8_t)(0) + +/** @internal @brief Maximum size of Character String (with Length octet) */ +#define ZB_ZCL_MAX_STRING_SIZE 0xFF +#define ZB_ZCL_INVALID_STRING_VALUE 0xFF +#define ZB_ZCL_INVALID_ARRAY_VALUE 0xFFFF + +/** @endcond */ + +/*! @} */ /* ZCL common types and definitions */ + +#ifdef DOXYGEN +/** @brief Fix data endian, if needed, and store it in the same buffer + @param data_ptr - pointer to data value + @param data_type - ZCL data type + */ +#define ZB_ZCL_FIX_ENDIAN(data_ptr, data_type) +#endif + +/** @cond internals_doc */ +#if ! defined ZB_LITTLE_ENDIAN + +/** @internal @brief Fix data endian, if needed, and store it in the same buffer + @param data_ptr - pointer to data value + @param data_type - ZCL data type + */ +#define ZB_ZCL_FIX_ENDIAN(data_ptr, data_type) zb_zcl_fix_endian(data_ptr, data_type) + +void zb_zcl_fix_endian(zb_uint8_t *data_ptr, zb_uint8_t data_type); + +#define ZB_ZCL_HTOLE16_INPLACE(data_ptr) \ + { \ + zb_uint16_t tmp_place; \ + ZB_HTOLE16(&tmp_place, (data_ptr)); \ + ZB_ASSIGN_UINT16((data_ptr), &tmp_place); \ + } + +#else + +#define ZB_ZCL_FIX_ENDIAN(data_ptr, data_type) (ZVUNUSED((data_ptr)), ZVUNUSED((data_type))) + +#define ZB_ZCL_HTOLE16_INPLACE(data_ptr) (ZVUNUSED((data_ptr))) + +#endif /* ZB_LITTLE_ENDIAN */ + +#define ZB_ZCL_TRAN_TABLE_HASH_PARAM(param) ZB_1INT_HASH_FUNC(param) % ZCL_TRAN_TABLE_SIZE + +/** @internal @brief ZCL hash entity, stores callback functions for commands specified by + * buffer index */ +typedef struct zcl_cb_hash_ent_s +{ + zb_callback_t func; /*!< callback pointer */ + zb_uint8_t buf; /*!< buffer index */ +} +zcl_cb_hash_ent_t; + +/** @endcond */ + +/** Command send status structure */ +typedef struct zb_zcl_command_send_status_s +{ + zb_ret_t status; /*!< command send status */ + zb_uint8_t dst_endpoint; /*!< Destination endpoint */ + zb_zcl_addr_t dst_addr; /*!< Destination address */ + zb_uint8_t src_endpoint; /*!< Source endpoint */ + /* add more fields here if needed */ +} +zb_zcl_command_send_status_t; + +/** @brief Set default value attribute callback + @param ep - endpoint number +*/ +typedef void (*zb_zcl_set_default_value_attr_cb_t)(zb_uint8_t ep); + +/** @brief Check attribute value callback + @param cluster_id - Cluster ID + @param cluster_role - cluster role (@ref zb_zcl_cluster_role_e) + @param endpoint - endpoint number + @param attr_id - attribute ID + @param value - new attribute value + + @return RET_OK - if new value is valid, RET_ERROR - if new value is wrong or + RET_IGNORE - if use default Check attribute functions +*/ +typedef zb_ret_t (*zb_zcl_app_check_attr_value_cb_t) + (zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *value); + +/* ZCL common functions */ + +/*! @brief Get registered attribute description by cluster descriptor + @param cluster_desc - cluster descriptor + @param attr_id - attribute identifier + @returns Pointer to attribute description, or NULL if no attribute description found. +*/ +zb_zcl_attr_t* zb_zcl_get_attr_desc(zb_zcl_cluster_desc_t *cluster_desc, zb_uint16_t attr_id); + +/** @brief Check registered attribute is writable one + @param attr_desc - attribute descriptor + @param endpoint - endpoint + @param cluster_id - cluster identifier + @param cluster_role - cluster role (@ref zb_zcl_cluster_role_e) + @param new_value - new value for an attribute + @param check_access - check READ_ONLY access or not + @returns ZB_ZCL_STATUS_SUCCESS on success, error status otherwise +*/ +zb_uint8_t zb_zcl_check_attribute_writable( + zb_zcl_attr_t* attr_desc, + zb_uint8_t endpoint, + zb_uint16_t cluster_id, + zb_uint8_t cluster_role, + zb_uint8_t *new_value, + zb_bool_t check_access); + +/*! + Hook on Write Attribute command + @param endpoint - endpoint + @param cluster_id - cluster ID + @param cluster_role - cluster role (@ref zb_zcl_cluster_role_e) + @param attr_id - attribute ID + @param new_value - pointer to newly assigned value +*/ +void zb_zcl_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id, zb_uint8_t *new_value); + +/** + * @brief Get size of value of given attribute type + * + * @param attr_type - attribute type in question (see @ref zb_zcl_attr_type_t) + * @param attr_value - pointer to value in question (needed for variable sized types) + * + * @return size in bytes or 0xFF if type is invalid + */ +zb_uint8_t zb_zcl_get_attribute_size(zb_uint8_t attr_type, zb_uint8_t *attr_value); + +/** + * @brief Get size of analog data type + * @param attr_type - attribute type in question (see @ref zb_zcl_attr_type_t) + * + * @return size in bytes of 0xFF in type is not analog or invalid + */ +zb_uint8_t zb_zcl_get_analog_attribute_size(zb_uint8_t attr_type); + +/** + * @brief Check whether type of ZCL attrbiute is analog + * @param attr_type - attribute type in question (see @ref zb_zcl_attr_type_t) + * + * @return ZB_TRUE if type is analog, ZB_FALSE otherwith + */ +zb_bool_t zb_zcl_is_analog_data_type(zb_uint8_t attr_type); + +/** + * @brief Check if attribute value is valid or not + * + * @param cluster_id - cluster ID + * @param cluster_role - cluster role (@ref zb_zcl_cluster_role_e) + * @param endpoint - endpoint + * @param attr_id - attribute ID + * @param value - pointer to attribute data + * + * @return ZB_TRUE if data value is valid, ZB_FALSE otherwise + */ +/*zb_bool_t zb_zcl_check_attr_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *value);*/ +zb_ret_t zb_zcl_check_attr_value(zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *value); + +zb_bool_t zb_zcl_is_target_endpoint(zb_af_endpoint_desc_t *ep_desc, zb_uint16_t profile_id); + +zb_uint8_t zb_zcl_get_next_target_endpoint( + zb_uint8_t start_from_ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t profile_id); + +/** + * @brief Search endpoint for cluster with given id + * + * @param ep_desc - application endpoint description + * @param cluster_id - cluster ID (see @ref zb_zcl_cluster_id_e) + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * @return cluster descriptor or NULL if not present + */ +zb_zcl_cluster_desc_t* get_cluster_desc(zb_af_endpoint_desc_t* ep_desc, zb_uint16_t cluster_id, zb_uint8_t cluster_role); + +/** + * @brief Find endpoint which has cluster with given ID + * + * @param cluster_id - cluster ID (see @ref zb_zcl_cluster_id_e) + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * @return endpoint number or 0 if not found + */ +zb_uint8_t get_endpoint_by_cluster(zb_uint16_t cluster_id, zb_uint16_t cluster_role); + +/** + * @brief Find if device has cluster with given ID + * + * @param cluster_id - cluster ID (see @ref zb_zcl_cluster_id_e) + * @return ZB_TRUE if cluser found + */ +zb_bool_t is_cluster_present(zb_uint16_t cluster_id); + +zb_uint16_t get_profile_id_by_endpoint(zb_uint8_t endpoint_id); + +/** + * @brief Find endpoint which has cluster with given ID and role + * + * @param cluster_id - cluster ID (see @ref zb_zcl_cluster_id_e) + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * + * @return endpoint number or 0 if not found + */ +zb_af_endpoint_desc_t *get_endpoint_by_cluster_with_role( + zb_uint16_t cluster_id, + zb_uint8_t cluster_role); + +/** + * Find attribute descriptor by given endpoint number, cluster ID and attribute ID + * + * @param ep - endpoint number (must exist) + * @param cluster_id - cluster ID (must exist on given ep, see @ref zb_zcl_cluster_id_t) + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * @param attr_id - attribute ID + * + * @return attribute descriptor + */ +zb_zcl_attr_t* zb_zcl_get_attr_desc_a(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +/** + * Put attribute value to command packet, fix endian if needed. + * + * @param cmd_ptr - pointer to destination + * @param attr_type - type of attribute being written (see @ref zb_zcl_attr_type_t) + * @param attr_value - pointer to value to be put into packet + * + * @return command pointer adjusted to point at the tail of written value +*/ +zb_uint8_t* zb_zcl_put_value_to_packet( + zb_uint8_t *cmd_ptr, zb_uint8_t attr_type, zb_uint8_t *attr_value); + + +/** + * @brief Sets attribute value, perform all needed checks before and after setting new value + * + * @param ep - endpoint number + * @param cluster_id - cluster ID (see @ref zb_zcl_cluster_id_t) + * @param cluster_role - role (see @ref zb_zcl_cluster_role_e) + * @param attr_id - ID of the attribute being set + * @param value - pointer to new value + * @param check_access - whether read-only check should be performed + * + * @return ZB_ZCL_STATUS_SUCCESS if value was written \n + * ZB_ZCL_STATUS_READ_ONLY if attribute is read only and check_access is false + * ZB_ZCL_STATUS_UNSUP_ATTRIB if attribute is not supported by cluster + * ZB_ZCL_STATUS_INVALID_VALUE if current value of attribute is invalid + * @note given endpoint with given cluster ID should exist + */ +zb_zcl_status_t zb_zcl_set_attr_val(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, + zb_uint16_t attr_id, zb_uint8_t *value, zb_bool_t check_access); + +/** + * @brief Register callback that should be called when APS acknowledge is received for ZCL command + * + * @param param - pointer to buffer with ZCL command + * @param cb - pointer to callback function + */ +zb_ret_t zb_zcl_register_cb(zb_uint8_t param, zb_callback_t cb); + +/** + * @brief Call callback on receiving APS acknowledge for ZCL command + * + * @param param - buffer with ZCL command + * + * @return RET_OK if callback was found and called + * RET_NOT_FOUND if no callback was registered + */ +zb_ret_t zb_zcl_ack_callback(zb_uint8_t param); + +/** + * Check whether ZCL command should be handled by stack + * + * @param param - reference to buffer with parsed ZCL command + * + * @return ZB_ZCL_STATUS_SUCCESS if command should be handled + * ZB_ZCL_STATUS_UNSUP_MANUF_CLUST_CMD if manufacturer specific command is not supported + * ZB_ZCL_STATUS_UNSUP_CLUST_CMD if general command is not supported + * ZB_ZCL_STATUS_UNSUP_CLUST if cluster with role specified in ZCL header is not supported + */ +zb_uint8_t zb_zcl_check_accept_command(zb_uint8_t param); + +/** @brief Common continue command + + Usualy use after invoke User App. If invoke User App finished with error (status!=RET_OK), + send error responce, else if not disabled default response send it or free buffer + + @param buffer - buffer for send response + @param pcmd_info - pointer of cmd_info (see @ref zb_zcl_parsed_hdr_s) + @param status - status of operation (see @ref zb_zcl_status_t) +*/ +void zb_zcl_process_command_finish(zb_bufid_t buffer, zb_zcl_parsed_hdr_t *pcmd_info, zb_uint8_t status); +#define ZB_ZCL_PROCESS_COMMAND_FINISH(buffer, pcmd_info, status) \ + zb_zcl_process_command_finish(buffer, pcmd_info, status) + +void zb_zcl_process_command_finish_new(zb_bufid_t buffer, zb_zcl_parsed_hdr_t *pcmd_info, zb_uint8_t status); +#define ZB_ZCL_PROCESS_COMMAND_FINISH_NEW(buffer, pcmd_info, status) \ + zb_zcl_process_command_finish_new(buffer, pcmd_info, status) + +/** @brief Declare for change attribute for User Application + * + * @note Size of values must be twice as large as maximum size of a possible attribute +*/ +typedef struct zb_zcl_set_attr_value_param_s +{ + zb_uint16_t cluster_id; /**< Cluster ID*/ + zb_uint16_t attr_id; /**< Attribute ID*/ + /* + * Constant size of values - for correct alloc place in buffer tail, as + * "ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t)". + * Current size = maximum of fixed size of any attribute. + * If will need to translate attribute with variable size then need + * set value as size and pointer of attribule. + * */ + union + { + zb_uint8_t data8; /**< 8bit data */ + zb_uint16_t data16; /**< 16bit data */ + zb_uint24_t data24; /**< 24bit data */ + zb_uint32_t data32; /**< 32bit data */ + zb_uint48_t data48; /**< 48bit data */ + zb_ieee_addr_t data_ieee; /**< 64bit data or IEEE address */ + struct + { + zb_uint8_t size; /**< Size of data (byte) */ + zb_uint8_t *p_data; /**< Pointer of data */ + } data_variable; /**< Variable size data - string or byte array */ + } + values; +} zb_zcl_set_attr_value_param_t; + +/** @cond internals_doc */ +/** @internal @brief Inform User Application about change attribute + * @param buffer - buffer for transmite data + * @param clusterId - cluster ID + * @param attrDesc - attribute description + * @param p_value - pointer of new value attribute + * @param result - [out] result user callback +*/ +#define ZB_ZCL_INVOKE_USER_APP_SET_ATTR_WITH_RESULT( \ + buffer, ep, clusterId, attrDesc, p_value, result) \ +{ \ + (result) = RET_OK; \ + \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *data = NULL; \ + zb_uint8_t size = \ + zb_zcl_get_attribute_size((attrDesc)->type, (attrDesc)->data_p); \ + \ + switch ((zb_zcl_attr_type_t)(attrDesc)->type) \ + { \ + case ZB_ZCL_ATTR_TYPE_OCTET_STRING: \ + case ZB_ZCL_ATTR_TYPE_CHAR_STRING: \ + { \ + zb_uint8_t *ptr = \ + (zb_uint8_t*)zb_buf_get_tail( \ + (buffer), sizeof(zb_zcl_device_callback_param_t) + size); \ + \ + ZB_MEMCPY(ptr, (p_value), size); \ + data = (zb_zcl_device_callback_param_t*)(void*)(ptr + size); \ + data->cb_param.set_attr_value_param.values.data_variable.size = size; \ + data->cb_param.set_attr_value_param.values.data_variable.p_data = ptr; \ + } \ + break; \ + \ + default: \ + data = ZB_BUF_GET_PARAM((buffer), zb_zcl_device_callback_param_t); \ + ZB_MEMCPY(&(data->cb_param.set_attr_value_param.values), \ + (p_value), \ + size); \ + break; \ + } \ + \ + if (data) \ + { \ + data->device_cb_id = ZB_ZCL_SET_ATTR_VALUE_CB_ID; \ + data->endpoint = (ep); \ + data->attr_type = (zb_zcl_attr_access_t) (attrDesc)->type; \ + data->cb_param.set_attr_value_param.cluster_id = (clusterId); \ + data->cb_param.set_attr_value_param.attr_id = (attrDesc)->id; \ + (ZCL_CTX().device_cb)((buffer)); \ + (result) = data->status; \ + } \ + } \ +} + +/** @internal @brief Inform User Application about change attribute + * @param buffer - buffer for transmite data + * @param clusterId - cluster ID + * @param attrDesc - attribute description + * @param p_value - pointer of new value attribute +*/ +#define ZB_ZCL_INVOKE_USER_APP_SET_ATTR( \ + buffer, ep, clusterId, attrDesc, p_value) \ +{ \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *data = NULL; \ + zb_uint8_t size = \ + zb_zcl_get_attribute_size((attrDesc)->type, (attrDesc)->data_p); \ + \ + switch ((zb_zcl_attr_type_t)(attrDesc)->type) \ + { \ + case ZB_ZCL_ATTR_TYPE_OCTET_STRING: \ + case ZB_ZCL_ATTR_TYPE_CHAR_STRING: \ + { \ + zb_uint8_t *ptr = \ + (zb_uint8_t*)zb_buf_get_tail( \ + (buffer), sizeof(zb_zcl_device_callback_param_t) + size); \ + \ + ZB_MEMCPY(ptr, (p_value), size); \ + data = (zb_zcl_device_callback_param_t*)(void*)(ptr + size); \ + data->cb_param.set_attr_value_param.values.data_variable.size = size; \ + data->cb_param.set_attr_value_param.values.data_variable.p_data = ptr; \ + } \ + break; \ + \ + default: \ + data = ZB_BUF_GET_PARAM((buffer), zb_zcl_device_callback_param_t); \ + ZB_MEMCPY(&(data->cb_param.set_attr_value_param.values), \ + (p_value), \ + size); \ + break; \ + } \ + \ + if (data) \ + { \ + data->device_cb_id = ZB_ZCL_SET_ATTR_VALUE_CB_ID; \ + data->endpoint = (ep); \ + data->attr_type = (zb_zcl_attr_access_t) (attrDesc)->type; \ + data->cb_param.set_attr_value_param.cluster_id = (clusterId); \ + data->cb_param.set_attr_value_param.attr_id = (attrDesc)->id; \ + (ZCL_CTX().device_cb)((buffer)); \ + } \ + } \ +} + +/** @endcond */ + +/** + * @} + */ + +void zb_zcl_schedule_status_abort(zb_bufid_t buffer, zb_addr_u *addr, + zb_uint8_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t ep, zb_callback_t cb); + +zb_uint8_t zb_zcl_handle_specific_commands(zb_uint8_t param); + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ +#endif /* ! defined ZB_ZCL_COMMON_H */ diff --git a/zboss/include/zcl/zb_zcl_config.h b/zboss/include/zcl/zb_zcl_config.h new file mode 100644 index 0000000000..99eab4b375 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_config.h @@ -0,0 +1,111 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Configuration for Zigbee cluster library +*/ + +#ifndef ZB_ZCL_CONFIG_H +#define ZB_ZCL_CONFIG_H 1 + +/** @cond DOXYGEN_ZCL_SECTION */ + +/************ ZCL specific configuration ******************/ + +/** + ZCL: transactions table size +*/ +#define ZCL_TRAN_TABLE_SIZE 16 + +/* DA: range check error */ +/* #define ZB_DISABLE_TEMP_MEASUREMENT_TOLERANCE_ID */ + +/* #define ZB_ZCL_OTA_INCREMENTAL_QUERY_INTERVAL */ + +/* Enable CVC feature */ +#define ZB_ZCL_ENABLE_CVC + +/* Disable Poll Control Check-Ins during OTA upgrade (to reduce the load) */ +#define xZB_ZCL_NO_CHECKINS_DURING_OTA + + +/*********************** Cluster to command configuration **********************/ + +/* General commands default processing */ +#define ZB_ZCL_ENABLE_DEFAULT_REPORT_ATTR_PROCESSING + +/* Control per-cluster default command processing */ + +#ifdef ZB_ZCL_SUPPORT_CLUSTER_GROUPS +#define ZB_ZCL_ENABLE_DEFAULT_GROUPS_PROCESSING +#endif /* ZB_ZCL_SUPPORT_CLUSTER_GROUPS */ + +#ifdef ZB_ZCL_SUPPORT_CLUSTER_GROUPS_CLIENT +#define ZB_ZCL_ENABLE_DEFAULT_GROUPS_PROCESSING_CLIENT +#endif /* ZB_ZCL_SUPPORT_CLUSTER_GROUPS_CLIENT */ + +/* Control per-cluster default scene extension processing */ +#if defined ZB_ZCL_SUPPORT_CLUSTER_SCENES + +#if defined ZB_ZCL_SUPPORT_CLUSTER_THERMOSTAT +#define ZB_ZCL_SUPPORT_THERMOSTAT_SCENE_EXTENSIONS +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_THERMOSTAT */ + +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_SCENES */ + +#if defined ZB_ZCL_SUPPORT_CLUSTER_POLL_CONTROL +#define ZB_HA_ENABLE_POLL_CONTROL_SERVER +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_POLL_CONTROL */ + +/* TODO: Divide Server and Client processing and turn on server part only when it is really needed - + * OTA cluster is rather big in terms of ROM size! */ +#if defined ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE +#define ZB_ZCL_ENABLE_DEFAULT_OTA_UPGRADE_PROCESSING +#define ZB_HA_ENABLE_OTA_UPGRADE_SERVER 1 +#define ZB_HA_ENABLE_OTA_UPGRADE_CLIENT 1 +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE */ + +#if defined ZB_ZCL_SUPPORT_CLUSTER_TUNNEL +#define ZB_ZCL_ENABLE_DEFAULT_TUNNEL_PROCESSING +#endif /* defined ZB_ENABLE_TUNNEL_CLUSTER */ + + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* ZB_ZCL_CONFIG_H */ diff --git a/zboss/include/zcl/zb_zcl_control4_networking.h b/zboss/include/zcl/zb_zcl_control4_networking.h new file mode 100644 index 0000000000..5fa51e69b0 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_control4_networking.h @@ -0,0 +1,481 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Poll Control cluster defintions +*/ + +#if ! defined ZB_ZCL_CONTROL4_NETWORKING_H +#define ZB_ZCL_CONTROL4_NETWORKING_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_CONTROL4 + * @{ + * @details + * @warning Using this cluster makes an application not conforming to the Zigbee PRO specification + * + * This cluster provides an application level interface between Zigbee devices and a Control4 + * Controller. + * + * This is implemented using Control4 specific profile ZB_AF_CONTROL4_PROFILE_ID. + * + * Control4 Network cluster also uses Many-To-One routing requests. + * + */ + +/** @name Control4 Network cluster attributes + * @{ + */ + +enum zb_zcl_control4_networking_attr_e +{ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_DEVICE_TYPE_ID = 0x0000, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_ID = 0x0001, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_MTORR_PERIOD_ID = 0x0002, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_FIRMWARE_VERSION_ID = 0x0004, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_REFLASH_VERSION_ID = 0x0005, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_BOOT_COUNT_ID = 0x0006, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_PRODUCT_STRING_ID = 0x0007, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_ID = 0x0008, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_ID = 0x0009, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_COST_ID = 0x000a, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_MESH_CHANNEL_ID = 0x000c, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_RSSI_ID = 0x0013, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_LQI_ID = 0x0014, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_BATTERY_LEVEL_ID = 0x0015, + + ZB_ZCL_ATTR_CONTROL4_NETWORKING_RADIO_4_BARS_ID = 0x0016 +}; + +enum zb_zcl_control4_networking_device_type_e +{ + /*! "Non-sleepy end device" value */ + ZB_ZCL_CONTROL4_NETWORKING_DEVICE_TYPE_END_DEVICE = 0x03, + /*! "Sleepy end device" value */ + ZB_ZCL_CONTROL4_NETWORKING_DEVICE_TYPE_SLEEPY_END_DEVICE = 0x04 +}; + + +#define ZB_ZCL_CONTROL4_NETWORKING_REFLASH_VERSION_VENDOR_SPECIFIC 0xff + +#define ZB_ZCL_CONTROL4_NETWORKING_BOOT_COUNT_DEF_VALUE 0 + +#define ZB_ZCL_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_MIN_VALUE ((zb_uint16_t)0x000f) + +#define ZB_ZCL_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_DEF_VALUE ((zb_uint16_t)0x012c) + +#define ZB_ZCL_CONTROL4_NETWORKING_MTORR_PERIOD_MIN_VALUE ((zb_uint16_t)0x000f) + +#define ZB_ZCL_CONTROL4_NETWORKING_MTORR_PERIOD_DEF_VALUE ((zb_uint16_t)0x012c) + +#define ZB_ZCL_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_DEF_VALUE ((zb_uint16_t)0xffff) + +#define ZB_ZCL_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_DEF_VALUE {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} + +#define ZB_ZCL_CONTROL4_NETWORKING_ACCESS_POINT_COST_DEF_VALUE 0xff + +#define ZB_ZCL_CONTROL4_NETWORKING_MESH_CHANNEL_MIN_VALUE 0x0b + +#define ZB_ZCL_CONTROL4_NETWORKING_MESH_CHANNEL_MAX_VALUE 0x19 + +#define ZB_ZCL_CONTROL4_NETWORKING_AVG_RSSI_MIN_VALUE -128 + +#define ZB_ZCL_CONTROL4_NETWORKING_AVG_RSSI_MAX_VALUE 0 + +#define ZB_ZCL_CONTROL4_NETWORKING_BATTERY_LEVEL_MIN_VALUE 0 + +#define ZB_ZCL_CONTROL4_NETWORKING_BATTERY_LEVEL_MAX_VALUE 100 + +#define ZB_ZCL_CONTROL4_NETWORKING_RADIO_4_BARS_MAX_VALUE 4 + +/* Number of searching ZAP attempts */ +#define ZB_ZCL_CONTROL4_NETWORK_SEARCHING_ZAP_ATTEMPTS 2 + +/** @brief Declare attribute list for C4 Network cluster + @param attr_list - attribute list name + @param device_type - pointer to variable to store Device Type attribute value + @param firmware_version - pointer to variable to store Firmware Version attribute value + @param reflash_version - pointer to variable to store Reflash Version attribute value + @param boot_count - pointer to variable to store Boot Count attribute value + @param product_string - pointer to variable to store Product String attribute value + @param access_point_node_ID - pointer to variable to store Access Point Node ID attribute value + @param access_point_long_ID - pointer to variable to store Access Point Long ID attribute value + @param access_point_cost - pointer to variable to store Access Point Cost ID attribute value + @param mesh_channel - pointer to variable to store Mesh Channel attribute value +*/ +#define ZB_ZCL_DECLARE_CONTROL4_NETWORKING_ATTRIB_LIST_SRV(attr_list, device_type, firmware_version, \ + reflash_version, boot_count, product_string, access_point_node_ID, access_point_long_ID, \ + access_point_cost, mesh_channel) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_DEVICE_TYPE_ID, (device_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_FIRMWARE_VERSION_ID, (firmware_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_REFLASH_VERSION_ID, (reflash_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_BOOT_COUNT_ID, (boot_count)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_PRODUCT_STRING_ID, (product_string)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_ID, (access_point_node_ID)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_ID, (access_point_long_ID)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_COST_ID, (access_point_cost)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_MESH_CHANNEL_ID, (mesh_channel)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @brief Declare extended attribute list for C4 Network cluster + @param attr_list - attribute list name + @param device_type - pointer to variable to store Device Type attribute value + @param firmware_version - pointer to variable to store Firmware Version attribute value + @param announce_window - pointer to variable to store Announce Window attribute value + @param MTORR_period - pointer to variable to store MTORR Period attribute value + @param reflash_version - pointer to variable to store Reflash Version attribute value + @param boot_count - pointer to variable to store Boot Count attribute value + @param product_string - pointer to variable to store Product String attribute value + @param access_point_node_ID - pointer to variable to store Access Point Node ID attribute value + @param access_point_long_ID - pointer to variable to store Access Point Long ID attribute value + @param access_point_cost - pointer to variable to store Access Point Cost ID attribute value + @param mesh_channel - pointer to variable to store Mesh Channel attribute value + @param avg_RSSI - pointer to variable to store Avg RSSSI attribute value + @param avg_LQI - pointer to variable to store Avg LQI attribute value + @param battery_level - pointer to variable to store Battery Level attribute value + @param radio_4_bars - pointer to variable to store Radio 4-Bar attribute value +*/ +#define ZB_ZCL_DECLARE_CONTROL4_NETWORKING_ATTRIB_LIST_SRV_EXT(attr_list, device_type, firmware_version, \ + announce_window, MTORR_period, \ + reflash_version, boot_count, product_string, access_point_node_ID, access_point_long_ID, \ + access_point_cost, mesh_channel, \ + avg_RSSI, avg_LQI, battery_level, radio_4_bars) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_DEVICE_TYPE_ID, (device_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_ID, (announce_window)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_MTORR_PERIOD_ID, (MTORR_period)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_FIRMWARE_VERSION_ID, (firmware_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_REFLASH_VERSION_ID, (reflash_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_BOOT_COUNT_ID, (boot_count)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_PRODUCT_STRING_ID, (product_string)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_ID, (access_point_node_ID)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_ID, (access_point_long_ID)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_COST_ID, (access_point_cost)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_MESH_CHANNEL_ID, (mesh_channel)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_RSSI_ID, (avg_RSSI)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_LQI_ID, (avg_LQI)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_BATTERY_LEVEL_ID, (battery_level)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CONTROL4_NETWORKING_RADIO_4_BARS_ID, (radio_4_bars)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /*Control4 Network cluster attributes */ + +/** @name Control4 Network cluster commands + * @{ + */ +enum zb_zcl_control4_networking_cmd_e +{ + ZB_ZCL_CMD_CONTROL4_NETWORKING_IMMEDIATE_ANNOUNCE_ID = 0x00 /**< "Immediate announce command" command. */ +}; + +#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_CONTROL4_NETWORKING_IMMEDIATE_ANNOUNCE_ID \ + +#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING_CLIENT_ROLE_GENERATED_CMD_LIST + +/** @cond internals_doc */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_DEVICE_TYPE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_DEVICE_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ANNOUNCE_WINDOW_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_MTORR_PERIOD_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_MTORR_PERIOD_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_FIRMWARE_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_FIRMWARE_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_REFLASH_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_REFLASH_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_BOOT_COUNT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_BOOT_COUNT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_PRODUCT_STRING_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_PRODUCT_STRING_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_NODE_ID_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_LONG_ID_ID, \ + ZB_ZCL_ATTR_TYPE_IEEE_ADDR, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_COST_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_ACCESS_POINT_COST_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_MESH_CHANNEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_MESH_CHANNEL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_RSSI_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_RSSI_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_LQI_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_AVG_LQI_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_BATTERY_LEVEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_BATTERY_LEVEL_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CONTROL4_NETWORKING_RADIO_4_BARS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CONTROL4_NETWORKING_RADIO_4_BARS_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} +/** @endcond */ /*internals_doc*/ + + +/** + * Control4 Network Cluster Endpoint. + * + * @attention This endpoint number is reserved for internal usage in the stack (for Control4 feature). + */ +#define ZB_CONTROL4_NETWORK_ENDPOINT 0xc4 + +#define ZB_ZCL_CONTROL4_NETWORK_DECLARE_CLUSTER_LIST( \ + cluster_list_name, \ + c4_network_attr_list) \ + zb_zcl_cluster_desc_t cluster_list_name[] = \ + { \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING, \ + ZB_ZCL_ARRAY_SIZE(c4_network_attr_list, zb_zcl_attr_t), \ + (c4_network_attr_list), \ + ZB_ZCL_CLUSTER_SERVER_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ), \ + ZB_ZCL_CLUSTER_DESC( \ + ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING, \ + 0, \ + NULL, \ + ZB_ZCL_CLUSTER_CLIENT_ROLE, \ + ZB_ZCL_MANUF_CODE_INVALID \ + ) \ + } + +/*! + @brief Declare simple descriptor for C4 Network Cluster endpoint + @param ep_name - endpoint variable name +*/ +#define ZB_ZCL_CONTROL4_NETWORK_DECLARE_SIMPLE_DESC(ep_name) \ + /* ZB_DECLARE_SIMPLE_DESC(1, 1); it is already defined */ \ + ZB_AF_SIMPLE_DESC_TYPE(1, 1) simple_desc_##ep_name = \ + { \ + ZB_CONTROL4_NETWORK_ENDPOINT, \ + ZB_AF_CONTROL4_PROFILE_ID, \ + 0, 1, 0, 1, 1, \ + { \ + ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING, \ + ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING \ + } \ + } + +/*! + @brief Declare endpoint for C4 Network Cluster + @param ep_name - endpoint variable name + @param cluster_list - endpoint cluster list + */ +#define ZB_ZCL_CONTROL4_NETWORK_DECLARE_EP(ep_name, cluster_list) \ + ZB_ZCL_CONTROL4_NETWORK_DECLARE_SIMPLE_DESC(ep_name); \ + ZB_AF_DECLARE_ENDPOINT_DESC(ep_name, \ + ZB_CONTROL4_NETWORK_ENDPOINT, ZB_AF_CONTROL4_PROFILE_ID, \ + 0, \ + NULL, \ + ZB_ZCL_ARRAY_SIZE(cluster_list, zb_zcl_cluster_desc_t), \ + cluster_list, \ + (zb_af_simple_desc_1_1_t*)&simple_desc_##ep_name, \ + 0, NULL, 0, NULL) + +/** + Control4 Network Cluster states +*/ +typedef enum zb_zcl_control4_network_state_e +{ + ZB_ZCL_CONTROL4_NETWORK_STATE_IDLE, + ZB_ZCL_CONTROL4_NETWORK_STATE_SEARCHING_ZAP, + ZB_ZCL_CONTROL4_NETWORK_STATE_RUNNING, + ZB_ZCL_CONTROL4_NETWORK_STATE_STOPPED, +} zb_zcl_control4_network_state_t; + +/** + Control4 Zigbee Access Point (ZAP) discovery events +*/ +typedef enum zb_zcl_control4_zap_discover_event_e +{ + /** Information from ZAP (NODE ID and/or LONG_NODE_ID) received and is different from the + * current and default value. Bindings and/or reporting in the user application may require to be updated + */ + ZB_ZCL_CONTROL4_NETWORK_ZAP_UPDATED, + /** ZAP discovered failed after retrying ZB_ZCL_CONTROL4_NETWORK_SEARCHING_ZAP_ATTEMPTS times. + * User application may retry restart the Control4 network cluster or leave the network. + */ + ZB_ZCL_CONTROL4_NETWORK_ZAP_DISCOVER_FAILED, +} zb_zcl_control4_zap_discover_event_t; + +/** Control4 ZAP discover user app notification payload */ +typedef struct zb_zcl_control4_zap_info_notify_s +{ + /** Event for user application to handle*/ + zb_zcl_control4_zap_discover_event_t event; +} zb_zcl_control4_zap_info_notify_t; + +/** + Start Control4 Network Cluster +*/ +zb_ret_t zb_zcl_control4_network_cluster_start(void); + +/** + Stop Control4 Network Cluster +*/ +void zb_zcl_control4_network_cluster_stop(void); + +/** + Get Control4 Network Cluster state +*/ +zb_zcl_control4_network_state_t zb_zcl_control4_network_cluster_get_state(void); + +/** + Handle Read Attribute Response from Control4 Network Cluster +*/ +void zb_zcl_control4_network_cluster_read_attr_resp_handler(zb_bufid_t param); +/** @} */ /*Control4 Network cluster commands */ + +/*! @} */ /* ZCL Control4 Network cluster */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +/** + Control4 Network Cluster Initialization +*/ +void zb_zcl_control4_networking_init_server(void); +void zb_zcl_control4_networking_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING_SERVER_ROLE_INIT zb_zcl_control4_networking_init_server +#define ZB_ZCL_CLUSTER_ID_CONTROL4_NETWORKING_CLIENT_ROLE_INIT zb_zcl_control4_networking_init_client + +#endif /* #if ! defined ZB_ZCL_CONTROL4_NETWORKING_H */ diff --git a/zboss/include/zcl/zb_zcl_custom_cluster.h b/zboss/include/zcl/zb_zcl_custom_cluster.h new file mode 100644 index 0000000000..b10f455417 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_custom_cluster.h @@ -0,0 +1,498 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Time cluster defintions +*/ + +#if ! defined ZB_ZCL_CUSTOM_ATTR_H +#define ZB_ZCL_CUSTOM_ATTR_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond (DOXYGEN_HA_SECTION && internals_doc) */ + +/** @addtogroup zcl_api + * @{ + */ + +#define ZB_ZCL_CLUSTER_ID_CUSTOM 0x1A0A +#define ZB_CUSTOM_DEVICE_ID 0x29A +#define ZB_CUSTOM_DEVICE_VERSION 6 + +/*! @name Custom Attributes cluster attributes + @{ +*/ + +/*! @brief Custom Attributes attribute identifiers + @see ZCL spec, subclause 3.12.2.2 +*/ +enum zb_zcl_custom_cluster_attr_e +{ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_U8_ID = 0x0001, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_S16_ID = 0x0002, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_24BIT_ID = 0x0003, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_32BITMAP_ID = 0x0004, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_IEEE_ID = 0x0005, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_ID = 0x0006, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_UTC_TIME_ID = 0x0007, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_OCTET_STRING_ID = 0x0008, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_BOOL_ID = 0x0009, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_128_BIT_KEY_ID = 0x000a, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_U16_ID = 0x000b, + ZB_ZCL_CUSTOM_CLUSTER_ATTR_U32_ID = 0x000c +}; + +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_U8_DEFAULT_VALUE 0 +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_S16_DEFAULT_VALUE 0 +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_24BIT_DEFAULT_VALUE { 0 } +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_32BITMAP_DEFAULT_VALUE 0 +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_IEEE_DEFAULT_VALUE { 0 } +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_DEFAULT_VALUE { 0 } +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_UTC_TIME_DEFAULT_VALUE 0 +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_BYTE_ARRAY_DEFAULT_VALUE { 0 } +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_BOOL_DEFAULT_VALUE ZB_FALSE +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_128_BIT_KEY_DEFAULT_VALUE { 0 } + +/*! @brief Max size of char string attribute (with length byte) */ +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_MAX_SIZE 11 + +/*! @brief Max sizeo of byte array attribute (with length bytes) */ +#define ZB_ZCL_CUSTOM_CLUSTER_ATTR_BYTE_ARRAY_MAX_SIZE 66 + +/*! @} */ /* Custom Attributes cluster attributes */ + +/*! @name Custom Attributes commands + @{ +*/ + +/*! @brief Custom cluster commands identifiers */ +enum zb_zcl_custom_cluster_cmd_e +{ + ZB_ZCL_CUSTOM_CLUSTER_CMD1_ID = 0x21, + ZB_ZCL_CUSTOM_CLUSTER_CMD2_ID = 0x22, + ZB_ZCL_CUSTOM_CLUSTER_CMD3_ID = 0x23 +}; + +/*! @brief Custom cluster responses identifiers */ +enum zb_zcl_custom_cluster_resp_e +{ + ZB_ZCL_CUSTOM_CLUSTER_CMD1_RESP_ID = 0xF1, + ZB_ZCL_CUSTOM_CLUSTER_CMD2_RESP_ID = 0xF2 +}; + +/******** Custom cluster command 1 ********/ + +enum zb_zcl_custom_cluster_cmd1_mode_e +{ + ZB_ZCL_CUSTOM_CLUSTER_CMD1_MODE1 = 0x01, + ZB_ZCL_CUSTOM_CLUSTER_CMD1_MODE2 = 0x02 +}; + +typedef ZB_PACKED_PRE struct zb_zcl_custom_cluster_cmd1_req_s +{ + zb_uint8_t mode; + zb_uint8_t value; +} +ZB_PACKED_STRUCT zb_zcl_custom_cluster_cmd1_req_t; + +#define ZB_ZCL_CUSTOM_CLUSTER_GET_CMD1_REQ(buf, req, parse_status) \ +{ \ + zb_zcl_custom_cluster_cmd1_req_t *req_ptr = \ + zb_buf_len(buf) >= sizeof(zb_zcl_custom_cluster_cmd1_req_t) ? \ + (zb_zcl_custom_cluster_cmd1_req_t*)zb_buf_begin(buf) : NULL; \ + parse_status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_custom_cluster_cmd1_req_t)); \ + parse_status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @brief Send Custom cluster command 1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param mode - mode value (@see zb_zcl_custom_cluster_cmd1_mode_t) + @param value - some value +*/ +#define ZB_ZCL_CUSTOM_CLUSTER_SEND_CMD1_REQ( \ + buffer, dst_addr, dst_addr_mode, dst_ep, \ + src_ep, def_resp, cb, mode, value) \ +{ \ + zb_uint8_t *ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CUSTOM_CLUSTER_CMD1_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (value)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (buffer), (dst_addr), (dst_addr_mode), (dst_ep), (src_ep), \ + ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_CUSTOM, (cb)); \ +} + +/******** Custom cluster Response to command 1 ********/ + +typedef ZB_PACKED_PRE struct zb_zcl_custom_cluster_cmd1_resp_s +{ + zb_uint8_t status; +} +ZB_PACKED_STRUCT zb_zcl_custom_cluster_cmd1_resp_t; + +#define ZB_ZCL_CUSTOM_CLUSTER_GET_CMD1_RESP(buf, resp, parse_status) \ +{ \ + zb_zcl_custom_cluster_cmd1_resp_t *resp_ptr = \ + zb_buf_len(buf) >= sizeof(zb_zcl_custom_cluster_cmd1_resp_t) ? \ + (zb_zcl_custom_cluster_cmd1_resp_t*)zb_buf_begin(buf) : NULL; \ + parse_status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (resp_ptr) \ + { \ + ZB_MEMCPY(&(resp), resp_ptr, sizeof(zb_zcl_custom_cluster_cmd1_resp_t)); \ + parse_status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @brief Send Custom cluster response to command 1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param status - status value + */ +#define ZB_ZCL_CUSTOM_CLUSTER_SEND_CMD1_RESP( \ + buffer, seq, dst_addr, dst_addr_mode, \ + dst_ep, src_ep, cb, status) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(cmd_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + cmd_ptr, (seq), ZB_ZCL_CUSTOM_CLUSTER_CMD1_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (status)); \ + ZB_ZCL_FINISH_PACKET((buffer), cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (buffer), (dst_addr), (dst_addr_mode), (dst_ep), (src_ep), \ + ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_CUSTOM, (cb)); \ +} + +/******** Custom cluster command 2 ********/ + +enum zb_zcl_custom_cluster_cmd2_param_e +{ + ZB_ZCL_CUSTOM_CLUSTER_CMD2_PARAM1 = 0x01, + ZB_ZCL_CUSTOM_CLUSTER_CMD2_PARAM2 = 0x02, + ZB_ZCL_CUSTOM_CLUSTER_CMD2_PARAM3 = 0x03, + ZB_ZCL_CUSTOM_CLUSTER_CMD2_PARAM4 = 0x04 +}; + +typedef ZB_PACKED_PRE struct zb_zcl_custom_cluster_cmd2_req_s +{ + zb_uint8_t param; + zb_uint16_t value; +} +ZB_PACKED_STRUCT zb_zcl_custom_cluster_cmd2_req_t; + +#define ZB_ZCL_CUSTOM_CLUSTER_GET_CMD2_REQ(buf, req, parse_status) \ +{ \ + zb_zcl_custom_cluster_cmd2_req_t *req_ptr = \ + zb_buf_len(buf) >= sizeof(zb_zcl_custom_cluster_cmd2_req_t) ? \ + (zb_zcl_custom_cluster_cmd2_req_t*)zb_buf_begin(buf) : NULL; \ + parse_status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_custom_cluster_cmd2_req_t)); \ + if (req_ptr->value < 0xFFFF) \ + { \ + parse_status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/*! @brief Send Custom cluster command 2 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param param - some parameter + @param value - some value + */ +#define ZB_ZCL_CUSTOM_CLUSTER_SEND_CMD2_REQ( \ + buffer, dst_addr, dst_addr_mode, dst_ep, \ + src_ep, def_resp, cb, param, value) \ +{ \ + zb_uint8_t *ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CUSTOM_CLUSTER_CMD2_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (param)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (value)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (buffer), (dst_addr), (dst_addr_mode), (dst_ep), (src_ep), \ + ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_CUSTOM, (cb)); \ +} + +/******** Custom cluster Response to command 2 ********/ + +typedef ZB_PACKED_PRE struct zb_zcl_custom_cluster_cmd2_resp_s +{ + zb_uint8_t status; +} +ZB_PACKED_STRUCT zb_zcl_custom_cluster_cmd2_resp_t; + +#define ZB_ZCL_CUSTOM_CLUSTER_GET_CMD2_RESP(buf, resp, status) \ +{ \ + zb_zcl_custom_cluster_cmd2_resp_t *resp_ptr = \ + zb_buf_len(buf) >= sizeof(zb_zcl_custom_cluster_cmd2_resp_t) ? \ + (zb_zcl_custom_cluster_cmd2_resp_t*)zb_buf_begin(buf) : NULL; \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (resp_ptr) \ + { \ + ZB_MEMCPY(&(resp), resp_ptr, sizeof(zb_zcl_custom_cluster_cmd2_resp_t)); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @brief Send Custom cluster response to command 2 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param status - status value + */ +#define ZB_ZCL_CUSTOM_CLUSTER_SEND_CMD2_RESP( \ + buffer, seq, dst_addr, dst_addr_mode, \ + dst_ep, src_ep, cb, status) \ +{ \ + zb_uint8_t *cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(cmd_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + cmd_ptr, seq, ZB_ZCL_CUSTOM_CLUSTER_CMD2_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (status)); \ + ZB_ZCL_FINISH_PACKET((buffer), cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (buffer), (dst_addr), (dst_addr_mode), (dst_ep), (src_ep), \ + ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_CUSTOM, (cb)); \ +} + +/******** Custom cluster command 3 ********/ + +typedef ZB_PACKED_PRE struct zb_zcl_custom_cluster_cmd3_req_s +{ + zb_char_t zcl_str[ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_MAX_SIZE]; +} +ZB_PACKED_STRUCT zb_zcl_custom_cluster_cmd3_req_t; + +#define ZB_ZCL_CUSTOM_CLUSTER_GET_CMD3_REQ(buf, req, parse_status) \ +{ \ + zb_uint8_t zcl_str_len = *((zb_uint8_t*)zb_buf_begin(buf)); \ + parse_status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (zcl_str_len + 1 == zb_buf_len(buf)) \ + { \ + ZB_MEMCPY(&(req), zb_buf_begin(buf), zcl_str_len + 1); \ + parse_status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @brief Send Custom cluster command 3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param zcl_str_ptr - pointer to ZCL string +*/ +#define ZB_ZCL_CUSTOM_CLUSTER_SEND_CMD3_REQ( \ + buffer, dst_addr, dst_addr_mode, dst_ep, \ + src_ep, def_resp, cb, zcl_str_ptr) \ +{ \ + zb_uint8_t *ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CUSTOM_CLUSTER_CMD3_ID); \ + ZB_ZCL_PACKET_PUT_STRING(ptr, (zcl_str_ptr)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (buffer), (dst_addr), (dst_addr_mode), (dst_ep), (src_ep), \ + ZB_AF_HA_PROFILE_ID, ZB_ZCL_CLUSTER_ID_CUSTOM, (cb)); \ +} + +/*! @} */ /* Custom Attributes commands */ + +/*! @internal @name Custom Attributes internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_U8_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_U8_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_S16_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_S16_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_WRITE_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_24BIT_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_24BIT_ID, \ + ZB_ZCL_ATTR_TYPE_24BIT, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_32BITMAP_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_32BITMAP_ID, \ + ZB_ZCL_ATTR_TYPE_32BITMAP, \ + ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_IEEE_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_IEEE_ID, \ + ZB_ZCL_ATTR_TYPE_IEEE_ADDR, \ + ZB_ZCL_ATTR_ACCESS_WRITE_OPTIONAL | ZB_ZCL_ATTR_ACCESS_WRITE_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_ID, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_UTC_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_UTC_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_OCTET_STRING_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_OCTET_STRING_ID, \ + ZB_ZCL_ATTR_TYPE_OCTET_STRING, \ + ZB_ZCL_ATTR_ACCESS_WRITE_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_BOOL_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_BOOL_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_CUSTOM_CLUSTER_ATTR_128_BIT_KEY_ID(data_ptr) \ +{ \ + ZB_ZCL_CUSTOM_CLUSTER_ATTR_128_BIT_KEY_ID, \ + ZB_ZCL_ATTR_TYPE_128_BIT_KEY, \ + ZB_ZCL_ATTR_MANUF_SPEC, \ + (zb_voidp_t) data_ptr \ +} + +/** @internal @brief Declare attribute list for Custom Attributes cluster +*/ + +#define ZB_ZCL_DECLARE_CUSTOM_ATTR_CLUSTER_ATTRIB_LIST( \ + attr_list, u8_attr, s16_attr, _24bit_attr, _32bitmap_attr, ieee_attr, \ + char_string_attr, utc_time_attr, octet_string_attr, bool_attr, _128_bit_key_attr) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_U8_ID, (u8_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_S16_ID, (s16_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_24BIT_ID, (_24bit_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_32BITMAP_ID, (_32bitmap_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_IEEE_ID, (ieee_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_CHAR_STRING_ID, (char_string_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_UTC_TIME_ID, (utc_time_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_OCTET_STRING_ID, (octet_string_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_BOOL_ID, (bool_attr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_CUSTOM_CLUSTER_ATTR_128_BIT_KEY_ID, (_128_bit_key_attr)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @internal Number of attributes mandatory for reporting in Custom Attributes cluster */ +#define ZB_ZCL_CUSTOM_ATTR_REPORT_ATTR_COUNT 8 + +/*! @} */ /* Custom Attributes cluster internals */ + +/*! @} */ /* ZCL Custom Attributes cluster definitions */ + +/** @endcond */ /* (DOXYGEN_ZCL_SECTION && internals_doc) */ + +zb_void_t zb_zcl_custom_attr_init_server(void); +zb_void_t zb_zcl_custom_attr_init_client(void); +#define ZB_ZCL_CLUSTER_ID_CUSTOM_SERVER_ROLE_INIT zb_zcl_custom_attr_init_server +#define ZB_ZCL_CLUSTER_ID_CUSTOM_CLIENT_ROLE_INIT zb_zcl_custom_attr_init_client + +#endif /* ! defined ZB_ZCL_CUSTOM_ATTR_H */ diff --git a/zboss/include/zcl/zb_zcl_cvc_commands.h b/zboss/include/zcl/zb_zcl_cvc_commands.h new file mode 100644 index 0000000000..200b996f30 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_cvc_commands.h @@ -0,0 +1,204 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZCL Continuous Value Change feature commands declarations +*/ + +#ifndef ZCL_CVC_COMMANDS_H +#define ZCL_CVC_COMMANDS_H 1 + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Documentation - doc/HA/continuous_value_change-detailed_design.doc */ + +/* Internal variables, + see 1.7.4 */ + +/** @brief CVC Transition Time As Fast As Able */ +#define ZB_ZCL_CVC_TRANSITION_TIME_AS_FAST_AS_ABLE 0xffff +/** @brief CVC Transition Time minimal */ +#define ZB_ZCL_CVC_TRANSITION_TIME_MINIMAL 0x0001 +/** @brief CVC Transition Time error */ +#define ZB_ZCL_CVC_TRANSITION_TIME_ERROR 20 +/** @brief CVC Transition Time Unit (in msec) */ +#define ZB_ZCL_CVC_TRANSITION_TIME_UNIT_MS 100 +/** @brief CVC Transition Time Unit (in beacon intervals) */ +#define ZB_ZCL_CVC_TRANSITION_TIME_UNIT_BE ZB_TIME_ONE_SECOND / 10 +/** @brief CVC Invalid Remaining Time */ +#define ZB_ZCL_CVC_INVALID_REMAINING_TIME 0xffff +/** @brief CVC Invalid Alarm Id */ +#define ZB_ZCL_CVC_INVALID_ALARM_ID (zb_uint8_t)-1 +/** @brief CVC Transition Timer Quant (in msec) */ +#define ZB_ZCL_CVC_TRANSITION_TIMER_QUANT_MS 16 +/** @brief CVC Transition Timer Quant */ +#define ZB_ZCL_CVC_TRANSITION_TIMER_QUANT_BE \ + ZB_MILLISECONDS_TO_BEACON_INTERVAL(ZB_ZCL_CVC_TRANSITION_TIMER_QUANT_MS) +/** @brief CVC Transition Time Unit */ +#define ZB_ZCL_CVC_TRANSITION_TIME_UNIT_IN_QUANTS \ + (ZB_ZCL_CVC_TRANSITION_TIME_UNIT_MS / ZB_ZCL_CVC_TRANSITION_TIMER_QUANT_MS) + +#define ZB_ZCL_UNDEFINED_CVC_SLOT 0xff +#define ZB_ZCL_MAX_CVC_SLOTS_BY_EP (ZB_ZCL_UNDEFINED_CVC_SLOT / ZB_ZCL_MAX_EP_NUMBER) + +/** @brief Value set function that will be used for setting value on device */ +typedef zb_ret_t (ZB_CODE * zb_zcl_cvc_value_set_func_t)(zb_uint8_t endpoint, zb_uint16_t* new_value, zb_uint16_t remaining_time); + + +/** @internal Structure of Input variables + */ +typedef struct zb_zcl_cvc_input_variables_s +{ +/** @brief Current Value */ + zb_uint16_t current_value16; +/** @brief End Value */ + zb_uint16_t end_value16; +/** @brief Min Value */ + zb_uint16_t min_value16; +/** @brief Max Value */ + zb_uint16_t max_value16; +/** @brief Overlapping flag */ + zb_uint8_t overlap; +/** @brief Transition Time */ + zb_uint16_t transition_time; +/** @brief Value set function */ + zb_zcl_cvc_value_set_func_t value_set_func; +/** @brief Buffer id for after_processing_cb */ + zb_uint8_t buf_id; +/** @brief After Processing callback */ + zb_callback_t after_processing_cb; +} zb_zcl_cvc_input_variables_t; + +/** @internal Structure of Continuous Value Change variables + */ +typedef struct zb_zcl_cvc_variables_s +{ +/** @brief Input variables */ + zb_zcl_cvc_input_variables_t input_var; +/** @brief Time to next sheduled operation (delta time) */ + zb_uint16_t delta_time; +/** @brief Delta value for one step */ + zb_int16_t delta_value16; +/** @brief Number of remaining steps for transition */ + zb_uint16_t steps_number; +/** @brief Step number for extra increment delta value */ + zb_uint16_t extra_inc_value_step; +/** @brief Step number for extra increment delta time */ + zb_uint16_t extra_inc_time_step; +/** @brief End time of transition */ + zb_time_t end_time; +/** @brief Availible time error */ + zb_uint16_t time_err; +} zb_zcl_cvc_variables_t; + +/** @internal Structure of Alarm variables + */ +typedef struct zb_zcl_cvc_alarm_variables_s +{ +/** @brief Endpoint id */ + zb_uint8_t endpoint_id; +/** @brief Cluster id */ + zb_uint16_t cluster_id; +/** @brief Attribute id */ + zb_uint16_t attribute_id; +/** @brief Alarm buffer id */ + zb_uint8_t alarm_buf_id; +/** @brief Is Used flag */ + zb_bool_t is_used; +} ZB_PACKED_STRUCT +zb_zcl_cvc_alarm_variables_t; + + +/*! + @brief Calculate transition values and put it into buffer. + @param input_var - pointer to zb_zcl_cvc_input_variables_s containing input data + @return buffer ID with zb_zcl_cvc_variables_s +*/ +zb_uint8_t zb_zcl_cvc_calculate_transition_values(zb_zcl_cvc_input_variables_t* input_var); + + +/*! + @brief Initialize and start transition. + @param endpoint_id - ep id + @param cluster_id - cluster id + @param attribute_id - attribute id (from cluster) + @param alarm_buf_id - buffer_id with zb_zcl_cvc_variables_s + @return alarm ID +*/ +zb_uint8_t zb_zcl_cvc_start_alarm(zb_uint8_t endpoint_id, + zb_uint16_t cluster_id, + zb_uint16_t attribute_id, + zb_uint8_t alarm_buf_id); + + +/*! + @brief Initialize and start transition. + @param alarm_id - alarm id + @return old transition's buffer (input_var.buf_id) +*/ +zb_uint8_t zb_zcl_cvc_stop_transition(zb_uint8_t alarm_id); + + +/*! + @brief Check transition running. + @param endpoint_id - ep id + @param cluster_id - cluster id + @param attribute_id - attribute id (from cluster) + @return alarm ID (ZB_ZCL_CVC_INVALID_ALARM_ID if it is not running) +*/ +zb_uint8_t zb_zcl_cvc_check_transition_running( + zb_uint8_t endpoint_id, + zb_uint16_t cluster_id, + zb_uint16_t attribute_id); + + +/*! @brief Initialize alarm list (stored in device context). */ +zb_void_t zb_zcl_init_cvc_alarm_info(void); + + +/*! + @brief Get remaining time of transition. + @param alarm_id - alarm id + @return remaining time +*/ +zb_uint16_t zb_zcl_cvc_get_remaining_time(zb_uint8_t alarm_id); + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* ZCL_LEVEL_CVC_COMMANDS_H */ diff --git a/zboss/include/zcl/zb_zcl_dehumidification_control.h b/zboss/include/zcl/zb_zcl_dehumidification_control.h new file mode 100644 index 0000000000..c55a7b15b7 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_dehumidification_control.h @@ -0,0 +1,205 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Dehumidification Control cluster defintions +*/ + +#if ! defined ZB_ZCL_DEHUMIDIFICATION_CONTROL_H +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_DEHUMIDIFICATION + * @{ + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_DEHUMIDIFICATION_CONTROL */ + +/*! @name Dehumidification Control cluster attributes + @{ +*/ + +/*! @brief Dehumidification Control cluster attribute identifiers + @see ZCL spec, subclause 6.4.2.2 +*/ +enum zb_zcl_dehumidification_control_attr_e +{ + /** The RelativeHumidity attribute is an 8-bit value that represents the current + * relative humidity (in %) measured by a local or remote sensor. */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RELATIVE_HUMIDITY_ID = 0x0000, + /** @brief Dehumidification Cooling attribute */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_COOLING_ID = 0x0001, + /** @brief RHDehumidification Setpoint attribute */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_ID = 0x0010, + /** The RelativeHumidityMode attribute is an 8-bit value that specifies how + * the RelativeHumidity value is being updated. */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RELATIVE_HUMIDITY_MODE_ID = 0x0011, + /** The DehumidificationLockout attribute is an 8-bit value that specifies + * whether dehumidification is allowed or not. */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_LOCKOUT_ID = 0x0012, + /** @brief Dehumidification Hysteresis attribute */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_ID = 0x0013, + /** @brief Dehumidification Max Cool attribute */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_ID = 0x0014, + /** The RelativeHumidityDisplay attribute is an 8-bit value that specifies + * whether the RelativeHumidity value is displayed to the user or not. */ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RELATIVE_HUMIDITY_DISPLAY_ID = 0x0015, +}; + +/** @brief Min value for RHDehumidification Setpoint attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_MIN_VALUE 0x1e + +/** @brief Man value for RHDehumidification Setpoint attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_MAX_VALUE 0x64 + +/** @brief Default value for RHDehumidification Setpoint attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_DEFAULT_VALUE 0x32 + +/** @brief Default value for RelativeHumidityMode attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_RELATIVE_HUMIDITY_MODE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for DehumidificationLockout attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_LOCKOUT_DEFAULT_VALUE ((zb_uint8_t)0x01) + +/** @brief Min value for Dehumidification Hysteresis attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_MIN_VALUE 0x02 + +/** @brief Max value for Dehumidification Hysteresis attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_MAX_VALUE 0x14 + +/** @brief Default value for Dehumidification Hysteresis attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_DEFAULT_VALUE 0x02 + +/** @brief Min value for Dehumidification Max Cool attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_MIN_VALUE 0x14 + +/** @brief Max value for Dehumidification Max Cool attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_MAX_VALUE 0x64 + +/** @brief Default value for Dehumidification Max Cool attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_DEFAULT_VALUE 0x14 + +/** @brief Default value for RelativeHumidityDisplay attribute */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_RELATIVE_HUMIDITY_DISPLAY_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Declare attribute list for Dehumidification Control cluster + @param attr_list - attribute list name + @param dehumid_cooling - pointer to variable to store Dehumidification Cooling attribute value + @param dehumid_setpoint - pointer to variable to store Dehumidification Setpoint attribute value + @param dehumid_hysteresis - pointer to variable to store Dehumidification Hysteresis attribute value + @param dehumid_max_cool - pointer to variable to store Dehumidification Max Cool attribute value +*/ +#define ZB_ZCL_DECLARE_DEHUMIDIFICATION_CONTROL_ATTRIB_LIST(attr_list, dehumid_cooling, dehumid_setpoint, \ + dehumid_hysteresis, dehumid_max_cool) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_COOLING_ID, (dehumid_cooling)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_ID, (dehumid_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_ID, (dehumid_hysteresis)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_ID, (dehumid_max_cool)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Dehumidification Control cluster attributes */ + +/*! @name Dehumidification Control cluster commands + @{ +*/ + +/*! @} */ /* Dehumidification Control cluster commands */ + +/** @cond internals_doc */ +/*! @internal @name Dehumidification Control cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_COOLING_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_COOLING_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_RHDEHUMIDIFICATION_SETPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_HYSTERESIS_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DEHUMIDIFICATION_CONTROL_DEHUMIDIFICATION_MAX_COOL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Dehumidification Control cluster */ +#define ZB_ZCL_DEHUMIDIFICATION_CONTROL_REPORT_ATTR_COUNT 1 + +/*! @} */ /* Dehumidification Control cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/*! @} */ /* ZCL HA Dehumidification Control cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_dehumidification_control_init_server(void); +void zb_zcl_dehumidification_control_init_client(void); +#define ZB_ZCL_CLUSTER_ID_DEHUMID_CONTROL_SERVER_ROLE_INIT zb_zcl_dehumidification_control_init_server +#define ZB_ZCL_CLUSTER_ID_DEHUMID_CONTROL_CLIENT_ROLE_INIT zb_zcl_dehumidification_control_init_client + +#endif /* ! defined ZB_ZCL_DEHUMID_CONTROL_H */ diff --git a/zboss/include/zcl/zb_zcl_diagnostics.h b/zboss/include/zcl/zb_zcl_diagnostics.h new file mode 100644 index 0000000000..cb534a3b33 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_diagnostics.h @@ -0,0 +1,454 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Diagnostics cluster defintions +*/ + +#if ! defined ZB_ZCL_DIAGNOSTICS_H +#define ZB_ZCL_DIAGNOSTICS_H + +#if defined(ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS) || defined(DOXYGEN) + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_DIAGNOSTICS + * @{ + * @details + * ZCL Diagnostics cluster definitions + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_DIAGNOSTICS */ + +/*! @name Diagnostics cluster attributes + @{ +*/ + +/*! @brief Structure saved all diagnostic attribute */ +typedef struct zb_zcl_diagnostics_data_s +{ + /*! @brief numberOfResets, Zigbee Diagnostic Cluster spec 1.2.2.1.1 */ + zb_uint16_t numberOfResets; + /*! @brief MacRxBcast, HA spec 9.3.2.2.2 */ + zb_uint16_t macRxBcast; + /*! @brief MacTxBcast, HA spec 9.3.2.2.2 */ + zb_uint16_t macTxBcast; + /*! @brief MacTxUcast, HA spec 9.3.2.2.2 */ + zb_uint16_t macTxUcast; + /*! @brief APSTxBcast, HA spec 9.3.2.2.2 */ + zb_uint16_t apsTxBcast; + /*! @brief APSTxUcastSuccess, HA spec 9.3.2.2.2 */ + zb_uint16_t apsTxUcastSuccess; + /*! @brief APSTxUcastzb_zcl_diagnostics_data_t diagnostics_data;Fail, HA spec 9.3.2.2.2 */ + zb_uint16_t apsTxUcastFail; + /*! @brief JoinIndication, Zigbee Diagnostic Cluster spec 1.2.2.2.17 */ + zb_uint16_t joinIndication; + /*! @brief AverageMACRetryPerAPSMessageSent, HA spec 9.3.2.2.2.27 */ + zb_uint16_t averageMACRetryPerAPSMessageSent; + /*! @brief JoinIndication, Zigbee Diagnostic Cluster spec 1.2.2.2.24 */ + zb_uint16_t packetBufferAllocateFeatures; + /*! @brief LastMessageLQI, HA spec 9.3.2.2.2. */ + zb_uint8_t lastMessageLQI; + /*! @brief LastMessageRSSI, HA spec 9.3.2.2.2. */ + zb_int8_t lastMessageRSSI; +} zb_zcl_diagnostics_data_t; + + + + +extern zb_zcl_diagnostics_data_t diagnostics_data; + + +/*! @brief Diagnostics cluster attribute identifiers + @see HA spec, Diagnostics Cluster 9.3.2.2.2 +*/ +enum zb_zcl_diagnostics_attr_e +{ + /** @brief NumberOfResets, Zigbee Diagnostic Cluster spec 1.2.2.1.1 */ + ZB_ZCL_ATTR_DIAGNOSTICS_NUMBER_OF_RESETS_ID = 0x0000, + /** This attribute keeps track of the number of writes to persistent memory. */ + ZB_ZCL_ATTR_DIAGNOSTICS_PERSISTENT_MEMORY_WRITES_ID = 0x0001, + /** @brief MacRxBcast, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_RX_BCAST_ID = 0x0100, + /** @brief MacTxBcast, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_BCAST_ID = 0x0101, + /** MacRxUcast Attribute A counter that is incremented each time the MAC + * layer receives a unicast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_RX_UCAST_ID = 0x0102, + /** @brief MacTxUcast, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_ID = 0x0103, + /** MacTxUcastRetry Attribute A counter that is incremented each time + * the MAC layer retries a unicast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_RETRY_ID = 0x0104, + /** MacTxUcastFail Attribute A counter that is incremented each time + * the MAC layer fails to send a unicast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_FAIL_ID = 0x0105, + /** APSRxBcast Attribute A counter that is incremented each time + * the APS layer receives a broadcast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_RX_BCAST_ID = 0x0106, + /** @brief APSTxBcast, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_BCAST_ID = 0x0107, + /** APSRxUcast Attribute A counter that is incremented each time + * the APS layer receives a unicast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_RX_UCAST_ID = 0x0108, + /** @brief APSTxUcastSuccess, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_SUCCESS_ID = 0x0109, + /** APSTxUcastRetry Attribute A counter that is incremented each time + * the APS layer retries the sending of a unicast. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_RETRY_ID = 0x010A, + /** @brief APSTxUcastFail, HA spec 9.3.2.2.2 */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_FAIL_ID = 0x010b, + /** RouteDiscInitiated Attribute A counter that is incremented each time + * a route request is initiated . */ + ZB_ZCL_ATTR_DIAGNOSTICS_ROUTE_DISC_INITIATED_ID = 0x010C, + /** NeighborAdded Attribute A counter that is incremented each time + * an entry is added to the neighbor table. */ + ZB_ZCL_ATTR_DIAGNOSTICS_NEIGHBOR_ADDED_ID = 0x010D, + /** NeighborRemoved Attribute A counter that is incremented each time + * an entry is removed from the neighbor table. */ + ZB_ZCL_ATTR_DIAGNOSTICS_NEIGHBOR_REMOVED_ID = 0x010E, + /** A counter that is incremented each time a neighbor table entry becomes stale + * because the neighbor has not been heard from. */ + ZB_ZCL_ATTR_DIAGNOSTICS_NEIGHBOR_STALE_ID = 0x010F, + /** @brief JoinIndication, HA spec 1.2.2.2.17 */ + ZB_ZCL_ATTR_DIAGNOSTICS_JOIN_INDICATION_ID = 0x0110, + /** A counter that is incremented each time an entry is removed from the child table. */ + ZB_ZCL_ATTR_DIAGNOSTICS_CHILD_MOVED_ID = 0x0111, + /** A counter that is incremented each time a message is dropped at the network + * layer because the APS frame counter was not higher than the last message seen + * from that source. */ + ZB_ZCL_ATTR_DIAGNOSTICS_NWKFC_FAILURE_ID = 0x0112, + /** A counter that is incremented each time a message is dropped at the APS layer + * because the APS frame counter was not higher than the last message seen from + * that source. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APSFC_FAILURE_ID = 0x0113, + /** A counter that is incremented each time a message is dropped at the APS layer + * because it had APS encryption but the key associated with the sender has + * not been authenticated, and thus the key is not authorized for use + * in APS data messages. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_UNAUTHORIZED_KEY_ID = 0x0114, + /** A counter that is incremented each time a NWK encrypted message was received + * but dropped because decryption failed. */ + ZB_ZCL_ATTR_DIAGNOSTICS_NWK_DECRYPT_FAILURES_ID = 0x0115, + /** A counter that is incremented each time an APS encrypted message was received + * but dropped because decryption failed. */ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_DECRYPT_FAILURES_ID = 0x0116, + /** @brief AverageMACRetryPerAPSMessageSent, HA spec 9.3.2.2.2.27 */ + ZB_ZCL_ATTR_DIAGNOSTICS_PACKET_BUFFER_ALLOCATE_FAILURES_ID = 0x0117, + /** A counter that is incremented each time a unicast packet is relayed. */ + ZB_ZCL_ATTR_DIAGNOSTICS_RELAYED_UCAST_ID = 0x0118, + ZB_ZCL_ATTR_DIAGNOSTICS_PHYTOMACQUEUELIMITREACHED_ID = 0x0119, + /** A counter that is incremented each time a packet was dropped due to a packet + * validation error. This could be due to length or other formatting problems + * in the packet. */ + ZB_ZCL_ATTR_DIAGNOSTICS_PACKET_VALIDATEDROPCOUNT_ID = 0x011A, + /** @brief PacketBufferAllocateFeatures, Zigbee Diagnostic Cluster spec 1.2.2.2.24 */ + ZB_ZCL_ATTR_DIAGNOSTICS_AVERAGE_MAC_RETRY_PER_APS_ID = 0x011b, + /** @brief LastMessageLQI, HA spec 9.3.2.2.2. */ + ZB_ZCL_ATTR_DIAGNOSTICS_LAST_LQI_ID = 0x011c, + /** @brief LastMessageRSSI, HA spec 9.3.2.2.2. */ + ZB_ZCL_ATTR_DIAGNOSTICS_LAST_RSSI_ID = 0x011d, +}; + +/** @brief Default value for NumberOfResets attribute */ +#define ZB_ZCL_DIAGNOSTICS_NUMBER_OF_RESETS_DEFAULT_VALUE ((zb_uint16_t)0x00000000) + +/** @brief Default value for PersistentMemoryWrites attribute */ +#define ZB_ZCL_DIAGNOSTICS_PERSISTENT_MEMORY_WRITES_DEFAULT_VALUE ((zb_uint16_t)0x00000000) + +/** @brief Default value for MacRxBcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_RX_BCAST_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for MacTxBcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_TX_BCAST_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for MacRxUcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_RX_UCAST_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for MacTxUcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_TX_UCAST_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for MacTxUcastRetry attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_TX_UCAST_RETRY_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for MacTxUcastFail attribute */ +#define ZB_ZCL_DIAGNOSTICS_MAC_TX_UCAST_FAIL_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSRxBcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_RX_BCAST_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSTxBcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_TX_BCAST_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSRxUcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_RX_UCAST_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSTxUcastSuccess attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_TX_UCAST_SUCCESS_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSTxUcastRetry attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_TX_UCAST_RETRY_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSTxUcastFail attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_TX_UCAST_FAIL_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for RouteDiscInitiated attribute */ +#define ZB_ZCL_DIAGNOSTICS_ROUTE_DISC_INITIATED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NeighborAdded attribute */ +#define ZB_ZCL_DIAGNOSTICS_NEIGHBOR_ADDED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NeighborRemoved attribute */ +#define ZB_ZCL_DIAGNOSTICS_NEIGHBOR_REMOVED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NeighborStale attribute */ +#define ZB_ZCL_DIAGNOSTICS_NEIGHBOR_STALE_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for JoinIndication attribute */ +#define ZB_ZCL_DIAGNOSTICS_JOIN_INDICATION_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for ChildMoved attribute */ +#define ZB_ZCL_DIAGNOSTICS_CHILD_MOVED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NWKFCFailure attribute */ +#define ZB_ZCL_DIAGNOSTICS_NWKFC_FAILURE_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSFCFailure attribute */ +#define ZB_ZCL_DIAGNOSTICS_APSFC_FAILURE_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSUnauthorizedKey attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_UNAUTHORIZED_KEY_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NWKDecryptFailures attribute */ +#define ZB_ZCL_DIAGNOSTICS_NWK_DECRYPT_FAILURES_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for APSDecryptFailures attribute */ +#define ZB_ZCL_DIAGNOSTICS_APS_DECRYPT_FAILURES_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for PacketBufferAllocateFailures attribute */ +#define ZB_ZCL_DIAGNOSTICS_PACKET_BUFFER_ALLOCATE_FAILURES_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for RelayedUcast attribute */ +#define ZB_ZCL_DIAGNOSTICS_RELAYED_UCAST_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for PhytoMACqueuelimitreached attribute */ +#define ZB_ZCL_DIAGNOSTICS_PHYTO_MA_CQUEUELIMITREACHED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for PacketValidatedropcount attribute */ +#define ZB_ZCL_DIAGNOSTICS_PACKET_VALIDATEDROPCOUNT_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for AverageMACRetryPerAPS attribute */ +#define ZB_ZCL_DIAGNOSTICS_AVERAGE_MAC_RETRY_PER_APS_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for LastLQI attribute */ +#define ZB_ZCL_DIAGNOSTICS_LAST_LQI_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for LastRSSI attribute */ +#define ZB_ZCL_DIAGNOSTICS_LAST_RSSI_DEFAULT_VALUE ((zb_int8_t)0) + +/** @cond internals_doc */ +/*! @internal @name Diagnostics cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_NUMBER_OF_RESETS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_NUMBER_OF_RESETS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_PACKET_BUFFER_ALLOCATE_FAILURES_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_PACKET_BUFFER_ALLOCATE_FAILURES_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_JOIN_INDICATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_JOIN_INDICATION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_MAC_RX_BCAST_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_RX_BCAST_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_BCAST_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_BCAST_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_BCAST_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_BCAST_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_SUCCESS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_SUCCESS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_FAIL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_FAIL_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_AVERAGE_MAC_RETRY_PER_APS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_AVERAGE_MAC_RETRY_PER_APS_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_LAST_LQI_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_LAST_LQI_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DIAGNOSTICS_LAST_RSSI_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_DIAGNOSTICS_LAST_RSSI_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! @} */ /* Diagnostics cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Diagnostics cluster - server side + @param attr_list - attribute list name +*/ +#define ZB_ZCL_DECLARE_DIAGNOSTICS_ATTRIB_LIST(attr_list) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_NUMBER_OF_RESETS_ID, \ + &(diagnostics_data.numberOfResets)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_MAC_RX_BCAST_ID, &(diagnostics_data.macRxBcast)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_BCAST_ID, &(diagnostics_data.macTxBcast)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_MAC_TX_UCAST_ID, &(diagnostics_data.macTxUcast)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_BCAST_ID, &(diagnostics_data.apsTxBcast)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_SUCCESS_ID, \ + &(diagnostics_data.apsTxUcastSuccess)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_APS_TX_UCAST_FAIL_ID, \ + &(diagnostics_data.apsTxUcastFail)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_PACKET_BUFFER_ALLOCATE_FAILURES_ID, \ + &(diagnostics_data.packetBufferAllocateFeatures)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_JOIN_INDICATION_ID, \ + &(diagnostics_data.joinIndication)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_AVERAGE_MAC_RETRY_PER_APS_ID, \ + &(diagnostics_data.packetBufferAllocateFeatures)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_LAST_LQI_ID, &(diagnostics_data.lastMessageLQI)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DIAGNOSTICS_LAST_RSSI_ID, &(diagnostics_data.lastMessageRSSI)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Diagnostics cluster attributes */ + + +/** @cond internals_doc */ +/*! @brief Increment diagnostic attribute + @param attr_id - attribute Id, see @ref zb_zcl_diagnostics_attr_e +*/ +zb_void_t zb_zcl_diagnostics_inc(zb_uint16_t attr_id, zb_uint8_t value); + +#define ZB_ZCL_DIAGNOSTICS_INC(attr_id) zb_zcl_diagnostics_inc((attr_id), 0) +#define ZB_ZCL_DIAGNOSTICS_SAVE(attr_id, value) zb_zcl_diagnostics_inc((attr_id), (value)) +/*! @} + * @endcond */ /* internals_doc */ + +/*! @} */ /* ZCL Diagnostics cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_diagnostics_init_server(void); +zb_void_t zb_zcl_diagnostics_init_client(void); +#define ZB_ZCL_CLUSTER_ID_DIAGNOSTICS_SERVER_ROLE_INIT zb_zcl_diagnostics_init_server +#define ZB_ZCL_CLUSTER_ID_DIAGNOSTICS_CLIENT_ROLE_INIT zb_zcl_diagnostics_init_client + +#else /* defined(ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS) */ + +#define ZB_ZCL_DIAGNOSTICS_INC(attr_id) +#define ZB_ZCL_DIAGNOSTICS_SAVE(attr_id, value) + +#define ZB_ZCL_CLUSTER_ID_DIAGNOSTICS_SERVER_ROLE_INIT +#define ZB_ZCL_CLUSTER_ID_DIAGNOSTICS_CLIENT_ROLE_INIT + +#endif /* defined(ZB_ZCL_SUPPORT_CLUSTER_DIAGNOSTICS) */ + +#endif /* ! defined ZB_ZCL_DIAGNOSTICS_H */ diff --git a/zboss/include/zcl/zb_zcl_door_lock.h b/zboss/include/zcl/zb_zcl_door_lock.h new file mode 100644 index 0000000000..19098fd656 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_door_lock.h @@ -0,0 +1,796 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: DOOR_LOCK cluster defintions +*/ + +#ifndef ZB_ZCL_DOOR_LOCK_H +#define ZB_ZCL_DOOR_LOCK_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_DOOR_LOCK + * @{ + * @details + * Door Lock cluster defined in ZCL spec, clause 7.3. + * + * The cluster contains 2 command sets: + * @li Lock Door request and response; + * @li Unlock Door request and response. + * + * Both requests have no payload and could be scheduled for sending with corresponding macros. + * Both responses have simple payload, and their sending and parsing with corresponding macros + * is almost trivial. + * + * @par Examples: + * + * Send Door Lock command: + * @snippet HA_samples/door_lock/sample_zed.c send_door_lock_req + * + * Send Door Unlock command: + * @snippet HA_samples/door_lock/sample_zed.c send_door_lock_unlock_req + * + * For more information see HA_samples/door_lock and HA_samples/door_lock_controller samples + */ + +/*! @name DoorLock cluster attributes + @{ +*/ + +/*! @brief Door Lock cluster attribute identifiers + @see ZCL spec, subclause 7.3.2.2 +*/ +enum zb_zcl_door_lock_attr_e +{ + /** @brief LockState attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_ID = 0x0000, + /** @brief LockType attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_ID = 0x0001, + /** @brief ActuatorEnabled attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ID = 0x0002, + /** @brief DoorState attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_ID = 0x0003, + /** @brief DoorOpenEvents attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_OF_DOOR_OPEN_EVENTS_ID = 0x0004, + /** @brief DoorClosedEvents attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_OF_DOOR_CLOSED_EVENTS_ID = 0x0005, + /** @brief OpenPeriod attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_OPEN_PERIOD_ID = 0x0006, + /** The number of available log records. */ + ZB_ZCL_ATTR_DOOR_LOCK_NUMBER_OF_LOG_RECORDS_SUPPORTED_ID = 0x0010, + /** @brief NumberOfTotalUsersSupported attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_TOTAL_USERS_ID = 0x0011, + /** @brief NumberOfPINUsersSupported attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_PIN_USERS_ID = 0x0012, + /** The number of RFID users supported. */ + ZB_ZCL_ATTR_DOOR_LOCK_NUMBER_OF_RFID_USERS_SUPPORTED_ID = 0x0013, + /** @brief NumberOfWeekDaySchedulesSupportedPerUser attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_WEEK_DAY_SCHEDULE_PER_USER_ID = 0x0014, + /** @brief NumberOfYearDaySchedulesSupportedPerUser attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_YEAR_DAY_SCHEDULE_PER_USER_ID = 0x0015, + /** @brief NumberOfHolidaySchedulesSupported attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_NUM_HOLIDAY_SCHEDULE_ID = 0x0016, + /** @brief Max PIN code length attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_MAX_PIN_LEN_ID = 0x0017, + /** @brief Min PIN code length attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_MIN_PIN_LEN_ID = 0x0018, + /** An 8-bit value indicates the maximum length in bytes of a RFID Code + * on this device. */ + ZB_ZCL_ATTR_DOOR_LOCK_MAX_RFID_CODE_LENGTH_ID = 0x0019, + /** An 8-bit value indicates the minimum length in bytes of a RFID Code + * on this device. */ + ZB_ZCL_ATTR_DOOR_LOCK_MIN_RFID_CODE_LENGTH_ID = 0x001A, + /** Enable/disable event logging. */ + ZB_ZCL_ATTR_DOOR_LOCK_ENABLE_LOGGING_ID = 0x0020, + /** Modifies the language for the on-screen or audible user interface using + * three bytes from ISO-639-1. */ + ZB_ZCL_ATTR_DOOR_LOCK_LANGUAGE_ID = 0x0021, + /** The settings for the LED support three different modes. */ + ZB_ZCL_ATTR_DOOR_LOCK_LED_SETTINGS_ID = 0x0022, + /** The number of seconds to wait after unlocking a lock before it automatically + * locks again. */ + ZB_ZCL_ATTR_DOOR_LOCK_AUTO_RELOCK_TIME_ID = 0x0023, + /** The sound volume on a door lock has three possible settings: silent, low + * and high volumes. */ + ZB_ZCL_ATTR_DOOR_LOCK_SOUND_VOLUME_ID = 0x0024, + /** @brief OperatingMode attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_OPERATING_MODE_ID = 0x0025, + /** @brief SupportedOperatingModes attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_OPERATION_MODES_SUPPORTED_ID = 0x0026, + /** This attribute represents the default configurations as they are physically + * set on the device (example: hardware dip switch setting, etc) and represents + * the default setting for some of the attributes within this Operational Setting + * Attribute Set (for example: LED, Auto Lock, Sound Volume, and Operating Mode + * attributes). */ + ZB_ZCL_ATTR_DOOR_LOCK_DEFAULT_CONFIGURATION_REGISTER_ID = 0x0027, + /** @brief EnableLocalProgramming attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_ENABLE_LOCAL_PROGRAMMING_ID = 0x0028, + /** Enable/disable the ability to lock the door lock with a single touch on + * the door lock. */ + ZB_ZCL_ATTR_DOOR_LOCK_ENABLE_ONE_TOUCH_LOCKING_ID = 0x0029, + /** Enable/disable an inside LED that allows the user to see at a glance + * if the door is locked. */ + ZB_ZCL_ATTR_DOOR_LOCK_ENABLE_INSIDE_STATUS_LED_ID = 0x002A, + /** Enable/disable a button inside the door that is used to put the lock + * into privacy mode. */ + ZB_ZCL_ATTR_DOOR_LOCK_ENABLE_PRIVACY_MODE_BUTTON_ID = 0x002B, + /** The number of incorrect codes or RFID presentment attempts a user + * is allowed to enter before the door will enter a lockout state. */ + ZB_ZCL_ATTR_DOOR_LOCK_WRONG_CODE_ENTRY_LIMIT_ID = 0x0030, + /** The number of seconds that the lock shuts down following wrong code entry. */ + ZB_ZCL_ATTR_DOOR_LOCK_USER_CODE_TEMPORARY_DISABLE_TIME_ID = 0x0031, + /** Boolean set to True if it is ok for the door lock server to send PINs + * over the air. */ + ZB_ZCL_ATTR_DOOR_LOCK_SEND_PIN_OVER_THE_AIR_ID = 0x0032, + /** @brief Require PIN for RF operation attribute */ + ZB_ZCL_ATTR_DOOR_LOCK_REQUIRE_PIN_RF_ID = 0x0033, + /** The Security Level attribute allows the door lock manufacturer to indicate + * what level of security the door lock requires. */ + ZB_ZCL_ATTR_DOOR_LOCK_SECURITY_LEVEL_ID = 0x0034, + /** The alarm mask is used to turn on/off alarms for particular functions */ + ZB_ZCL_ATTR_DOOR_LOCK_ALARM_MASK_ID = 0x0040, + /** Event mask used to turn on and off the transmission of keypad operation events. */ + ZB_ZCL_ATTR_DOOR_LOCK_KEYPAD_OPERATION_EVENT_MASK_ID = 0x0041, + /** Event mask used to turn on and off the transmission of RF operation events. */ + ZB_ZCL_ATTR_DOOR_LOCK_RF_OPERATION_EVENT_MASK_ID = 0x0042, + /** Event mask used to turn on and off manual operation events. */ + ZB_ZCL_ATTR_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_ID = 0x0043, + /** Event mask used to turn on and off RFID operation events. */ + ZB_ZCL_ATTR_DOOR_LOCK_RFID_OPERATION_EVENT_MASK_ID = 0x0044, + /** Event mask used to turn on and off keypad programming events. */ + ZB_ZCL_ATTR_DOOR_LOCK_KEYPAD_PROGRAMMING_EVENT_MASK_ID = 0x0045, + /** Event mask used to turn on and off RF programming events. */ + ZB_ZCL_ATTR_DOOR_LOCK_RF_PROGRAMMING_EVENT_MASK_ID = 0x0046, + /** Event mask used to turn on and off RFID programming events. */ + ZB_ZCL_ATTR_DOOR_LOCK_RFID_PROGRAMMING_EVENT_MASK_ID = 0x0047, +}; + + +/** @brief Values for LockState attribute + * @see ZCL spec, subclause 7.3.2.2.1 + */ +enum zb_zcl_door_lock_lock_state_e +{ + /*! "Not fully locked" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_NOT_FULLY_LOCKED = 0x00, + /*! "Locked" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_LOCKED = 0x01, + /*! "Unlocked" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_UNLOCKED = 0x02, + /*! "Not Defined" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_UNDEFINED = 0xff +}; + +/** @brief Default value for Lock State attribute. */ +#define ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_DEFAULT_VALUE ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_UNDEFINED + +/** @brief Values for LockType attribute + * @see ZCL spec, subclause 7.3.2.2.2 + */ +enum zb_zcl_door_lock_lock_type_e +{ + /*! "Deadbolt" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_DEADBOLT = 0x00, + /*! "Magnetic" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_MAGNETIC = 0x01, + /*! "Other" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_OTHER = 0x02, + /*! "Not Defined" value */ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_UNDEFINED = 0xff +}; + +/** @brief Default value for Lock Type attribute. */ +#define ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_DEFAULT_VALUE ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_UNDEFINED + +/** @brief Values for ActuatorEnabled attribute + * @see ZCL spec, subclause 7.3.2.2.3 + */ +enum zb_zcl_door_lock_actuator_enabled_e +{ + /*! "Disabled" value */ + ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_DISABLED = 0x0b0, + /*! "Enabled" value */ + ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ENABLED = 0x0b1 +}; + +/** @brief Default value for Actuator Enabled attribute. */ +#define ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_DEFAULT_VALUE \ + ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ENABLED + +/** @brief Values for DoorState attribute + * @see ZCL specx, subclause 7.3.2.2.4 + */ +enum zb_zcl_door_lock_door_state_e +{ + /*! "Open" value */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_OPEN = 0x00, + /*! "Closed" value */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_CLOSED = 0x01, + /*! "Error (jammed)" value */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_ERROR_JAMMED = 0x02, + /*! "Error (forced open)" value */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_ERROR_FORCED_OPEN = 0x03, + /*! "Error (unspecified)" value */ + ZB_ZCL_ATTR_DOOR_LOCK_DOOR_STATE_ERROR_UNSPECIFIED = 0x04 +}; + +/** @brief Declare attribute list for DoorLock cluster + @param attr_list - attribute list name + @param lock_state + @param lock_type + @param actuator_enabled +*/ +#define ZB_ZCL_DECLARE_DOOR_LOCK_ATTRIB_LIST(attr_list, \ + lock_state, \ + lock_type, \ + actuator_enabled) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_ID, (lock_state)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_ID, (lock_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ID, (actuator_enabled)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* DoorLock cluster attributes */ + +/*! @name DoorLock cluster commands + @{ +*/ + +/*! @brief DoorLock cluster commands + @see ZCL spec, subclause 7.3.2.3 Commands Received +*/ +enum zb_zcl_door_lock_cmd_e +{ + /** This command causes the lock device to lock the door. */ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR = 0x00, + /** This command causes the lock device to unlock the door. */ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR = 0x01, + /** Request the status of the lock. */ + ZB_ZCL_CMD_DOOR_LOCK_TOGGLE = 0x02, + /** This command causes the lock device to unlock the door with a timeout parameter. */ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_WITH_TIMEOUT = 0x03, + /** Request a log record. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_LOG_RECORD = 0x04, + /** Set a PIN into the lock. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE = 0x05, + /** Retrieve a PIN Code. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_PIN_CODE = 0x06, + /** Delete a PIN. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_PIN_CODE = 0x07, + /** Clear out all PINs on the lock. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_ALL_PIN_CODES = 0x08, + /** Set the status of a user ID. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_USER_STATUS = 0x09, + /** Get the status of a user. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_USER_STATUS = 0x0A, + /** Set a weekly repeating schedule for a specified user. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_WEEKDAY_SCHEDULE = 0x0B, + /** Retrieve the specific weekly schedule for the specific user. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_WEEKDAY_SCHEDULE = 0x0C, + /** Clear the specific weekly schedule for the specific user. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_WEEKDAY_SCHEDULE = 0x0D, + /** Set a time-specific schedule ID for a specified user. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_YEAR_DAY_SCHEDULE = 0x0E, + /** Retrieve the specific year day schedule for the specific user. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_YEAR_DAY_SCHEDULE = 0x0F, + /** Clears the specific year day schedule for the specific user. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_YEAR_DAY_SCHEDULE = 0x10, + /** Set the holiday Schedule by specifying local start time and local end time + * with respect to any Lock Operating Mode. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_HOLIDAY_SCHEDULE = 0x11, + /** Get the holiday Schedule by specifying Holiday ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_HOLIDAY_SCHEDULE = 0x12, + /** Clear the holiday Schedule by specifying Holiday ID. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_HOLIDAY_SCHEDULE = 0x13, + /** Set the type byte for a specified user. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_USER_TYPE = 0x14, + /** Retrieve the type byte for a specific user. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_USER_TYPE = 0x15, + /** Set an ID for RFID access into the lock. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_RFID_CODE = 0x16, + /** Retrieve an ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_RFID_CODE = 0x17, + /** Delete an ID. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_RFID_CODE = 0x18, + /** Clear out all RFIDs on the lock. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_ALL_RFID_CODES = 0x19, +}; + +/*! @brief DoorLock cluster commands response + @see ZCL spec, subclause 7.3.2.4 Commands Generated +*/ +enum zb_zcl_door_lock_cmd_resp_e +{ + /** This command is sent in response to a Lock command with one status byte payload. */ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR_RES = 0x00, + /** This command is sent in response to a Unlock command with one status byte payload. */ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR_RES = 0x01, + /** This command is sent in response to a Toggle command with one status byte payload. */ + ZB_ZCL_CMD_DOOR_LOCK_TOGGLE_RESPONSE = 0x02, + /** This command is sent in response to an Unlock with Timeout command + * with one status byte payload. */ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_WITH_TIMEOUT_RESPONSE = 0x03, + /** Returns the specified log record. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_LOG_RECORD_RESPONSE = 0x04, + /** Returns status of the PIN set command. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_PIN_CODE_RESPONSE = 0x05, + /** Returns the PIN for the specified user ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_PIN_CODE_RESPONSE = 0x06, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_PIN_CODE_RESPONSE = 0x07, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_ALL_PIN_CODES_RESPONSE = 0x08, + /** Returns the pass or fail value for the setting of the user status. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_USER_STATUS_RESPONSE = 0x09, + /** Returns the user status for the specified user ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_USER_STATUS_RESPONSE = 0x0A, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_WEEKDAY_SCHEDULE_RESPONSE = 0x0B, + /** Returns the weekly repeating schedule data for the specified schedule ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_WEEKDAY_SCHEDULE_RESPONSE = 0x0C, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_WEEKDAY_SCHEDULE_RESPONSE = 0x0D, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_YEAR_DAY_SCHEDULE_RESPONSE = 0x0E, + /** Returns the weekly repeating schedule data for the specified schedule ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_YEAR_DAY_SCHEDULE_RESPONSE = 0x0F, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_YEAR_DAY_SCHEDULE_RESPONSE = 0x10, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_HOLIDAY_SCHEDULE_RESPONSE = 0x11, + /** Returns the Holiday Schedule Entry for the specified Holiday ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_HOLIDAY_SCHEDULE_RESPONSE = 0x12, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_HOLIDAY_SCHEDULE_RESPONSE = 0x13, + /** Returns the pass or fail value for the setting of the user type. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_USER_TYPE_RESPONSE = 0x14, + /** Returns the user type for the specified user ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_USER_TYPE_RESPONSE = 0x15, + /** Returns status of the Set RFID Code command. */ + ZB_ZCL_CMD_DOOR_LOCK_SET_RFID_CODE_RESPONSE = 0x16, + /** Returns the RFID code for the specified user ID. */ + ZB_ZCL_CMD_DOOR_LOCK_GET_RFID_CODE_RESPONSE = 0x17, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_RFID_CODE_RESPONSE = 0x18, + /** Returns pass/fail of the command. */ + ZB_ZCL_CMD_DOOR_LOCK_CLEAR_ALL_RFID_CODES_RESPONSE = 0x19, + /** The door lock server sends out operation event notification when the + * event is triggered by the various event sources. */ + ZB_ZCL_CMD_DOOR_LOCK_OPERATION_EVENT_NOTIFICATION_ID = 0x20, + /** The door lock server sends out a programming event notification + * whenever a programming event takes place on the door lock. */ + ZB_ZCL_CMD_DOOR_LOCK_PROGRAMMING_EVENT_NOTIFICATION = 0x21, +}; + +enum zb_zcl_door_lock_operation_event_source_e +{ + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_SOURCE_KEYPAD = 0x00, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_SOURCE_RF = 0x01, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_SOURCE_MANUAL = 0x02, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_SOURCE_RFID = 0x03, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_SOURCE_INDETERMINATE = 0xFF, +}; + +/** @cond internals_doc */ +/* Door lock cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR_RES, \ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR_RES + +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_DOOR_LOCK_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR, \ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR + +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_DOOR_LOCK_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Default value for NumberOfLogRecordsSupported attribute */ +#define ZB_ZCL_DOOR_LOCK_NUMBER_OF_LOG_RECORDS_SUPPORTED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NumTotalUsers attribute */ +#define ZB_ZCL_DOOR_LOCK_NUM_TOTAL_USERS_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NumPINUsers attribute */ +#define ZB_ZCL_DOOR_LOCK_NUM_PIN_USERS_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NumberOfRFIDUsersSupported attribute */ +#define ZB_ZCL_DOOR_LOCK_NUMBER_OF_RFID_USERS_SUPPORTED_DEFAULT_VALUE ((zb_uint16_t)0) + +/** @brief Default value for NumWeekDaySchedulePerUser attribute */ +#define ZB_ZCL_DOOR_LOCK_NUM_WEEK_DAY_SCHEDULE_PER_USER_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for NumYearDaySchedulePerUser attribute */ +#define ZB_ZCL_DOOR_LOCK_NUM_YEAR_DAY_SCHEDULE_PER_USER_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for NumHolidaySchedule attribute */ +#define ZB_ZCL_DOOR_LOCK_NUM_HOLIDAY_SCHEDULE_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for MaxPINLen attribute */ +#define ZB_ZCL_DOOR_LOCK_MAX_PIN_LEN_DEFAULT_VALUE ((zb_uint8_t)0x08) + +/** @brief Default value for MinPINLen attribute */ +#define ZB_ZCL_DOOR_LOCK_MIN_PIN_LEN_DEFAULT_VALUE ((zb_uint8_t)0x04) + +/** @brief Default value for MaxRFIDCodeLength attribute */ +#define ZB_ZCL_DOOR_LOCK_MAX_RFID_CODE_LENGTH_DEFAULT_VALUE ((zb_uint8_t)0x14) + +/** @brief Default value for MinRFIDCodeLength attribute */ +#define ZB_ZCL_DOOR_LOCK_MIN_RFID_CODE_LENGTH_DEFAULT_VALUE ((zb_uint8_t)0x08) + +/** @brief Default value for EnableLogging attribute */ +#define ZB_ZCL_DOOR_LOCK_ENABLE_LOGGING_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for Language attribute */ +#define ZB_ZCL_DOOR_LOCK_LANGUAGE_DEFAULT_VALUE {0} + +/** @brief Default value for LEDSettings attribute */ +#define ZB_ZCL_DOOR_LOCK_LED_SETTINGS_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for AutoRelockTime attribute */ +#define ZB_ZCL_DOOR_LOCK_AUTO_RELOCK_TIME_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for SoundVolume attribute */ +#define ZB_ZCL_DOOR_LOCK_SOUND_VOLUME_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for OperatingMode attribute */ +#define ZB_ZCL_DOOR_LOCK_OPERATING_MODE_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for OperationModesSupported attribute */ +#define ZB_ZCL_DOOR_LOCK_OPERATION_MODES_SUPPORTED_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DefaultConfigurationRegister attribute */ +#define ZB_ZCL_DOOR_LOCK_DEFAULT_CONFIGURATION_REGISTER_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for EnableLocalProgramming attribute */ +#define ZB_ZCL_DOOR_LOCK_ENABLE_LOCAL_PROGRAMMING_DEFAULT_VALUE ((zb_bool_t)0x01) + +/** @brief Default value for EnableOneTouchLocking attribute */ +#define ZB_ZCL_DOOR_LOCK_ENABLE_ONE_TOUCH_LOCKING_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for EnableInsideStatusLED attribute */ +#define ZB_ZCL_DOOR_LOCK_ENABLE_INSIDE_STATUS_LED_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for EnablePrivacyModeButton attribute */ +#define ZB_ZCL_DOOR_LOCK_ENABLE_PRIVACY_MODE_BUTTON_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for WrongCodeEntryLimit attribute */ +#define ZB_ZCL_DOOR_LOCK_WRONG_CODE_ENTRY_LIMIT_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for UserCodeTemporaryDisableTime attribute */ +#define ZB_ZCL_DOOR_LOCK_USER_CODE_TEMPORARY_DISABLE_TIME_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for SendPINOverTheAir attribute */ +#define ZB_ZCL_DOOR_LOCK_SEND_PIN_OVER_THE_AIR_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for RequirePIN_RF_ID attribute */ +#define ZB_ZCL_DOOR_LOCK_REQUIRE_PIN_RF_ID_DEFAULT_VALUE ((zb_bool_t)0) + +/** @brief Default value for SecurityLevel attribute */ +#define ZB_ZCL_DOOR_LOCK_SECURITY_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for AlarmMask attribute */ +#define ZB_ZCL_DOOR_LOCK_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for KeypadOperationEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_KEYPAD_OPERATION_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RFOperationEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_RF_OPERATION_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for ManualOperationEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RFIDOperationEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_RFID_OPERATION_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for KeypadProgrammingEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_KEYPAD_PROGRAMMING_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RFProgrammingEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_RF_PROGRAMMING_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RFIDProgrammingEventMask attribute */ +#define ZB_ZCL_DOOR_LOCK_RFID_PROGRAMMING_EVENT_MASK_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +enum zb_zcl_door_lock_operation_event_code_e +{ + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_UNKNOWN = 0x00, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_LOCK = 0x01, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_UNLOCK = 0x02, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_KEY_LOCK = 0x08, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_KEY_UNLOCK = 0x09, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_MANUAL_LOCK = 0x0D, + ZB_ZCL_DOOR_LOCK_OPERATION_EVENT_CODE_MANUAL_UNLOCK = 0x0E, +}; + +enum zb_zcl_door_lock_keypad_operation_event_mask_e +{ + ZB_ZCL_DOOR_LOCK_KEYPAD_OPERATION_EVENT_MASK_UNKNOWN = (1l << 0), + ZB_ZCL_DOOR_LOCK_KEYPAD_OPERATION_EVENT_MASK_LOCK = (1l << 1), + ZB_ZCL_DOOR_LOCK_KEYPAD_OPERATION_EVENT_MASK_UNLOCK = (1l << 2), +}; + +enum zb_zcl_door_lock_rf_operation_event_mask_e +{ + ZB_ZCL_DOOR_LOCK_RF_OPERATION_EVENT_MASK_UNKNOWN = (1l << 0), + ZB_ZCL_DOOR_LOCK_RF_OPERATION_EVENT_MASK_LOCK = (1l << 1), + ZB_ZCL_DOOR_LOCK_RF_OPERATION_EVENT_MASK_UNLOCK = (1l << 2), +}; + +enum zb_zcl_door_lock_manual_operation_event_mask_e +{ + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_UNKNOWN = (1l << 0), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_THUMBTURN_LOCK = (1l << 1), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_THUMBTURN_UNLOCK = (1l << 2), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_KEY_LOCK = (1l << 4), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_KEY_UNLOCK = (1l << 5), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_MANUAL_LOCK = (1l << 9), + ZB_ZCL_DOOR_LOCK_MANUAL_OPERATION_EVENT_MASK_MANUAL_UNLOCK = (1l << 10), +}; + + +/*! @brief General macro for sending a "Door Lock" cluster command + @param buffer to put command payload and headers to + @param dst_addr address to send to + @param dst_addr_mode destination address mode + @param dst_ep destination endpoint + @param ep source endpoint + @param dis_default_resp "Disable default response" flag + @param cb command send status callback +*/ +#define ZB_ZCL_DOOR_LOCK_SEND_LOCK_DOOR_REQ(buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + dis_default_resp, \ + cb) \ + ZB_ZCL_SEND_CMD( buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + ZB_AF_HA_PROFILE_ID, \ + dis_default_resp, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR, \ + cb) + +/*! @brief General macro for sending a "Door Unlock" cluster command + @param buffer to put command payload and headers to + @param dst_addr address to send to + @param dst_addr_mode destination address mode + @param dst_ep destination endpoint + @param ep source endpoint + @param dis_default_resp "Disable default response" flag + @param cb command send status callback +*/ +#define ZB_ZCL_DOOR_LOCK_SEND_UNLOCK_DOOR_REQ(buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + dis_default_resp, \ + cb) \ + ZB_ZCL_SEND_CMD(buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + ZB_AF_HA_PROFILE_ID, \ + dis_default_resp, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR, cb) + +/*! @brief Door Lock command send response macro + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq_num - sequence number + @param status - result of command execute + @param aps_secured - APS security mode +*/ +#define ZB_ZCL_DOOR_LOCK_SEND_LOCK_DOOR_RES(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + seq_num, \ + status, \ + aps_secured) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_DOOR_LOCK_LOCK_DOOR_RES); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, status); \ + ZB_ZCL_FINISH_N_SEND_PACKET_NEW(buffer, \ + ptr, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + NULL, \ + aps_secured, \ + ZB_FALSE, \ + 0); \ +} + +/*! @brief Door Unlock command send response macro + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq_num - sequence number + @param status - result of command execute + @param aps_secured - APS security mode +*/ +#define ZB_ZCL_DOOR_LOCK_SEND_UNLOCK_DOOR_RES(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + seq_num, \ + status, \ + aps_secured) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_DOOR_LOCK_UNLOCK_DOOR_RES); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, status); \ + ZB_ZCL_FINISH_N_SEND_PACKET_NEW(buffer, \ + ptr, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + ZB_ZCL_CLUSTER_ID_DOOR_LOCK, \ + NULL, \ + aps_secured, \ + ZB_FALSE, \ + 0); \ +} + +/*! Door lock commands response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_door_lock_read_lock_door_res_payload_s +{ + zb_uint8_t status; /*!< Command execution status */ +} ZB_PACKED_STRUCT zb_zcl_door_lock_read_lock_door_res_payload_t; + +/*! @brief Door Lock response structured reading + @param buffer - ID of the message buffer (of type zb_bufid_t) containing payload + @return pointer to @ref zb_zcl_door_lock_read_lock_door_res_payload_s structure + @attention returned pointer will point to the same data in the buffer thus being valid until + buffer data will be overwritten. +*/ +#define ZB_ZCL_DOOR_LOCK_READ_LOCK_DOOR_RES(buffer) \ + ( (zb_buf_len((buffer)) != sizeof(zb_zcl_door_lock_read_lock_door_res_payload_t)) \ + ? NULL \ + : (zb_zcl_door_lock_read_lock_door_res_payload_t*)zb_buf_begin((buffer))) + +/*! Door unlock commands response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_door_lock_read_unlock_door_res_payload_s +{ + zb_uint8_t status; /*!< Command execution status */ +} ZB_PACKED_STRUCT zb_zcl_door_lock_read_unlock_door_res_payload_t; + +/*! @brief Door unLock response structured reading + @param buffer - ID of the message buffer (of type zb_buf_t) + containing payload + @return pointer to @ref zb_zcl_door_lock_read_unlock_door_res_payload_s structure + @attention returned pointer will point to the same data in the buffer thus + being valid until buffer data will be overwritten. +*/ +#define ZB_ZCL_DOOR_LOCK_READ_UNLOCK_DOOR_RES(buffer) \ + ( (zb_buf_len((buffer)) != sizeof(zb_zcl_door_lock_read_unlock_door_res_payload_t)) \ + ? NULL \ + : (zb_zcl_door_lock_read_unlock_door_res_payload_t*)zb_buf_begin((buffer))) + +/*! @} */ /* DoorLock cluster commands */ + +/*! @cond internals_doc + @internal @name DoorLock cluster internals + Internal structures for DoorLock cluster + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_STATE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ + } + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_DOOR_LOCK_LOCK_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ + } + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_DOOR_LOCK_ACTUATOR_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ + } + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_DOOR_LOCK_RF_OPERATION_EVENT_MASK_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_DOOR_LOCK_RF_OPERATION_EVENT_MASK_ID, \ + ZB_ZCL_ATTR_TYPE_16BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ + } + +/*! @internal @brief Number of attributes mandatory for reporting in Door Lock cluster */ +#define ZB_ZCL_DOOR_LOCK_REPORT_ATTR_COUNT 1 + +/*! @} + @endcond */ /* DoorLock cluster internals */ + +/*! @} */ /* ZCL DoorLock cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_door_lock_init_server(void); +void zb_zcl_door_lock_init_client(void); +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_SERVER_ROLE_INIT zb_zcl_door_lock_init_server +#define ZB_ZCL_CLUSTER_ID_DOOR_LOCK_CLIENT_ROLE_INIT zb_zcl_door_lock_init_client + +#endif /* ZB_ZCL_DOOR_LOCK_H */ diff --git a/zboss/include/zcl/zb_zcl_drlc.h b/zboss/include/zcl/zb_zcl_drlc.h new file mode 100644 index 0000000000..3ebb11f15d --- /dev/null +++ b/zboss/include/zcl/zb_zcl_drlc.h @@ -0,0 +1,677 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Demand Response and Load Control cluster defintions +*/ + +#ifndef ZB_ZCL_DRLC_H_ +#define ZB_ZCL_DRLC_H_ + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_DRLC + * @{ + * @details This cluster provides an interface to the functionality of Smart + * Energy Demand Response and Load Control. + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_DRLC */ + +/** @defgroup ZB_ZCL_DRLC_ATTRS_AND_ENUMS DRLC attributes and enumerations + * @{ + * @details + * This section describes DRLC client attributes and common cluster enumerations. + */ + +/** DRLC Client attributes. @see SE spec, subclause D.2.3.2 */ +typedef enum zb_zcl_drlc_cli_attr_e +{ + ZB_ZCL_ATTR_DRLC_UTILITY_ENROLLMENT_GROUP = 0x0000, /**< UtilityEnrollmentGroup attribute. + * Provides for utilites to assing devices to groups. + */ + + ZB_ZCL_ATTR_DRLC_START_RANDOMIZATION_MINUTES = 0x0001, /**< StartRandomizationMinutes attribute. + * Represents the maximum number of minutes to be used + * when randomizing the start of an event. + */ + + ZB_ZCL_ATTR_DRLC_DURATION_RANDOMIZATION_MINUTES = 0x0002, /**< DurationRandomizationMinutes attribute. + * Represents the maximum number of minutes to be used + * when randomizing the duration of an event. + */ + + ZB_ZCL_ATTR_DRLC_DEVICE_CLASS_VALUE = 0x0003, /**< DeviceClassValue attribute. + * Identifies which bits the device will match in the + * Device Class fields. + */ +} zb_zcl_drlc_cli_attr_t; + + +/** Criticality Level value applied by the device. + * @see SE spe, Table D-3 + */ +typedef enum zb_zcl_drlc_criticality_levels_e +{ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_0 = 0x00, /**< Reserved */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_1, /**< Green */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_2, /**< Level 1 */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_3, /**< Level 2 */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_4, /**< Level 3 */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_5, /**< Level 4 */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_6, /**< Level 5 */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_7, /**< Emergency */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_8, /**< Planned Outage */ + ZB_ZCL_DRLC_CRITICALITY_LEVEL_9 /**< Service Disconnect */ +} zb_zcl_drlc_criticality_levels_t; + +/** DRLC device classes enumeration. + * @see SE spec, Table D-2. + */ +typedef enum zb_zcl_drlc_device_class_e +{ + ZB_ZCL_DRLC_DEVICE_CLASS_HVAC = 1 << 0, /**< HVAC Compressor or Furnace */ + ZB_ZCL_DRLC_DEVICE_CLASS_STRIP_HEATER = 1 << 1, /**< Strip Heaters/Baseboard Heaters */ + ZB_ZCL_DRLC_DEVICE_CLASS_WATER_HEATER = 1 << 2, /**< Water Heater */ + ZB_ZCL_DRLC_DEVICE_CLASS_POOL_PUMP = 1 << 3, /**< Pool Pump/Spa/Jacuzzi */ + ZB_ZCL_DRLC_DEVICE_CLASS_SMART_APPLIANCE = 1 << 4, /**< Smart Appliances */ + ZB_ZCL_DRLC_DEVICE_CLASS_IRRIGATION_PUMP = 1 << 5, /**< Irrigation Pump */ + ZB_ZCL_DRLC_DEVICE_CLASS_MCI_LOADS = 1 << 6, /**< Managed Commercial & Industrial (C&I) loads */ + ZB_ZCL_DRLC_DEVICE_CLASS_SIMPLE_LOADS = 1 << 7, /**< Simple misc. (Residential On/Off) loads */ + ZB_ZCL_DRLC_DEVICE_CLASS_EXTERIOR_LIGHTNING = 1 << 8, /**< Exterior Lighting */ + ZB_ZCL_DRLC_DEVICE_CLASS_INTERIOR_LIGHTNING = 1 << 9, /**< Interior Lighting */ + ZB_ZCL_DRLC_DEVICE_CLASS_ELECTRIC_VEHICLE = 1 << 10, /**< Electric Vehicle */ + ZB_ZCL_DRLC_DEVICE_CLASS_GENERATION_SYSTEMS = 1 << 11 /**< Generation Systems */ +} zb_zcl_drlc_device_class_t; + +/** DRLC Event Status enum + * @see SE spec, Table D-9 + */ +typedef enum zb_zcl_drlc_event_status_e +{ + ZB_ZCL_DRLC_EVENT_RESERVED_00 = 0x00, /**< Reserved for future use. */ + ZB_ZCL_DRLC_EVENT_LCE_RECEIVED, /**< Load Control Event command received */ + ZB_ZCL_DRLC_EVENT_EVENT_STARTED, /**< Event started */ + ZB_ZCL_DRLC_EVENT_EVENT_COMPLETED, /**< Event completed */ + ZB_ZCL_DRLC_EVENT_OPT_OUT, /**< User has chosen to “Opt-Out”, user will not participate in this event */ + ZB_ZCL_DRLC_EVENT_OPT_IN, /**< User has chosen to “Opt-In”, user will participate in this event */ + ZB_ZCL_DRLC_EVENT_EVENT_CANCELLED, /**< The event has been cancelled */ + ZB_ZCL_DRLC_EVENT_EVENT_SUPERSEDED, /**< The event has been superseded */ + ZB_ZCL_DRLC_EVENT_EVENT_PARTIALLY_OPT_OUT, /**< Event partially completed with User “Opt-Out”. */ + ZB_ZCL_DRLC_EVENT_EVENT_PARTIALLY_OPT_IN, /**< Event partially completed due to User “Opt-In”. */ + ZB_ZCL_DRLC_EVENT_EVENT_COMPLETED_NO_USER, /**< Event completed, no User participation (Previous “Opt-Out”). */ + ZB_ZCL_DRLC_EVENT_RESERVED_0B, /**< Reserved for future use. */ + ZB_ZCL_DRLC_EVENT_RESERVED_F7 = 0xF7, /**< Reserved for future use. */ + ZB_ZCL_DRLC_EVENT_REJECTED_INVALID_CANCEL_CMD, /**< Rejected - Invalid Cancel Command (Default) */ + ZB_ZCL_DRLC_EVENT_REJECTED_INVALID_EFFECTIVE_TIME, /**< Rejected - Invalid Cancel Command (Invalid Effective Time) */ + ZB_ZCL_DRLC_EVENT_RESERVED_FA, /**< Reserved */ + ZB_ZCL_DRLC_EVENT_REJECTED_EXPIRED, /**< Rejected - Event was received after it had expired@n (Current Time > Start Time + Duration) */ + ZB_ZCL_DRLC_EVENT_RESERVED_FC, /**< Reserved for future use. */ + ZB_ZCL_DRLC_EVENT_REJECTED_UNDEFINED_EVENT, /**< Rejected - Invalid Cancel Command (Undefined Event) */ + ZB_ZCL_DRLC_EVENT_REJECTED, /**< Load Control Event command Rejected */ + ZB_ZCL_DRLC_EVENT_RESERVED_FF /**< Reserved for future use. */ +} zb_zcl_drlc_event_status_t; + +/** DRLC signature type enum */ +typedef enum zb_zcl_drlc_signature_type_e +{ + ZB_ZCL_DRLC_LCE_NO_SIGNATURE = 0x00, /**< No Signature */ + ZB_ZCL_DRLC_LCE_SIGNATURE_ECDSA, /**< ECDSA */ + ZB_ZCL_DRLC_LCE_SIGNATURE_RESERVED /**< Reserved */ +} zb_zcl_drlc_signature_type_t; + +/** @} */ /* ZB_ZCL_DRLC_ATTRS_AND_ENUMS */ + + +/** @defgroup ZB_ZCL_DRLC_COMMANDS_STRUCTURES_AND_DEFINITIONS DRLC commands + * @{ + * @details + * This section describes all commands structures and data payloads. + */ + + +/** Commands are generated by DRLC Server. + * @see SE spec, Table D-1 + */ +typedef enum zb_zcl_drlc_srv_cmd_e +{ + ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT = 0x00, /**< LoadControlEvent is generated when the ESI wants to control one or more + * load control devices usually as the result of an energy curtailment + * command from the Smart Energy Network. + * @see zb_zcl_drlc_lce_payload_s + */ + + ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT = 0x01, /**< CancelLoadControlEvent is generated when the ESI wants to cancel + * previously scheduled control of one or more load control devices, usually + * as the result of an energy curtailment command from the Smart Energy + * Network + * @see zb_zcl_drlc_cancel_lce_payload_s + */ + + ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS = 0x02, /**< CancellAllLoadControlEvents is generated when the ESI wants to cancel all + * events for control device(s) + */ +} zb_zcl_drlc_srv_cmd_t; + + +/** Commands are generated by DRLC Client. + * @see SE spec, Table D-8 + */ +typedef enum zb_zcl_drlc_cli_cmd_e +{ + ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS = 0x00, /**< ReportEventStatus is generated when the client device detects a change of + * state for an active LoadControl event. + * @see zb_zcl_drlc_report_event_status_payload_s + */ + + ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS = 0x01, /**< GetScheduledEvents is generated when the client device wishes to verify + * the available LoadControl events. + * @see zb_zcl_drlc_get_scheduled_events_payload_s + */ +} zb_zcl_drlc_cli_cmd_t; + +/** @cond internals_doc */ +/* DRLC cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_DRLC_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT, \ + ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT, \ + ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS + +#define ZB_ZCL_CLUSTER_ID_DRLC_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_DRLC_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_DRLC_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS, \ + ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS + +#define ZB_ZCL_CLUSTER_ID_DRLC_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_DRLC_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/* Payload description */ + +/** @ref ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT "LoadControlEvent" command payload. + * @see SE spec, Figure D-2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_drlc_lce_payload_s { + + /** Unique identifier generated by the Energy provider. + * The value of this field allows matching of Event reports + * with a specific Demand Response and Load Control event. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** Bit encoded field representing the Device Class to apply the + * current Load Control Event. Each bit, if set individually or + * in combination, indicates the class device(s) needing to + * participate in the event. + */ + zb_uint16_t device_class; /* (M) */ + + /** This field can be used in conjunction with the Device Class bits + * for providing a mechanism to direct Load Control Events + * to groups of Devices. + */ + zb_uint8_t utility_enrollment_group; /* (M) */ + + /** UTC Timestamp representing when the event is scheduled to start. + * A start time of 0x00000000 is a special time denoting “now.” + */ + zb_uint32_t start_time; /* (M) */ + + /** Duration of this event in number of minutes. + * Maximum value is 1440 (one day). + */ + zb_uint16_t duration_in_minutes; /* (M) */ + + /** This field defines the level of criticality of event. The + * action for an event can be solely based on this value, + * or combination with other Load Control Event fields. + */ + zb_uint8_t criticality_level; /* (M) */ + + /** Requested offset to apply to the normal cooling setpoint + * at the time of the start of the event in + 0.1 Celsius. + */ + zb_uint8_t cooling_temperature_offset; /* (O) - use 0xff if optional */ + + /** Requested offset to apply to the normal heating setpoint + * at the time of the start of the event in + 0.1 Celsius. + */ + zb_uint8_t heating_temperature_offset; /* (O) - use 0xff if optional */ + + /** Requested cooling set point in 0.01 degrees Celsius. */ + zb_int16_t cooling_temperature_set_point; /* (O) - use 0x8000 if optional */ + + /** Requested heating set point in 0.01 degrees Celsius. */ + zb_int16_t heating_temperature_set_point; /* (O) - use 0x8000 if optional */ + + /** Defines a maximum energy usage limit as a percentage of + * the client implementations specific average energy usage. + */ + zb_int8_t average_load_adjustment_percentage; /* (O) */ + + /** Defines the maximum on state duty cycle as a percentage of time. */ + zb_uint8_t duty_cycle; /* (O) */ + + /** Identifies additional control options for the event. */ + zb_uint8_t event_control; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_drlc_lce_payload_t; + + +/** @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT "CancelLoadControlEvent" command payload + * @see SE spec, Figure D-3 + */ +typedef ZB_PACKED_PRE struct zb_zcl_drlc_cancel_lce_payload_s { + /* Mandatory fields. */ + + /** Unique identifier generated by the Energy provider. The value of + * this field allows matching of Event reports with a specific Demand Response + * and Load Control event. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** Bit encoded field representing the Device Class to apply the + * current Load Control Event. Each bit, if set individually or in combination, + * indicates the class device(s) needing to participate in the event. + */ + zb_uint16_t device_class; /* (M) */ + + /** This field can be used in conjunction with the Device Class bits + * for providing a mechanism to direct Load Control Events + * to groups of Devices. + */ + zb_uint8_t utility_enrollment_group; /* (M) */ + + /** This field is used to indicate that the Event is currently in process and + * a cancel command is received.*/ + zb_uint8_t cancel_control; /* (M) */ + + /** UTC Timestamp representing when the canceling of the event is + * scheduled to start. An effective time of 0x00000000 is a special + * time denoting “now.” + */ + zb_uint32_t effective_time; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_drlc_cancel_lce_payload_t; + +/** @ref ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS "ReportEventStatus" command payload + * @see SE spec, Figure D-5 + */ +typedef ZB_PACKED_PRE struct zb_zcl_drlc_report_event_status_payload_s { + /* Mandatory fields. */ + + /** Unique identifier generated by the Energy provider. The value of + * this field allows matching of Event reports with a specific Demand Response + * and Load Control event. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** This field stores value from set of event statuses*/ + zb_uint8_t event_status; /* (M) */ + + /** UTC Timestamp representing when the event status + * occurred. This field shall not use the value of 0x00000000. + */ + zb_uint32_t event_status_time; /* (M) */ + + /** Criticality Level value applied by the device */ + zb_uint8_t criticality_level_applied; /* (M) */ + + /** Defines Cooling Temperature Set Point value applied by the device. + * The value 0x8000 means that this field has not been used by the end device. + */ + zb_uint16_t cooling_temperature_set_point_applied; /* (O) */ + + /** Defines Heating Temperature Set Point value applied by the device. + * The value 0x8000 means that this field has not been used by + * the end device. + */ + zb_uint16_t heating_temperature_set_point_applied; /* (O) */ + + /** Defines Average Load Adjustment Percentage value applied by the device. + * The value 0x80 means that this field has not been used by the end device. + */ + zb_int8_t average_load_adjustment_percentage_applied; /* (O) */ + + /** Defines the maximum on state duty cycle applied by the device. + * The value 0xFF means that this field has not been used by the end device. + */ + zb_uint8_t duty_cycle_applied; /* (O) */ + + /** Identifies additional control options for the event. */ + zb_uint8_t event_control; /* (M) */ + + /** This field is used to enumerate the type of algorithm use to create the signature.*/ + zb_uint8_t signature_type; /* (M) */ + + /** A non-repudiation signature created by using the Matyas-Meyer-Oseas + * hash function used in conjunction with ECDSA. + */ + zb_uint8_t signature[42]; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_drlc_report_event_status_payload_t; + + +/** @ref ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS "GetScheduledEvents" command payload + * @see SE spec, Figure D-6 + */ +typedef ZB_PACKED_PRE struct zb_zcl_drlc_get_scheduled_events_payload_s { + /* Mandatory fields. */ + + /** UTC Timestamp representing the minimum Start Time of events that shall be + * matched and sent by the Server. A Start Time of 0x00000000 has no special + * meaning. + */ + zb_uint32_t start_time; /* (M) */ + + /** Represents the maximum number of events to be sent. A value of 0 indicates + * no maximum limit. + */ + zb_uint8_t number_of_events; /* (M) */ + + /** Represents the minimum Issuer Event ID of events to be matched and sent + * by the server with the same Start Time as the Get Scheduled Events command. + * A value of 0xFFFFFFFF indicates this field will not be used. + */ + zb_uint32_t issuer_event_id; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_drlc_get_scheduled_events_payload_t; + + +/** Initialize @ref ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT "LoadControlEvent" command @ref zb_zcl_drlc_lce_payload_t payload*/ +#define ZB_ZCL_DRLC_LCE_PAYLOAD_INIT \ + (zb_zcl_drlc_lce_payload_t) \ +{ \ + .cooling_temperature_offset = 0xFF, \ + .heating_temperature_offset = 0xFF, \ + .cooling_temperature_set_point = (zb_int16_t) 0x8000, \ + .heating_temperature_set_point = (zb_int16_t) 0x8000, \ + .average_load_adjustment_percentage = (zb_int8_t) 0x80, \ + .duty_cycle = 0xFF, \ +} + +/** Initialize @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT "CancelLoadControlEvent" command @ref zb_zcl_drlc_cancel_lce_payload_t payload */ +#define ZB_ZCL_DRLC_CANCEL_LCE_PAYLOAD_INIT \ + (zb_zcl_drlc_cancel_lce_payload_t) {0} + +/** Initialize @ref ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS "ReportEventStatus" command @ref zb_zcl_drlc_report_event_status_payload_t payload */ +#define ZB_ZCL_DRLC_REPORT_EVENT_STATUS_PAYLOAD_INIT \ + (zb_zcl_drlc_report_event_status_payload_t) \ +{ \ + .cooling_temperature_set_point_applied = (zb_uint16_t) 0x8000, \ + .heating_temperature_set_point_applied = (zb_uint16_t) 0x8000, \ + .average_load_adjustment_percentage_applied = (zb_int8_t) 0x80, \ + .duty_cycle_applied = (zb_uint8_t) 0xFF, \ + .signature = \ + { \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + }, \ +} + +/** Initialize @ref ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS "GetScheduledEvents" command @ref zb_zcl_drlc_get_scheduled_events_payload_t payload */ +#define ZB_ZCL_DRLC_CMD_GET_SCHEDULED_EVENTS_PAYLOAD_INIT \ + (zb_zcl_drlc_get_scheduled_events_payload_t) \ +{ \ + .issuer_event_id = 0xFFFFFFFF, \ +} + + +/** Function for send @ref ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT "LoadControlEvent" command. + * On sender's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with @ref ZB_ZCL_DRLC_GET_SCHEDULED_EVENTS_CB_ID + * callback id on reception of @ref ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS "GetScheduledEvents" command. + * @n On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_DRLC_LOAD_CONTROL_EVENT_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_drlc_lce_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Handle @ref ZB_ZCL_DRLC_GET_SCHEDULED_EVENTS_CB_ID + * @snippet se/energy_service_interface/se_esi_zc.c handle_get_scheduled_events + * @n Example of sending @ref ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT "LoadControlEvent" command + * @snippet se/energy_service_interface/se_esi_zc.c esi_dev_cmd_send_lce_event1 + */ +zb_void_t zb_drlc_server_send_load_control_event(zb_uint8_t param, + zb_addr_u *dst_addr, zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_zcl_drlc_lce_payload_t *payload, zb_callback_t cb); + + +/** Function for send @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT "CancelLoadControlEvent" command. + * On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_DRLC_CANCEL_LOAD_CONTROL_EVENT_CB_ID + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_drlc_cancel_lce_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Example of sending @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT "CancelLoadControlEvent" command + * @snippet se/energy_service_interface/se_esi_zc.c esi_dev_cmd_send_lce_event2 + */ +zb_void_t zb_drlc_server_send_cancel_load_control_event(zb_uint8_t param, + zb_addr_u *dst_addr, zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_zcl_drlc_cancel_lce_payload_t *payload, zb_callback_t cb); + + +/** Function for send @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS "CancellAllLoadControlEvents" command. + * On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_DRLC_CANCEL_ALL_LOAD_CONTROL_EVENTS_CB_ID + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload: pointer to zb_uint8_t, where + * "Cancel Control" field value is placed (see SE spec, D.2.2.3.3.1). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Example of sending @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS "CancellAllLoadControlEvents" command + * @snippet se/energy_service_interface/se_esi_zc.c esi_dev_cmd_send_lce_event3 + */ +zb_void_t zb_drlc_server_send_cancel_all_load_control_events(zb_uint8_t param, + zb_addr_u *dst_addr, zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_uint8_t *payload, zb_callback_t cb); + + +/** Function for send @ref ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS "ReportEventStatus" command. + * On sender's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with one of @ref ZB_ZCL_DRLC_LOAD_CONTROL_EVENT_CB_ID, + * @ref ZB_ZCL_DRLC_CANCEL_LOAD_CONTROL_EVENT_CB_ID, @ref ZB_ZCL_DRLC_CANCEL_ALL_LOAD_CONTROL_EVENTS_CB_ID + * callback ids on reception of @ref ZB_ZCL_DRLC_SRV_CMD_LOAD_CONTROL_EVENT "LoadControlEvent", + * @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_LOAD_CONTROL_EVENT "CancelLoadControlEvent", + * @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS "CancellAllLoadControlEvents" commands respectively. + * @n On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_DRLC_REPORT_EVENT_STATUS_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_drlc_report_event_status_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Handle @ref ZB_ZCL_DRLC_SRV_CMD_CANCEL_ALL_LOAD_CONTROL_EVENTS "CancellAllLoadControlEvents" command + * @snippet se/in_home_display/se_ihd_zr.c ihd_handle_cancel_all_load_control_events + * @n Example of sending @ref ZB_ZCL_DRLC_CLI_CMD_REPORT_EVENT_STATUS "ReportEventStatus" command + * @snippet se/in_home_display/se_ihd_zr.c ihd_send_report_event_status + */ +zb_void_t zb_drlc_client_send_report_event_status(zb_uint8_t param, + zb_addr_u *dst_addr, zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_zcl_drlc_report_event_status_payload_t *payload, zb_callback_t cb); + + +/** Function for send @ref ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS "GetScheduledEvents" command. + * On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_DRLC_GET_SCHEDULED_EVENTS_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_drlc_get_scheduled_events_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Example of sending @ref ZB_ZCL_DRLC_CLI_CMD_GET_SCHEDULED_EVENTS "GetScheduledEvents" + * @snippet se/in_home_display/se_ihd_zr.c ihd_dev_cmd_get_scheduled_events + */ +zb_void_t zb_drlc_client_send_get_scheduled_events(zb_uint8_t param, + zb_addr_u *dst_addr, zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_zcl_drlc_get_scheduled_events_payload_t *payload, zb_callback_t cb); + +/** Macro for call @ref zb_drlc_server_send_load_control_event function + */ +#define ZB_ZCL_DRLC_SEND_CMD_LOAD_CONTROL_EVENT(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload ) \ + zb_drlc_server_send_load_control_event(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_drlc_server_send_cancel_load_control_event function + */ +#define ZB_ZCL_DRLC_SEND_CMD_CANCEL_LCE(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload ) \ + zb_drlc_server_send_cancel_load_control_event(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_drlc_server_send_cancel_all_load_control_events function + */ +#define ZB_ZCL_DRLC_SEND_CMD_CANCEL_ALL_LCE(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload ) \ + zb_drlc_server_send_cancel_all_load_control_events(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_drlc_client_send_get_scheduled_events function + */ +#define ZB_ZCL_DRLC_SEND_CMD_GET_SCHEDULED_EVENTS(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload ) \ + zb_drlc_client_send_get_scheduled_events(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_drlc_client_send_report_event_status function + */ +#define ZB_ZCL_DRLC_SEND_CMD_REPORT_EVENT_STATUS( _param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload ) \ + zb_drlc_client_send_report_event_status(_param, \ + _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + + +/** @} */ /* ZB_ZCL_DRLC_COMMANDS_STRUCTURES_AND_DEFINITIONS */ + +/** @brief Declare attribute list for DRLC cluster + * @param[in] attr_list - attribute list variable name + * @param[in] utility_enrollment_group - pointer to variable to store @ref ZB_ZCL_ATTR_DRLC_UTILITY_ENROLLMENT_GROUP value + * @param[in] start_randomization_munutes - pointer to variable to store @ref ZB_ZCL_ATTR_DRLC_START_RANDOMIZATION_MINUTES value + * @param[in] duration_randomization_minutes - pointer to variable to store @ref ZB_ZCL_ATTR_DRLC_DURATION_RANDOMIZATION_MINUTES value + * @param[in] device_class - pointer to variable to store @ref ZB_ZCL_ATTR_DRLC_DEVICE_CLASS_VALUE value + */ + #define ZB_ZCL_DECLARE_DRLC_ATTRIB_LIST(attr_list, utility_enrollment_group, \ + start_randomization_munutes, duration_randomization_minutes, device_class) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC_M(ZB_ZCL_ATTR_DRLC_UTILITY_ENROLLMENT_GROUP, (utility_enrollment_group), ZB_ZCL_ATTR_TYPE_8BIT, ZB_ZCL_ATTR_ACCESS_READ_WRITE) \ + ZB_ZCL_SET_ATTR_DESC_M(ZB_ZCL_ATTR_DRLC_START_RANDOMIZATION_MINUTES, (start_randomization_munutes), ZB_ZCL_ATTR_TYPE_8BIT, ZB_ZCL_ATTR_ACCESS_READ_WRITE) \ + ZB_ZCL_SET_ATTR_DESC_M(ZB_ZCL_ATTR_DRLC_DURATION_RANDOMIZATION_MINUTES, (duration_randomization_minutes), ZB_ZCL_ATTR_TYPE_8BIT, ZB_ZCL_ATTR_ACCESS_READ_WRITE) \ + ZB_ZCL_SET_ATTR_DESC_M(ZB_ZCL_ATTR_DRLC_DEVICE_CLASS_VALUE, (device_class), ZB_ZCL_ATTR_TYPE_16BIT, ZB_ZCL_ATTR_ACCESS_READ_WRITE) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + + +/** Initialize @ref zb_zcl_drlc_client_attrs_s DRLC cluster's attributes */ +#define ZB_ZCL_DECLARE_DRLC_ATTR_LIST_INIT \ + (zb_zcl_drlc_client_attrs_t) \ + { .utility_enrollment_group = 0, \ + .start_randomization_munutes = 0x1e, \ + .duration_randomization_minutes = 0, } + + +/** + * @brief DRLC client cluster attributes + */ +typedef struct zb_zcl_drlc_client_attrs_s +{ + /** @copydoc ZB_ZCL_ATTR_DRLC_UTILITY_ENROLLMENT_GROUP + * @see ZB_ZCL_ATTR_DRLC_UTILITY_ENROLLMENT_GROUP + */ + zb_uint8_t utility_enrollment_group; + + /** @copydoc ZB_ZCL_ATTR_DRLC_START_RANDOMIZATION_MINUTES + * @see ZB_ZCL_ATTR_DRLC_START_RANDOMIZATION_MINUTES + */ + zb_uint8_t start_randomization_munutes; + + /** @copydoc ZB_ZCL_ATTR_DRLC_DURATION_RANDOMIZATION_MINUTES + * @see ZB_ZCL_ATTR_DRLC_DURATION_RANDOMIZATION_MINUTES + */ + zb_uint8_t duration_randomization_minutes; + + /** @copydoc ZB_ZCL_ATTR_DRLC_DEVICE_CLASS_VALUE + * @see ZB_ZCL_ATTR_DRLC_DEVICE_CLASS_VALUE + */ + zb_uint16_t device_class_value; +} zb_zcl_drlc_client_attrs_t; + + +/** @brief Declare attribute list for DRLC cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - variable of @ref zb_zcl_drlc_client_attrs_t type (containing DRLC cluster attributes) + */ +#define ZB_ZCL_DECLARE_DRLC_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_DRLC_ATTRIB_LIST(attr_list, &attrs.utility_enrollment_group, \ + &attrs.start_randomization_munutes, &attrs.duration_randomization_minutes, \ + &attrs.device_class_value) + +/** @} */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ +/** Internal handler for DRLC Cluster commands */ + +zb_void_t zb_zcl_drlc_init_server(void); +zb_void_t zb_zcl_drlc_init_client(void); +#define ZB_ZCL_CLUSTER_ID_DRLC_SERVER_ROLE_INIT zb_zcl_drlc_init_server +#define ZB_ZCL_CLUSTER_ID_DRLC_CLIENT_ROLE_INIT zb_zcl_drlc_init_client + +#endif /* ZB_ZCL_DRLC_H_ */ diff --git a/zboss/include/zcl/zb_zcl_el_measurement.h b/zboss/include/zcl/zb_zcl_el_measurement.h new file mode 100644 index 0000000000..34cf37d5c7 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_el_measurement.h @@ -0,0 +1,891 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Electrical Measurement cluster defintions +*/ + +#if ! defined ZB_ZCL_ELECTRICAL_MEASUREMENT_H +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Cluster ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT */ + +/*! @addtogroup ZB_ZCL_ELECTRICAL_MEASUREMENT + @{ + @name Electrical Measurement cluster attributes + @{ +*/ + +/*! @brief Electrical Measurement cluster attribute identifiers + @see HA spec, subclause 9.2.2.2 +*/ +enum zb_zcl_electrical_measurement_attr_e +{ + /** This attribute indicates a device s measurement capabilities. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID = 0x0000, + /** The DCVoltage attribute represents the most recent DC voltage reading in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_ID = 0x0100, + /** The DCVoltageMin attribute represents the lowest DC voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MIN_ID = 0x0101, + /** The DCVoltageMax attribute represents the highest DC voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MAX_ID = 0x0102, + /** The DCCurrent attribute represents the most recent DC current reading in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_ID = 0x0103, + /** The DCCurrentMin attribute represents the lowest DC current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MIN_ID = 0x0104, + /** The DCCurrentMax attribute represents the highest DC current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MAX_ID = 0x0105, + /** The @e DCPower attribute represents the most recent DC power reading in @e Watts (W) */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DCPOWER_ID = 0x0106, + /** The DCPowerMin attribute represents the lowest DC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MIN_ID = 0x0107, + /** The DCPowerMax attribute represents the highest DC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MAX_ID = 0x0108, + /** The DCVoltageMultiplier provides a value to be multiplied against the DCVoltage, + * DCVoltageMin, and DCVoltageMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MULTIPLIER_ID = 0x0200, + /** The DCVoltageDivisor provides a value to be divided against the DCVoltage, + * DCVoltageMin, and DCVoltageMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_DIVISOR_ID = 0x0201, + /** The DCCurrentMultiplier provides a value to be multiplied against the DCCurrent, + * DCCurrentMin, and DCCurrentMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_MULTIPLIER_ID = 0x0202, + /** The DCCurrentDivisor provides a value to be divided against the DCCurrent, + * DCCurrentMin, and DCCurrentMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_DIVISOR_ID = 0x0203, + /** The DCPowerMultiplier provides a value to be multiplied against the DCPower, + * DCPowerMin, and DCPowerMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_MULTIPLIER_ID = 0x0204, + /** The DCPowerDivisor provides a value to be divided against the DCPower, + * DCPowerMin, and DCPowerMax attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_POWER_DIVISOR_ID = 0x0205, + /** The ACFrequency attribute represents the most recent AC Frequency reading in Hertz (Hz). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_ID = 0x0300, + /** The ACFrequencyMin attribute represents the lowest AC Frequency value measured in Hertz (Hz). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MIN_ID = 0x0301, + /** The ACFrequencyMax attribute represents the highest AC Frequency value measured in Hertz (Hz). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MAX_ID = 0x0302, + /** The NeutralCurrent attribute represents the AC neutral (Line-Out) current value + * at the moment in time the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_NEUTRAL_CURRENT_ID = 0x0303, + /** Active power represents the current demand of active power delivered or + * received at the premises, in @e kW */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_TOTAL_ACTIVE_POWER_ID = 0x0304, + /** Reactive power represents the current demand of reactive power delivered or + * received at the premises, in kVAr. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_TOTAL_REACTIVE_POWER_ID = 0x0305, + /** Represents the current demand of apparent power, in @e kVA */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_TOTAL_APPARENT_POWER_ID = 0x0306, + /** Attribute represent the most recent 1st harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED1ST_HARMONIC_CURRENT_ID = 0x0307, + /** Attribute represent the most recent 3rd harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED3RD_HARMONIC_CURRENT_ID = 0x0308, + /** Attribute represent the most recent 5th harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED5TH_HARMONIC_CURRENT_ID = 0x0309, + /** Attribute represent the most recent 7th harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED7TH_HARMONIC_CURRENT_ID = 0x030a, + /** Attribute represent the most recent 9th harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED9TH_HARMONIC_CURRENT_ID = 0x030b, + /** Attribute represent the most recent 11th harmonic current reading in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED11TH_HARMONIC_CURRENT_ID = 0x030c, + /** Attribute represent the most recent phase of the 1st harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE1ST_HARMONIC_CURRENT_ID = 0x030d, + /** Attribute represent the most recent phase of the 3rd harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE3RD_HARMONIC_CURRENT_ID = 0x030e, + /** Attribute represent the most recent phase of the 5th harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE5TH_HARMONIC_CURRENT_ID = 0x030f, + /** Attribute represent the most recent phase of the 7th harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE7TH_HARMONIC_CURRENT_ID = 0x0310, + /** Attribute represent the most recent phase of the 9th harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE9TH_HARMONIC_CURRENT_ID = 0x0311, + /** Attribute represent the most recent phase of the 11th harmonic current reading + * in an AC frequency. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASURED_PHASE11TH_HARMONIC_CURRENT_ID = 0x0312, + /** Provides a value to be multiplied against the ACFrequency attribute. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MULTIPLIER_ID = 0x0400, + /** Provides a value to be divided against the ACFrequency attribute. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_DIVISOR_ID = 0x0401, + /** Provides a value to be multiplied against a raw or uncompensated + * sensor count of power being measured by the metering device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_MULTIPLIER_ID = 0x0402, + /** Provides a value to divide against the results of applying the + * @e Multiplier attribute against a raw or uncompensated sensor + * count of power being measured by the metering device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_DIVISOR_ID = 0x0403, + /** Represents the unit value for the MeasuredNthHarmonicCurrent attribute in the + * format MeasuredNthHarmonicCurrent * 10 ^ HarmonicCurrentMultiplier amperes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_HARMONIC_CURRENT_MULTIPLIER_ID = 0x0404, + /** Represents the unit value for the MeasuredPhaseNthHarmonicCurrent attribute in + * the format MeasuredPhaseNthHarmonicCurrent * 10 ^ PhaseHarmonicCurrentMultiplier + * degrees. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_PHASE_HARMONIC_CURRENT_MULTIPLIER_ID = 0x0405, + /** Represents the single phase or Phase A, AC line current (Square root of active and + * reactive current) value at the moment in time the attribute is read, in @e Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_LINE_CURRENT_ID = 0x0501, + /** Represents the single phase or Phase A, AC active/resistive current value at the + * moment in time the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_ID = 0x0502, + /** Represents the single phase or Phase A, AC reactive current value at the moment + * in time the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_ID = 0x0503, + /** Represents the most recent RMS voltage reading in @e Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID = 0x0505, + /** Represents the lowest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_ID = 0x0506, + /** Represents the highest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_ID = 0x0507, + /** Represents the most recent RMS current reading in @e Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID = 0x0508, + /** Represents the lowest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_ID = 0x0509, + /** Represents the highest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_ID = 0x050a, + /** Represents the single phase or Phase A, current demand of active power delivered or + * received at the premises, in @e Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID = 0x050B, + /** Represents the lowest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_ID = 0x050c, + /** Represents the highest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_ID = 0x050d, + /** Represents the single phase or Phase A, current demand of reactive power delivered + * or received at the premises, in VAr. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_ID = 0x050e, + /** Represents the single phase or Phase A, current demand of apparent (Square root + * of active and reactive power) power, in @e VA. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_APPARENT_POWER_ID = 0x050F, + /** Contains the single phase or PhaseA, Power Factor ratio in 1/100ths. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID = 0x0510, + /** The Period in seconds that the RMS voltage is averaged over. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_ID = 0x0511, + /** The number of times the average RMS voltage, has been above the AverageRMS + * OverVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_ID = 0x0512, + /** The number of times the average RMS voltage, has been below the AverageRMS + * underVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_ID = 0x0513, + /** The duration in seconds used to measure an extreme over voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_ID = 0x0514, + /** The duration in seconds used to measure an extreme under voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_ID = 0x0515, + /** The duration in seconds used to measure a voltage sag condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_ID = 0x0516, + /** The duration in seconds used to measure a voltage swell condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_ID = 0x0517, + /** Provides a value to be multiplied against the @e InstantaneousVoltage and @e + * RMSVoltage attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_MULTIPLIER_ID = 0x0600, + /** Provides a value to be divided against the @e InstantaneousVoltage and + * @e RMSVoltage attributes. This attribute must be used in conjunction with the @e + * ACVoltageMultiplier attribute. 0x0000 is an invalid value for this attribute. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACVOLTAGE_DIVISOR_ID = 0x0601, + /** Provides a value to be multiplied against the @e InstantaneousCurrent and @e + * RMSCurrent attributes */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_MULTIPLIER_ID = 0x0602, + /** Provides a value to be divided against the @e ACCurrent, @e InstantaneousCurrent + * and @e RMSCurrent attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACCURRENT_DIVISOR_ID = 0x0603, + /** Provides a value to be multiplied against the @e InstantaneousPower and @e + * ActivePower attributes */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_ID = 0x0604, + /** Provides a value to be divided against the @e InstantaneousPower and @e + * ActivePower attributes. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_ID = 0x0605, + /** Specifies which configurable alarms may be generated. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_OVERLOAD_ALARMS_MASK_ID = 0x0700, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * voltage supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_OVERLOAD_ID = 0x0701, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * current supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DC_CURRENT_OVERLOAD_ID = 0x0702, + /** Specifies which configurable alarms may be generated. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_ALARMS_MASK_ID = 0x0800, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * voltage supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_VOLTAGE_OVERLOAD_ID = 0x0801, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * current supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_CURRENT_OVERLOAD_ID = 0x0802, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * active power supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_ACTIVE_POWER_OVERLOAD_ID = 0x0803, + /** Specifies the alarm threshold, set by the manufacturer, for the maximum output + * reactive power supported by device. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AC_REACTIVE_POWER_OVERLOAD_ID = 0x0804, + /** The average RMS voltage above which an over voltage condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_ID = 0x0805, + /** The average RMS voltage below which an under voltage condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_ID = 0x0806, + /** The RMS voltage above which an extreme under voltage condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_ID = 0x0807, + /** The RMS voltage below which an extreme under voltage condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_ID = 0x0808, + /** The RMS voltage below which a sag condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_ID = 0x0809, + /** The RMS voltage above which a swell condition is reported. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_ID = 0x080a, + /** Represents the Phase B, AC line current (Square root sum of active and reactive + * currents) value at the moment in time the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_LINE_CURRENT_PH_B_ID = 0x0901, + /** Represents the Phase B, AC active/resistive current value at the moment in time + * the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_PH_B_ID = 0x0902, + /** Represents the Phase B, AC reactive current value at the moment in time the + * attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_PH_B_ID = 0x0903, + /** Represents the most recent RMS voltage reading in @e Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_ID = 0x0905, + /** Represents the lowest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_B_ID = 0x0906, + /** Represents the highest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_B_ID = 0x0907, + /** Represents the most recent RMS current reading in @e Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_ID = 0x0908, + /** Represents the lowest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_B_ID = 0x0909, + /** Represents the highest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_B_ID = 0x090a, + /** Represents the Phase B, current demand of active power delivered or received at + * the premises, in @e Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_ID = 0x090B, + /** Represents the lowest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_B_ID = 0x090c, + /** Represents the highest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_B_ID = 0x090d, + /** Represents the Phase B, current demand of reactive power delivered or received + * at the premises, in VAr. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_PH_B_ID = 0x090e, + /** Represents the Phase B, current demand of apparent (Square root of active and + * reactive power) power, in @e VA. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_APPARENT_POWER_PHB_ID = 0x090F, + /** Contains the PhaseB, Power Factor ratio in 1/100ths. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_B_ID = 0x0910, + /** The number of times the average RMS voltage, has been above the + * @e AverageRMS @e OverVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_PHB_ID = 0x0911, + /** The number of times the average RMS voltage, has been above the AverageRMS + * OverVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_PH_B_ID = 0x0912, + /** The number of times the average RMS voltage, has been below the AverageRMS + * underVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_PH_B_ID = 0x0913, + /** The duration in seconds used to measure an extreme over voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_PH_B_ID = 0x0914, + /** The duration in seconds used to measure an extreme under voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_PH_B_ID = 0x0915, + /** The duration in seconds used to measure a voltage sag condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_PH_B_ID = 0x0916, + /** The duration in seconds used to measure a voltage swell condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_PH_B_ID = 0x0917, + /** Represents the Phase C, AC line current (Square root of active and reactive + * current) value at the moment in time the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_LINE_CURRENT_PH_C_ID = 0x0a01, + /** Represents the Phase C, AC active/resistive current value at the moment in time + * the attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_PH_C_ID = 0x0a02, + /** Represents the Phase C, AC reactive current value at the moment in time the + * attribute is read, in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_PH_C_ID = 0x0a03, + /** Represents the most recent RMS voltage reading in @e Volts (V).*/ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_ID = 0x0A05, + /** Represents the lowest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_C_ID = 0x0a06, + /** Represents the highest RMS voltage value measured in Volts (V). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_C_ID = 0x0a07, + /** Represents the most recent RMS current reading in @e Amps (A).*/ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_ID = 0x0A08, + /** Represents the lowest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_C_ID = 0x0a09, + /** Represents the highest RMS current value measured in Amps (A). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_C_ID = 0x0a0a, + /** Represents the Phase C, current demand of active power delivered + * or received at the premises, in @e Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_ID = 0x0A0B, + /** Represents the lowest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_C_ID = 0x0a0c, + /** Represents the highest AC power value measured in Watts (W). */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_C_ID = 0x0a0d, + /** Represents the Phase C, current demand of reactive power delivered or received + * at the premises, in VAr. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_PH_C_ID = 0x0a0e, + /** Represents the Phase C, current demand of apparent (Square root of active and + * reactive power) power, in @e VA. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_APPARENT_POWER_PHC_ID = 0x0A0F, + /** Contains the Phase C, Power Factor ratio in 1/100ths. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_C_ID = 0x0a10, + /** The Period in seconds that the RMS voltage is averaged over*/ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_PHC_ID = 0x0A11, + /** The number of times the average RMS voltage, has been above the AverageRMS + * OverVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_PH_C_ID = 0x0a12, + /** The number of times the average RMS voltage, has been below the AverageRMS + * underVoltage threshold since last reset. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_PH_C_ID = 0x0a13, + /** The duration in seconds used to measure an extreme over voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_PH_C_ID = 0x0a14, + /** The duration in seconds used to measure an extreme under voltage condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_PH_C_ID = 0x0a15, + /** The duration in seconds used to measure a voltage sag condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_PH_C_ID = 0x0a16, + /** The duration in seconds used to measure a voltage swell condition. */ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_PH_C_ID = 0x0a17, +}; + +/*! @brief Bit mapping for Measurement Type attribute, + @see HA spec, subclause 9.2.2.2.1.1 */ +enum zb_zcl_electrical_measurement_measurement_type_e +{ + /*! Active Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_MEASUREMENT = 0x00000001, + /*! Reactive Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_MEASUREMENT = 0x00000002, + /*! Apparent Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_APPARENT_MEASUREMENT = 0x00000004, + /*! Phase A Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_A_MEASUREMENT = 0x00000008, + /*! Phase B Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_B_MEASUREMENT = 0x00000010, + /*! Phase C Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_C_MEASUREMENT = 0x00000020, + /*! DC Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_MEASUREMENT = 0x00000040, + /*! Harmonic Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_HARMONIC_MEASUREMENT = 0x00000080, + /*! Power Quality Measurement bit */ + ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_QUALITY_MEASUREMENT = 0x00000100, + + ZB_ZCL_ELECTRICAL_MEASUREMENT_RESERVED = 0x00000200 +}; + +/** @brief Default value for Measurement Type attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_DEFAULT_VALUE 0x00000000 + +/** @brief Default value for DCVoltage attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCVoltageMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MIN_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCVoltageMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MAX_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCCurrentMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_MIN_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCCurrentMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_MAX_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCPowerMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_POWER_MIN_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCPowerMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_POWER_MAX_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for DCVoltageMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_MULTIPLIER_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCVoltageDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_DIVISOR_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCCurrentMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_MULTIPLIER_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCCurrentDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_DIVISOR_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCPowerMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_POWER_MULTIPLIER_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCPowerDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_POWER_DIVISOR_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for ACFrequency attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ACFrequencyMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MIN_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ACFrequencyMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MAX_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for NeutralCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_NEUTRAL_CURRENT_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for DCPower attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DCPOWER_DEFAULT_VALUE 0x8000 + +/** @brief Default value for Measured1stHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED1ST_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for Measured3rdHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED3RD_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for Measured5thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED5TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for Measured7thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED7TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for Measured9thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED9TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for Measured11thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED11TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase1stHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE1ST_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase3rdHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE3RD_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase5thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE5TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase7thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE7TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase9thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE9TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MeasuredPhase11thHarmonicCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_MEASURED_PHASE11TH_HARMONIC_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ACFrequencyMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_MULTIPLIER_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for ACFrequencyDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_FREQUENCY_DIVISOR_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for PowerMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_MULTIPLIER_DEFAULT_VALUE ((zb_uint32_t)0x000001) + +/** @brief Default value for PowerDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_DIVISOR_DEFAULT_VALUE ((zb_uint32_t)0x000001) + +/** @brief Default value for HarmonicCurrentMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_HARMONIC_CURRENT_MULTIPLIER_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for PhaseHarmonicCurrentMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_PHASE_HARMONIC_CURRENT_MULTIPLIER_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for LineCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_LINE_CURRENT_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActiveCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactiveCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for RMSVoltageMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSVoltageMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActivePowerMin attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ActivePowerMax attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactivePower attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ApparentPower attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_APPARENT_POWER_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for AverageRmsvoltageMeasurementPeriod attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSOverVoltageCounter attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSUnderVoltageCounter attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeOverVoltagePeriod attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeUnderVoltagePeriod attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSagPeriod attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSwellPeriod attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AcvoltageMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACVOLTAGE_MULTIPLIER_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for AcvoltageDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACVOLTAGE_DIVISOR_DEFAULT_VALUE ((zb_uint16_t)0x0001) + +/** @brief Default value for DCOverloadAlarmsMask attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_OVERLOAD_ALARMS_MASK_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for DCVoltageOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_VOLTAGE_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for DCCurrentOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_DC_CURRENT_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for ACAlarmsMask attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_ALARMS_MASK_DEFAULT_VALUE ((zb_uint16_t)0x00) + +/** @brief Default value for ACVoltageOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_VOLTAGE_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for ACCurrentOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_CURRENT_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for ACActivePowerOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_ACTIVE_POWER_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for ACReactivePowerOverload attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AC_REACTIVE_POWER_OVERLOAD_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for RMSVoltage attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_DEFAULT_VALUE 0xffff + +/** @brief Default value for RMSCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSCURRENT_DEFAULT_VALUE 0xffff + +/** @brief Default value for ActivePower attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_DEFAULT_VALUE 0xffff + +/** @brief Default value for RMSCurrent attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_FACTOR_DEFAULT_VALUE 0x0 + +/** @brief Default value for PowerMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_DEFAULT_VALUE 0x0001 + +/** @brief Default value for PowerDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_DEFAULT_VALUE 0x0001 + +/** @brief Default value for ACCurrentMultiplier attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACCURRENT_MULTIPLIER_DEFAULT_VALUE 0x0001 + +/** @brief Default value for ACCurrentDivisor attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACCURRENT_DIVISOR_DEFAULT_VALUE 0x0001 + +/** @brief Default value for LineCurrentPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_LINE_CURRENT_PH_B_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActiveCurrentPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_PH_B_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactiveCurrentPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_PH_B_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for RmsvoltagePHB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHB_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSVoltageMinPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x8000) + +/** @brief Default value for RMSVoltageMaxPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x8000) + +/** @brief Default value for RmscurrentPHB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHB_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMinPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_B_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMaxPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_B_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActivePowerPHB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHB_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ActivePowerMinPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_B_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ActivePowerMaxPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_B_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactivePowerPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_PH_B_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ApparentPowerPHB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_APPARENT_POWER_PHB_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for PowerFactorPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_B_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for AverageRmsvoltageMeasurementPeriodPHB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_PHB_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSOverVoltageCounterPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSUnderVoltageCounterPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeOverVoltagePeriodPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeUnderVoltagePeriodPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSagPeriodPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSwellPeriodPhB attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_PH_B_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for LineCurrentPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_LINE_CURRENT_PH_C_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActiveCurrentPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_CURRENT_PH_C_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactiveCurrentPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_CURRENT_PH_C_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for rmsvoltagePHC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_PHC_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSVoltageMinPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MIN_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x8000) + +/** @brief Default value for RMSVoltageMaxPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_MAX_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x8000) + +/** @brief Default value for rmscurrentPHC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMSCURRENT_PHC_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMinPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MIN_PH_C_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for RMSCurrentMaxPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_CURRENT_MAX_PH_C_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ActivePowerPHC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_PHC_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ActivePowerMinPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MIN_PH_C_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ActivePowerMaxPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_MAX_PH_C_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ReactivePowerPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REACTIVE_POWER_PH_C_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for ApparentPowerPHC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_APPARENT_POWER_PHC_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for PowerFactorPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_POWER_FACTOR_PH_C_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for AverageRmsvoltageMeasurementPeriodPHC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMSVOLTAGE_MEASUREMENT_PERIOD_PHC_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSOverVoltageCounterPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_OVER_VOLTAGE_COUNTER_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AverageRMSUnderVoltageCounterPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_AVERAGE_RMS_UNDER_VOLTAGE_COUNTER_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeOverVoltagePeriodPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_OVER_VOLTAGE_PERIOD_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSExtremeUnderVoltagePeriodPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_EXTREME_UNDER_VOLTAGE_PERIOD_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSagPeriodPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SAG_PERIOD_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for RMSVoltageSwellPeriodPhC attribute */ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_RMS_VOLTAGE_SWELL_PERIOD_PH_C_DEFAULT_VALUE ((zb_uint16_t)0x0000) + + +/*! @} */ /* Electrical Measurement cluster attributes */ + +/*! @brief Electrical Measurement cluster server command identifiers + @see ZCL spec, subclause 4.9.2.3.1 +*/ +enum zb_zcl_on_off_srv_cmd_e +{ + /** This command is generated when the Client command GetProfileInfo is received. */ + ZB_ZCL_CMD_ELECTRICAL_MEASUREMENT_GET_PROFILE_INFO_RESPONSE_COMMAND = 0x00, + /** This command is generated when the Client command GetMeasurementProfile is received. */ + ZB_ZCL_CMD_ELECTRICAL_MEASUREMENT_GET_MEASUREMENT_PROFILE_RESPONSE_COMMAND = 0x01, +}; + +/*! @brief Electrical Measurement cluster client command identifiers + @see ZCL spec, subclause 4.9.2.4.1 +*/ +enum zb_zcl_on_off_cli_cmd_e +{ + /** Get Profile Info Command */ + ZB_ZCL_CMD_ELECTRICAL_MEASUREMENT_GET_PROFILE_INFO_COMMAND = 0x00, + /** Get Measurement Profile Command */ + ZB_ZCL_CMD_ELECTRICAL_MEASUREMENT_GET_MEASUREMENT_PROFILE_COMMAND = 0x01, +}; + +/*! @cond internals_doc + @internal @name Electrical Measurement cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_32BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DCPOWER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DCPOWER_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSVOLTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_RMSCURRENT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACTIVE_POWER_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_POWER_FACTOR_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_MULTIPLIER_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_ACPOWER_DIVISOR_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! +* @} +* @endcond +*/ +/** @brief Declare attribute list for Electrical Measurement cluster + @param attr_list - attribute list name + @param measurement_type - pointer to variable to store Measurement Type attribute value + @param dcpower - pointer to variable to store DCPower attribute value +*/ +#define ZB_ZCL_DECLARE_ELECTRICAL_MEASUREMENT_ATTRIB_LIST(attr_list, measurement_type, dcpower) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_MEASUREMENT_TYPE_ID, (measurement_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ELECTRICAL_MEASUREMENT_DCPOWER_ID, (dcpower)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! + @cond internals_doc + @{ + @internal Number of attributes mandatory for reporting in Electrical Measurement cluster +*/ +#define ZB_ZCL_ELECTRICAL_MEASUREMENT_REPORT_ATTR_COUNT 2 + +/*! @} + @endcond */ /* Electrical Measurement cluster internals */ + +/*! @} */ /* ZCL HA Electrical Measurement cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_el_measurement_init_server(void); +void zb_zcl_el_measurement_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT_SERVER_ROLE_INIT zb_zcl_el_measurement_init_server +#define ZB_ZCL_CLUSTER_ID_ELECTRICAL_MEASUREMENT_CLIENT_ROLE_INIT zb_zcl_el_measurement_init_client + +#endif /* ! defined ZB_ZCL_ELECTRICAL_MEASUREMENT_H */ diff --git a/zboss/include/zcl/zb_zcl_en50523_appliance_events_and_alerts.h b/zboss/include/zcl/zb_zcl_en50523_appliance_events_and_alerts.h new file mode 100644 index 0000000000..3ee0470ed4 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_en50523_appliance_events_and_alerts.h @@ -0,0 +1,446 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: EN50523 Appliance events and alerts cluster defintions +*/ + +#if ! defined ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_H +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_H + +/** @cond DOXYGEN_ZCL_SECTION */ + +/*! @addtogroup ZB_ZCL_EN50523_APP_EVENTS_ALERTS + @{ +*/ +/*! @name EN50523 Appliance events and alerts cluster commands + @{ +*/ +/*! @brief EN50523 Appliance events and alerts cluster + command received identifiers + @see ZCL 6.0 spec, subclause 15.4.2.3 +*/ +enum zb_zcl_en50523_appl_ev_and_alerts_recv_cmd_e +{ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_ID = 0x00, /**< "Get alerts" command. */ +}; + +/*! @brief EN50523 Appliance events and alerts cluster + commands generated identifiers + @see ZCL 6.0 spec, subclause 15.4.2.4 +*/ +enum zb_zcl_en50523_appl_ev_and_alerts_send_cmd_e +{ + /*! "Get alerts response" command. */ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_RESP_ID = 0x00, + /*! "Alerts notification" command. */ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_ALERTS_NOTIFICATION_ID = 0x01, + /*! "Event notification" command. */ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_EVENT_NOTIFICATION_ID = 0x02, +}; + +/** @cond internals_doc */ +/* en50523 cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_ID + +#define ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_RESP_ID, \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_ALERTS_NOTIFICATION_ID, \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_EVENT_NOTIFICATION_ID + +#define ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_CLIENT_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_APPL_EV_AND_ALERTS_SERVER_ROLE_RECEIVED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/******************************* Get Alerts Command ******************************/ + +/*! @brief Get Alerts command, ZCL spec 15.4.2.2.1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS, cb); \ +} + +/******************************* Get Alerts Response Command ******************************/ + +/*! @brief Maximum number of Alerts */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_MAX_ALERTS_NUM 15 + +/*! @brief Type of alert */ +enum zb_zcl_en50523_appl_ev_and_alerts_alerts_type_e +{ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_TYPE_UNSTRUCTURED = 0x00, +}; + +/*! @brief Alert category */ +enum zb_zcl_en50523_appl_ev_and_alerts_alert_category_e +{ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_CATEGORY_WARNING = 0x01, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_CATEGORY_DANGER = 0x02, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_CATEGORY_FAILURE = 0x03, +}; + +/*! @brief Alert presence recovery */ +enum zb_zcl_en50523_appl_ev_and_alerts_alert_presence_e +{ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_RECOVERY = 0x00, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_PRESENCE = 0x01, +}; + +/*! @brief Get Number of Alerts */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_NUM(_alerts_count) ((_alerts_count) & 0x0F) + +/*! @brief Set Number of Alerts */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_SET_NUM(_alerts_count, num) ((_alerts_count) |= (num & 0x0F)) + +/*! @brief Get Type of alert */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_TYPE(_alerts_count) (((_alerts_count) & 0xF0) >> 4) + +/*! @brief Set Type of alert */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_SET_TYPE(_alerts_count, type) ((_alerts_count) |= ((type & 0x0F) << 4)) + +/*! @brief Get Alert ID */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_GET_ID(_alert_struct) ((_alert_struct).alert[2] & 0xFF) + +/*! @brief Set Alert ID */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_SET_ID(_alert_struct, id) ((_alert_struct).alert[2] = (id & 0xFF)) + +/*! @brief Get Alert Category */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_GET_CATEGORY(_alert_struct) ((_alert_struct).alert[1] & 0x0F) + +/*! @brief Set Alert Category */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_SET_CATEGORY(_alert_struct, cat) ((_alert_struct).alert[1] |= (cat & 0x0F)) + +/*! @brief Get Alert Presence recovery */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_GET_PRESENCE(_alert_struct) (((_alert_struct).alert[1] & 0xF0) >> 4) + +/*! @brief Set Alert Presence recovery */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_SET_PRESENCE(_alert_struct, pres) ((_alert_struct).alert[1] |= (pres & 0x0F) << 4) + +/*! @brief Get Alert Manufacturer specific bits */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_GET_MANUF_SPEC(_alert_struct) ((_alert_struct).alert[0] & 0xFF) + +/*! @brief Set Alert Manufacturer specific bits */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERT_STRUCT_SET_MANUF_SPEC(_alert_struct, val) ((_alert_struct).alert[0] = (val & 0xFF)) + +/*! @brief Alert structure */ +typedef ZB_PACKED_PRE struct zb_zcl_en50523_appl_ev_and_alerts_alert_struct_s +{ + /** Alert field - Alert ID, Category, Presense recovery, Manufacturer specific bits */ + zb_uint8_t alert[3]; +} ZB_PACKED_STRUCT zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t; + +/*! @brief Structure representsation of Get Alerts Response command */ +typedef ZB_PACKED_PRE struct zb_zcl_en50523_appl_ev_and_alerts_get_alerts_resp_s +{ + /** Alerts count fiels - Number of Alerts, Type of alert */ + zb_uint8_t alerts_count; + /** Alert structure fields, see zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t */ + zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t alert_struct[ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_MAX_ALERTS_NUM]; + +} ZB_PACKED_STRUCT zb_zcl_en50523_appl_ev_and_alerts_get_alerts_resp_t; + +/*! Get Alerts Response command payload size */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_RESP_PAYLOAD_SIZE(ptr) (sizeof(((zb_zcl_en50523_appl_ev_and_alerts_get_alerts_resp_t *)(ptr))->alerts_count) + \ + (ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_NUM(((zb_zcl_en50523_appl_ev_and_alerts_get_alerts_resp_t *)(ptr))->alerts_count)* \ + sizeof(zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t))) + +/*! @brief Start Get Alerts Response command, ZCL spec 15.4.2.3.1 + @param buffer - to put packet to + @param seq - sequence + @param alerts_count - Alerts count field + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_RESP_ADD + and @ref ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_RESP_END +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_RESP_START( \ + buffer, seq, alerts_count, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (alerts_count)); \ +} + +/*! @brief Add Alert Structure to Get Alerts Response command, ZCL spec 15.4.2.3.1 + @param ptr - [in/out] (zb_uint8_t*) current position + @param alert_struct - pointer to the Alert structure to put into packet +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_RESP_ADD(ptr, alert_struct) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA24(ptr, (alert_struct)); \ +} + +/*! @brief End form Get Alerts Response command and send it, ZCL spec 15.4.2.3.1 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_GET_ALERTS_RESP_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS, NULL); \ +} + +/** @brief Macro for getting Get Alerts Response command, ZCL spec 15.4.2.3.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_en50523_appl_ev_and_alerts_get_alerts_resp_t + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_GET_GET_ALERTS_RESP(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != \ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_RESP_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->alerts_count, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->alert_struct, data, \ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_NUM((data_ptr)->alerts_count)*sizeof(zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************************* Alerts Notification Command ******************************/ + +/*! @brief Structure representsation of Alerts Notification command */ +typedef ZB_PACKED_PRE struct zb_zcl_en50523_appl_ev_and_alerts_alerts_notif_s +{ + /** Alerts count fiels - Number of Alerts, Type of alert */ + zb_uint8_t alerts_count; + /** Alert structure fields, see zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t */ + zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t alert_struct[ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_MAX_ALERTS_NUM]; + +} ZB_PACKED_STRUCT zb_zcl_en50523_appl_ev_and_alerts_alerts_notif_t; + +/*! Alerts Notification command payload size */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_NOTIF_PAYLOAD_SIZE(ptr) (sizeof(((zb_zcl_en50523_appl_ev_and_alerts_alerts_notif_t *)(ptr))->alerts_count) + \ + (ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_NUM(((zb_zcl_en50523_appl_ev_and_alerts_alerts_notif_t *)(ptr))->alerts_count)* \ + sizeof(zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t))) + +/*! @brief Start Alerts Notification command, ZCL spec 15.4.2.3.2 + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param alerts_count - Alerts count field + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_ALERTS_NOTIF_ADD + and @ref ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_ALERTS_NOTIF_END +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_ALERTS_NOTIF_START( \ + buffer, def_resp, alerts_count, ptr) \ +{ \ + (ptr) = zb_zcl_start_command_header(buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + (def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_ALERTS_NOTIFICATION_ID, \ + NULL); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (alerts_count)); \ +} + +/*! @brief Add Alert Structure to Alerts Notification command, ZCL spec 15.4.2.3.2 + @param ptr - [in/out] (zb_uint8_t*) current position + @param alert_struct - pointer to Alert structure to put into packet +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_ALERTS_NOTIF_ADD(ptr, alert_struct) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA24(ptr, (alert_struct)); \ +} + +/*! @brief End form Alerts Notification command and send it, ZCL spec 15.4.2.3.2 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_ALERTS_NOTIF_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS, cb); \ +} + +/** @brief Macro for getting Alerts Notification command, ZCL spec 15.4.2.3.2 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_en50523_appl_ev_and_alerts_alerts_notif_t + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_GET_ALERTS_NOTIF(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != \ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_NOTIF_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->alerts_count, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->alert_struct, data, \ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_ALERTS_COUNT_GET_NUM((data_ptr)->alerts_count)*sizeof(zb_zcl_en50523_appl_ev_and_alerts_alert_struct_t)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************************* Event Notification Command ******************************/ + +/*! @brief Event Identificatoin */ +enum zb_zcl_en50523_appl_ev_and_alerts_event_identification_e +{ + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_EVENT_ID_END_OF_CYCLE = 0x01, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_EVENT_ID_TEMP_REACHED = 0x04, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_EVENT_ID_END_OF_COOKING = 0x05, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_EVENT_ID_SWITCHING_OFF = 0x06, + ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_EVENT_ID_WRONG_DATA = 0xf7, +}; + +/*! @brief Structure representsation of Event Notification command + @param event_header - Event header field + @param event_identification - Event Identification field, see zb_zcl_en50523_appl_ev_and_alerts_event_identification_e +*/ +typedef ZB_PACKED_PRE struct zb_zcl_en50523_appl_ev_and_alerts_event_notif_s +{ + zb_uint8_t event_header; + zb_uint8_t event_identification; + +} ZB_PACKED_STRUCT zb_zcl_en50523_appl_ev_and_alerts_event_notif_t; + +/*! @brief Event Notification command, ZCL spec 15.4.2.3.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param event_identification - Event ID +*/ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_SEND_EVENT_NOTIF( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + event_identification) \ +{ \ + zb_uint8_t* ptr = zb_zcl_start_command_header(buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + (def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_CMD_EN50523_APPL_EV_AND_ALERTS_EVENT_NOTIFICATION_ID, \ + NULL); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, 0); \ + ZB_ZCL1_PACKET_PUT_DATA8(ptr, (event_identification)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS, cb); \ +} + +/** @brief Macro for getting Event Notification command, see ZCL spec 15.4.2.3.3 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type zb_zcl_en50523_appl_ev_and_alerts_event_notif_e + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_GET_EVENT_NOTIF(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != \ + sizeof(zb_zcl_en50523_appl_ev_and_alerts_event_notif_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->event_header, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->event_identification, data); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} +/*! @} */ /* Appliance events and alerts cluster commands */ +/*! @} */ /*ZB_ZCL_EN50523_APP_EVENTS_ALERTS */ +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_en50523_appliance_events_and_alerts_init_server(void); +void zb_zcl_en50523_appliance_events_and_alerts_init_client(void); +#define ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS_SERVER_ROLE_INIT zb_zcl_en50523_appliance_events_and_alerts_init_server +#define ZB_ZCL_CLUSTER_ID_APPLIANCE_EVENTS_AND_ALERTS_CLIENT_ROLE_INIT zb_zcl_en50523_appliance_events_and_alerts_init_client + +#endif /* ZB_ZCL_EN50523_APPL_EV_AND_ALERTS_H */ diff --git a/zboss/include/zcl/zb_zcl_fan_control.h b/zboss/include/zcl/zb_zcl_fan_control.h new file mode 100644 index 0000000000..79d09c2b56 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_fan_control.h @@ -0,0 +1,175 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Fan Control cluster defintions +*/ + +#if ! defined ZB_ZCL_FAN_CONTROL_H +#define ZB_ZCL_FAN_CONTROL_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_FAN_CONTROL */ + +/*! @addtogroup ZB_ZCL_FAN_CONTROL + @{ + @name Fan Control cluster attributes + @{ +*/ + +/*! @brief Fan Control cluster attribute identifiers + @see ZCL spec, subclause 6.4.2.2 +*/ +enum zb_zcl_fan_control_attr_e +{ + /*! @brief Fan Mode attribute */ + ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID = 0x0000, + /*! @brief Fan Mode Sequence attribute */ + ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID = 0x0001 +}; + +/*! @brief Values for Fan Mode attribute, + @see ZCL spec, subclause 6.4.2.2.1 */ +enum zb_zcl_fan_control_fan_mode_e +{ + /*! Off value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_OFF = 0x00, + /*! Low value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_LOW = 0x01, + /*! Medium value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_MEDIUM = 0x02, + /*! High value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_HIGH = 0x03, + /*! On value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_ON = 0x04, + /*! Auto value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_AUTO = 0x05, + /*! Smart value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SMART = 0x06, + + ZB_ZCL_FAN_CONTROL_FAN_MODE_RESERVED = 0x07 +}; + +/*! @brief Values for Fan Mode Sequence attribute, + @see ZCL spec, subclause 6.4.2.2.2 */ +enum zb_zcl_fan_control_fan_mode_sequence_e +{ + /*! Low/Med/High value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH = 0x00, + /*! Low/High value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH = 0x01, + /*! Low/Med/High/Auto value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_MED_HIGH_AUTO = 0x02, + /*! Low/High/Auto value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_LOW_HIGH_AUTO = 0x03, + /*! On/Auto value */ + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_ON_AUTO = 0x04, + + ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_RESERVED = 0x05 +}; + +/** @brief Default value for Fan Mode attribute */ +#define ZB_ZCL_FAN_CONTROL_FAN_MODE_DEFAULT_VALUE 0x05 + +/** @brief Default value for Fan Mode attribute */ +#define ZB_ZCL_FAN_CONTROL_FAN_MODE_SEQUENCE_DEFAULT_VALUE 0x02 + +/** @brief Declare attribute list for Fan Control cluster + @param attr_list - attribute list name + @param fan_mode - pointer to variable to store Fan Mode attribute value + @param fan_mode_sequence - pointer to variable to store Fan Mode Sequence attribute value +*/ +#define ZB_ZCL_DECLARE_FAN_CONTROL_ATTRIB_LIST(attr_list, fan_mode, fan_mode_sequence) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID, (fan_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID, (fan_mode_sequence)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Fan Control cluster attributes */ + +/*! @name Fan Control cluster commands + @{ +*/ + +/*! @} */ /* Fan Control cluster commands */ + +/*! @cond internals_doc + @internal @name Fan Control cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_FAN_CONTROL_FAN_MODE_SEQUENCE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Fan Control cluster */ +#define ZB_ZCL_FAN_CONTROL_REPORT_ATTR_COUNT 0 + +/*! @} + @endcond */ /* Fan Control cluster internals */ + +/*! @} */ /* ZCL HA Fan Control cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_fan_control_init_server(void); +void zb_zcl_fan_control_init_client(void); +#define ZB_ZCL_CLUSTER_ID_FAN_CONTROL_SERVER_ROLE_INIT zb_zcl_fan_control_init_server +#define ZB_ZCL_CLUSTER_ID_FAN_CONTROL_CLIENT_ROLE_INIT zb_zcl_fan_control_init_client + +#endif /* ! defined ZB_ZCL_FAN_CONTROL_H */ diff --git a/zboss/include/zcl/zb_zcl_groups.h b/zboss/include/zcl/zb_zcl_groups.h new file mode 100644 index 0000000000..7e0d6bb718 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_groups.h @@ -0,0 +1,807 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Groups cluster defintions +*/ + +#ifndef ZB_ZCL_GROUPS_H +#define ZB_ZCL_GROUPS_H 1 + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_GROUPS + * @{ + * @details + * Groups cluster defined in ZCL spec, clause 3.6. Currently no group name attribute support is + * implemented. However, this attribute must be supported for sending and receiving in commands' + * payload, so it is being sent as zero string (i. e. single zero byte). On receipt of the + * command is able to contain a scene name in the payload, this field will be ignored as a string. + * + * Cluster requests and responses are documented in submodules. + */ + +/** @name Groups cluster attributes + @{ +*/ + +/* ZB_ZCL_CLUSTER_ID_GROUPS = 0x0004 */ + +/** @brief Groups cluster attribute identifiers + @see ZCL spec, subclause 3.6.2.2 +*/ +enum zb_zcl_groups_attr_e +{ + /** @brief NameSupport attribute */ + ZB_ZCL_ATTR_GROUPS_NAME_SUPPORT_ID = 0 +}; + +/** @brief Values for NameSupport attribute */ +enum zb_zcl_groups_name_support_e +{ + /** "Not supported" value */ + ZB_ZCL_ATTR_GROUPS_NAME_NOT_SUPPORTED = 0, + /** "On" value */ + ZB_ZCL_ATTR_GROUPS_NAME_SUPPORTED = 1 << 7 /* set to 1 the most significant bit */ +}; + +/** + * @brief Declare attribute list for Groups cluster. + * @param attr_list - attribute list name. + * @param name_support - pointer to variable to store name_support attribute value + */ +#define ZB_ZCL_DECLARE_GROUPS_ATTRIB_LIST(attr_list, name_support) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_GROUPS_NAME_SUPPORT_ID, (name_support)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* Groups cluster attributes */ + +/** @name Groups cluster command identifiers + @{ +*/ + +/** + * @brief Groups cluster command identifiers. + * @see ZCL spec, subclause 3.6.2.2.2. + */ +enum zb_zcl_groups_cmd_e +{ + ZB_ZCL_CMD_GROUPS_ADD_GROUP = 0x00, /**< Add group command identifier. */ + ZB_ZCL_CMD_GROUPS_VIEW_GROUP = 0x01, /**< View group command identifier. */ + ZB_ZCL_CMD_GROUPS_GET_GROUP_MEMBERSHIP = 0x02, /**< Get group membership command identifier. + */ + ZB_ZCL_CMD_GROUPS_REMOVE_GROUP = 0x03, /**< Remove group command identifier. */ + ZB_ZCL_CMD_GROUPS_REMOVE_ALL_GROUPS = 0x04, /**< Remove all groups command identifier. */ + ZB_ZCL_CMD_GROUPS_ADD_GROUP_IF_IDENTIFYING = 0x05 /**< Add group if identifying command + identifier. */ +}; + +/** @brief Groups cluster response command identifiers + @see ZCL spec, subclause 3.6.2.3 +*/ +enum zb_zcl_groups_cmd_resp_e +{ + ZB_ZCL_CMD_GROUPS_ADD_GROUP_RES = 0x00, /**< Add group response command identifier. */ + ZB_ZCL_CMD_GROUPS_VIEW_GROUP_RES = 0x01, /**< View group response command identifier. + */ + ZB_ZCL_CMD_GROUPS_GET_GROUP_MEMBERSHIP_RES = 0x02, /**< Get group response membership command + identifier. */ + ZB_ZCL_CMD_GROUPS_REMOVE_GROUP_RES = 0x03 /**< Remove group response command identifier. + */ +}; + +/** @cond internals_doc */ +/* GROUPS cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_GROUPS_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_GROUPS_ADD_GROUP_RES, \ + ZB_ZCL_CMD_GROUPS_VIEW_GROUP_RES, \ + ZB_ZCL_CMD_GROUPS_GET_GROUP_MEMBERSHIP_RES, \ + ZB_ZCL_CMD_GROUPS_REMOVE_GROUP_RES + +#define ZB_ZCL_CLUSTER_ID_GROUPS_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_GROUPS_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_GROUPS_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_GROUPS_ADD_GROUP, \ + ZB_ZCL_CMD_GROUPS_VIEW_GROUP, \ + ZB_ZCL_CMD_GROUPS_GET_GROUP_MEMBERSHIP, \ + ZB_ZCL_CMD_GROUPS_REMOVE_GROUP, \ + ZB_ZCL_CMD_GROUPS_REMOVE_ALL_GROUPS, \ + ZB_ZCL_CMD_GROUPS_ADD_GROUP_IF_IDENTIFYING + +#define ZB_ZCL_CLUSTER_ID_GROUPS_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_GROUPS_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** @} */ /* Groups cluster command identifiers */ + +/************************** Add group command definitions ****************************/ + +/** @defgroup ZB_ZCL_GROUPS_ADD_GROUP Add group command definitions + * @{ + * @details + * Add group request and response commands have simple payload. Response command is being filled + * and sent by ZCL internals. + * + * @par Examples + * + * Filling and sending Add Group request: + * @snippet HA_samples/door_lock/sample_zed.c send_add_group_req + * + * Parsing Add Group request: + * @code + * ZB_ZCL_GROUPS_GET_ADD_GROUP_REQ(buffer, add_group); + * @endcode + * + * Parsing Add Group response: + * @snippet doxygen_snippets.dox Parse Add Group response_snippet_groups_dut_553_c + * @par + * + * For more information see 5.5.3_groups sample + */ + +/** @brief Add group command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_add_group_req_s +{ + zb_uint16_t group_id; /**< Group id */ + zb_char_t group_name[1]; /**< Group name, optional */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_add_group_req_t; + +/** @cond internals_doc */ + +/** @internal Minimum size of Add group request (group name maybe omitted) */ +#define ZB_ZCL_ADD_GROUP_REQ_SIZE sizeof(zb_uint16_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Add group command and fills in data request + structure. If request contains invlid data, ZB_ZCL_NULL_ID is stored as group_id. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param add_group_req - variable to save command request + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_GROUPS_GET_ADD_GROUP_REQ(data_buf, add_group_req) \ +{ \ + zb_zcl_groups_add_group_req_t *add_group_req_ptr; \ + (add_group_req_ptr) = zb_buf_len(data_buf) >= ZB_ZCL_ADD_GROUP_REQ_SIZE ? \ + (zb_zcl_groups_add_group_req_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (add_group_req_ptr) \ + { \ + ZB_HTOLE16(&(add_group_req).group_id, &add_group_req_ptr->group_id);\ + /* group name currently is not supported - do not check it */ \ + } \ + else \ + { \ + add_group_req.group_id = ZB_ZCL_NULL_ID; \ + } \ +} + +/** @brief Add group response command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_add_group_res_s +{ + zb_uint8_t status; /**< Operation status */ + zb_uint16_t group_id; /**< Group id */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_add_group_res_t; + +/** @cond internals_doc */ + +/** @internal Add group response size */ +#define ZB_ZCL_ADD_GROUP_RES_SIZE sizeof(zb_zcl_groups_add_group_res_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Add group response command and returns response data + structure or NULL if request contains invlid data. + @param data_buf - pointer to zb_buf_t buffer containing command response data + @param add_group_res - out pointer to zb_zcl_groups_add_group_res_t, containing command + response record + @note data_buf buffer should contain response command payload without ZCL header + */ +#define ZB_ZCL_GROUPS_GET_ADD_GROUP_RES(data_buf, add_group_res) \ +{ \ + (add_group_res) = zb_buf_len(data_buf) >= ZB_ZCL_ADD_GROUP_RES_SIZE ? \ + (zb_zcl_groups_add_group_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (add_group_res) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(add_group_res)->group_id); \ + /* group name currently is not supported - do not check it */ \ + } \ +} + +/** @brief Send Add group command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param group_id - group ID to add +*/ +#define ZB_ZCL_GROUPS_SEND_ADD_GROUP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, group_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_ADD_GROUP); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + /* Group name currently is not supported, put empty string */ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_NULL_STRING); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* Add group command definitions */ + + +/************************** View group command definitions ****************************/ + +/** @defgroup ZB_ZCL_GROUPS_VIEW_GROUP View group command definitions + * @{ + * @details + * View Group command and response have simpe payload. View group command is being processed, + * and View Group responce command originates from ZCL internals. + * + * @par Examples + * View Group request command can be formed as: + * @snippet HA_samples/door_lock/sample_zed.c view_group_req + * View Group response command can be parsed as: + * @snippet doxygen_snippets.dox Parse View Group response_snippet_groups_dut_c + * @par + * + * For more information see 545_groups sample + */ + +/** @brief View group command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_view_group_req_s +{ + zb_uint16_t group_id; /**< Group id */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_view_group_req_t; + +/** @cond internals_doc */ + +/** @internal Size of View group request */ +#define ZB_ZCL_VIEW_GROUP_REQ_SIZE sizeof(zb_zcl_groups_view_group_req_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses View group command and fills in data request + structure. If request contains invlid data, ZB_ZCL_NULL_ID is stored as group_id. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param view_group_req - variable to save command request + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_GROUPS_GET_VIEW_GROUP_REQ(data_buf, view_group_req) \ +{ \ + zb_zcl_groups_view_group_req_t *view_group_req_ptr; \ + (view_group_req_ptr) = zb_buf_len(data_buf) >= ZB_ZCL_VIEW_GROUP_REQ_SIZE ? \ + (zb_zcl_groups_view_group_req_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (view_group_req_ptr) \ + { \ + ZB_HTOLE16(&(view_group_req).group_id, &view_group_req_ptr->group_id); \ + } \ + else \ + { \ + view_group_req.group_id = ZB_ZCL_NULL_ID; \ + } \ +} + +/** @brief View group command response structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_view_group_res_s +{ + zb_uint8_t status; /**< Operation status */ + zb_uint16_t group_id; /**< Group id */ + zb_uint8_t group_name[1]; /**< Group name */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_view_group_res_t; + +/** @cond internals_doc */ + +/** @internal View group response size */ +#define ZB_ZCL_VIEW_GROUP_RES_SIZE sizeof(zb_zcl_groups_view_group_res_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses View group response command and returns response data + structure or NULL if request contains invlid data. + @param data_buf - pointer to zb_buf_t buffer containing command response data + @param view_group_res - out pointer to zb_zcl_groups_add_group_res_t, containing command + response record + @note data_buf buffer should contain response command payload without ZCL header + */ +#define ZB_ZCL_GROUPS_GET_VIEW_GROUP_RES(data_buf, view_group_res) \ +{ \ + (view_group_res) = zb_buf_len(data_buf) >= ZB_ZCL_VIEW_GROUP_RES_SIZE ? \ + (zb_zcl_groups_view_group_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (view_group_res) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(view_group_res)->group_id); \ + /* group name currently is not supported - empty string is returned */ \ + } \ +} + +/** @brief Send view group command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param group_id - group ID to add +*/ +#define ZB_ZCL_GROUPS_SEND_VIEW_GROUP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, group_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_VIEW_GROUP); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* View group command definitions */ + +/************************** Get Group Membership command definitions ****************************/ +/** @defgroup ZB_ZCL_GROUPS_GET_GRP_MEMB Get Group Membership command definitions + * @{ + * @details + * Both Get Group Membership command request and response have a complex array-style payload. + * + * @par Examples + * Get Group Membership request can be filled in as: + * @snippet HA_samples/door_lock/sample_zed.c send_get_group_membership_req + * + * Get Group Membership response can be parsed as: + * @snippet doxygen_snippets.dox Parse Get Group Membership response_snippet_groups_dut_c + * If there are more then one response record, macro call can be iterated. + * @par + * + * For more information see 516_groups sample + */ + +/** @brief Get Group Membership command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_get_group_membership_req_s +{ + zb_uint8_t group_count; /**< Group count */ + zb_uint16_t group_id[1]; /**< Group id list */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_get_group_membership_req_t; + +/** @cond internals_doc */ + +/** @internal Minimum size of Get Group Membership request */ +#define ZB_ZCL_GET_GROUP_MEMBERSHIP_REQ_SIZE sizeof(zb_uint8_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Get Group Membership command and returns pointer to data request + structure. If request contains invlid data, NULL is returned + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param group_member_req - pointer to command request + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_GROUPS_GET_GROUP_MEMBERSHIP_REQ(data_buf, group_member_req) \ +{ \ + zb_uint8_t i_tmp; \ + zb_uint8_t cmd_size = ZB_ZCL_GET_GROUP_MEMBERSHIP_REQ_SIZE; \ + \ + (group_member_req) = (zb_buf_len(data_buf) >= cmd_size) ? \ + (zb_zcl_groups_get_group_membership_req_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (group_member_req) \ + { \ + cmd_size += sizeof(zb_uint16_t) * (group_member_req)->group_count; \ + if (cmd_size <= zb_buf_len(data_buf)) \ + { \ + for(i_tmp = 0; i_tmp < (group_member_req)->group_count; i_tmp++) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(group_member_req)->group_id[i_tmp]); \ + } \ + } \ + else \ + { \ + group_member_req = NULL; \ + } \ + } \ +} + +/** @brief Get Group Membership command response structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_get_group_membership_res_s +{ + zb_uint8_t capacity; /**< Capacity of group table */ + zb_uint8_t group_count; /**< Group count */ + zb_uint16_t group_id[1]; /**< Group id list */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_get_group_membership_res_t; + +/** @cond internals_doc */ + +/** @internal Minimum size of Get Group Membership command response */ +#define ZB_ZCL_GET_GROUP_MEMBERSHIP_RES_SIZE (2*sizeof(zb_uint8_t)) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Get Group Membership command response and returns pointer to data response + structure. If response contains invlid data, NULL is returned. + @param data_buf - pointer to zb_buf_t buffer containing command response data + @param group_member_res - pointer to command response + @note data_buf buffer should contain command response payload without ZCL header. + */ +#define ZB_ZCL_GROUPS_GET_GROUP_MEMBERSHIP_RES(data_buf, group_member_res) \ +{ \ + zb_uint8_t i; \ + zb_uint8_t cmd_size = ZB_ZCL_GET_GROUP_MEMBERSHIP_RES_SIZE; \ + \ + (group_member_res) = (zb_buf_len(data_buf) >= cmd_size) ? \ + (zb_zcl_groups_get_group_membership_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (group_member_res) \ + { \ + cmd_size += sizeof(zb_uint16_t) * (group_member_res)->group_count; \ + if (cmd_size <= zb_buf_len(data_buf)) \ + { \ + for(i = 0; i < (group_member_res)->group_count; i++) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(group_member_res)->group_id[i]); \ + } \ + } \ + else \ + { \ + group_member_res = NULL; \ + } \ + } \ +} + +/** @brief Initialize Get group membership command + @param buffer to put packet to + @param ptr - command buffer pointer + @param def_resp - enable/disable default response + @param group_cnt - group count +*/ +#define ZB_ZCL_GROUPS_INIT_GET_GROUP_MEMBERSHIP_REQ(buffer, ptr, def_resp, group_cnt) \ +{ \ + ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_GET_GROUP_MEMBERSHIP); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (group_cnt)); \ +} + +/** @brief Add group id to command payload + @param ptr - command buffer pointer + @param group_id - group ID +*/ +#define ZB_ZCL_GROUPS_ADD_ID_GET_GROUP_MEMBERSHIP_REQ(ptr, group_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ +} + +/** @brief Sends Get group membership command + @param buffer to place data to + @param ptr - pointer to the memory area after the command data end + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GROUPS_SEND_GET_GROUP_MEMBERSHIP_REQ( \ + buffer, ptr, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* Get Group Membership command definitions */ + + +/************************** Remove Group command definitions ****************************/ +/** @defgroup ZB_ZCL_GROUPS_RM_GRP Remove Group command definitions + * @{ + * @details + * Remove Group request and response commands have simple payload. Actual request handling takes + * place in ZCL internals. + * + * @par Examples + * Remove Group request sending: + * @snippet HA_samples/door_lock/sample_zed.c send_remove_group_req + * + * Remove Group response parsing: + * @snippet doxygen_snippets.dox Parse Remove Group response_snippet_groups_dut_c + * @par + * + * For more information see 516_groups sample + */ + +/** @brief Remove Group command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_remove_group_req_s +{ + zb_uint16_t group_id; /**< Group id */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_remove_group_req_t; + +/** @cond internals_doc */ + +/** @internal Minimum size of Get Group Membership request */ +#define ZB_ZCL_REMOVE_GROUP_REQ_SIZE sizeof(zb_zcl_groups_remove_group_req_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Remove group command and fills in data request + structure. If request contains invlid data, ZB_ZCL_NULL_ID is stored as group_id. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param rem_group_req - variable to save command request + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_GROUPS_GET_REMOVE_GROUP_REQ(data_buf, rem_group_req) \ +{ \ + zb_zcl_groups_remove_group_req_t *rem_group_req_ptr; \ + (rem_group_req_ptr) = zb_buf_len(data_buf) >= ZB_ZCL_REMOVE_GROUP_REQ_SIZE ? \ + (zb_zcl_groups_remove_group_req_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (rem_group_req_ptr) \ + { \ + ZB_HTOLE16(&(rem_group_req).group_id, &rem_group_req_ptr->group_id); \ + } \ + else \ + { \ + rem_group_req.group_id = ZB_ZCL_NULL_ID; \ + } \ +} + +/** @brief Remove group response command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_groups_remove_group_res_s +{ + zb_uint8_t status; /**< Operation status */ + zb_uint16_t group_id; /**< Group id */ +} +ZB_PACKED_STRUCT +zb_zcl_groups_remove_group_res_t; + +/** @cond internals_doc */ + +/** @internal Add group response size */ +#define ZB_ZCL_REMOVE_GROUP_RES_SIZE sizeof(zb_zcl_groups_remove_group_res_t) + +/** @endcond */ /* internals_doc */ + +/** @brief Parses Remove group response command and returns response data + structure or NULL if request contains invlid data. + @param data_buf - pointer to zb_buf_t buffer containing command response data + @param rem_group_res - out pointer to zb_zcl_groups_remove_group_res_t, containing command + response record + @note data_buf buffer should contain response command payload without ZCL header + */ +#define ZB_ZCL_GROUPS_GET_REMOVE_GROUP_RES(data_buf, rem_group_res) \ +{ \ + (rem_group_res) = zb_buf_len(data_buf) >= ZB_ZCL_REMOVE_GROUP_RES_SIZE ? \ + (zb_zcl_groups_remove_group_res_t*)zb_buf_begin(data_buf) : NULL; \ + \ + if (rem_group_res) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&(rem_group_res)->group_id); \ + } \ +} + +/** @brief Send Remove group command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param group_id - group ID to remove +*/ +#define ZB_ZCL_GROUPS_SEND_REMOVE_GROUP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, group_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_REMOVE_GROUP); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* Remove Group command definitions */ + + +/************************** Remove All Groups command definitions ****************************/ +/** @defgroup ZB_ZCL_GROUPS_RM_ALL_GRPS Remove All Groups command definitions + * @{ + * @details + * Remove All Groups command has only request form, and has no payload. Command is being + * processed in ZCL internals. If not disabled, command can be responded with Default Response + * command. + * + * @par Example + * Remove All Groups command sending: + * @snippet HA_samples/door_lock/sample_zed.c send_remove_all_groups_req + * @par + * + * For more information see 516_groups sample + */ + +/** @brief Send Remove all groups command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_GROUPS_SEND_REMOVE_ALL_GROUPS_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_REMOVE_ALL_GROUPS); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* Remove All Groups command definitions */ + +/************************** Add group if identifying command definitions **************************/ + +/** @defgroup ZB_ZCL_GROUPS_ADD_IDENT Add group if identifying command definitions + * @{ + * @details + * Add Group if Identifying command has simple payload. The command is being processed in ZCL + * internals. Since the command has only request form, it can be responded with Default Response + * command frame, if not disabled explicitly. + * + * @b Example: + * Add Group if Identifying send: + * @snippet HA_samples/door_lock/sample_zed.c add_group_if_ident_req + * + * For more information see 545_groups sample + */ + +/** @brief Send Add group if identifying command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param group_id - group ID to add +*/ +#define ZB_ZCL_GROUPS_SEND_ADD_GROUP_IF_IDENT_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, group_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_GROUPS_ADD_GROUP_IF_IDENTIFYING); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + /* Group name currently is not supported, put empty string */ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_NULL_STRING); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_GROUPS, cb); \ +} + +/** @} */ /* Add group if identifying command definitions */ + +/** + * Handler for incoming group commands directed to server + * + * @param param - reference to buffer containing command + * + * @return ZB_TRUE - if command was processed + * ZB_FALSE - if command is not for server or is not supported + */ +zb_bool_t zb_zcl_process_groups_commands_srv(zb_uint8_t param); + +/** + * Handler for incoming group commands directed to client + * + * @param param - reference to buffer containing command + * + * @return ZB_TRUE - if command was processed + * ZB_FALSE - if command is not for client or is not supported + */ +zb_bool_t zb_zcl_process_groups_commands_cli(zb_uint8_t param); + +/** @cond internals_doc + @internal @name Groups cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_GROUPS_NAME_SUPPORT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_GROUPS_NAME_SUPPORT_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/** @internal @brief Number of attributes mandatory for reporting in Groups cluster. */ +#define ZB_ZCL_GROUPS_REPORT_ATTR_COUNT 0 + +#if defined ZB_ZCL_SUPPORT_CLUSTER_SCENES +/** Scenes fieldset length for Groups cluster */ +#define ZB_ZCL_CLUSTER_ID_GROUPS_SCENE_FIELD_SETS_LENGTH 0 +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_SCENES */ + +/** @} + @endcond */ /* Groups cluster internals */ + +/** @} */ /* ZCL Groups cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_groups_init_server(void); +zb_void_t zb_zcl_groups_init_client(void); +#define ZB_ZCL_CLUSTER_ID_GROUPS_SERVER_ROLE_INIT zb_zcl_groups_init_server +#define ZB_ZCL_CLUSTER_ID_GROUPS_CLIENT_ROLE_INIT zb_zcl_groups_init_client + +#endif /* ZB_ZCL_GROUPS_H */ diff --git a/zboss/include/zcl/zb_zcl_grpw_bed_sensor.h b/zboss/include/zcl/zb_zcl_grpw_bed_sensor.h new file mode 100644 index 0000000000..ce4906c234 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_grpw_bed_sensor.h @@ -0,0 +1,68 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Bed Sensor for GreenPower cluster +*/ + +#if !defined ZB_ZCL_GRPW_BED_SENSOR_H +#define ZB_ZCL_GRPW_BED_SENSOR_H + +#define ZB_ZCL_CLUSTER_ID_GRPW_BED_SENSOR 0xfd00 + +enum zb_zcl_grpw_bed_sensor_attr_e +{ + ZB_ZCL_ATTR_GRPW_BED_SENSOR_STATUS_ID = 0x0000, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_CALC_DATA_0_ID = 0x0010, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_CALC_DATA_1_ID = 0x0011, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_SENSITIVITY_SETTING = 0x0020, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_CALC_DATA_SEND_INTERVAL = 0x0021, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_CALC_DATA_SEND_MODE = 0x0022, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_EXIT_DETECT_ADD_DELAY = 0x0023, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_OCCUPANCY_DETECT_ALG_SEL = 0x0024, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_TYPE = 0x0025, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_STATUS_REPORT_INTERVAL = 0x0026, + ZB_ZCL_ATTR_GRPW_BED_SENSOR_COMMANDS_FOR_SENSING_MODULE = 0x0030, + ZB_ZCL_ATTR_GRPW_BED_PENDING_CONFIGURATION = 0x00F0, +}; + +#define ZB_ZCL_CLUSTER_ID_GRPW_BED_SENSOR_SERVER_ROLE_INIT (zb_zcl_cluster_init_t)NULL +#define ZB_ZCL_CLUSTER_ID_GRPW_BED_SENSOR_CLIENT_ROLE_INIT (zb_zcl_cluster_init_t)NULL + +#endif /* ZB_ZCL_GRPW_BED_SENSOR_H */ diff --git a/zboss/include/zcl/zb_zcl_grpw_freq_agility.h b/zboss/include/zcl/zb_zcl_grpw_freq_agility.h new file mode 100644 index 0000000000..5b2ba21c6e --- /dev/null +++ b/zboss/include/zcl/zb_zcl_grpw_freq_agility.h @@ -0,0 +1,58 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Frequency agility for GreenPower cluster +*/ + +#if !defined ZB_ZCL_GRPW_FREQ_AGILITY_H +#define ZB_ZCL_GRPW_FREQ_AGILITY_H + +#define ZB_ZCL_CLUSTER_ID_GRPW_FREQ_AGILITY 0xFCFA + +enum zb_zcl_grpw_freq_agility_attr_e +{ + ZB_ZCL_ATTR_GRPW_FREQ_AGILITY_BRIDGE_ADDR = 0x0000, + ZB_ZCL_ATTR_GRPW_FREQ_AGILITY_ACTIVE_CHANNEL_MASK = 0x0001, +}; + +#define ZB_ZCL_CLUSTER_ID_GRPW_FREQ_AGILITY_SERVER_ROLE_INIT (zb_zcl_cluster_init_t)NULL +#define ZB_ZCL_CLUSTER_ID_GRPW_FREQ_AGILITY_CLIENT_ROLE_INIT (zb_zcl_cluster_init_t)NULL + +#endif /* ZB_ZCL_GRPW_FREQ_AGILITY_H */ diff --git a/zboss/include/zcl/zb_zcl_ias_ace.h b/zboss/include/zcl/zb_zcl_ias_ace.h new file mode 100644 index 0000000000..a7043da7d7 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_ias_ace.h @@ -0,0 +1,1577 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Ace cluster defintions +*/ + +#if ! defined ZB_ZCL_IAS_ACE_H +#define ZB_ZCL_IAS_ACE_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_IAS_ACE + * @{ + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_IAS_ACE */ + +/*! @name IAS Ace cluster attributes + @{ +*/ + +/*! @brief Structure representsation of IAS ACE Zone Table + * see ZCL spec 8.3.2.3, table 8.11 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_zone_table_s +{ + /** Zone ID */ + zb_uint8_t zone_id; + /** Zone Type, see @ref zb_zcl_ias_zone_zonetype_e */ + zb_uint16_t zone_type; + /** Zone Address */ + zb_ieee_addr_t zone_address; + /** The pointer to a string with Zone Label. If the pointer is zero, the Zone Label + * is not programmed */ + zb_char_t *zone_label; +} ZB_PACKED_STRUCT zb_zcl_ias_ace_zone_table_t; + +/** @brief IAS ACE Zone Table maximum length */ +#define ZB_ZCL_IAS_ACE_ZONE_TABLE_LENGTH 255 + +/** @brief IAS ACE ZoneType attribute maximum value */ +#define ZB_ZCL_IAS_ACE_ZONE_TYPE_MAX_VALUE 0xfffe + +/** @brief IAS ACE ZoneID attribute maximum value */ +#define ZB_ZCL_IAS_ACE_ZONE_ID_MAX_VALUE 0xfe + +/** @brief IAS ACE ZoneID attribute default value */ +#define ZB_ZCL_IAS_ACE_ZONE_ID_DEFAULT_VALUE 0 + +/** @brief IAS ACE Set Zone Address default value */ +#define ZB_ZCL_IAS_ACE_SET_ZONE_ADDRESS_DEFAULT_VALUE(ptr) (ZB_IEEE_ADDR_COPY(ptr, &g_unknown_ieee_addr)) + +/*! @brief IAS Ace cluster custom attribute identifiers +*/ +enum zb_zcl_ias_ace_attr_e +{ + /*! @brief Ace table length, ZCL spec 8.3.2.3 */ + ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_LENGTH_ID = 0xeffe, + /*! @brief Ace table ZCL spec 8.3.2.3 */ + ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_ID = 0xefff, + +}; + +/*! @cond internals_doc + @name IAS Ace cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_LENGTH_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_LENGTH_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in IAS Ace cluster */ +#define ZB_ZCL_IAS_ACE_REPORT_ATTR_COUNT 0 + +/*! @} + * @endcond*/ /* IAS Ace cluster internals */ + +/** @brief Declare attribute list for IAS Ace cluster - server side + @param attr_list - attribute list name + @param length - (zb_uint16_t*) pointer to variable to store Length of IAS ACE Zone Table attribute, + see ZCL spec 8.3.2.3, table 8.11 + @param table - pointer to variable to store IAS ACE Zone Table attribute, + see ZCL spec 8.3.2.3, table 8.11 +*/ +#define ZB_ZCL_DECLARE_IAS_ACE_ATTRIB_LIST(attr_list, length, table) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_LENGTH_ID, (length)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ACE_ZONE_TABLE_ID, (table)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* IAS Ace cluster attributes */ + +/*! @name IAS Ace cluster commands + @{ +*/ + +/*! @brief IAS Ace cluster command identifiers + @see ZCL spec, IAS Ace Cluster, 8.3.2.4 +*/ +enum zb_zcl_ias_ace_cmd_e +{ + /** Arm command, ZCL spec 8.3.2.4.1 */ + ZB_ZCL_CMD_IAS_ACE_ARM_ID = 0x00, + /** Bypass command, ZCL spec 8.3.2.4.2 */ + ZB_ZCL_CMD_IAS_ACE_BYPASS_ID = 0x01, + /** Emergency command, ZCL spec 8.3.2.4.3 */ + ZB_ZCL_CMD_IAS_ACE_EMERGENCY_ID = 0x02, + /** Fire command, ZCL spec 8.3.2.4.3 */ + ZB_ZCL_CMD_IAS_ACE_FIRE_ID = 0x03, + /** Panic command, ZCL spec 8.3.2.4.3 */ + ZB_ZCL_CMD_IAS_ACE_PANIC_ID = 0x04, + /** Get Zone ID Map command, ZCL spec 8.3.2.4.4 */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_ID = 0x05, + /** Get Zone Information command, ZCL spec 8.3.2.4.5 */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_ID = 0x06, + /** This command is used by ACE clients to request an update to the status + * (e.g. security system arm state) of the ACE server (i.e. the IAS CIE) */ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_ID = 0x07, + /** Provides IAS ACE clients with a way to retrieve the list of zones to be bypassed. */ + ZB_ZCL_CMD_IAS_ACE_GET_BYPASSED_ZONE_LIST_ID = 0x08, + /** This command is used by ACE clients to request an update of the status + * of the IAS Zone devices managed by the ACE server (i.e. the IAS CIE). */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_ID = 0x09, +}; + +/*! @brief IAS Ace cluster responce command identifiers + @see ZCL spec, IAS Ace Cluster, 8.3.2.5 +*/ +enum zb_zcl_ias_ace_resp_cmd_e +{ + /** Arm Response command, ZCL spec 8.3.2.5.1 */ + ZB_ZCL_CMD_IAS_ACE_ARM_RESP_ID = 0x00, + /** Get Zone ID Map Response command, ZCL spec 8.3.2.5.2 */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_RESP_ID = 0x01, + /** Get Zone Information Response command, ZCL spec 8.3.2.5.3 */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_RESP_ID = 0x02, + /** This command updates ACE clients in the system of changes to zone status + * recorded by the ACE server (e.g., IAS CIE device). */ + ZB_ZCL_CMD_IAS_ACE_ZONE_STATUS_CHANGED_ID = 0x03, + /** This command updates ACE clients in the system of changes to zone status + * recorded by the ACE server (e.g., IAS CIE device). */ + ZB_ZCL_CMD_IAS_ACE_PANEL_STATUS_CHANGED_ID = 0x04, + /** This command updates ACE clients in the system of changes to panel status + * recorded by the ACE server (e.g., IAS CIE device). */ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_RESPONSE_ID = 0x05, + /** Sets the list of bypassed zones on the IAS ACE client. */ + ZB_ZCL_CMD_IAS_ACE_SET_BYPASSED_ZONE_LIST_ID = 0x06, + /** Provides the response of the security panel to the request from the IAS ACE client + * to bypass zones via a Bypass command. */ + ZB_ZCL_CMD_IAS_ACE_BYPASS_RESPONSE_ID = 0x07, + /** Get Zone Status Response Command. */ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_RESPONSE_ID = 0x08, +}; + +/** @cond internals_doc */ +/* IAS ACE cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_IAS_ACE_ARM_RESP_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_RESP_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_RESP_ID, \ + ZB_ZCL_CMD_IAS_ACE_ZONE_STATUS_CHANGED_ID, \ + ZB_ZCL_CMD_IAS_ACE_PANEL_STATUS_CHANGED_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_RESPONSE_ID, \ + ZB_ZCL_CMD_IAS_ACE_SET_BYPASSED_ZONE_LIST_ID, \ + ZB_ZCL_CMD_IAS_ACE_BYPASS_RESPONSE_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_RESPONSE_ID + +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_ACE_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_IAS_ACE_ARM_ID, \ + ZB_ZCL_CMD_IAS_ACE_BYPASS_ID, \ + ZB_ZCL_CMD_IAS_ACE_EMERGENCY_ID, \ + ZB_ZCL_CMD_IAS_ACE_FIRE_ID, \ + ZB_ZCL_CMD_IAS_ACE_PANIC_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_BYPASSED_ZONE_LIST_ID, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_ID + +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_ACE_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + + +/******************************* Arm Command ******************************/ + +/** @brief Values of the Arm Mode + * see ZCL spec 8.3.2.4.1.2 +*/ +enum zb_zcl_ias_ace_arm_mode_e +{ + /** Disarm */ + ZB_ZCL_IAS_ACE_ARM_MODE_DISARM = 0x00, + /** Arm Day/Home Zones Only */ + ZB_ZCL_IAS_ACE_ARM_MODE_DAY = 0x01, + /** Arm Night/Sleep Zones Only */ + ZB_ZCL_IAS_ACE_ARM_MODE_NIGHT = 0x02, + /** Arm All Zones */ + ZB_ZCL_IAS_ACE_ARM_MODE_ALL = 0x03, +}; + +/*! @brief Structure representsation of Arm command, ZCL spec 8.3.2.4.1.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_arm_s +{ + /** Arm Mode, see @ref zb_zcl_ias_ace_arm_mode_e*/ + zb_uint8_t arm_mode; + /** Arm/Disarm Code */ + zb_uchar_t arm_disarm_code[ZB_ZCL_MAX_STRING_SIZE]; + /** Zone ID */ + zb_uint8_t zone_id; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_arm_t; + +/*! Arm request command payload size */ +#define ZB_ZCL_IAS_ACE_ARM_REQ_PAYLOAD_SIZE(ptr) (sizeof(zb_zcl_ias_ace_arm_t)-sizeof(((zb_zcl_ias_ace_arm_t *)(ptr))->arm_disarm_code)+ \ + 1+ZB_ZCL_GET_STRING_LENGTH(((zb_zcl_ias_ace_arm_t *)(ptr))->arm_disarm_code)) + +/*! @brief Arm command, ZCL spec 8.3.2.4.1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param arm_mode - Arm Mode, see @ref zb_zcl_ias_ace_arm_mode_e + @param arm_disarm_code - Arm/Disarm Code string + @param zone_id - Zone ID +*/ +#define ZB_ZCL_IAS_ACE_SEND_ARM_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + arm_mode, arm_disarm_code, zone_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_ARM_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (arm_mode)); \ + ZB_ZCL_PACKET_PUT_STRING(ptr, (arm_disarm_code)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Arm command, see ZCL spec 8.3.2.4.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_arm_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_ARM_REQ(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != \ + ZB_ZCL_IAS_ACE_ARM_REQ_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->arm_mode, data); \ + ZB_ZCL_PACKET_GET_STATIC_STRING((data_ptr)->arm_disarm_code, data); \ + if (!data) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->zone_id, data); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/******************************* Bypass Command ******************************/ + +/*! @brief Structure representsation of Bypass command, ZCL spec 8.3.2.4.2.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_bypass_s +{ + /** Number of Zones */ + zb_uint8_t length; + /** Zone ID array, see @ref zb_zcl_ias_ace_zone_table_s */ + zb_uint8_t zone_id[ZB_ZCL_IAS_ACE_ZONE_TABLE_LENGTH]; + /** Arm/Disarm Code */ + zb_uchar_t arm_disarm_code[ZB_ZCL_MAX_STRING_SIZE]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_bypass_t; + +/*! Bypass command payload size */ +#define ZB_ZCL_IAS_ACE_BYPASS_PAYLOAD_SIZE(ptr) (zb_uint_t)(1+(ptr)[0]+1+ZB_ZCL_GET_STRING_LENGTH((ptr)+1+(ptr)[0])) + +/*! @brief Start Bypass command, ZCL spec 8.3.2.4.1 + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_BYPASS_REQ_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_BYPASS_REQ_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_REQ_START(buffer, def_resp, length, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_BYPASS_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Add Zone Id to Bypass command, ZCL spec 8.3.2.4.1 + @param ptr - [in/out] (zb_uint8_t*) current position + @param zone_id - Zone ID, see @ref zb_zcl_ias_ace_zone_table_s +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_REQ_ADD(ptr, zone_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ +} + +/*! @brief End form Bypass command and send it, ZCL spec 8.3.2.4.1 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param arm_disarm_code - Arm/Disarm Code string + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_REQ_END( \ + ptr, buffer, arm_disarm_code, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_PACKET_PUT_STRING(ptr, (arm_disarm_code)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Bypass command, see ZCL spec 8.3.2.4.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_bypass_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_BYPASS_REQ(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_BYPASS_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->length, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->zone_id, data, (data_ptr)->length); \ + ZB_ZCL_PACKET_GET_STATIC_STRING((data_ptr)->arm_disarm_code, data); \ + if (!data) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/******************************* Emergency Command ******************************/ + +/*! @brief Emergency command, ZCL spec 8.3.2.4.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_EMERGENCY_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_EMERGENCY_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Fire Command ******************************/ + +/*! @brief Fire command, ZCL spec 8.3.2.4.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_FIRE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_FIRE_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Panic Command ******************************/ + +/*! @brief Panic command, ZCL spec 8.3.2.4.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_PANIC_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_PANIC_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Get Zone ID Map command ******************************/ + +/*! @brief Get Zone ID Map command, ZCL spec 8.3.2.4.4 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_ID_MAP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Get Zone Information command ******************************/ + +/*! @brief Structure representsation of Get Zone Information command, ZCL spec 8.3.2.4.5 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_zone_info_s +{ + /** Zone ID, see @ref zb_zcl_ias_ace_zone_table_s */ + zb_uint8_t zone_id; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_zone_info_t; + +/*! @brief Get Zone Information command, ZCL spec 8.3.2.4.5 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param zone_id - Zone ID, see @ref zb_zcl_ias_ace_zone_table_s +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_INFO_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + zone_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Get Zone Information command, ZCL spec 8.3.2.4.5 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_get_zone_info_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_GET_ZONE_INFO_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_ace_get_zone_info_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_ace_get_zone_info_t *src_ptr = \ + (zb_zcl_ias_ace_get_zone_info_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->zone_id = src_ptr->zone_id; \ + } \ +} + +/******************************* Get Panel Status command ******************************/ + +/*! @brief Get Panel Status command, ZCL spec 8.3.2.3.6 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_PANEL_STATUS_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Get Bypassed Zone List command ******************************/ + +/*! @brief Get Bypassed Zone List command, ZCL spec 8.3.2.3.7 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_BYPASSED_ZONE_LIST_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_GET_BYPASSED_ZONE_LIST_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/******************************* Get Zone Status command ******************************/ + +/*! @brief Structure representsation of Get Zone Status command, ZCL spec 8.3.2.3.8.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_zone_status_s +{ + /** Starting Zone ID, see @ref zb_zcl_ias_ace_zone_table_s */ + zb_uint8_t starting_zone_id; + /** Max Number of Zone IDs Requested Field */ + zb_uint8_t max_num_zone_ids; + /** Zone Status Mask Flag Field */ + zb_uint8_t zone_status_mask_flag; + /** Zone Status Mask Field, see @ref zb_zcl_ias_zone_zonestatus_e */ + zb_uint16_t zone_status_mask; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_zone_status_t; + +/*! @brief Get Zone Status command, ZCL spec 8.3.2.3.8 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param starting_zone_id - Starting Zone ID, see @ref zb_zcl_ias_ace_zone_table_s + @param max_num_zone_ids - Max Number of Zone IDs Requested Field + @param zone_status_mask_flag - Zone Status Mask Flag Field + @param zone_status_mask - Zone Status Mask Field +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + starting_zone_id, max_num_zone_ids, zone_status_mask_flag, \ + zone_status_mask) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (starting_zone_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (max_num_zone_ids)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_status_mask_flag)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (zone_status_mask)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Get Zone Status command, ZCL spec 8.3.2.3.8 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_get_zone_status_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_GET_ZONE_STATUS_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_ace_get_zone_status_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_ace_get_zone_status_t *src_ptr = \ + (zb_zcl_ias_ace_get_zone_status_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->starting_zone_id = src_ptr->starting_zone_id; \ + (data_ptr)->max_num_zone_ids = src_ptr->max_num_zone_ids; \ + (data_ptr)->zone_status_mask_flag = src_ptr->zone_status_mask_flag; \ + ZB_HTOLE16(&((data_ptr)->zone_status_mask), &(src_ptr->zone_status_mask)); \ + } \ +} + + +/******************************* Arm Response command ******************************/ + +/*! @brief Values of the Arm Notification + * see ZCL spec 8.3.2.5.1.2 +*/ +enum zb_zcl_ias_ace_arm_not_e +{ + /*! All Zones Disarmed */ + ZB_ZCL_IAS_ACE_ARM_NOT_DISARM = 0x00, + /*! Only Day/Home Zones Armed */ + ZB_ZCL_IAS_ACE_ARM_NOT_DAY = 0x01, + /*! Only Night/Sleep Zones Armed */ + ZB_ZCL_IAS_ACE_ARM_NOT_NIGHT = 0x02, + /*! All Zones Armed */ + ZB_ZCL_IAS_ACE_ARM_NOT_ALL = 0x03, +}; + +/*! @brief Structure representation of Arm Response command, ZCL spec 8.3.2.5.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_arm_resp_s +{ + /** Arm Notification, see @ref zb_zcl_ias_ace_arm_not_e */ + zb_uint8_t arm_notification; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_arm_resp_t; + + +/*! @brief Arm Response command, ZCL spec 8.3.2.5.1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param arm_notification - Arm Notification, see @ref zb_zcl_ias_ace_arm_not_e +*/ +#define ZB_ZCL_IAS_ACE_SEND_ARM_RESP( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + arm_notification) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_ARM_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (arm_notification)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, NULL); \ +} + +/** @brief Macro for getting Arm Response command, ZCL spec 8.3.2.5.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_arm_resp_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_ARM_RESP(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_ace_arm_resp_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_ace_arm_resp_t *src_ptr = \ + (zb_zcl_ias_ace_arm_resp_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->arm_notification = src_ptr->arm_notification; \ + } \ +} + +/******************************* Get Zone ID Map Response command ******************************/ + +/*! @brief Length of array of Bitmap of Zone ID Map, ZCL spec 8.3.2.5.2.1 */ +#define ZB_ZCL_IAS_ACE_GET_ZONE_ID_MAP_LENGTH 16 + +/*! @brief Structure representsation of Get Zone ID Map Response command, ZCL spec 8.3.2.5.2.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_zone_id_map_resp_s +{ + /** Zone ID Map */ + zb_uint16_t zone_id_map[ZB_ZCL_IAS_ACE_GET_ZONE_ID_MAP_LENGTH]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_zone_id_map_resp_t; + +/*! @brief Get Zone ID Map Response command, ZCL spec 8.3.2.5.2 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param zone_id_map - Zone ID Map, array[16] of zb_uint16_t +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_ID_MAP_RESP( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + zone_id_map) \ +{ \ + zb_uint8_t i; \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_ID_MAP_RESP_ID); \ + for(i=0; izone_id_map[i]), &(src_ptr->zone_id_map[i])); \ + } \ + } \ +} + +/******************* Get Zone Information Response command ******************************/ + +/*! @brief Zone Type is empty, ZCL spec 8.3.2.5.3.1 */ +#define ZB_ZCL_IAS_ACE_GET_ZONE_INFO_TYPE_NONE 0xffff + +/*! @brief Structure representsation of Get Zone Information Response command, ZCL spec 8.3.2.5.3.1 + * see @ ref zb_zcl_ias_ace_zone_table_s*/ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_zone_info_resp_s +{ + /** Zone ID */ + zb_uint8_t zone_id; + /** Zone Type, see @ref zb_zcl_ias_zone_zonetype_e */ + zb_uint16_t zone_type; + /** Zone Address */ + zb_ieee_addr_t address; + /** Zone Label Field */ + zb_uchar_t zone_label[ZB_ZCL_MAX_STRING_SIZE]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_zone_info_resp_t; + +/*! Get Zone Information Response command payload size */ +#define ZB_ZCL_IAS_ACE_GET_ZONE_INFO_RESP_PAYLOAD_SIZE(ptr) (sizeof(zb_zcl_ias_ace_get_zone_info_resp_t)-sizeof(((zb_zcl_ias_ace_get_zone_info_resp_t *)(ptr))->zone_label)+ \ + 1+ZB_ZCL_GET_STRING_LENGTH(((zb_zcl_ias_ace_get_zone_info_resp_t *)(ptr))->zone_label)) + +/*! @brief Get Zone Information Response command, ZCL spec 8.3.2.5.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param zone_id - Zone ID + @param zone_type - Zone Type, see @ref zb_zcl_ias_zone_zonetype_e + @param address - Zone Address + @param zone_label - Zone Label Field +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_INFO_RESP( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + zone_id, zone_type, address, zone_label) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_INFO_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (zone_type)); \ + ZB_ZCL_PACKET_PUT_DATA_IEEE(ptr, (address)); \ + ZB_ZCL_PACKET_PUT_STRING(ptr, (zone_label)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, NULL); \ +} + +/** @brief Macro for getting Get Zone Information Response command, ZCL spec 8.3.2.5.3 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_get_zone_info_resp_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_GET_ZONE_INFO_RESP(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_GET_ZONE_INFO_RESP_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->zone_id, data); \ + ZB_ZCL_PACKET_GET_DATA16(&(data_ptr)->zone_type, data); \ + ZB_ZCL_PACKET_GET_DATA_IEEE(&(data_ptr)->address, data); \ + ZB_ZCL_PACKET_GET_STATIC_STRING((data_ptr)->zone_label, data); \ + if (!data) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/******************* Zone Status Changed command ******************************/ + +/*! @brief IAS ACE Audible Notification Field + @see ZCL spec 8.3.2.4.4.4 +*/ +enum zb_zcl_ias_ace_aud_notification_e +{ + /** Mute (i.e., no audible notification) */ + ZB_ZCL_IAS_ACE_AUD_NOTIFICATION_MUTE = 0x00, + /** Default sound */ + ZB_ZCL_IAS_ACE_AUD_NOTIFICATION_DEF_SOUND = 0x01, + /** Manufacturer specific */ + ZB_ZCL_IAS_ACE_AUD_NOTIFICATION_MANUF_SPECIFIC = 0x80, +}; + +/*! @brief Structure representsation of Zone Status Changed command, ZCL spec 8.3.2.4.4 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_zone_status_changed_s +{ + /** Zone ID */ + zb_uint8_t zone_id; + /** Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e */ + zb_uint16_t zone_status; + /** Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e */ + zb_uint8_t aud_notification; + /** Zone Label Field */ + zb_uchar_t zone_label[ZB_ZCL_MAX_STRING_SIZE]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_zone_status_changed_t; + +/*! Zone Status Changed command payload size */ +#define ZB_ZCL_IAS_ACE_ZONE_STATUS_CHANGED_PAYLOAD_SIZE(ptr) (sizeof(zb_zcl_ias_ace_zone_status_changed_t)-sizeof(((zb_zcl_ias_ace_zone_status_changed_t *)(ptr))->zone_label)+ \ + 1+ZB_ZCL_GET_STRING_LENGTH(((zb_zcl_ias_ace_zone_status_changed_t *)(ptr))->zone_label)) + +/*! @brief Zone Status Changed command, ZCL spec 8.3.2.4.4 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param zone_id - Zone ID + @param zone_status - Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e + @param aud_notification - Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e + @param zone_label - Zone Label Field +*/ +#define ZB_ZCL_IAS_ACE_SEND_ZONE_STATUS_CHANGED_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, \ + cb, zone_id, zone_status, aud_notification, zone_label) \ +{ \ + zb_uint8_t* ptr = zb_zcl_start_command_header(buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + (def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_CMD_IAS_ACE_ZONE_STATUS_CHANGED_ID, \ + NULL); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (zone_status)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (aud_notification)); \ + ZB_ZCL_PACKET_PUT_STRING(ptr, (zone_label)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Zone Status Changed command, ZCL spec 8.3.2.4.4 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_zone_status_changed_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_ZONE_STATUS_CHANGED_REQ(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_ZONE_STATUS_CHANGED_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->zone_id, data); \ + ZB_ZCL_PACKET_GET_DATA16(&(data_ptr)->zone_status, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->aud_notification, data); \ + ZB_ZCL_PACKET_GET_STATIC_STRING((data_ptr)->zone_label, data); \ + if (!data) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/******************* Panel Status Changed command ******************************/ + +/*! @brief IAS ACE PanelStatus Parameter + @see ZCL spec 8.3.2.4.5.2 +*/ +enum zb_zcl_ias_ace_panel_status_e +{ + /** Panel disarmed (all zones disarmed) and ready to arm */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_DISARMED = 0x00, + /** Armed stay */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMED_STAY = 0x01, + /** Armed night */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMED_NIGHT = 0x02, + /** Armed away */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMED_AWAY = 0x03, + /** Exit delay */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_EXIT_DELAY = 0x04, + /** Entry delay */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ENTRY_DELAY = 0x05, + /** Not ready to arm */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_NOT_READY = 0x06, + /** In alarm */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_IN_ALARM = 0x07, + /** Arming Stay */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMING_STAY = 0x08, + /** Arming Night */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMING_NIGHT = 0x09, + /** Arming Away */ + ZB_ZCL_IAS_ACE_PANEL_STATUS_ARMING_AWAY = 0x0a, +}; + +/*! @brief IAS ACE Alarm Status Field + @see ZCL spec 8.3.2.4.5.4 +*/ +enum zb_zcl_ias_ace_alarm_status_e +{ + /** No alarm */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_NO_ALARM = 0x00, + /** Burglar */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_BURGLAR = 0x01, + /** Fire */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_FIRE = 0x02, + /** Emergency */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_EMERGENCY = 0x03, + /** Police Panic */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_POLICE_PANIC = 0x04, + /** Fire Panic */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_FIRE_PANIC = 0x05, + /** Emergency Panic */ + ZB_ZCL_IAS_ACE_ALARM_STATUS_EMERGENCY_PANIC = 0x06, +}; + +/*! @brief Structure representsation of Panel Status Changed command, ZCL spec 8.3.2.4.5 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_panel_status_changed_s +{ + /** Panel Status, see @ref zb_zcl_ias_ace_panel_status_e */ + zb_uint8_t panel_status; + /** Seconds Remaining Parameter */ + zb_uint8_t seconds_remaining; + /** Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e */ + zb_uint8_t aud_notification; + /** Alarm Status Field, see @ref zb_zcl_ias_ace_alarm_status_e */ + zb_uint8_t alarm_status; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_panel_status_changed_t; + +/*! @brief Panel Status Changed command, ZCL spec 8.3.2.4.5 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param panel_status - Panel Status, see @ref zb_zcl_ias_ace_panel_status_e + @param seconds_remaining - Seconds Remaining Parameter + @param aud_notification - Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e + @param alarm_status - Alarm Status Field, see @ref zb_zcl_ias_ace_alarm_status_e +*/ +#define ZB_ZCL_IAS_ACE_SEND_PANEL_STATUS_CHANGED_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, \ + cb, panel_status, seconds_remaining, aud_notification, \ + alarm_status) \ +{ \ + zb_uint8_t* ptr = zb_zcl_start_command_header(buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + (def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_CMD_IAS_ACE_PANEL_STATUS_CHANGED_ID, \ + NULL); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (panel_status)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (seconds_remaining)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (aud_notification)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (alarm_status)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Panel Status Changed command, ZCL spec 8.3.2.4.5 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_panel_status_changed_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_PANEL_STATUS_CHANGED_REQ(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_ace_panel_status_changed_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->panel_status, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->seconds_remaining, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->aud_notification, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->alarm_status, data); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************* Get Panel Status Response command ******************************/ + +/*! @brief Structure representsation of Get Panel Status Response command, ZCL spec 8.3.2.4.6 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_panel_status_resp_s +{ + /** Panel Status, see @ref zb_zcl_ias_ace_panel_status_e */ + zb_uint8_t panel_status; + /** Seconds Remaining Parameter */ + zb_uint8_t seconds_remaining; + /** Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e */ + zb_uint8_t aud_notification; + /** Alarm Status Field, see @ref zb_zcl_ias_ace_alarm_status_e */ + zb_uint8_t alarm_status; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_panel_status_resp_t; + +/*! @brief Get Panel Status Response command, ZCL spec 8.3.2.4.6 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param panel_status - Panel Status, see @ref zb_zcl_ias_ace_panel_status_e + @param seconds_remaining - Seconds Remaining Parameter + @param aud_notification - Audible Notification, see @ref zb_zcl_ias_ace_aud_notification_e + @param alarm_status - Alarm Status Field, see @ref zb_zcl_ias_ace_alarm_status_e +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_PANEL_STATUS_RESP( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + panel_status, seconds_remaining, aud_notification, \ + alarm_status) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_GET_PANEL_STATUS_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (panel_status)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (seconds_remaining)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (aud_notification)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (alarm_status)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, NULL); \ +} + +/** @brief Macro for getting Get Panel Status Response command, ZCL spec 8.3.2.4.6 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_get_panel_status_resp_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_GET_PANEL_STATUS_RESP(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_ace_panel_status_changed_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->panel_status, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->seconds_remaining, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->aud_notification, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->alarm_status, data); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************* Set Bypassed Zone List command ******************************/ + +/*! @brief Structure representsation of Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_set_bypassed_zone_list_s +{ + /** Number of Zones */ + zb_uint8_t length; + /** Zone ID array, see @ref zb_zcl_ias_ace_zone_table_s */ + zb_uint8_t zone_id[ZB_ZCL_IAS_ACE_ZONE_TABLE_LENGTH]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_set_bypassed_zone_list_t; + +/*! Set Bypassed Zone List command payload size */ +#define ZB_ZCL_IAS_ACE_SET_BYPASSED_ZONE_LIST_PAYLOAD_SIZE(ptr) (sizeof(zb_zcl_ias_ace_set_bypassed_zone_list_t)-sizeof(((zb_zcl_ias_ace_set_bypassed_zone_list_t *)(ptr))->zone_id)+ \ + ((zb_zcl_ias_ace_set_bypassed_zone_list_t *)(ptr))->length) + +/*! @brief Start Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 + @param buffer - to put packet to + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_START( \ + buffer, length, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ACE_SET_BYPASSED_ZONE_LIST_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Start Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 + (response to the Get Bypassed Zone List command) + @param buffer - to put packet to + @param seq - sequence + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_START_RESP( \ + buffer, seq, length, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_SET_BYPASSED_ZONE_LIST_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Start Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 + (unsolicited request) + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_START_REQ( \ + buffer, def_resp, length, ptr) \ +{ \ + (ptr) = zb_zcl_start_command_header(buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL( \ + ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + (def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_CMD_IAS_ACE_SET_BYPASSED_ZONE_LIST_ID, \ + NULL); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Add Zone Id to Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 + @param ptr - [in/out] (zb_uint8_t*) current position + @param zone_id - Zone ID, see @ref zb_zcl_ias_ace_zone_table_s +*/ +#define ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_ADD(ptr, zone_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ +} + +/*! @brief End form Set Bypassed Zone List command and send it, ZCL spec 8.3.2.4.7 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ACE_SEND_SET_BYPASSED_ZONE_LIST_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, cb); \ +} + +/** @brief Macro for getting Set Bypassed Zone List command, ZCL spec 8.3.2.4.7 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_set_bypassed_zone_list_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_SET_BYPASSED_ZONE_LIST(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_SET_BYPASSED_ZONE_LIST_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->length, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->zone_id, data, (data_ptr)->length); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************* Bypass Response command ******************************/ + +/*! @brief IAS ACE Bypass Result + @see ZCL spec 8.3.2.4.8.3 +*/ +enum zb_zcl_ias_ace_bypass_result_e +{ + /** The Zone ID requested to be bypassed is successful. Zone is bypassed. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_BYPASSED = 0x00, + /** The Zone ID requested to be bypassed is unsuccessful. Zone is not bypassed. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_NOT_BYPASSED = 0x01, + /** The Zone ID requested to be bypassed is not eligible to be bypassed per the + * policy or user configurations on the IAS ACE server. Zone is not bypassed. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_NOT_ALLOWED = 0x02, + /** The Zone ID requested to be bypassed is not in the valid range of Zone IDs. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_INVALID_ZONE_ID = 0x03, + /** The Zone ID requested to be bypassed is in the valid range of Zone IDs, but + * the IAS ACE server does not have a record of the Zone ID requested. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_UNKNOWN_ZONE_ID = 0x04, + /** A value returned indicating that the Arm/Disarm Code was entered incorrectly. */ + ZB_ZCL_IAS_ACE_BYPASS_RESULT_INVALID_ARM_CODE = 0x05, +}; + +/*! @brief Structure representsation of Bypass Response command, ZCL spec 8.3.2.4.8 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_bypass_resp_s +{ + /** Number of Zones */ + zb_uint8_t length; + /** Bypass Result for Zone IDs, see @ref zb_zcl_ias_ace_bypass_result_e */ + zb_uint8_t bypass_result[ZB_ZCL_IAS_ACE_ZONE_TABLE_LENGTH]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_bypass_resp_t; + +/*! Bypass Response command payload size */ +#define ZB_ZCL_IAS_ACE_BYPASS_RESP_PAYLOAD_SIZE(ptr) (sizeof(zb_zcl_ias_ace_bypass_resp_t)-sizeof(((zb_zcl_ias_ace_bypass_resp_t *)(ptr))->bypass_result)+ \ + ((zb_zcl_ias_ace_bypass_resp_t *)(ptr))->length) + +/*! @brief Start Bypass Response command, ZCL spec 8.3.2.4.8 + @param buffer - to put packet to + @param seq - sequence + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_BYPASS_RESP_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_BYPASS_RESP_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_RESP_START( \ + buffer, seq, length, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_BYPASS_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Add Bypass results to Bypass Response command, ZCL spec 8.3.2.4.8 + @param ptr - [in/out] (zb_uint8_t*) current position + @param bypass_result - Bypass Result for Zone IDs, see @ref zb_zcl_ias_ace_bypass_result_e +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_RESP_ADD(ptr, bypass_result) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (bypass_result)); \ +} + +/*! @brief End form Bypass Response command and send it, ZCL spec 8.3.2.4.8 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_IAS_ACE_SEND_BYPASS_RESP_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, NULL); \ +} + +/** @brief Macro for getting Bypass Response command, ZCL spec 8.3.2.4.8 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_bypass_resp_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_BYPASS_RESP(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_BYPASS_RESP_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->length, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->bypass_result, data, (data_ptr)->length); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/******************* Get Zone Status Response command ******************************/ + +/*! @brief IAS ACE Zone Status structure */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_zone_status_s +{ + /** Zone ID, see @ref zb_zcl_ias_ace_zone_table_s */ + zb_uint8_t zone_id; + /** Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e */ + zb_uint16_t zone_status; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_zone_status_t; + +/*! @brief Structure representsation of Get Zone Status Response command, ZCL spec 8.3.2.4.9 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_ace_get_zone_status_resp_s +{ + /** Zone Status Complete Field */ + zb_uint8_t zone_status_complete; + /** Number of Zones */ + zb_uint8_t length; + /** Status of Zone IDs, see @ref zb_zcl_ias_ace_zone_status_t */ + zb_zcl_ias_ace_zone_status_t zone_id_status[ZB_ZCL_IAS_ACE_ZONE_TABLE_LENGTH]; + +} ZB_PACKED_STRUCT zb_zcl_ias_ace_get_zone_status_resp_t; + +/*! Get Zone Status Response command payload size */ +#define ZB_ZCL_IAS_ACE_GET_ZONE_STATUS_RESP_PAYLOAD_SIZE(ptr) ((sizeof(zb_zcl_ias_ace_get_zone_status_resp_t)-sizeof(((zb_zcl_ias_ace_get_zone_status_resp_t *)(ptr))->zone_id_status))+ \ + ((zb_zcl_ias_ace_get_zone_status_resp_t *)(ptr))->length * sizeof(zb_zcl_ias_ace_zone_status_t)) + +/*! @brief Get Zone Status Response command, ZCL spec 8.3.2.4.9 + @param buffer - to put packet to + @param seq - sequence + @param zone_status_complete - Zone Status Complete + @param length - Number of Zones + @param ptr - [out] (zb_uint8_t*) current position for @ref ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_RESP_ADD + and @ref ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_RESP_END +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_RESP_START( \ + buffer, seq, zone_status_complete, length, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_IAS_ACE_GET_ZONE_STATUS_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (zone_status_complete)); \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (length)); \ +} + +/*! @brief Add Zone Id and Zone Status to Get Zone Status Response command, ZCL spec 8.3.2.4.9 + @param ptr - [in/out] (zb_uint8_t*) current position + @param zone_id - Zone ID, see @ref zb_zcl_ias_ace_zone_table_s + @param zone_status - Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_RESP_ADD( \ + ptr, zone_id, zone_status) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_status)); \ +} + +/*! @brief End form Get Zone Status Response command and send it, ZCL spec 8.3.2.4.9 + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_IAS_ACE_SEND_GET_ZONE_STATUS_RESP_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ACE, NULL); \ +} + +/** @brief Macro for getting Get Zone Status Response command, ZCL spec 8.3.2.4.9 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_ace_get_zone_status_resp_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ACE_GET_GET_ZONE_STATUS_RESP(data_ptr, buffer, status) \ +{ \ + zb_uint8_t *data = zb_buf_begin(buffer); \ + if (zb_buf_len((buffer)) != ZB_ZCL_IAS_ACE_GET_ZONE_STATUS_RESP_PAYLOAD_SIZE(data)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->zone_status_complete, data); \ + ZB_ZCL_PACKET_GET_DATA8(&(data_ptr)->length, data); \ + ZB_ZCL_PACKET_GET_DATA_N((data_ptr)->zone_id_status, data, \ + (data_ptr)->length * sizeof(zb_zcl_ias_ace_zone_status_t)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @} */ /* IAS Ace cluster commands */ + +/*! @} */ /* ZCL IAS Ace cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_ias_ace_init_server(void); +void zb_zcl_ias_ace_init_client(void); +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_SERVER_ROLE_INIT zb_zcl_ias_ace_init_server +#define ZB_ZCL_CLUSTER_ID_IAS_ACE_CLIENT_ROLE_INIT zb_zcl_ias_ace_init_client + +#endif /* ! defined ZB_ZCL_IAS_ACE_H */ diff --git a/zboss/include/zcl/zb_zcl_ias_wd.h b/zboss/include/zcl/zb_zcl_ias_wd.h new file mode 100644 index 0000000000..04f60fe7ed --- /dev/null +++ b/zboss/include/zcl/zb_zcl_ias_wd.h @@ -0,0 +1,470 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS WD cluster defintions +*/ + +#if ! defined ZB_ZCL_IAS_WD_H +#define ZB_ZCL_IAS_WD_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_IAS_WD + * @{ + * @details + * IAS WD cluster definitions + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_IAS_WD */ + +/*! @name IAS WD cluster attributes + @{ +*/ + +/*! @brief IAS WD cluster attribute identifiers + @see ZCL spec, IAS WD Cluster 8.4.2.2 +*/ +enum zb_zcl_ias_wd_attr_e +{ + /*! @brief Max Duration attribute, ZCL spec 8.4.2.2.1 */ + ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_ID = 0x0000, + +}; + +/** @brief Max Duration attribute default value */ +#define ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_DEF_VALUE 240 + +/** @brief Max Duration attribute minimum value */ +#define ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_MIN_VALUE 0 + +/** @brief Max Duration attribute maximum value */ +#define ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_MAX_VALUE 0xfffe + +/** @cond internals_doc */ +/*! @internal @name IAS WD cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in IAS WD cluster */ +#define ZB_ZCL_IAS_WD_REPORT_ATTR_COUNT 0 + +/*! @} */ /* IAS WD cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for IAS WD cluster - server side + @param attr_list - attribute list name + @param max_duration - pointer to variable to store Max Duration attribute +*/ +#define ZB_ZCL_DECLARE_IAS_WD_ATTRIB_LIST(attr_list, \ + max_duration) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_WD_MAX_DURATION_ID, (max_duration)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* IAS WD cluster attributes */ + +/*! @name IAS WD cluster commands + @{ +*/ + +/*! @brief IAS WD cluster command identifiers + @see ZCL spec, IAS WD Cluster, 8.4.2.3 +*/ +enum zb_zcl_ias_wd_cmd_e +{ + ZB_ZCL_CMD_IAS_WD_START_WARNING_ID = 0x00, /**< Start warning command. ZCL spec 8.4.2.3.1 */ + ZB_ZCL_CMD_IAS_WD_SQUAWK_ID = 0x01 /**< Squawk command. ZCL spec 8.4.2.3.2 */ +}; + +/** @cond internals_doc */ +/* IAS WD cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_IAS_WD_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_IAS_WD_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_WD_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_IAS_WD_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_IAS_WD_START_WARNING_ID, \ + ZB_ZCL_CMD_IAS_WD_SQUAWK_ID + +#define ZB_ZCL_CLUSTER_ID_IAS_WD_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_WD_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/******************************* Start warning command ******************************/ + +/** @brief Warning Mode Field, see ZCL spec 8.4.2.3.1.2 */ +enum zb_zcl_ias_wd_warning_mode_e +{ + /** Stop */ + ZB_ZCL_IAS_WD_WARNING_MODE_STOP = 0x00, + /** Burglar */ + ZB_ZCL_IAS_WD_WARNING_MODE_BURGLAR = 0x01, + /** Fire */ + ZB_ZCL_IAS_WD_WARNING_MODE_FIRE = 0x02, + /** Emergency */ + ZB_ZCL_IAS_WD_WARNING_MODE_EMERGENCY = 0x03, + /* Police panic */ + ZB_ZCL_IAS_WD_WARNING_MODE_POLICE_PANIC = 0x04, + /* Fire panic */ + ZB_ZCL_IAS_WD_WARNING_MODE_FIRE_PANIC = 0x05, + /* Emergency panic (i.e., medical issue) */ + ZB_ZCL_IAS_WD_WARNING_MODE_EMERGENCY_PANIC = 0x06, +}; + +/** @brief Strobe Field, see ZCL spec 8.4.2.3.1.3 */ +enum zb_zcl_ias_wd_strobe_e +{ + /** No strobe */ + ZB_ZCL_IAS_WD_STROBE_NO_STROBE = 0x00, + /** Use strobe in parallel to warning */ + ZB_ZCL_IAS_WD_STROBE_USE_STROBE = 0x01, +}; + +/** @brief Siren Level Field, see ZCL spec 8.4.2.3.1.4 */ +enum zb_zcl_ias_wd_siren_level_e +{ + /** Low level sound */ + ZB_ZCL_IAS_WD_SIREN_LEVEL_LOW = 0x00, + /** Medium level sound */ + ZB_ZCL_IAS_WD_SIREN_LEVEL_MEDIUM = 0x01, + /** High level sound */ + ZB_ZCL_IAS_WD_SIREN_LEVEL_HIGH = 0x02, + /** Very high level sound */ + ZB_ZCL_IAS_WD_SIREN_LEVEL_VERY_HIGH = 0x03, +}; + +/** + @brief Strobe Level Field, see ZCL spec 8.4.2.2.1.7 + */ +enum zb_zcl_ias_wd_strobe_level_e +{ + /** Low level strobe */ + ZB_ZCL_IAS_WD_STROBE_LEVEL_LOW = 0x00, + /** Medium level strobe */ + ZB_ZCL_IAS_WD_STROBE_LEVEL_MEDIUM = 0x01, + /** High level strobe */ + ZB_ZCL_IAS_WD_STROBE_LEVEL_HIGH = 0x02, + /** Very high level strobe */ + ZB_ZCL_IAS_WD_STROBE_LEVEL_VERY_HIGH = 0x03, +}; + +/*! @brief Structure representsation Start warning command. ZCL spec 8.4.2.3.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_wd_start_warning_s +{ + /** Status - enum flags Warning mode, Strobe and Siren Level, see ZCL spec 8.4.2.3.1 */ + zb_uint8_t status; + /** Warning duration*/ + zb_uint16_t duration; + /** Strobe Duty Cycle */ + zb_uint8_t strobe_duty_cycle; + /** Strobe Level (enum zb_zcl_ias_wd_strobe_level_e) */ + zb_uint8_t strobe_level; +} ZB_PACKED_STRUCT zb_zcl_ias_wd_start_warning_t; + +/*! @brief Get Warning Mode from payload Start warning command */ +#define ZB_ZCL_IAS_WD_GET_WARNING_MODE(status) (((status) >> 4) & 0x0f) + +/*! @brief Get Strobe from payload Start warning command */ +#define ZB_ZCL_IAS_WD_GET_STROBE(status) (((status) >> 2) & 0x03) + +/*! @brief Get Siren level from payload Start warning command */ +#define ZB_ZCL_IAS_WD_GET_SIREN_LEVEL(status) ((status) & 0x03) + +/*! @brief Make Status field Start warning command from Warning Mode, Strobe and Siren Level */ +#define ZB_ZCL_IAS_WD_MAKE_START_WARNING_STATUS(warning_mode, strobe, siren_level) \ + (((siren_level) & 0x03) | (((strobe) & 0x03) << 2) | (((warning_mode) & 0x0f) << 4)) + +/*! @brief Strobe Duty Cycle default value */ +#define ZB_ZCL_IAS_WD_STROBE_DUTY_CYCLE_DEFAULT_VALUE 0 +/*! @brief Strobe Duty Cycle maximum value */ +#define ZB_ZCL_IAS_WD_STROBE_DUTY_CYCLE_MAX_VALUE 100 + +/*! @brief Start warning command. ZCL spec 8.4.2.3.1 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param status - Status - enum flags Warning mode, Strobe and Siren Level + @param duration - Warning duration + @param strobe_duty_cycle - Strobe Duty Cycle + @param strobe_level - Strobe Level, see @ref zb_zcl_ias_wd_strobe_level_e +*/ +#define ZB_ZCL_IAS_WD_SEND_START_WARNING_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + status, duration, strobe_duty_cycle, strobe_level) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_WD_START_WARNING_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (duration)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (strobe_duty_cycle)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (strobe_level)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_WD, cb); \ +} + +/** @brief Macro for getting Start warning command. ZCL spec 8.4.2.3.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_wd_start_warning_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_WD_GET_START_WARNING_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_wd_start_warning_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_wd_start_warning_t *src_ptr = \ + (zb_zcl_ias_wd_start_warning_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + ZB_HTOLE16(&((data_ptr)->duration), &(src_ptr->duration)); \ + (data_ptr)->strobe_duty_cycle = src_ptr->strobe_duty_cycle; \ + (data_ptr)->strobe_level = src_ptr->strobe_level; \ + } \ +} + +/******************************* Squawk command ******************************/ + +/** @brief Squawk Mode Field, see ZCL spec 8.4.2.3.2.2 */ +enum zb_zcl_ias_wd_squawk_mode_e +{ + /** Notification sound for "System is armed" */ + ZB_ZCL_IAS_WD_SQUAWK_MODE_ARMED = 0x00, + /** Notification sound for "System is disarmed" */ + ZB_ZCL_IAS_WD_SQUAWK_MODE_DISARMED = 0x01, +}; + +/** @brief Strobe Field, see ZCL spec 8.4.2.3.2.3 */ +enum zb_zcl_ias_wd_squawk_strobe_e +{ + /** No strobe*/ + ZB_ZCL_IAS_WD_SQUAWK_STROBE_NO_STROBE = 0x00, + /** Use strobe blink in parallel to squawk */ + ZB_ZCL_IAS_WD_SQUAWK_STROBE_USE_STROBE = 0x01, +}; + +/** @brief Squawk level Field, see ZCL spec 8.4.2.3.2.4 */ +enum zb_zcl_ias_wd_squawk_level_e +{ + /** Low level sound */ + ZB_ZCL_IAS_WD_SQUAWK_LEVEL_LOW = 0x00, + /** Medium level sound */ + ZB_ZCL_IAS_WD_SQUAWK_LEVEL_MEDIUM = 0x01, + /** High level sound */ + ZB_ZCL_IAS_WD_SQUAWK_LEVEL_HIGH = 0x02, + /** Very High level sound */ + ZB_ZCL_IAS_WD_SQUAWK_LEVEL_VERY_HIGH = 0x03, +}; + +/*! @brief Structure representsation Squawk command. ZCL spec 8.4.2.3.2 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_wd_squawk_s +{ + /** Status - enum flags Squawk mode, Strobe and Squawk level, see ZCL spec 8.4.2.3.2 */ + zb_uint8_t status; +} ZB_PACKED_STRUCT zb_zcl_ias_wd_squawk_t; + +/*! @brief Get Squawk Mode from payload Squawk command */ +#define ZB_ZCL_IAS_WD_GET_SQUAWK_MODE(status) (((status) >> 4) & 0x0f) + +/*! @brief Get Squawk Strobe from payload Squawk command */ +#define ZB_ZCL_IAS_WD_GET_SQUAWK_STROBE(status) (((status) >> 3) & 0x01) + +/*! @brief Get Squawk Level from payload Squawk command */ +#define ZB_ZCL_IAS_WD_GET_SQUAWK_LEVEL(status) ((status) & 0x03) + +/*! @brief Make Status field Squawk command from Squawk mode, Strobe and Squawk level */ +#define ZB_ZCL_IAS_WD_MAKE_SQUAWK_STATUS(mode, strobe, level) \ + (((level) & 0x03) | (((strobe) & 0x01) << 3) | (((mode) & 0x0f) << 4)) + +/*! @brief Squawk command. ZCL spec 8.4.2.3.2 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param status - Status, see @ref zb_zcl_ias_wd_squawk_s +*/ +#define ZB_ZCL_IAS_WD_SEND_SQUAWK_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + status) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_WD_SQUAWK_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_WD, cb); \ +} + +/** @brief Macro for getting Squawk command. ZCL spec 8.4.2.3.2 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_wd_squawk_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_WD_GET_SQUAWK_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_wd_squawk_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_wd_squawk_t *src_ptr = \ + (zb_zcl_ias_wd_squawk_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + } \ +} + +/*! @} */ /* IAS WD cluster commands */ + +/*! @} */ /* ZCL IAS WD cluster definitions */ + + +/** @brief Declare run Start Warning command for User Application +*/ +typedef struct zb_zcl_ias_wd_start_warning_value_param_s +{ + zb_uint8_t warning_mode; /*!< Warning Mode */ + zb_uint8_t strobe; /*!< Strobe */ + zb_uint8_t siren_level; /*!< Siren level */ + zb_uint16_t duration; /*!< Duration */ + zb_uint8_t strobe_duty_cycle; /*!< Strobe duty cycle */ + zb_uint8_t strobe_level; /*!< Strobe level */ +} zb_zcl_ias_wd_start_warning_value_param_t; + +/*! Struct for invoke User App & continue after */ +typedef struct zb_zcl_ias_wd_start_warning_user_app_schedule_e +{ + zb_zcl_parsed_hdr_t cmd_info; /**< Parameters for continue command, + see @ref zb_zcl_parsed_hdr_s */ + zb_zcl_ias_wd_start_warning_value_param_t param; /**< User App command parameters, + see @ref zb_zcl_ias_wd_start_warning_value_param_s */ +} zb_zcl_ias_wd_start_warning_user_app_schedule_t; + +#define ZB_ZCL_IAS_WD_START_WARNING_SCHEDULE_USER_APP(buffer, pcmd_info, \ + warningMode, strobe_, siren_level_, duration_, strobe_duty_cycle_, strobe_level_) \ +{ \ + zb_zcl_ias_wd_start_warning_user_app_schedule_t* user_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_ias_wd_start_warning_user_app_schedule_t); \ + ZB_MEMMOVE(&(user_data->cmd_info), (pcmd_info), sizeof(zb_zcl_parsed_hdr_t)); \ + user_data->param.warning_mode = (warningMode); \ + user_data->param.strobe = (strobe_); \ + user_data->param.siren_level = (siren_level_); \ + user_data->param.duration = (duration_); \ + user_data->param.strobe_duty_cycle = (strobe_duty_cycle_); \ + user_data->param.strobe_level = (strobe_level_); \ + ZB_SCHEDULE_CALLBACK(zb_zcl_ias_wd_start_warning_invoke_user_app, (buffer)); \ +} + +/** @brief Declare run Squawk command for User Application +*/ +typedef struct zb_zcl_ias_wd_squawk_value_param_s +{ + zb_uint8_t squawk_mode; /*!< Squawk Mode */ + zb_uint8_t strobe; /*!< Strobe */ + zb_uint8_t squawk_level; /*!< Squawk level */ +} zb_zcl_ias_wd_squawk_value_param_t; + +/*! Struct for invoke User App & continue after */ +typedef struct zb_zcl_ias_wd_squawk_user_app_schedule_e +{ + zb_zcl_parsed_hdr_t cmd_info; /**< Parameters for continue command, + see @ref zb_zcl_parsed_hdr_s */ + zb_zcl_ias_wd_squawk_value_param_t param; /**< User App command parameters, + see @ref zb_zcl_ias_wd_squawk_value_param_s */ +} zb_zcl_ias_wd_squawk_user_app_schedule_t; + +#define ZB_ZCL_IAS_WD_SQUAWK_SCHEDULE_USER_APP(buffer, pcmd_info, \ + squawkMode, strobe_, level) \ +{ \ + zb_zcl_ias_wd_squawk_user_app_schedule_t* user_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_ias_wd_squawk_user_app_schedule_t); \ + ZB_MEMMOVE(&(user_data->cmd_info), (pcmd_info), sizeof(zb_zcl_parsed_hdr_t)); \ + user_data->param.squawk_mode = (squawkMode); \ + user_data->param.strobe = (strobe_); \ + user_data->param.squawk_level = (level); \ + ZB_SCHEDULE_CALLBACK(zb_zcl_ias_wd_squawk_invoke_user_app, ((buffer))); \ +} + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_ias_wd_init_server(void); +void zb_zcl_ias_wd_init_client(void); +#define ZB_ZCL_CLUSTER_ID_IAS_WD_SERVER_ROLE_INIT zb_zcl_ias_wd_init_server +#define ZB_ZCL_CLUSTER_ID_IAS_WD_CLIENT_ROLE_INIT zb_zcl_ias_wd_init_client + +#endif /* ! defined ZB_ZCL_IAS_WD_H */ diff --git a/zboss/include/zcl/zb_zcl_ias_zone.h b/zboss/include/zcl/zb_zcl_ias_zone.h new file mode 100644 index 0000000000..80087dac10 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_ias_zone.h @@ -0,0 +1,896 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: IAS Zone cluster defintions +*/ + +#if ! defined ZB_ZCL_IAS_ZONE_H +#define ZB_ZCL_IAS_ZONE_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_IAS_ZONE + * @{ + * @details + * IAS Zone cluster definitions + */ + +/** @cond internals_doc */ +/** @brief Hook on Write attribute + * send Zone Status Change Notification Command if change ZoneStatus attribute */ +zb_void_t zb_zcl_ias_zone_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); +/*! @} + * @endcond */ /* internals_doc */ + +/* Cluster ZB_ZCL_CLUSTER_ID_IAS_ZONE */ + +/*! @name IAS Zone cluster attributes + @{ +*/ + +/*! @brief IAS Zone cluster attribute identifiers + @see ZCL spec, IAS Zone Cluster 8.2.2.2 +*/ +enum zb_zcl_ias_zone_attr_e +{ + /*! @brief ZoneState attribute, ZCL spec 8.2.2.2.1.1 */ + ZB_ZCL_ATTR_IAS_ZONE_ZONESTATE_ID = 0x0000, + /*! @brief ZoneType attribute, ZCL spec 8.2.2.2.1.2 */ + ZB_ZCL_ATTR_IAS_ZONE_ZONETYPE_ID = 0x0001, + /*! @brief ZoneStatus attribute, ZCL spec 8.2.2.2.1.3 */ + ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID = 0x0002, + /*! @brief IAS_CIE_Address attribute, ZCL spec 8.2.2.2.2.1. */ + ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID = 0x0010, + /*! @brief ZoneID attribute, ZCL spec 8.2.2.1.2.2 */ + ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID = 0x0011, + /*! @brief NumberOfZoneSensitivityLevelsSupported attribute, ZCL spec 8.2.2.1.2.3 */ + ZB_ZCL_ATTR_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_ID = 0x0012, + /*! @brief CurrentZoneSensitivityLevel attribute, ZCL spec 8.2.2.1.2.4 */ + ZB_ZCL_ATTR_IAS_ZONE_CURRENT_ZONE_SENSITIVITY_LEVEL_ID = 0x0013, + /* custom attribute */ + ZB_ZCL_ATTR_CUSTOM_ZGP_CALIBRATION = 0x8000, + ZB_ZCL_ATTR_CUSTOM_ZGP_CLOUD_ACK = 0x8003, + ZB_ZCL_ATTR_CUSTOM_CIE_EP = 0xE001, + ZB_ZCL_ATTR_CUSTOM_CIE_SHORT_ADDR = 0xE002, + /* TODO: move this attribute to IAS Zone ZCL implementation */ + /*! @brief Struct with pointers on User App callbacks */ + ZB_ZCL_ATTR_IAS_ZONE_INT_CTX_ID = 0xeffe, +}; + +/** + * @brief IAS Zone ZoneState value + */ +enum zb_zcl_ias_zone_zonestate_e +{ + /** @brief ZoneState not enrolled value */ + ZB_ZCL_IAS_ZONE_ZONESTATE_NOT_ENROLLED = 0, + + /** @brief ZoneState enrolled value */ + ZB_ZCL_IAS_ZONE_ZONESTATE_ENROLLED = 1, +}; + +/** @brief IAS Zone ZoneState attribute default value */ +#define ZB_ZCL_IAS_ZONE_ZONESTATE_DEF_VALUE ZB_ZCL_IAS_ZONE_ZONESTATE_NOT_ENROLLED + +/** + * @brief IAS Zone ZoneType value + */ +enum zb_zcl_ias_zone_zonetype_e +{ + /** @brief ZoneType Standard CIE System Alarm value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_STANDARD_CIE = 0x0000, + + /** @brief ZoneType Motion value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_MOTION = 0x000d, + + /** @brief ZoneType Contact switch value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_CONTACT_SWITCH = 0x0015, + + /** @brief ZoneType Fire sensor value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_FIRE_SENSOR = 0x0028, + + /** @brief ZoneType Water sensor value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_WATER_SENSOR = 0x002a, + + /** @brief ZoneType Gas sensor value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_GAS_SENSOR = 0x002b, + + /** @brief ZoneType Personal emergency value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_PERSONAL_EMERGENCY = 0x002c, + + /** @brief ZoneType Vibration / Movement sensor value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_VIBRATION_MOVEMENT = 0x002d, + + /** @brief ZoneType Remote Control value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_REMOTE_CONTROL = 0x010f, + + /** @brief ZoneType Key fob value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_KEY_FOB = 0x0115, + + /** @brief ZoneType Keypad value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_KEYPAD = 0x021d, + + /** @brief ZoneType Standard Warning Device value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_STANDARD_WARNING = 0x0225, + + /** @brief Manufacturer specific ZoneType value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_MANUF_SPEC = 0x8000, + + /** @brief ZoneType Invalid Zone Type value */ + ZB_ZCL_IAS_ZONE_ZONETYPE_INVALID = 0xffff, + +}; + +/*! @brief IAS Zone ZoneStatus attribute flags + @see ZCL spec 8.2.2.2.1.3 +*/ +enum zb_zcl_ias_zone_zonestatus_e +{ + /** Alarm 1 */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM1 = 1 << 0, + /** Alarm 2 */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_ALARM2 = 1 << 1, + /** Tamper */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_TAMPER = 1 << 2, + /** Battery */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_BATTERY = 1 << 3, + /** Supervision reports */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_SUPERVISION = 1 << 4, + /** Restore reports */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_RESTORE = 1 << 5, + /** Trouble */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_TROUBLE = 1 << 6, + /** AC (mains) */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_AC_MAINS = 1 << 7, + /** Test */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_TEST = 1 << 8, + /** Battery Defect */ + ZB_ZCL_IAS_ZONE_ZONE_STATUS_BATTERY_DEFECT = 1 << 9, +}; + +/** @brief IAS Zone ZoneStatus attribute default value */ +#define ZB_ZCL_IAS_ZONE_ZONE_STATUS_DEF_VALUE 0 + +/** @brief Min value for NumberOfZoneSensitivityLevelsSupported attribute */ +#define ZB_ZCL_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_MIN_VALUE ((zb_uint8_t)0x02) + +/** @brief Default value for NumberOfZoneSensitivityLevelsSupported attribute */ +#define ZB_ZCL_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_DEFAULT_VALUE \ + ZB_ZCL_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_MIN_VALUE + +/** @brief Default value for CurrentZoneSensitivityLevel attribute */ +#define ZB_ZCL_IAS_ZONE_CURRENT_ZONE_SENSITIVITY_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief IAS Zone ZoneID attribute default value */ +#define ZB_ZCL_IAS_ZONEID_ID_DEF_VALUE 0xff + +/** @cond internals_doc */ +/** This macros should not be used by the user application directly */ +/*! @internal @name IAS Zone cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CUSTOM_CIE_EP(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CUSTOM_CIE_EP, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_CUSTOM_CIE_SHORT_ADDR(data_ptr) \ +{ \ + ZB_ZCL_ATTR_CUSTOM_CIE_SHORT_ADDR, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_ZONESTATE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_ZONESTATE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_ZONETYPE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_ZONETYPE_ID, \ + ZB_ZCL_ATTR_TYPE_16BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID, \ + ZB_ZCL_ATTR_TYPE_16BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID, \ + ZB_ZCL_ATTR_TYPE_IEEE_ADDR, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_CURRENT_ZONE_SENSITIVITY_LEVEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_CURRENT_ZONE_SENSITIVITY_LEVEL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IAS_ZONE_INT_CTX_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IAS_ZONE_INT_CTX_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in IAS Zone cluster */ +#define ZB_ZCL_IAS_ZONE_REPORT_ATTR_COUNT 1 + +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for IAS Zone cluster - server side + @param attr_list - attribute list name + @param zone_state - pointer to variable to store ZoneState attribute + @param zone_type - pointer to variable to store ZoneType attribute + @param zone_status - pointer to variable to store ZoneStatus attribute + @param ias_cie_address - pointer to variable to store IAS-CIE address attribute + @param cie_short_addr - custom attribute to store CIE short address + @param cie_ep - custom attribute to store CIE Endpoint number +*/ +/* FIXME: declare custom attributes internally */ +#define ZB_ZCL_DECLARE_IAS_ZONE_ATTRIB_LIST( \ + attr_list, zone_state, zone_type, zone_status,ias_cie_address, \ + cie_short_addr, cie_ep) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONESTATE_ID, (zone_state)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONETYPE_ID, (zone_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID, (zone_status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID, (ias_cie_address)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CUSTOM_CIE_SHORT_ADDR, (cie_short_addr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CUSTOM_CIE_EP, (cie_ep)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @brief Declare attribute list for IAS Zone cluster - server side (extended attribute set) + @param attr_list - attribute list name + @param zone_state - pointer to variable to store ZoneState attribute + @param zone_type - pointer to variable to store ZoneType attribute + @param zone_status - pointer to variable to store ZoneStatus attribute + @param ias_cie_address - pointer to variable to store IAS-CIE address attribute + @param zone_id - pointer to variable to store Zone ID attribute + @param number_of_zone_sens_levels_supported - pointer to variable to store + NumberOfZoneSensitivityLevelsSupported attribute + @param current_zone_sens_level - pointer to variable to store CurrentZoneSensitivityLevel attribute + @param cie_short_addr - custom attribute to store CIE short address + @param cie_ep - custom attribute to store CIE Endpoint number +*/ +/* FIXME: declare custom attributes internally */ +#define ZB_ZCL_DECLARE_IAS_ZONE_ATTRIB_LIST_EXT( \ + attr_list, zone_state, zone_type, zone_status, number_of_zone_sens_levels_supported, current_zone_sens_level, \ + ias_cie_address, zone_id, cie_short_addr, cie_ep) \ + zb_uint16_t last_change_##attr_list; \ + zb_zcl_ias_zone_int_ctx_t int_ctx_##attr_list; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONESTATE_ID, (zone_state)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONETYPE_ID, (zone_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONESTATUS_ID, (zone_status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_IAS_CIE_ADDRESS_ID, (ias_cie_address)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_ZONEID_ID, (zone_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_NUMBER_OF_ZONE_SENSITIVITY_LEVELS_SUPPORTED_ID, \ + (number_of_zone_sens_levels_supported)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_CURRENT_ZONE_SENSITIVITY_LEVEL_ID, \ + (current_zone_sens_level)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IAS_ZONE_INT_CTX_ID, &(int_ctx_##attr_list)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CUSTOM_CIE_SHORT_ADDR, (cie_short_addr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_CUSTOM_CIE_EP, (cie_ep)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* IAS Zone cluster attributes */ + +/*! @name IAS Zone cluster commands + @{ +*/ + +/*! @brief IAS Zone cluster command identifiers + @see ZCL spec, IAS Zone Cluster, 8.2.2.3 +*/ +enum zb_zcl_ias_zone_cmd_e +{ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_RESPONSE_ID = 0x00, /**< "Zone Enroll Response" command, + * ZCL spec 8.2.2.3.1 */ + /**< "Initiate Normal Operation Mode" command, ZCL spec 8.2.2.2.1 */ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_NORMAL_OPERATION_MODE_ID = 0x01, + /**< "Initiate Test Mode" command, ZCL spec 8.2.2.2.2.3 */ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_TEST_MODE_ID = 0x02, +}; + + +/*! @brief IAS Zone cluster response command identifiers + @see ZCL spec, IAS Zone Cluster, 8.2.2.4 +*/ +enum zb_zcl_ias_zone_resp_cmd_e +{ + ZB_ZCL_CMD_IAS_ZONE_ZONE_STATUS_CHANGE_NOT_ID = 0x00, /**< "Zone Status Change Notification" command. + ZCL spec 8.2.2.4.1 */ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_REQUEST_ID = 0x01 /**< "Zone Enroll Request" command. + ZCL spec 8.2.2.4.2 */ +}; + +/** @cond internals_doc */ +/* Ias zone cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_SERVER_ROLE_RECEIVED_CMD_LIST \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_RESPONSE_ID, \ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_NORMAL_OPERATION_MODE_ID, \ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_TEST_MODE_ID + +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_CLIENT_ROLE_RECEIVED_CMD_LIST \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_STATUS_CHANGE_NOT_ID, \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_REQUEST_ID + +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_SERVER_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_ZONE_CLIENT_ROLE_RECEIVED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_CLIENT_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_IAS_ZONE_SERVER_ROLE_RECEIVED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/*! @brief Structure representsation of Initiate Test Mode - Errata to 05-3520-29 Spec, 1.1.23.2.2.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_zone_init_test_mode_ha_s +{ + /** Test mode duration */ + zb_uint8_t test_mode_duration; + /** Current Zone Sensitivity Level */ + zb_uint8_t current_zone_sens_level; +} ZB_PACKED_STRUCT zb_zcl_ias_zone_init_test_mode_t; + +/** @brief Macro for getting "Initiate Test Mode" command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_zone_init_test_mode_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ZONE_GET_INITIATE_TEST_MODE_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_zone_init_test_mode_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_zone_init_test_mode_t *src_ptr = \ + (zb_zcl_ias_zone_init_test_mode_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->test_mode_duration = src_ptr->test_mode_duration; \ + (data_ptr)->current_zone_sens_level = src_ptr->current_zone_sens_level; \ + } \ +} + +/*! @brief Initiate Test Mode command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param test_mode_duration - Test Mode duration + @param current_zone_sens_level - CurrentZoneSensitivityLevel +*/ +#define ZB_ZCL_IAS_ZONE_SEND_INITIATE_TEST_MODE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, \ + test_mode_duration, current_zone_sens_level) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_TEST_MODE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (test_mode_duration)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (current_zone_sens_level)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/*! @brief Initiate Normal Operation Mode command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IAS_ZONE_SEND_INITIATE_NORMAL_OPERATION_MODE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, ZB_ZCL_ENABLE_DEFAULT_RESPONSE) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ZONE_INITIATE_NORMAL_OPERATION_MODE_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/******************************* Zone Status Change Notification ******************************/ + +/*! @brief Structure representsation of Zone Status Change Notification + * see ZCL spec 8.2.2.4.1.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_zone_status_change_not_s +{ + /** Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e*/ + zb_uint16_t zone_status; + /** Extended Status */ + zb_uint8_t extended_status; + /** Zone ID*/ + zb_uint8_t zone_id; + /** Delay */ + zb_uint16_t delay; +} ZB_PACKED_STRUCT zb_zcl_ias_zone_status_change_not_t; + + +/*! @brief Zone Status Change Notification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param zone_status - Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e + @param extended_status - Extended Status + @param zone_id - Zone ID + @param delay - Delay +*/ +#define ZB_ZCL_IAS_ZONE_SEND_STATUS_CHANGE_NOTIFICATION_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, \ + zone_status, extended_status, zone_id, delay ) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_STATUS_CHANGE_NOT_ID); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (zone_status)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (extended_status)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (delay)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/** @brief Macro for getting Zone Status Change Notification command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_zone_status_change_not_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ZONE_GET_STATUS_CHANGE_NOTIFICATION_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_zone_status_change_not_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_zone_status_change_not_t *src_ptr = \ + (zb_zcl_ias_zone_status_change_not_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->zone_status), &(src_ptr->zone_status)); \ + (data_ptr)->extended_status = src_ptr->extended_status; \ + (data_ptr)->zone_id = src_ptr->zone_id; \ + ZB_HTOLE16(&((data_ptr)->delay), &(src_ptr->delay)); \ + } \ +} + +/******************************* Zone Enroll Request command ******************************/ + +/*! @brief Structure representsation of "Zone Enroll Request" command + * see ZCL spec 8.2.2.4.1.2 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_zone_enroll_request_s +{ + /** Zone Type, see @ref zb_zcl_ias_zone_zonetype_e*/ + zb_uint16_t zone_type; + /** Manufacturer code */ + zb_uint16_t manufacturer_code; +} ZB_PACKED_STRUCT zb_zcl_ias_zone_enroll_request_t; + + +/*! @brief Zone "Zone Enroll Request" command, see ZCL spec 8.2.2.4.2 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param zone_type - Zone Type, see @ref zb_zcl_ias_zone_zonetype_e + @param manufacturer_code - Manufacture code +*/ +#define ZB_ZCL_IAS_ZONE_SEND_ZONE_ENROLL_REQUEST_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, \ + zone_type, manufacturer_code) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_REQUEST_ID); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (zone_type)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (manufacturer_code)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/** @brief Macro for getting Zone Status Change Notification command, see ZCL spec 8.2.2.4.1 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_zone_enroll_request_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ZONE_GET_ZONE_ENROLL_REQUEST_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_zone_enroll_request_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_zone_enroll_request_t *src_ptr = \ + (zb_zcl_ias_zone_enroll_request_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->zone_type), &(src_ptr->zone_type)); \ + ZB_HTOLE16(&((data_ptr)->manufacturer_code), &(src_ptr->manufacturer_code)); \ + } \ +} + +/******************************* Zone Enroll response ******************************/ + +/** @brief Values of the Enroll Response Code + * see ZCL spec 8.2.2.3.1.1 */ +enum zb_zcl_ias_zone_enroll_responce_code_e +{ + /** Success */ + ZB_ZCL_IAS_ZONE_ENROLL_RESPONCE_CODE_SUCCESS = 0x00, + /** Not supported */ + ZB_ZCL_IAS_ZONE_ENROLL_RESPONCE_CODE_NOT_SUPPORTED = 0x01, + /** No enroll permit */ + ZB_ZCL_IAS_ZONE_ENROLL_RESPONCE_CODE_NO_ENROLL = 0x02, + /** Too many zones */ + ZB_ZCL_IAS_ZONE_ENROLL_RESPONCE_CODE_TOO_MANY_ZONES = 0x03, +}; + +/*! @brief Structure representsation of Enroll response command payload + * see ZCL spec 8.2.2.3.1.1 */ +typedef ZB_PACKED_PRE struct zb_zcl_ias_zone_enroll_res_s +{ + /** Enroll response code */ + zb_uint8_t code; + /** Zone ID */ + zb_uint8_t zone_id; +} ZB_PACKED_STRUCT zb_zcl_ias_zone_enroll_res_t; + +/*! @brief Send "Zone Enroll response" command, see ZCL spec 8.2.2.3.1 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param code - Enroll response code, see @ref zb_zcl_ias_zone_enroll_responce_code_e + @param zone_id - Zone ID +*/ +#define ZB_ZCL_IAS_ZONE_SEND_ZONE_ENROLL_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + code, zone_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (code)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/*! @brief Send "Zone Enroll response with add parameters - sequency" command, see ZCL spec 8.2.2.3.1 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param code - Enroll response code, see @ref zb_zcl_ias_zone_enroll_responce_code_e + @param zone_id - Zone ID + @param seq - known sequency +*/ +#define ZB_ZCL_IAS_ZONE_SEND_ZONE_ENROLL_RES_EXT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + code, zone_id, seq) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, (seq), \ + ZB_ZCL_CMD_IAS_ZONE_ZONE_ENROLL_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (code)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (zone_id)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_IAS_ZONE, cb); \ +} + +/** @brief Macro for getting "Zone Enroll response" command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ias_zone_enroll_res_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IAS_ZONE_GET_ZONE_ENROLL_RES(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ias_zone_enroll_res_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ias_zone_enroll_res_t *src_ptr = \ + (zb_zcl_ias_zone_enroll_res_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->code = src_ptr->code; \ + (data_ptr)->zone_id = src_ptr->zone_id; \ + } \ +} + +/*! @} */ /* IAS Zone cluster commands */ + +/******************************* Set/Clear Zone Status bits ******************************/ + +/* Set or clear Zone Status bits + */ +zb_void_t zb_zcl_ias_zone_change_status(zb_uint8_t param); + +/** @brief Declare Set/Clear Zone Status bits +*/ +typedef struct zb_zcl_ias_zone_status_param_s +{ + zb_uint16_t bits; /*!< Bits map, see @ref zb_zcl_ias_zone_zonestatus_e */ + zb_bool_t is_set; /*!< true - set, fasle - clean */ + zb_uint8_t endpoint; /*!< endpoint */ + +} zb_zcl_ias_zone_status_param_t; + +/*! @brief Set Zone Status bits custom server command + @param buffer - to put packet to + @param ep - endpoint + @param set_bits - flag set of Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e +*/ +#define ZB_ZCL_IAS_ZONE_SET_BITS(buffer, ep, set_bits) \ +{ \ + zb_zcl_ias_zone_status_param_t* cmd_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_ias_zone_status_param_t); \ + cmd_data->endpoint = (ep); \ + cmd_data->bits = (set_bits); \ + cmd_data->is_set = ZB_TRUE; \ + ZB_SCHEDULE_CALLBACK(zb_zcl_ias_zone_change_status, ((buffer))); \ +} + +/*! @brief Clear Zone Status bits custom server command + @param buffer - to put packet to + @param ep - sending endpoint + @param set_bits - flag set of Zone Status, see @ref zb_zcl_ias_zone_zonestatus_e +*/ +#define ZB_ZCL_IAS_ZONE_CLEAR_BITS(buffer, ep, set_bits) \ +{ \ + zb_zcl_ias_zone_status_param_t* cmd_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_ias_zone_status_param_t); \ + cmd_data->endpoint = (ep); \ + cmd_data->bits = (set_bits); \ + cmd_data->is_set = ZB_FALSE; \ + ZB_SCHEDULE_CALLBACK(zb_zcl_ias_zone_change_status, ((buffer))); \ +} + +/** + @brief Structure is used to pass parameters for ZoneStatus + notification command + */ +typedef struct zb_zcl_ias_zone_notification_param_s +{ + zb_uint8_t ep; /*!< endpoint number */ + zb_uint16_t status_val; /*!< new value of zone_zone_status, see @ref zb_zcl_ias_zone_zonestatus_e */ + zb_uint16_t delay; /*!< Delay */ +} +zb_zcl_ias_zone_notification_param_t; + + +/** + @brief Use this function to change IAS Zone status. This function + will set new value of ZoneStatus and will send Zone status change + notification. + @note If another API (ZB_ZCL_SET_ATTRIBUTE()) is used for modifying + ZoneStatus, notification will NOT be send. This is limitation of + the current implementation. + @param ep - local endpoint number + @param new_val - new value for ZoneStatus + @param delay - delay in quater seconds (actual only for HA ZCL + version, is ignored for pure ZCL implementation) + @param buf_param - reference to a buffer that will be used for + sending notification. If buffer reference is not specified, + notification will NOT be sent + @return Returns ZB_TRUE if notification is scheduled for send, + ZB_FALSE otherwise + @note Notifiacation send result is reported to user App using + callback that is registered with zb_zcl_ias_zone_registrer_cb() +*/ +zb_bool_t zb_zcl_ias_zone_set_status( + zb_uint8_t ep, + zb_uint16_t new_val, + zb_uint16_t delay, + zb_uint8_t buf_param); + +enum zb_zcl_general_cb_params_e +{ + ZB_ZCL_VALID_CIE_ADDR_SET = 1, + ZB_ZCL_CURR_ZONE_SENSITIVITY_LEVEL_SET = 2, + ZB_ZCL_INIT_TEST_MODE = 3, + ZB_ZCL_INIT_NORMAL_MODE = 4, +}; + +typedef zb_ret_t (ZB_CODE * zb_ias_zone_app_callback_t)(zb_uint8_t param, zb_uint16_t general_val); + +typedef struct zb_zcl_ias_zone_int_ctx_s +{ + zb_callback_t process_result_cb; + zb_ias_zone_app_callback_t general_cb; + zb_uint8_t restore_current_zone_sens_level; + zb_uint8_t new_current_zone_sens_level; +} +zb_zcl_ias_zone_int_ctx_t; + +/** @brief Declare run Enroll Response command for User Application +*/ +typedef struct zb_zcl_ias_zone_enroll_response_value_param_s +{ + zb_uint8_t enroll_response; /*!< Enroll response code */ + zb_uint8_t zone_id; /*!< Zone ID */ +} zb_zcl_ias_zone_enroll_response_value_param_t; + +/*! Struct for invoke User App & continue after */ +typedef struct zb_zcl_ias_zone_enroll_response_user_app_schedule_e +{ + /**< Parameters for continue command, see @ref zb_zcl_parsed_hdr_s */ + zb_zcl_parsed_hdr_t cmd_info; + /**< User App command parameters, see @ref zb_zcl_ias_zone_enroll_response_value_param_s */ + zb_zcl_ias_zone_enroll_response_value_param_t param; +} zb_zcl_ias_zone_enroll_response_user_app_schedule_t; + +#define ZB_ZCL_IAS_ZONE_ENROLL_RESPONSE_SCHEDULE_USER_APP(buffer, pcmd_info, enroll_response_, zone_id_) \ +{ \ + zb_zcl_ias_zone_enroll_response_user_app_schedule_t* user_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_ias_zone_enroll_response_user_app_schedule_t); \ + ZB_MEMMOVE(&(user_data->cmd_info), (pcmd_info), sizeof(zb_zcl_parsed_hdr_t)); \ + user_data->param.enroll_response = (enroll_response_); \ + user_data->param.zone_id = (zone_id_); \ + ZB_SCHEDULE_CALLBACK(zb_zcl_ias_zone_enroll_response_invoke_user_app, ((buffer))); \ +} + +/** @brief Registry callbacks to get status of Zone Status Change Notification command + @param endpoint - local endpoint number + @param process_result_cb - notification sent callback function + @param general_cb - general callback function +*/ +zb_void_t zb_zcl_ias_zone_register_cb( + zb_uint8_t endpoint, + zb_callback_t process_result_cb, + zb_ias_zone_app_callback_t general_cb); + +/** + @brief checks, if Zone Status change notification should be sent + and schedules command if it is needed + @return ZB_TRUE if command is sent +*/ +zb_bool_t zb_zcl_ias_zone_check_attr_notify( + zb_uint8_t buf_param); + +/** + @brief fills in notification command and sends it +*/ +zb_void_t zb_zcl_ias_zone_send_status_change_not(zb_uint8_t param); + + +/*! @} */ /* ZCL IAS Zone cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_ias_zone_init_server(void); +zb_void_t zb_zcl_ias_zone_init_client(void); +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_SERVER_ROLE_INIT zb_zcl_ias_zone_init_server +#define ZB_ZCL_CLUSTER_ID_IAS_ZONE_CLIENT_ROLE_INIT zb_zcl_ias_zone_init_client + +zb_bool_t zb_zcl_process_ias_zone_specific_commands(zb_uint8_t param); +zb_bool_t zb_zcl_ias_zone_check_bind_unbind_request(zb_apsme_binding_req_t *aps_bind_req); + +#endif /* ! defined ZB_ZCL_IAS_ZONE_H */ diff --git a/zboss/include/zcl/zb_zcl_identify.h b/zboss/include/zcl/zb_zcl_identify.h new file mode 100644 index 0000000000..f6a3b068dd --- /dev/null +++ b/zboss/include/zcl/zb_zcl_identify.h @@ -0,0 +1,465 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZCL "Identify cluster" definitions +*/ + +#if ! defined ZB_ZCL_IDENTIFY_H +#define ZB_ZCL_IDENTIFY_H + +#if defined(ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY) || defined(DOXYGEN) + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_IDENTIFY + * @{ + * @details + * Identify cluster implementation supports Identify command and Identify Query request-response + * command pair. All these commands have simple payload. Both Identify and Identify Query + * request are being processed, and Identify Query response is being generated in ZCL internals. + * + * @par Example + * Identify sending: + * @snippet HA_samples/door_lock/sample_zed.c send_identify_req + * + * Identify Query request sending: + * @snippet HA_samples/on_off_switch/sample_zed.c identify_send_identify_query_req + * + * For more information see HA_samples/door_lock and HA_samples/on_off_switch samples + */ + +/** @name Identify cluster attributes + * @{ + */ + +/** @brief Identify cluster attribute identifier + @see ZCL spec, subclause 3.5.2.2 +*/ +enum zb_zcl_identify_attr_e +{ + /*! Identify time attribute */ + ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID = 0x0000 +}; + +/** @brief Default value for Identify attribute */ +#define ZB_ZCL_IDENTIFY_IDENTIFY_TIME_DEFAULT_VALUE 0x0000 + +/** @} */ /* Identify cluster attributes */ + +/*! @name Identify cluster command structures and definitions + @{ +*/ + +/** @brief Command identifiers for "Identify" cluster + @see ZCL spec, subclauses 3.5.2.3, 3.5.2.4 +*/ +enum zb_zcl_identify_cmd_e +{ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_ID = 0x00, /**< Identify command */ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_ID = 0x01, /**< Identify query command */ + ZB_ZCL_CMD_IDENTIFY_TRIGGER_EFFECT_ID = 0x40, /**< "Trigger effect" command identifier. */ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_RSP_ID = 0x00 /**< Identify query response */ +}; + +/** @cond internals_doc */ +/* Identify cluster commands lists : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_SERVER_ROLE_RECEIVED_CMD_LIST \ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_ID, \ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_ID, \ + ZB_ZCL_CMD_IDENTIFY_TRIGGER_EFFECT_ID, + +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_CLIENT_ROLE_RECEIVED_CMD_LIST \ + ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_RSP_ID, + +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_SERVER_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_IDENTIFY_CLIENT_ROLE_RECEIVED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_CLIENT_ROLE_GENERATED_CMD_LIST ZB_ZCL_CLUSTER_ID_IDENTIFY_SERVER_ROLE_RECEIVED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** Effect identifier enum + * @see ZCL spec 3.5.2.2.3.1 */ +enum zb_zcl_identify_trigger_effect_e +{ + /**< Effect identifier field value: Light is turned on/off once */ + ZB_ZCL_IDENTIFY_EFFECT_ID_BLINK = 0x00, + /**< Effect identifier field value: Light turned on/off over 1 second and + * repeated 15 times */ + ZB_ZCL_IDENTIFY_EFFECT_ID_BREATHE = 0x01, + /**< Effect identifier field value: Colored light turns green for 1 second; + * non-colored light flashes twice */ + ZB_ZCL_IDENTIFY_EFFECT_ID_OKAY = 0x02, + /**< Effect identifier field value: Colored light turns orange for 8 seconds; non-colored + * light switches to maximum brightness for 0.5s and then minimum brightness for 7.5s */ + ZB_ZCL_IDENTIFY_EFFECT_ID_CHANNEL_CHANGE = 0xb, + /**< Effect identifier field value: Complete the current effect sequence before terminating. + * E.g., if in the middle of a breathe effect (as above), first complete the current 1s + * breathe effect and then terminate the effect*/ + ZB_ZCL_IDENTIFY_EFFECT_ID_FINISH_EFFECT = 0xfe, + /**< Effect identifier field value: Terminate the effect as soon as possible */ + ZB_ZCL_IDENTIFY_EFFECT_ID_STOP = 0xff, +}; + + +/** Effect identifier enum + * @see ZCL spec 3.5.2.2.3.2 */ +enum zb_zcl_identify_trigger_variant_e +{ + /**< Effect variant field value: Default */ + ZB_ZCL_IDENTIFY_EFFECT_ID_VARIANT_DEFAULT = 0x00, +}; + + +/*! @brief Structured representsation of Trigger effect command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_identify_effect_req_s +{ + zb_uint8_t effect_id; /*!< Effect identify, see @ref zb_zcl_identify_trigger_effect_e */ + zb_uint8_t effect_variant; /*!< Effect variant, see @ref zb_zcl_identify_trigger_variant_e */ +} ZB_PACKED_STRUCT zb_zcl_identify_effect_req_t; + + +/*! @brief Send Trigger effect command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param def_resp - flag "Default response required" + @param cb - callback for getting command send status + @param effect_id - effect identify, see @ref zb_zcl_identify_trigger_effect_e + @param effect_var - effect variant, see @ref zb_zcl_identify_trigger_variant_e +*/ +#define ZB_ZCL_IDENTIFY_SEND_TRIGGER_VARIANT_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, def_resp, cb, effect_id, effect_var) \ +{ \ +zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ +ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_IDENTIFY_TRIGGER_EFFECT_ID); \ +ZB_ZCL_PACKET_PUT_DATA8(ptr, (effect_id)); \ +ZB_ZCL_PACKET_PUT_DATA8(ptr, (effect_var)); \ +ZB_ZCL_FINISH_PACKET(buffer, ptr) \ +ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prof_id, ZB_ZCL_CLUSTER_ID_IDENTIFY, cb); \ +} + + +/** @brief Parses Trigger effect command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_identify_effect_req_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IDENTIFY_GET_TRIGGER_VARIANT_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_identify_effect_req_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_identify_effect_req_t *src_ptr = \ + (zb_zcl_identify_effect_req_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_MEMCPY((data_ptr), src_ptr, sizeof(zb_zcl_identify_effect_req_t)); \ + } \ +} + +/** + * @name Inform User App about ZCL Identify cluster command and change attributes. + * Internal structures and define-procedure for inform User App about ZCL Identify + * cluster command and change attributes. + * @internal + * @{ + */ + +/** @brief Declare change Identify attribute for User Application +*/ +typedef struct zb_zcl_identify_effect_value_param_s +{ + zb_uint8_t effect_id; /*!< Effect identify */ + zb_uint8_t effect_variant; /*!< Effect variant */ +} zb_zcl_identify_effect_value_param_t; + + +/*! Struct for invoke User App & continue after */ +typedef struct zb_zcl_identify_effect_user_app_schedule_e +{ + zb_zcl_parsed_hdr_t cmd_info; /**< Parameters for continue command, + see @ref zb_zcl_parsed_hdr_s */ + zb_zcl_identify_effect_value_param_t param; /**< User App command parameters, + see @ref zb_zcl_identify_effect_value_param_s */ +} zb_zcl_identify_effect_user_app_schedule_t; + +#define ZB_ZCL_IDENTIFY_EFFECT_SCHEDULE_USER_APP(buffer, pcmd_info, effectId, effectVar) \ +{ \ + zb_zcl_identify_effect_user_app_schedule_t* data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_identify_effect_user_app_schedule_t); \ + ZB_MEMMOVE(&(data->cmd_info), (pcmd_info), sizeof(zb_zcl_parsed_hdr_t)); \ + data->param.effect_id = (effectId); \ + data->param.effect_variant = (effectVar); \ + ZB_SCHEDULE_CALLBACK(zb_zcl_identify_effect_invoke_user_app, (buffer)); \ +} +/*! @} */ /* internal */ + +/*! @brief Send Identify command + @param buffer to put packet to + @param time the device will be identifying + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - flag "Default response required" + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_IDENTIFY_SEND_IDENTIFY_REQ( \ + buffer, time, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_IDENTIFY_IDENTIFY_ID); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, time); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_IDENTIFY, cb); \ +} + +/*! @brief Send Identify Query command + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - flag "Default response required" + @param cb - callback for getting command send status + + @snippet on_off_switch/sample_zed.c identify_send_identify_query_req +*/ +#define ZB_ZCL_IDENTIFY_SEND_IDENTIFY_QUERY_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_IDENTIFY, cb); \ +} + +/*! @brief Send Identify Query Response command + @param buffer to put packet to + @param time the device will be identifying + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq_num - sequence number + @param aps_secured - APS sequrity mode +*/ +#define ZB_ZCL_IDENTIFY_SEND_IDENTIFY_QUERY_RES( \ + buffer, time, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq_num, aps_secured) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq_num, ZB_ZCL_CMD_IDENTIFY_IDENTIFY_QUERY_RSP_ID); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, time); \ + ZB_ZCL_FINISH_N_SEND_PACKET_NEW(buffer, ptr, \ + addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_IDENTIFY, NULL, aps_secured, \ + ZB_FALSE, 0); \ +} + +/** + * @brief Start identify process on given endpoint + * + * @param endpoint - endpoint to start identifying on + * @param timeout - time (in seconds) after which identifying will stop + */ +zb_uint8_t zb_zcl_start_identifying(zb_uint8_t endpoint, zb_uint16_t timeout); + +/** + * @brief Stop identify process on given endpoint + * Complimentary function to @ref zb_zcl_start_identifying. + * Used to force identify termination before timeout provided to + * @ref zb_zcl_start_identifying is elapsed + * + * @param endpoint Endpoint + */ +void zb_zcl_stop_identifying(zb_uint8_t endpoint); + +/** + * @brief Indicates that endpoint supports Identify cluster and is identifying + * @param endpoint number to analyze + * @return ZB_TRUE if endpoint is in the "identifying" state, ZB_FALSE otherwise. + */ +zb_uint8_t zb_zcl_is_identifying(zb_uint8_t endpoint); + +/*! @brief Structured representation of Identify command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_identify_req_s +{ + zb_uint16_t timeout; /*!< Time to identify */ +} ZB_PACKED_STRUCT zb_zcl_identify_req_t; + +/*! @brief Structured representation of Identify Query Response command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_identify_query_res_s +{ + zb_uint16_t timeout; /*!< Reported time to identify */ +} ZB_PACKED_STRUCT zb_zcl_identify_query_res_t; + +/*! @brief Identify cluster Identify command payload structured read + * @param data_ptr - pointer to a variable of type @ref zb_zcl_identify_req_t + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). +*/ +#define ZB_ZCL_IDENTIFY_GET_IDENTIFY_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_identify_req_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_identify_req_t *src_ptr = \ + (zb_zcl_identify_req_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->timeout), &(src_ptr->timeout)); \ + } \ +} + +/*! @brief Identify cluster Identify Query Response command payload structured + read + * @param data_ptr - pointer to a variable of type @ref zb_zcl_identify_query_res_t + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_IDENTIFY_GET_IDENTIFY_QUERY_RES(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_identify_query_res_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_identify_query_res_t *src_ptr = \ + (zb_zcl_identify_query_res_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->timeout), &(src_ptr->timeout)); \ + } \ +} + +/*! @} */ /* Identify cluster command structures and definitions */ + +/** @cond internals_doc */ +/*! + @name Identify cluster internals + @internal + Internal structures for attribute representation in cluster definitions. + @{ +*/ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#if defined ZB_ZCL_SUPPORT_CLUSTER_SCENES +/*! Scenes fieldset length for Identify cluster */ +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_SCENE_FIELD_SETS_LENGTH 0 +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_SCENES */ + +/*! @} */ /* Identify cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Identify cluster + @param attr_list - attribute list name + @param identify_time - pointer to variable to store identify time attribute value +*/ +#define ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(attr_list, identify_time) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID, (identify_time)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** + * @brief Identify cluster attributes + */ +typedef struct zb_zcl_identify_attrs_s +{ + /** @copydoc ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID + * @see ZB_ZCL_ATTR_IDENTIFY_IDENTIFY_TIME_ID + */ + zb_uint16_t identify_time; +} zb_zcl_identify_attrs_t; + + +/** @brief Declare attribute list for Identify cluster cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - variable of zb_zcl_identify_attrs_t type (containing Identify cluster attributes) + */ +#define ZB_ZCL_DECLARE_IDENTIFY_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_IDENTIFY_ATTRIB_LIST(attr_list, &attrs.identify_time) + + + +#if defined ZB_ENABLE_HA + +zb_uint8_t zb_zcl_get_cmd_list_identify(zb_bool_t is_client_generated, zb_uint8_t **cmd_list); + +#endif /* defined ZB_ENABLE_HA */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_identify_init_server(void); +void zb_zcl_identify_init_client(void); +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_SERVER_ROLE_INIT zb_zcl_identify_init_server +#define ZB_ZCL_CLUSTER_ID_IDENTIFY_CLIENT_ROLE_INIT zb_zcl_identify_init_client + +#endif /* defined(ZB_ZCL_SUPPORT_CLUSTER_IDENTIFY) */ + +#endif /* ! defined ZB_ZCL_IDENTIFY_H */ diff --git a/zboss/include/zcl/zb_zcl_illuminance_measurement.h b/zboss/include/zcl/zb_zcl_illuminance_measurement.h new file mode 100644 index 0000000000..3e92622801 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_illuminance_measurement.h @@ -0,0 +1,182 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Illuminance Measurement cluster defintions +*/ + +#ifndef ZB_ZCL_ILLUMINANCE_MEASUREMENT_H +#define ZB_ZCL_ILLUMINANCE_MEASUREMENT_H 1 + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_ILLUMINANCE_MEASUREMENT + * @{ + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT */ + +/*! @name Illuminance Measurement cluster attributes + @{ +*/ + +/*! @brief Illuminance Measurement cluster attribute identifiers + @see ZCL spec, Illuminance Measurement Cluster 4.2.2.2.1 +*/ +enum zb_zcl_illuminance_measurement_attr_e +{ + /** @brief MeasuredValue, ZCL spec 4.2.2.2.1.1 */ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID = 0x0000, + /** @brief MinMeasuredValue, ZCL spec 4.2.2.2.1.2 */ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID = 0x0001, + /** @brief MaxMeasuredValue, ZCL spec 4.2.2.2.1.3 */ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID = 0x0002, + /** The Tolerance attribute SHALL indicate the magnitude of the + * possible error that is associated with MeasuredValue, using the + * same units and resolution. */ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_TOLERANCE_ID = 0x0003, + /** The LightSensorType attribute specifies the electronic type of + * the light sensor. */ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_LIGHT_SENSOR_TYPE_ID = 0x0004, +}; + +/** @brief MeasuredValue attribute too-low value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_TOO_LOW 0 + +/** @brief MeasuredValue attribute invalid value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_INVALID 0xFFFF + +/** @brief MeasuredValue attribute default value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_DEFAULT \ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_TOO_LOW + +/** @brief Default value for LightSensorType attribute */ +#define ZB_ZCL_ILLUMINANCE_MEASUREMENT_LIGHT_SENSOR_TYPE_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief MinMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_MIN_VALUE 0x0001 + +/** @brief MinMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_MAX_VALUE 0xFFFD + +/** @brief MinMeasuredValue attribute not-defined value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_UNDEFINED 0xFFFF + +/** @brief MaxMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_MIN_VALUE 0x0002 + +/** @brief MaxMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_MAX_VALUE 0xFFFE + +/** @brief MaxMeasuredValue attribute not-defined value */ +#define ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_UNDEFINED 0xFFFF + + +/** @cond internals_doc */ +/*! @internal @name Illuminance Measurement cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_ZCL_ILLUMINANCE_MEASUREMENT_REPORT_ATTR_COUNT 1 + +/*! @} */ /* Illuminance Measurement cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Illuminance Measurement cluster - server side + @param attr_list - attribute list name + @param value - pointer to variable to store MeasuredValue attribute + @param min_value - pointer to variable to store MinMeasuredValue attribute + @param max_value - pointer to variable to store MAxMeasuredValue attribute +*/ +#define ZB_ZCL_DECLARE_ILLUMINANCE_MEASUREMENT_ATTRIB_LIST(attr_list, \ + value, min_value, max_value) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MEASURED_VALUE_ID, (value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MIN_MEASURED_VALUE_ID, (min_value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ILLUMINANCE_MEASUREMENT_MAX_MEASURED_VALUE_ID, (max_value)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Illuminance Measurement cluster attributes */ + +/*! @name Illuminance Measurement cluster commands + @{ +*/ + +/*! @} */ /* Illuminance Measurement cluster commands */ + +/*! @} */ /* ZCL Illuminance Measurement cluster definitions */ + +/** @endcond */ + +void zb_zcl_illuminance_measurement_init_server(void); +void zb_zcl_illuminance_measurement_init_client(void); +#define ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT_SERVER_ROLE_INIT zb_zcl_illuminance_measurement_init_server +#define ZB_ZCL_CLUSTER_ID_ILLUMINANCE_MEASUREMENT_CLIENT_ROLE_INIT zb_zcl_illuminance_measurement_init_client + +#endif /* ZB_ZCL_ILLUMINANCE_MEASUREMENT_H */ diff --git a/zboss/include/zcl/zb_zcl_level_control.h b/zboss/include/zcl/zb_zcl_level_control.h new file mode 100644 index 0000000000..5f7ead4a2e --- /dev/null +++ b/zboss/include/zcl/zb_zcl_level_control.h @@ -0,0 +1,923 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Level control cluster definitions +*/ + +#if !defined ZB_ZCL_LEVEL_CONTROL_H +#define ZB_ZCL_LEVEL_CONTROL_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_LEVEL_CONTROL + @{ +*/ + +/* ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL = 0x0008 defined in zb_zcl_common.h */ + +/*! @name Level Control cluster attributes + @{ +*/ + +/** @brief Level Control cluster information attribute identifiers + @see ZCL spec, subclause 3.10.2.2 +*/ + +/** + * @brief Level control attribute list + */ +enum zb_zcl_level_control_attr_e +{ + /** @brief Current Level attribute */ + ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID = 0x0000, + /** @brief Remaining Time attribute */ + ZB_ZCL_ATTR_LEVEL_CONTROL_REMAINING_TIME_ID = 0x0001, + /** @brief On Off Transition Time attribute */ + /** The MinLevel attribute indicates the minimum value of CurrentLevel that is capable + * of being assigned. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_MIN_LEVEL_ID = 0x0002, + /** The MaxLevel attribute indicates the maximum value of CurrentLevel that is capable + * of being assigned. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_MAX_LEVEL_ID = 0x0003, + /** The CurrentFrequency attribute represents the frequency that the devices is + * at CurrentLevel. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_FREQUENCY_ID = 0x0004, + /** The MinFrequency attribute indicates the minimum value of CurrentFrequency that + * is capable of being assigned. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_MIN_FREQUENCY_ID = 0x0005, + /** The MaxFrequency attribute indicates the maximum value of CurrentFrequency that + * is capable of being assigned. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_MAX_FREQUENCY_ID = 0x0006, + + ZB_ZCL_ATTR_LEVEL_CONTROL_ON_OFF_TRANSITION_TIME_ID = 0x0010, + /** @brief On Level attribute */ + + /* TODO: A close relationship between this cluster and the On/Off + * cluster is needed. Refer to ZCL spec, subclause 3.10.2.1 */ + ZB_ZCL_ATTR_LEVEL_CONTROL_ON_LEVEL_ID = 0x0011, + + /** The OnTransitionTime attribute represents the time taken to move the current level + * from the minimum level to the maximum level when an On command is received by + * an On/Off cluster on the same endpoint. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_ON_TRANSITION_TIME_ID = 0x0012, + /** The OffTransitionTime attribute represents the time taken to move the current level + * from the maximum level to the minimum level when an Off command is received by + * an On/Off cluster on the same endpoint. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_OFF_TRANSITION_TIME_ID = 0x0013, + /** The DefaultMoveRate attribute determines the movement rate, in units per second, + * when a Move command is received with a Rate parameter of 0xFF. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_DEFAULT_MOVE_RATE_ID = 0x0014, + /** The Options attribute is a bitmap that determines the default behavior of some + * cluster commands. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_OPTIONS_ID = 0x000F, + /** The StartUpCurrentLevel attribute SHALL define the desired startup level for a + * device when it is supplied with power and this level SHALL be reflected in + * the CurrentLevel attribute. */ + ZB_ZCL_ATTR_LEVEL_CONTROL_START_UP_CURRENT_LEVEL_ID = 0x4000, + + /** @internal Special Move Variables attribute */ + ZB_ZCL_ATTR_LEVEL_CONTROL_MOVE_STATUS_ID = 0xefff +}; + +/** + * @brief Level control Options attribute, ZCL spec 3.10.2.2.8 + */ +enum zb_zcl_level_control_options_e +{ + /** @brief ExecuteIfOff bit */ + ZB_ZCL_LEVEL_CONTROL_OPTIONS_EXECUTE_IF_OFF = 0, + ZB_ZCL_LEVEL_CONTROL_OPTIONS_RESERVED = 1, +}; + +/** @brief Current Level attribute minimum value */ +#define ZB_ZCL_LEVEL_CONTROL_LEVEL_MIN_VALUE 0x00 + +/** @brief Current Level attribute maximum value */ +#define ZB_ZCL_LEVEL_CONTROL_LEVEL_MAX_VALUE 0xff +/** @brief Current Level attribute maximum value */ +#define ZB_ZCL_LEVEL_CONTROL_LEVEL_MAX_VALUE_SHADE 0xff + +/** @brief Current Level attribute default value */ +#define ZB_ZCL_LEVEL_CONTROL_CURRENT_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0xFF) +/** @brief Default value for RemainingTime attribute */ +#define ZB_ZCL_LEVEL_CONTROL_REMAINING_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for MinLevel attribute */ +#define ZB_ZCL_LEVEL_CONTROL_MIN_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for MaxLevel attribute */ +#define ZB_ZCL_LEVEL_CONTROL_MAX_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for CurrentFrequency attribute */ +#define ZB_ZCL_LEVEL_CONTROL_CURRENT_FREQUENCY_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for MinFrequency attribute */ +#define ZB_ZCL_LEVEL_CONTROL_MIN_FREQUENCY_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for MaxFrequency attribute */ +#define ZB_ZCL_LEVEL_CONTROL_MAX_FREQUENCY_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for OnOffTransitionTime attribute */ +#define ZB_ZCL_LEVEL_CONTROL_ON_OFF_TRANSITION_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for OnLevel attribute */ +#define ZB_ZCL_LEVEL_CONTROL_ON_LEVEL_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for OnTransitionTime attribute */ +#define ZB_ZCL_LEVEL_CONTROL_ON_TRANSITION_TIME_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for OffTransitionTime attribute */ +#define ZB_ZCL_LEVEL_CONTROL_OFF_TRANSITION_TIME_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for Options attribute */ +#define ZB_ZCL_LEVEL_CONTROL_OPTIONS_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for OnLevel attribute */ +#define ZB_ZCL_LEVEL_CONTROL_START_UP_CURRENT_LEVEL_USE_PREVIOUS_VALUE ((zb_uint8_t)0xFF) + +/** @brief Transition Time as fast as able value + see ZCL spec 3.10.2.3.1.2 */ +#define ZB_ZCL_LEVEL_CONTROL_TRANSITION_TIME_AS_FAST_AS_ABLE 0xffff + +//#define ZB_ZCL_LEVEL_CONTROL_TRANSITION_TIME_ERROR 20 + +/** @cond internals_doc */ +#define ZB_ZCL_LEVEL_CONTROL_RATE_AS_FAST_AS_ABLE 0xff +/*! @} + * @endcond */ /* internals_doc */ + +/*! + @brief Declare attribute list for Level Control cluster + @param attr_list - attribute list name + @param current_level - pointer to variable to store current_level attribute value + @param remaining_time - pointer to variable to store remaining_time attribute value +*/ +#define ZB_ZCL_DECLARE_LEVEL_CONTROL_ATTRIB_LIST(attr_list, current_level, remaining_time) \ + zb_zcl_level_control_move_status_t move_status_data_ctx## _attr_list; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, (current_level)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_REMAINING_TIME_ID, (remaining_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_MOVE_STATUS_ID, \ + (&(move_status_data_ctx## _attr_list))) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + + +/*! + @brief Declare attribute list for Level Control cluster + @param attr_list - attribute list name + @param current_level - pointer to variable to store current_level attribute value + @param remaining_time - pointer to variable to store remaining_time attribute value + @param options - pointer to variable to store options attribute value + @param start_up_current_level - pointer to variable to store start_up_current_level attribute value +*/ +#define ZB_ZCL_DECLARE_LEVEL_CONTROL_ATTRIB_LIST_EXT(attr_list, current_level, remaining_time, \ + start_up_current_level, options) \ + zb_zcl_level_control_move_status_t move_status_data_ctx## _attr_list; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, (current_level)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_REMAINING_TIME_ID, (remaining_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_OPTIONS_ID, (options)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_START_UP_CURRENT_LEVEL_ID, (start_up_current_level)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_LEVEL_CONTROL_MOVE_STATUS_ID, \ + (&(move_status_data_ctx## _attr_list))) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Level Control cluster attributes */ + +/** @cond internals_doc */ +/*! @name Level Control cluster internals + Internal structures for Level Control cluster + @internal + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_LEVEL_CONTROL_CURRENT_LEVEL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_LEVEL_CONTROL_REMAINING_TIME_ID(data_ptr)\ +{ \ + ZB_ZCL_ATTR_LEVEL_CONTROL_REMAINING_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_LEVEL_CONTROL_OPTIONS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_LEVEL_CONTROL_OPTIONS_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_LEVEL_CONTROL_MOVE_STATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_LEVEL_CONTROL_MOVE_STATUS_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_LEVEL_CONTROL_START_UP_CURRENT_LEVEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_LEVEL_CONTROL_START_UP_CURRENT_LEVEL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} +/** @internal Structure of addr variables for Move commands + */ +typedef struct zb_zcl_level_control_move_addr_s +{ + zb_uint16_t src_addr; + zb_uint8_t src_endpoint; + zb_uint8_t dst_endpoint; + zb_uint8_t cmd_id; + zb_uint8_t seq_number; + zb_bool_t disable_default_response; + zb_uint16_t profile_id; +} zb_zcl_level_control_move_addr_t; + +/** @internal Structure of Move variables for Move alarm + */ +typedef struct zb_zcl_level_control_move_variables_s +{ + /** @brief Level to set */ + zb_uint8_t curr_level; + /** @brief End level */ + zb_uint8_t end_level; + /** @brief On/Off flag: ZB_TRUE - need to setting On/Off attribute, ZB_FALSE - do not need */ + zb_bool_t is_onoff; + /** @brief Address for response sending */ + zb_zcl_level_control_move_addr_t addr; + /** @brief Start time for set Remaining Time attribute */ + zb_uint16_t start_time; +} zb_zcl_level_control_move_variables_t; + +/** @internal Structure of Move Status attribute for Move alarm + */ +typedef struct zb_zcl_level_control_move_status_s +{ + zb_zcl_level_control_move_variables_t move_var; + zb_uint8_t buf_id; +} ZB_PACKED_STRUCT zb_zcl_level_control_move_status_t; + +/*! Number of attributes mandatory for reporting in Level Control cluster */ +#define ZB_ZCL_LEVEL_CONTROL_REPORT_ATTR_COUNT 1 + +/*! @} */ /* Level Control cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/*! @name Level Control cluster commands + @{ +*/ + +/*! @brief Level control cluster command identifiers + @see ZCL spec, subclause 3.10.2.3 +*/ +enum zb_zcl_level_control_cmd_e +{ + /** Move To Level command */ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL = 0x00, + /** Move command */ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE = 0x01, + /** Step command */ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP = 0x02, + /** Stop command */ + ZB_ZCL_CMD_LEVEL_CONTROL_STOP = 0x03, + /** Move To Level with On/Off command */ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL_WITH_ON_OFF = 0x04, + /** Move with On/Off command */ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_WITH_ON_OFF = 0x05, + /** Step with On/Off command */ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP_WITH_ON_OFF = 0x06, + /** Step with On/Off command */ + ZB_ZCL_CMD_LEVEL_CONTROL_STOP_WITH_ON_OFF = 0x07, + /** Upon receipt of "Move to Closest Frequency" command, the device shall change + * its current frequency to the requested frequency, or to the closest frequency + * that it can generate */ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_CLOSEST_FREQUENCY = 0x08, +}; + +/** @cond internals_doc */ +/* LEVEL control cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_LEVEL_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_LEVEL_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_LEVEL_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_LEVEL_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STOP, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL_WITH_ON_OFF, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_WITH_ON_OFF, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP_WITH_ON_OFF, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STOP_WITH_ON_OFF + +#define ZB_ZCL_CLUSTER_ID_LEVEL_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_LEVEL_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/************************** Level Control cluster command definitions ****************************/ + +/* command request structure */ + +/*! @brief Structured representsation of Level Control command payload (optional part) + @see ZCL spec, subclause 3.10.2.3.1.1*/ +typedef ZB_PACKED_PRE struct zb_zcl_level_control_req_options_s +{ + /** OptionsMask field */ + zb_uint8_t options_mask; + /** OptionsOverride field */ + zb_uint8_t options_override; +} ZB_PACKED_STRUCT zb_zcl_level_control_req_options_t; + +/** @brief Move to Level payload length macro */ +#define ZB_ZCL_LEVEL_CONTROL_REQ_OPTIONS_PAYLOAD_LEN \ + sizeof(zb_zcl_level_control_req_options_t) + +/** @internal Macro for getting Move to Level command */ +#define ZB_ZCL_LEVEL_CONTROL_GET_CMD_OPTIONS(data_buf, req_options, status) \ +{ \ + zb_zcl_level_control_req_options_t *req_options_ptr; \ + (req_options_ptr) = zb_buf_len(data_buf) >= \ + ZB_ZCL_LEVEL_CONTROL_REQ_OPTIONS_PAYLOAD_LEN ? \ + (zb_zcl_level_control_req_options_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_options_ptr) \ + { \ + req_options.options_mask = req_options_ptr->options_mask; \ + req_options.options_override = req_options_ptr->options_override; \ + status = ZB_TRUE; \ + (void)zb_buf_cut_left(data_buf, sizeof(zb_zcl_level_control_req_options_t)); \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/*! @brief Structured representsation of MOVE_TO_LEVEL command payload + @see ZCL spec, subclause 3.10.2.3.1.1*/ +typedef ZB_PACKED_PRE struct zb_zcl_level_control_move_to_level_req_s +{ + /** Level field */ + zb_uint8_t level; + /** Transition time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_level_control_move_to_level_req_t; + +/** @brief Move to Level payload length macro */ +#define ZB_ZCL_LEVEL_CONTROL_MOVE_TO_LEVEL_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_level_control_move_to_level_req_t) + +/** @internal Macro for sending Move to Level command */ +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_TO_LEVEL_CMD(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, level, transition_time, cmd_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), (cmd_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (level)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, cb); \ +} + +/** @internal Macro for getting Move to Level command */ +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_TO_LEVEL_CMD(data_buf, move_to_level_req, status) \ +{ \ + zb_zcl_level_control_move_to_level_req_t *move_to_level_req_ptr; \ + (move_to_level_req_ptr) = zb_buf_len(data_buf) >= \ + ZB_ZCL_LEVEL_CONTROL_MOVE_TO_LEVEL_REQ_PAYLOAD_LEN ? \ + (zb_zcl_level_control_move_to_level_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (move_to_level_req_ptr) \ + { \ + ZB_HTOLE16(&(move_to_level_req).transition_time, &(move_to_level_req_ptr->transition_time)); \ + move_to_level_req.level = move_to_level_req_ptr->level; \ + status = ZB_TRUE; \ + (void)zb_buf_cut_left(data_buf, sizeof(zb_zcl_level_control_move_to_level_req_t)); \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/*! @brief Send Move to Level command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param level - Level value + @param transition_time - Transition Time value +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_TO_LEVEL_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, level, transition_time) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_TO_LEVEL_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + level, \ + transition_time, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL) \ +} + +/*! + @brief Parses Get Move to Level command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param move_to_level_req - variable to save command request + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_TO_LEVEL_REQ(data_buf, move_to_level_req, status) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_GET_MOVE_TO_LEVEL_CMD(data_buf, move_to_level_req, status); \ +} + +/*! @brief Send Move to Level with On/Off command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param level - Level value + @param transition_time - Transition Time value +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_TO_LEVEL_WITH_ON_OFF_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, level, transition_time) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_TO_LEVEL_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + level, \ + transition_time, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_TO_LEVEL_WITH_ON_OFF) \ +} + +/*! + @brief Parses Get Move to Level with On/Off command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param move_to_level_req - variable to save command request. + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_TO_LEVEL_WITH_ON_OFF_REQ( \ + data_buf, move_to_level_req, status) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_GET_MOVE_TO_LEVEL_CMD(data_buf, move_to_level_req, status); \ +} + + +enum zb_zcl_level_control_move_mode_e +{ + ZB_ZCL_LEVEL_CONTROL_MOVE_MODE_UP = 0x00, + ZB_ZCL_LEVEL_CONTROL_MOVE_MODE_DOWN = 0x01 +}; + +/*! @brief Structured representsation of MOVE command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_level_control_move_req_s +{ + /** Move Mode field */ + zb_uint8_t move_mode; + /** Rate field */ + zb_uint8_t rate; +} ZB_PACKED_STRUCT zb_zcl_level_control_move_req_t; + +/** @brief Move payload length macro */ +#define ZB_ZCL_LEVEL_CONTROL_MOVE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_level_control_move_req_t) + +/** @internal Macro for sending Move command */ +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_CMD( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate, cmd_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), cmd_id); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (move_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (rate)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, cb); \ +} + +/** @internal Macro for getting Move command */ +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_CMD(data_buf, move_req, status) \ +{ \ + zb_zcl_level_control_move_req_t *move_req_ptr; \ + (move_req_ptr) = zb_buf_len(data_buf) >= ZB_ZCL_LEVEL_CONTROL_MOVE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_level_control_move_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (move_req_ptr) \ + { \ + ZB_MEMCPY(&(move_req), move_req_ptr, sizeof(zb_zcl_level_control_move_req_t)); \ + (void)zb_buf_cut_left(data_buf, sizeof(zb_zcl_level_control_move_req_t)); \ + status = ZB_TRUE; \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/*! @brief Send Move command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - Move Mode value + @param rate - Rate value +*/ +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_REQ(buffer, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + move_mode, \ + rate, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE); \ +} + +/*! + @brief Parses Get Move command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param move_req - variable to save command request + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_REQ(data_buf, move_req, status) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_GET_MOVE_CMD(data_buf, move_req, status); \ +} + +/*! @brief Send Move with On/Off command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param move_mode - Move Mode value + @param rate - Rate value +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_WITH_ON_OFF_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, move_mode, rate) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_MOVE_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + move_mode, \ + rate, \ + ZB_ZCL_CMD_LEVEL_CONTROL_MOVE_WITH_ON_OFF); \ +} + +/*! + @brief Parses Get Move with On/Off command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param move_req - variable to save command request + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_MOVE_WITH_ON_OFF_REQ(data_buf, move_req, status) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_GET_MOVE_CMD(data_buf, move_req, status); \ +} + +enum zb_zcl_level_control_step_mode_e +{ + ZB_ZCL_LEVEL_CONTROL_STEP_MODE_UP = 0x00, + ZB_ZCL_LEVEL_CONTROL_STEP_MODE_DOWN = 0x01 +}; + +/*! @brief Structured representsation of STEP command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_level_control_step_req_s +{ + /** Step Mode field */ + zb_uint8_t step_mode; + /** Step Size field */ + zb_uint8_t step_size; + /** Transition Time field */ + zb_uint16_t transition_time; +} ZB_PACKED_STRUCT zb_zcl_level_control_step_req_t; + +/** @brief Step payload length macro */ +#define ZB_ZCL_LEVEL_CONTROL_STEP_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_level_control_step_req_t) + + +/** @internal Macro for sending Step command */ +#define ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time, \ + cmd_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), cmd_id); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (step_size)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (transition_time)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, \ + cb); \ +} + + +/** @internal Macro for getting Step command */ +#define ZB_ZCL_LEVEL_CONTROL_GET_STEP_CMD(data_buf, step_req, status) \ +{ \ + zb_zcl_level_control_step_req_t *step_req_ptr; \ + (step_req_ptr) = zb_buf_len(data_buf) >= ZB_ZCL_LEVEL_CONTROL_STEP_REQ_PAYLOAD_LEN ? \ + (zb_zcl_level_control_step_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (step_req_ptr) \ + { \ + step_req.step_mode = step_req_ptr->step_mode; \ + step_req.step_size = step_req_ptr->step_size; \ + ZB_HTOLE16(&(step_req).transition_time, &step_req_ptr->transition_time); \ + (void)zb_buf_cut_left(data_buf, sizeof(zb_zcl_level_control_step_req_t)); \ + status = ZB_TRUE; \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/*! @brief Send Step command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - Step Mode value + @param step_size - Step Size value + @param transition_time - Transition Time value +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_STEP_REQ(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP); \ +} + +/*! + @brief Parses Get Step command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param step_req - variable to save command request + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_STEP_REQ(data_buf, step_req, status) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_GET_STEP_CMD(data_buf, step_req, status); \ +} + +/*! @brief Send Step with On/Off command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param step_mode - Step Mode value + @param step_size - Step Size value + @param transition_time - Transition Time value +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_STEP_WITH_ON_OFF_REQ(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time) \ +{ \ + ZB_ZCL_LEVEL_CONTROL_SEND_STEP_CMD(buffer, \ + addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prfl_id, \ + def_resp, \ + cb, \ + step_mode, \ + step_size, \ + transition_time, \ + ZB_ZCL_CMD_LEVEL_CONTROL_STEP_WITH_ON_OFF); \ +} + +/*! + @brief Parses Get Step with On/Off command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param step_req - variable to save command request + @param status - succsess or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_LEVEL_CONTROL_GET_STEP_WITH_ON_OFF_REQ(data_buf, step_req, status) \ + { \ + ZB_ZCL_LEVEL_CONTROL_GET_STEP_CMD(data_buf, step_req, status); \ +} + +/*! @brief Send Stop command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_STOP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), ZB_ZCL_CMD_LEVEL_CONTROL_STOP); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL, cb); \ +} + +/*! @brief Send Stop with On/off command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ + +#define ZB_ZCL_LEVEL_CONTROL_SEND_STOP_WITH_ON_OFF_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ + ZB_ZCL_LEVEL_CONTROL_SEND_STOP_REQ(buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) + +/** @cond internals_doc */ +typedef struct zb_zcl_level_control_set_value_param_s +{ + zb_uint8_t new_value; +} zb_zcl_level_control_set_value_param_t; +/*! @} + * @endcond */ /* internals_doc */ + + /* definition to parse request */ + + /* command response structure */ + + /* definition to parse response */ + + /* definition to send command request */ + +/*! @} */ /* Level Control cluster commands */ + +/*! @} */ /* ZCL Level Control cluster definitions */ + +/** @endcond */ + +void zb_zcl_level_control_init_server(void); +void zb_zcl_level_control_init_client(void); +#define ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL_SERVER_ROLE_INIT zb_zcl_level_control_init_server +#define ZB_ZCL_CLUSTER_ID_LEVEL_CONTROL_CLIENT_ROLE_INIT zb_zcl_level_control_init_client + +#endif /* ZB_ZCL_LEVEL_CONTROL_H */ diff --git a/zboss/include/zcl/zb_zcl_messaging.h b/zboss/include/zcl/zb_zcl_messaging.h new file mode 100644 index 0000000000..0b0f40eb02 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_messaging.h @@ -0,0 +1,631 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Messaging cluster defintions +*/ +#ifndef ZB_ZCL_MESSAGING_H_ +#define ZB_ZCL_MESSAGING_H_ + +#include "zboss_api_core.h" /* ZBOSS core API types */ +#include "zboss_api_aps.h" + +#define ZB_ZCL_MESSAGING_DISPLAY_MSG_MAX_NON_FRAG_SIZE 48 +#define ZB_ZCL_MESSAGING_MSG_CONFIRM_RESP_MSG_MAX_SIZE 21 + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_MESSAGING + * @{ + * @details + * The Messaging cluster provides an interface for passing text messages + * between Zigbee devices. + */ + + +/** @defgroup ZB_ZCL_MESSAGING_COMMANDS Messaging cluster commands + * @{ + */ + + +/** Commands generated by Messaging Server + * @see SE spec, subclause D.5.2.3 + */ +typedef enum zb_zcl_messaging_srv_cmd_e +{ + + /** @see SE spec, subclause D.5.2.3.1 + * @see zb_zcl_messaging_display_message_payload_s + */ + ZB_ZCL_MESSAGING_SRV_CMD_DISPLAY_MESSAGE = 0x00, + + /** @e TheCancelMessage command provides the ability + * to cancel the sending or acceptance of previously sent messages. When this + * message is received the recipient device has the option of clearing any + * display or user interfaces it supports, or has the option of logging the + * message for future reference. + * @see SE spec, subclause D.5.2.3.2 + * @see zb_zcl_messaging_cancel_message_payload_s + */ + ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_MESSAGE = 0x01, + + /** The Display Protected Message command is for use with messages that are + * protected by a password or PIN. + * @see zb_zcl_messaging_display_message_payload_s + */ + ZB_ZCL_MESSAGING_SRV_CMD_DISPLAY_PROTECTED_MESSAGE = 0x02, + + /** @e TheCancelAllMessages command indicates to a client device that it should + * cancel all display messages currently held by it. + * @note @e TheCancelAllMessages command in this revision of this specification + * is provisional and not certifiable. This feature may change before reaching + * certifiable status in a future revision of this specification. + * @see zb_zcl_messaging_cancel_all_message_payload_s + */ + ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_ALL_MESSAGES = 0x03 +} zb_zcl_messaging_srv_cmd_t; + + +/** Commands generated by Messaging Client + * @see SE spec, D.5.3.3 + */ +typedef enum zb_zcl_messaging_cli_cmd_e +{ + + /** On receipt of this command, the device shall send a @e DisplayMessage or + * @e DisplayProtectedMessage command as appropriate. A ZCL Default Response + * with status @e NOT_FOUND shall be returned if no message is available. + * @see SE spec, subclause D.5.3.3.1 + * @note This command has no payload. + */ + ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE = 0x00, + + /** @e TheMessageConfirmation command provides an indication that a Utility + * Customer has acknowledged and/or accepted the contents of a message + * previously received from the Messaging cluster server. Enhanced Message + * Confirmation commands shall contain an answer of ‘NO’, ‘YES’ and/or a + * message confirmation string. + * If the optional Message Confirmation Response is required, the Message + * Confirmation Control field shall also be present. + * @see SE spec, subclause D.5.3.3.2 + * @see zb_zcl_messaging_message_confirm_payload_s + */ + ZB_ZCL_MESSAGING_CLI_CMD_MESSAGE_CONFIRMATION = 0x01, + + /** This command initiates the return of the first (and maybe only) @e + * CancelAllMessages command held on the associated server, and which has an + * implementation time equal to or later than the value indicated in the payload. + * @note The @e GetMessageCancellation command in this revision of this + * specification is provisional and not certifiable. This feature may change + * before reaching certifiable status in a future revision of this specification. + * @see zb_zcl_messaging_get_message_cancellation_payload_s + */ + ZB_ZCL_MESSAGING_CLI_CMD_GET_MESSAGE_CANCELLATION = 0x02 +} zb_zcl_messaging_cli_cmd_t; + +/* MESSAGING cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_MESSAGING_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_MESSAGE, \ + ZB_ZCL_MESSAGING_SRV_CMD_DISPLAY_MESSAGE + +#define ZB_ZCL_CLUSTER_ID_MESSAGING_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_MESSAGING_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_MESSAGING_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE, \ + ZB_ZCL_MESSAGING_CLI_CMD_MESSAGE_CONFIRMATION + +#define ZB_ZCL_CLUSTER_ID_MESSAGING_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_MESSAGING_CLIENT_ROLE_GENERATED_CMD_LIST + + +/* Payload description */ + +/** Extended Message Control Field values + * @see SE spec, Table D-118 + * @see zb_zcl_messaging_display_message_payload_t::extended_message_control + */ +typedef enum zb_zcl_messaging_extended_message_control_e +{ + ZB_ZCL_MESSAGING_MESSAGE_HAS_NOT_BEEN_CONFIRMED = 0, /**< Message has not been confirmed */ + ZB_ZCL_MESSAGING_MESSAGE_HAS_BEEN_CONFIRMED = 1, /**< Message has been confirmed */ +} zb_zcl_messaging_extended_message_control_field_t; + +/** Extended Message Control Field Bit Map + * @see SE spec, Table D-118 + */ +enum zb_zcl_messaging_extended_message_control_field_bitmap_e +{ + ZB_ZCL_MESSAGING_MESSAGE_CONFIRMATION_STATUS = 0, /**< @see zb_zcl_messaging_extended_message_control_field_e*/ +}; + + +/** @ref ZB_ZCL_MESSAGING_SRV_CMD_DISPLAY_MESSAGE "DisplayMessage" command payload + * @see SE spec, subclause D.5.2.3.1.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_messaging_display_message_payload_s +{ + /** 32-bit number identifier for the message. */ + zb_uint32_t message_id; /* (M) */ + + /** BitMap field indicating control information related to the message */ + zb_uint8_t message_control; /* (M) */ + + /** The time at which the message becomes valid */ + zb_uint32_t start_time; /* (M) */ + + /** The amount of time in minutes after the Start Time during which + * the message is displayed */ + zb_uint16_t duration_in_minutes; /* (M) */ + + /** Message (variable): Character String + * WARNING: Variable length of message supported, but remember to pass strings in global memory only! + */ + zb_uint8_t message_len; /* (M) */ + zb_uint8_t *message; /* (M) */ + + /** BitMap field indicating additional control + * and status information for a given message. + */ + zb_uint8_t extended_message_control; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_messaging_display_message_payload_t; + + +/** @e MessageControl field's transmission mechanism values + * @see SE spec, Table D-117 + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_TRANSMISSION_MECHANISM + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_TRANSMISSION_MECHANISM + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_TRANSMISSION_MECHANISM + */ +typedef enum zb_zcl_messaging_message_control_transmission_mechanism_e +{ + ZB_ZCL_MESSAGING_NORMAL_TRANSMISSION_ONLY = 0, /**< Send message through normal command + * function to client. + */ + ZB_ZCL_MESSAGING_NORMAL_AND_INTERNAL_PAN_TRANSMISSION = 1, /**< Send message through normal command + * function to client and pass message onto the + * Inter-PAN transmission mechanism. + */ + ZB_ZCL_MESSAGING_INTER_PAN_TRANSMISSION_ONLY = 2, /**< Send message through the Inter-PAN + * transmission mechanism. + */ +} zb_zcl_messaging_control_field_transmission_mechanism_t; + + +/** + * Set @e MessageControl's transmission mechanism value + * @param x - variable to store transmission mechanism value + * @param val - @ref zb_zcl_messaging_control_field_transmission_mechanism_t value + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_TRANSMISSION_MECHANISM(x, val) ((x) &= (0xFC | ((val) & 0x03))) + + +/** + * Get @e MessageControl's transmission mechanism value + * @param x - variable that stores transmission mechanism value + * @see zb_zcl_messaging_control_field_transmission_mechanism_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_TRANSMISSION_MECHANISM(x) ((x) & 0x03) + + +/** + * Clear @e MessageControl's transmission mechanism value + * @param x - variable that stores transmission mechanism value + * @see zb_zcl_messaging_control_field_transmission_mechanism_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_TRANSMISSION_MECHANISM(x) ((x) &= 0xFC) + + +/** @e MessageControl field's control importance values + * @see SE spec, Table D-117 + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_IMPORTANCE_LEVEL + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_IMPORTANCE_LEVEL + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_IMPORTANCE_LEVEL + */ +typedef enum zb_zcl_messaging_message_control_importance_level_e +{ + ZB_ZCL_MESSAGING_IMPORTANCE_LEVEL_LOW = 0, /**< Low importance level */ + ZB_ZCL_MESSAGING_IMPORTANCE_LEVEL_MEDIUM = 1, /**< Medium importance level */ + ZB_ZCL_MESSAGING_IMPORTANCE_LEVEL_HIGH = 2, /**< High importance level */ + ZB_ZCL_MESSAGING_IMPORTANCE_LEVEL_CRITICAL = 3, /**< Critical importance level */ +} zb_zcl_messaging_message_control_importance_level_t; + + +/** + * Set @e MessageControl's control importance value + * @param x - variable to store control importance value + * @param val - @ref zb_zcl_messaging_message_control_importance_level_t value + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_IMPORTANCE_LEVEL(x, val) ((x) &= (0xF3 | ((val) & 0x03) << 2) + + +/** + * Get @e MessageControl's control importance value + * @param x - variable that stores control importance value + * @see zb_zcl_messaging_message_control_importance_level_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_IMPORTANCE_LEVEL(x) (((x) >> 2) & 0x03) + + +/** + * Clear @e MessageControl's control importance value + * @param x - variable that stores control importance value + * @see zb_zcl_messaging_message_control_importance_level_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_IMPORTANCE_LEVEL(x) ((x) &= 0xF3) + + +/** @e MessageControl field's enhanced confirmation values + * @see SE spec, Table D-117 + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_ENHANCED_CONFIRMATION + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_ENHANCED_CONFIRMATION + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_ENHANCED_CONFIRMATION + */ +typedef enum zb_zcl_messaging_message_control_enhanced_confirmation_e +{ + ZB_ZCL_MESSAGING_ENHANCED_CONFIRMATION_NOT_REQUIRED = 0, /**< Enhanced Confirmation not required */ + ZB_ZCL_MESSAGING_ENHANCED_CONFIRMATION_REQUIRED = 1, /**< Enhanced Confirmation required */ +} zb_zcl_messaging_message_control_enhanced_confirmation_t; + + +/** + * Set @e MessageControl's enhanced confirmation value + * @param x - variable to store enhanced confirmation value + * @param val - @ref zb_zcl_messaging_message_control_enhanced_confirmation_t value + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_ENHANCED_CONFIRMATION(x, val) ((x) &= (0xDF | ((val) & 0x01) << 5) + +/** + * Get @e MessageControl's enhanced confirmation value + * @param x - variable that stores enhanced confirmation value + * @see zb_zcl_messaging_message_control_enhanced_confirmation_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_ENHANCED_CONFIRMATION(x) (((x) >> 5) & 0x01) + +/** + * Clear @e MessageControl's enhanced confirmation value + * @param x - variable that stores enhanced confirmation value + * @see zb_zcl_messaging_message_control_enhanced_confirmation_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_ENHANCED_CONFIRMATION(x) ((x) &= 0xDF ) + + +/** @e MessageControl field's message confirmation values + * @see SE spec, Table D-117 + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_MESSAGE_CONFIRMATION + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_MESSAGE_CONFIRMATION + * @see ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_MESSAGE_CONFIRMATION + */ +typedef enum zb_zcl_messaging_message_control_message_confirmation_e +{ + ZB_ZCL_MESSAGING_MESSAGE_CONFIRMATION_NOT_REQUIRED = 0x00, /**< Message Confirmation not required. */ + ZB_ZCL_MESSAGING_MESSAGE_CONFIRMATION_REQUIRED = 0x01, /**< Message Confirmation required. */ +} zb_zcl_messaging_message_control_message_confirmation_t; + + +/** + * Set @e MessageControl's message confirmation value + * @param x - variable to store message confirmation value + * @param val - @ref zb_zcl_messaging_message_control_message_confirmation_t value + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_SET_MESSAGE_CONFIRMATION(x, val) ((x) &= (0x7F | ((val) & 0x01) << 7) + + +/** + * Get @e MessageControl's message confirmation value + * @param x - variable that stores message confirmation value + * @see zb_zcl_messaging_message_control_message_confirmation_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_GET_MESSAGE_CONFIRMATION(x) (((x) >> 7) & 0x01) + +/** + * Clear @e MessageControl's message confirmation value + * @param x - variable that stores message confirmation value + * @see zb_zcl_messaging_message_control_message_confirmation_t + */ +#define ZB_ZCL_MESSAGING_MESSAGE_CONTROL_CLR_MESSAGE_CONFIRMATION(x) ((x) &= 0x7F) + + +/** Check if some size in range of variable size of specified payload. + */ +#define ZB_ZCL_MESSAGING_DISPLAY_MSG_PAYLOAD_SIZE_IS_VALID(size) \ +((size) > ((zb_int16_t)sizeof(zb_zcl_messaging_display_message_payload_t) - \ +(zb_int16_t)ZB_SIZEOF_FIELD(zb_zcl_messaging_display_message_payload_t, \ + message) - 1/*extended_message_control field is optional*/)) + +/* 8/16/2017 NK CR:MINOR Do all compilers support such initializing? More common way to initialize + * is to provide pointer as parameter and operate with it inside the macro. */ +/* 8/21/2017 IA: It is C99 features. I hope, they are supported by all "our" compilers. */ + +/** @ref zb_zcl_messaging_display_message_payload_t initializer */ +#define ZB_ZCL_MESSAGING_DISPLAY_MSG_PAYLOAD_INIT \ + (zb_zcl_messaging_display_message_payload_t)\ + { \ + .extended_message_control = 0x00, \ + } + +/** @ref ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_MESSAGE "CancelMessage" command payload + * @see SE spec, subclause D.5.2.3.2.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_messaging_cancel_message_payload_s +{ + /** 32-bit number identifier for the message. */ + zb_uint32_t message_id; /* (M) */ + + /** This field is deprecated and should be set to 0x00 */ + zb_uint8_t message_control; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_messaging_cancel_message_payload_t; + +/** @ref zb_zcl_messaging_cancel_message_payload_t initializer */ +#define ZB_ZCL_MESSAGING_CANCEL_MSG_PAYLOAD_INIT \ + (zb_zcl_messaging_cancel_message_payload_t) {0} + + +/* Get last message command has no payload */ + + +/** Message Confirmation Control + * @see SE spec, Table D-120 + * @see zb_zcl_messaging_message_confirm_payload_t::message_confirmation_control + */ +typedef enum zb_zcl_messaging_message_confirmation_control_e +{ + ZB_ZCL_MESSAGING_NO_RETURNED = 1 << 0, /**< The answer is ‘NO’ */ + ZB_ZCL_MESSAGING_YES_RETURNED = 1 << 1, /**< The answer is ‘YES’ */ +} zb_zcl_messaging_message_confirmation_control_t; + + +/** @ref ZB_ZCL_MESSAGING_CLI_CMD_MESSAGE_CONFIRMATION "MessageConfirmation" command payload + * @see SE spec, subclause D.5.3.3.2.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_messaging_message_confirm_payload_s +{ + /** 32-bit number identifier for the message being confirmed. */ + zb_uint32_t message_id; /* (M) */ + + /** UTCTime of user confirmation of message */ + zb_uint32_t confirmation_time; /* (M) */ + + /** BitMap field indicating the simple confirmation that is + * contained within the response. + */ + zb_uint8_t message_confirmation_control; /* (O) */ + + /** ZCL Octet String containing the message to be returned. + * The first Octet indicates length (21 is max). + * The string shall be encoded in the UTF-8 format. + * If this optional field is not available, a default value of 0x00 shall be used. + */ + zb_uint8_t message_confirmation_response[ZB_ZCL_MESSAGING_MSG_CONFIRM_RESP_MSG_MAX_SIZE]; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_messaging_message_confirm_payload_t; + + +/** @ref ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_ALL_MESSAGES "CancelAllMessages" command payload + * @see SE spec, subclause D.5.2.3.4.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_messaging_cancel_all_message_payload_s +{ + /** A UTC Time field to indicate the date/time at which all existing display + * messages should be cleared. + */ + zb_uint32_t implementation_date; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_messaging_cancel_all_message_payload_t; + + +/** @ref ZB_ZCL_MESSAGING_CLI_CMD_GET_MESSAGE_CANCELLATION "GetMessageCancellation" command payload + * @see SE spec, subclause D.5.3.3.3.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_messaging_get_message_cancellation_payload_s +{ + /** UTC Timestamp indicating the earliest implementation time of a @e CancelAllMessages + * command to be returned. + */ + zb_uint32_t earliest_implementation_time; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_messaging_get_message_cancellation_payload_t; + + +/** Check if some size in range of variable size of specified payload. */ +#define ZB_ZCL_MESSAGING_MSG_CONFIRM_PAYLOAD_SIZE_IS_VALID(size) \ + ((size) <= sizeof(zb_zcl_messaging_message_confirm_payload_t)) && \ + ((size) > sizeof(zb_zcl_messaging_message_confirm_payload_t) - \ + ZB_SIZEOF_FIELD(zb_zcl_messaging_message_confirm_payload_t, \ + message_confirmation_response)) + +typedef enum zb_zcl_messaging_response_type_e { + ZB_ZCL_MESSAGING_RESPONSE_TYPE_NORMAL, + ZB_ZCL_MESSAGING_RESPONSE_TYPE_PROTECTED, + ZB_ZCL_MESSAGING_RESPONSE_TYPE_NOT_FOUND, +} zb_zcl_messaging_response_type_t; + + +/** According to SE spec, server could send following responses to + * @ref ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE "GetLastMessage" command: + *
    + *
  • + * \b NOT_FOUND as default response + *
  • + *
  • + * \b DisplayMessage command + *
  • + *
  • + * \b DisplayProtectedMessage command + *
  • + *
+ */ +typedef struct zb_zcl_messaging_get_last_message_response_s { + zb_zcl_messaging_response_type_t resp_type; + union { + zb_zcl_messaging_display_message_payload_t display_message; + zb_zcl_messaging_display_message_payload_t display_protected_message; + } resp; +} zb_zcl_messaging_get_last_message_response_t; + +/** @ref zb_zcl_messaging_get_last_message_response_t initializer */ +#define ZB_ZCL_MESSAGING_GET_LAST_MESSAGE_RESPONSE_INIT \ + (zb_zcl_messaging_get_last_message_response_t) \ + { \ + .resp_type = ZB_ZCL_MESSAGING_RESPONSE_TYPE_NOT_FOUND, \ + .resp.display_message = ZB_ZCL_MESSAGING_DISPLAY_MSG_PAYLOAD_INIT, \ + } + +/** @ref zb_zcl_messaging_message_confirm_payload_t initializer */ +#define ZB_ZCL_MESSAGING_MSG_CONFIRM_PAYLOAD_INIT \ + (zb_zcl_messaging_message_confirm_payload_t) \ + {\ + .message_confirmation_response = {0x00} \ + } + +/** Function for send @ref ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE "GetLastMessage" command + * @n On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_MESSAGING_GET_LAST_MSG_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Example of sending ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE "GetLastMessage" command + */ +zb_void_t zb_zcl_messaging_send_get_last_msg(zb_uint8_t param, + const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, + zb_uint8_t dst_ep, + zb_uint8_t src_ep, + zb_callback_t cb); + +/** Function for send @ref ZB_ZCL_MESSAGING_SRV_CMD_DISPLAY_MESSAGE "DisplayMessage" command. + * On sender's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with @ref ZB_ZCL_MESSAGING_GET_LAST_MSG_CB_ID + * callback id on reception of @ref ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE "GetLastMessage" command. + * @n On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_MESSAGING_DISPLAY_MSG_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_messaging_display_message_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + * @par Usage + * @n Handle @ref ZB_ZCL_MESSAGING_CLI_CMD_GET_LAST_MESSAGE "GetLastMessage" command + */ +zb_void_t zb_zcl_messaging_send_display_msg(zb_uint8_t param, + const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, + zb_uint8_t dst_ep, + zb_uint8_t src_ep, + const zb_zcl_messaging_display_message_payload_t *payload, + zb_callback_t cb); + +/** Function for send @ref ZB_ZCL_MESSAGING_CLI_CMD_MESSAGE_CONFIRMATION "MessageConfirmation" command + * On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_MESSAGING_MSG_CONFIRMATION_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_messaging_message_confirm_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + */ +zb_void_t zb_zcl_messaging_send_msg_confirmation(zb_uint8_t param, + const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, + zb_uint8_t dst_ep, + zb_uint8_t src_ep, + const zb_zcl_messaging_message_confirm_payload_t *payload, + zb_callback_t cb); + +/** Function for send @ref ZB_ZCL_MESSAGING_SRV_CMD_CANCEL_MESSAGE "CancelMessage" command + * On receiver's side callback ZCL device callback @ref ZB_ZCL_REGISTER_DEVICE_CB will be called with + * @ref ZB_ZCL_MESSAGING_CANCEL_MSG_CB_ID callback id. + * @param param - Reference to buffer. + * @param dst_addr - Address of the device to send command to. + * @param dst_addr_mode - Address mode for dst_addr. + * @param dst_ep - Destination endpoint. + * @param src_ep - Current endpoint. + * @param payload - Packet payload (@ref zb_zcl_messaging_cancel_message_payload_t). + * @param cb - Callback which should be called when the ZCL stack receives APS ack. + */ +zb_void_t zb_zcl_messaging_send_cancel_msg(zb_uint8_t param, + const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, + zb_uint8_t dst_ep, + zb_uint8_t src_ep, + const zb_zcl_messaging_cancel_message_payload_t *payload, + zb_callback_t cb); + +/** Macro for call @ref zb_zcl_messaging_send_get_last_msg function */ +#define ZB_ZCL_MESSAGING_SEND_GET_LAST_MSG(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep) \ + zb_zcl_messaging_send_get_last_msg(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, NULL) \ + +/** Macro for call @ref zb_zcl_messaging_send_display_msg function */ +#define ZB_ZCL_MESSAGING_SEND_DISPLAY_MSG(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload) \ + zb_zcl_messaging_send_display_msg(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_zcl_messaging_send_msg_confirmation function */ +#define ZB_ZCL_MESSAGING_SEND_MSG_CONFIRMATION(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload) \ + zb_zcl_messaging_send_msg_confirmation(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload, NULL) + +/** Macro for call @ref zb_zcl_messaging_send_cancel_msg function */ +#define ZB_ZCL_MESSAGING_SEND_CANCEL_MSG(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload) \ + zb_zcl_messaging_send_cancel_msg(_param, _dst_addr, _addr_mode, \ + _dst_ep, _src_ep, _payload, NULL) + +/** @cond internals_doc */ + +zb_void_t zb_zcl_messaging_init_server(void); +zb_void_t zb_zcl_messaging_init_client(void); +#define ZB_ZCL_CLUSTER_ID_MESSAGING_SERVER_ROLE_INIT zb_zcl_messaging_init_server +#define ZB_ZCL_CLUSTER_ID_MESSAGING_CLIENT_ROLE_INIT zb_zcl_messaging_init_client + +/** @endcond */ /* internal_doc */ + +/** @} */ /* ZB_ZCL_MESSAGING_COMMANDS */ + +/** @} */ /* ZCL Messaging cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* ZB_ZCL_MESSAGING_H_ */ diff --git a/zboss/include/zcl/zb_zcl_meter_identification.h b/zboss/include/zcl/zb_zcl_meter_identification.h new file mode 100644 index 0000000000..0d2342ef93 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_meter_identification.h @@ -0,0 +1,293 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Meter Identification cluster defintions +*/ + +#if ! defined ZB_ZCL_METER_IDENTIFICATION_H +#define ZB_ZCL_METER_IDENTIFICATION_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Cluster ZB_ZCL_CLUSTER_ID_METER_IDENTIFICATION */ + +/** @addtogroup ZB_ZCL_METER_IDENTIFICATION + * @{ + * @name Meter Identification cluster attributes + * @{ + */ + +/** @brief Meter Identification server attributes identifiers + @see ZCL spec, subclause 3.18.2.1 +*/ +enum zb_zcl_meter_identification_attr_e +{ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_COMPANY_NAME = 0x0000, /**< @e CompanyName is a ZCL Octet String field capable + * of storing up to 16 character string (the first + * Octet indicates length) encoded in the UTF-8 format. + * Company Name defines the meter manufacturer name, + * decided by manufacturer + */ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_METER_TYPE_ID = 0x0001, /**< @e MeterTypeID defines the Meter installation features, + * decided by manufacturer. + */ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID = 0x0004, /**< @e DataQualityID defines the Meter Simple Metering + * information certification type, decided by manufacturer. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_CUSTOMER_NAME = 0x0005, /**< @e CustomerName is a ZCL Character String field capable + * of storing up to 16 character string (the first Octet + * indicates length) encoded in the ASCII format. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_MODEL = 0x0006, /**< @e Model is a ZCL Octet String field capable of storing + * up to 16 character string (the first Octet indicates length) + * encoded in the UTF-8 format. @e Model defines the meter model + * name, decided by manufacturer. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_PART_NUMBER = 0x0007, /**< @e PartNumber is a ZCL Octet String field capable of storing + * up to 16 character string (the first Octet indicates length) + * encoded in the UTF-8 format. @e PartNumber defines the meter part + * number, decided by manufacturer. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_PRODUCT_REVISION = 0x0008, /**< @e ProductRevision is a ZCL Octet String field capable + * of storing up to 6 character string (the first Octet + * indicates length) encoded in the UTF-8 format. + * @e ProductRevision defines the meter revision code, + * decided by manufacturer. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_SOFTWARE_REVISION = 0x000A, /**< @e SoftwareRevision is a ZCL Octet String field capable + * of storing up to 6 character string (the first Octet indicates + * length) encoded in the UTF-8 format. SoftwareRevision defines + * the meter software revision code, decided by manufacturer. + */ + /* (O) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_UTILITY_NAME = 0x000B, /**< @e UtilityName is a ZCL Character String field capable of + * storing up to 16 character string (the first Octet indicates + * length) encoded in the ASCII format. + */ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_POD = 0x000C, /**< @e POD (Point of Delivery) is a ZCL Character String field + * capable of storing up to 16 character string (the first Octet + * indicates length) encoded in the ASCII format. POD is the unique + * identification ID of the premise connection point. It is also a + * contractual information known by the clients and indicated in the bill. + */ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_AVAILABLE_POWER = 0x000D, /**< @e AvailablePower represents the @e InstantaneousDemand that + * can be distributed to the customer (e.g., @e 3.3KW power) + * without any risk of overload. The Available Power SHALL use + * the same formatting conventions as the one used in the simple + * metering cluster formatting attribute set for the + * @e InstantaneousDemand attribute, i.e., + * the @e UnitOfMeasure and @e DemandFormatting. + */ + /* (M) */ + ZB_ZCl_ATTR_METER_IDENTIFICATION_POWER_THRESHOLD = 0x000E /**< @e PowerThreshold represents a threshold of @e InstantaneousDemand + * distributed to the customer (e.g., 4.191KW) that will lead to an + * imminent risk of overload. + */ +}; + + +/** @ref ZB_ZCl_ATTR_METER_IDENTIFICATION_METER_TYPE_ID "MeterTypeID" attribute values + * @see ZCL spec, subclause 3.18.2.1.2 + */ +typedef enum zb_zcl_meter_identification_meter_type_e +{ + ZB_ZCL_METER_TYPE_UTILITY_PRIMARY = 0x0000, /**< Utility Primary Meter */ + ZB_ZCL_METER_TYPE_UTILITY_PRODUCTION = 0x0001, /**< Utility Production Meter */ + ZB_ZCL_METER_TYPE_UTILITY_SECONDARY = 0x0002, /**< Utility Secondary Meter */ + ZB_ZCL_METER_TYPE_PRIVATE_PRIMARY = 0x0100, /**< Private Primary Meter */ + ZB_ZCL_METER_TYPE_PRIVATE_PRODUCTION = 0x0101, /**< Private Production Meter */ + ZB_ZCL_METER_TYPE_PRIVATE_SECONDARY = 0x0102, /**< Private Secondary Meters */ + ZB_ZCL_METER_TYPE_GENERIC = 0x0110 /**< Generic Meter */ +} zb_zcl_meter_identification_meter_type_t; + + +/** @ref ZB_ZCl_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID "DataQualityID" attribute values + * @see ZCL spec, subclause 3.18.2.1.3 + */ +typedef enum zb_zcl_meter_identification_data_quality_e +{ + ZB_ZCL_DATA_QUALITY_ALL_DATA_CERTIFIED = 0x0000, /**< All Data Certified */ + ZB_ZCL_DATA_QUALITY_ONLY_INSTANTANEOUS_POWER_NOT_CERTIFIED = 0x0001, /**< Only Instantaneous Power not Certified */ + ZB_ZCL_DATA_QUALITY_ONLY_CUMULATED_CONSUMPTION_NOT_CERTIFIED = 0x0002, /**< Only Cumulated Consumption not Certified */ + ZB_ZCL_DATA_QUALITY_NOT_CERTIFIED_DATA = 0x0003 /**< Not Certified data */ +} zb_zcl_meter_identification_data_quality_t; + +/** @brief Default value for Company Name attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_COMPANY_NAME_DEFAULT_VALUE { 0 } + +/** @brief Default value for Meter Type ID attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_METER_TYPE_ID_DEFAULT_VALUE 0 + +/** @brief Default value for Data Quality ID attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID_DEFAULT_VALUE 0 + +/** @brief Default value for POD (Point of Delivery) attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_POD_DEFAULT_VALUE { 0 } + +/** @brief Default value for Available Power attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_AVAILABLE_POWER_DEFAULT_VALUE ZB_INIT_UINT24(0,0) + +/** @brief Default value for Power Threshold attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_POWER_THRESHOLD_DEFAULT_VALUE ZB_INIT_UINT24(0, 0) + +/** @brief Max length of Company Name attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_COMPANY_NAME_MAX_LENGTH 16 + +/** @brief Max length of POD (Poinf of Delivery) attribute */ +#define ZB_ZCl_ATTR_METER_IDENTIFICATION_POD_MAX_LENGTH 16 + +/** @brief Declare attribute list for Thermostat cluster + @param attr_list - attribute list name + @param company_name - pointer to variable to store Company Name attribute value + @param meter_type_id - pointer to variable to store Meter Type ID attribute value + @param data_quality_id - pointer to variable to store Data Quality ID attribute value + @param pod - pointer to variable to store POD (Point of Delivery) attribute value + @param available_power - pointer to variable to store Availabe Power attribute value + @param power_threshold - pointer to variable to store Power Threshold attribute value +*/ +#define ZB_ZCL_DECLARE_METER_IDENTIFICATION_ATTRIB_LIST(attr_list, \ + company_name, meter_type_id, data_quality_id, \ + pod, available_power, power_threshold) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_COMPANY_NAME, (company_name)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_METER_TYPE_ID, (meter_type_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID, (data_quality_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_POD, (pod)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_AVAILABLE_POWER, (available_power)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_METER_IDENTIFICATION_POWER_THRESHOLD, (power_threshold)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* Meter Identification cluster attributes */ + + + +/*! @name Meter Identification cluster commands + @{ +*/ + +/*! @} */ /* Meter Identification cluster commands */ + + +/*! + @cond internals_doc + @internal @name Meter Identification cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_COMPANY_NAME(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_COMPANY_NAME, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_METER_TYPE_ID(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_METER_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_DATA_QUALITY_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_POD(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_POD, \ + ZB_ZCL_ATTR_TYPE_CHAR_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_AVAILABLE_POWER(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_AVAILABLE_POWER, \ + ZB_ZCL_ATTR_TYPE_S24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_METER_IDENTIFICATION_POWER_THRESHOLD(data_ptr) \ +{ \ + ZB_ZCl_ATTR_METER_IDENTIFICATION_POWER_THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_S24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Meter Identification cluster */ +#define ZB_ZCL_METER_IDENTIFICATION_REPORT_ATTR_COUNT 0 + +/*! @} + @endcond */ /* Thermostat cluster internals */ + +/*! @} */ /* ZB_ZCL_METER_IDENTIFICATION */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_meter_identification_init_server(void); +zb_void_t zb_zcl_meter_identification_init_client(void); + +#define ZB_ZCL_CLUSTER_ID_METER_IDENTIFICATION_SERVER_ROLE_INIT zb_zcl_meter_identification_init_server +#define ZB_ZCL_CLUSTER_ID_METER_IDENTIFICATION_CLIENT_ROLE_INIT zb_zcl_meter_identification_init_client + +#endif /* ! defined ZB_ZCL_METER_IDENTIFICATION_H */ diff --git a/zboss/include/zcl/zb_zcl_metering.h b/zboss/include/zcl/zb_zcl_metering.h new file mode 100644 index 0000000000..2d9f7e14ee --- /dev/null +++ b/zboss/include/zcl/zb_zcl_metering.h @@ -0,0 +1,2539 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Metering cluster defintions +*/ + +#if ! defined ZB_ZCL_METERING_H +#define ZB_ZCL_METERING_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_METERING + * @{ + * @details + * The Metering Cluster provides a mechanism to retrieve usage information + * from Electric, Gas, Water, and potentially Thermal metering devices. + */ + +/** @defgroup ZB_ZCL_METERING_CLI_ATTRS Metering cluster client attributes and enumerations + * @{ + */ + +/** @brief Metering cluster client attribute sets + * @see SE 1.4 spec, table D.58. + */ +enum zb_zcl_metering_cli_attr_set_e +{ + ZB_ZCL_METERING_SET_CLI_NOTIFICATION_ATTRIBUTE = 0x00, /**< Notification Attribute Set */ +}; + + +/** @brief Metering cluster client attributes */ +enum zb_zcl_metering_cli_attr_e +{ + ZB_ZCL_ATTR_METERING_CLI_FUNCTIONAL_NOTIFICATION_FLAGS = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_CLI_NOTIFICATION_ATTRIBUTE, 0x00), + /**< @e FunctionalNotificationFlags attribute is implemented as a set of bit flags + * which are have a predefined action associated with a bit that is not based on a specific command, + * but may require the Mirrored device to trigger some additional functionality within the system */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2, /**< @e NotificationFlagsN are 32-bit bitmaps that each represent a series of flags. + * Each flag represents an outstanding command that the Mirror is holding on behalf of the BOMD. + * Each flag represents a different command. + * The format of these attributes is dictated by the scheme that is currently in operation. */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS3, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS4, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS5, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS6, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS7, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ + ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS8, /**< @copydoc ZB_ZCL_ATTR_METERING_CLI_NOTIFICATION_FLAGS2 */ +}; + +/** @} */ /* ZB_ZCL_METERING_CLI_ATTRS */ + +/** @defgroup ZB_ZCL_METERING_SRV_ATTRS Metering cluster server attributes and enumerations + * @{ + */ + +/** @brief Metering cluster server attribute sets + * @see SE 1.4 spec, table D.10. + */ +enum zb_zcl_metering_srv_attr_set_e +{ + ZB_ZCL_METERING_SET_READ_INFO = 0x00, /**< Reading Information Set */ + ZB_ZCL_METERING_SET_TOU_INFORMATION = 0x01, /**< TOU Information Set */ + ZB_ZCL_METERING_SET_METER_STATUS = 0x02, /**< Meter Status */ + ZB_ZCL_METERING_SET_FORMATTING = 0x03, /**< Formatting */ + ZB_ZCL_METERING_SET_HISTORICAL_CONSUMPTION = 0x04, /**< Historical Consumption */ + ZB_ZCL_METERING_SET_LOAD_PROFILE_CONFIGURATION = 0x05, /**< Load Profile Configuration */ + ZB_ZCL_METERING_SET_SUPPLY_LIMIT = 0x06, /**< Supply Limit */ + ZB_ZCL_METERING_SET_BLOCK_INFORMATION_DELIVERED = 0x07, /**< Block Information (Delivered) */ + ZB_ZCL_METERING_SET_ALARMS = 0x08, /**< Alarms */ + ZB_ZCL_METERING_SET_BLOCK_INFORMATION_RECEIVED = 0x09, /**< Block Information (Received) */ + ZB_ZCL_METERING_SET_METER_BILLING = 0x0A, /**< Meter Billing Attribute Set */ + ZB_ZCL_METERING_SET_SUPPLY_CONTROL = 0x0B, /**< Supply Control Attribute Set */ + ZB_ZCL_METERING_SET_ALTERNATIVE_HISTORICAL_CONSUMPTION = 0x0C, /**< Alternative Historical Consumption */ + ZB_ZCL_METERING_SET_FOUR_QUADRANT_ELECTRICITY = 0x0D, /**< Four-Quadrant Electricity */ +}; + + +/** @brief Metering cluster server attributes */ +enum zb_zcl_metering_attr_e +{ + /* Reading Information Attribute Set, table D.11 */ + ZB_ZCL_ATTR_METERING_CURRENT_SUMMATION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_READ_INFO, 0x00), /**< @e CurrentSummationDelivered attribute + * represents the most recent summed value of Energy, Gas, or Water delivered and consumed + * in the premises. */ + ZB_ZCL_ATTR_METERING_CURRENT_SUMMATION_RECEIVED_ID, /**< @e CurrentSummationReceived attribute represents the most recent summed value of Energy, + * Gas, or Water generated and delivered from the premises. */ + ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_DELIVERED_ID, /**< @e CurrentMaxDemandDelivered attribute represents the maximum demand or rate of delivered + * value of Energy, Gas, or Water being utilized at the premises. */ + ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_RECEIVED_ID, /**< @e CurrentMaxDemandReceived attribute represents the maximum demand or rate of received + * value of Energy, Gas, or Water being utilized by the utility. */ + ZB_ZCL_ATTR_METERING_DFT_SUMMATION_ID, /**< @e DFTSummation attribute represents a snapshot of attribute CurrentSummationDelivered + * captured at the time indicated by attribute @ref ZB_ZCL_ATTR_METERING_DAILY_FREEZE_TIME_ID "DailyFreezeTime". */ + ZB_ZCL_ATTR_METERING_DAILY_FREEZE_TIME_ID, /**< @e DailyFreezeTime attribute represents the time of day when DFTSummation is captured + * (hour and minutes). */ + ZB_ZCL_ATTR_METERING_POWER_FACTOR_ID, /**< @e PowerFactor attribute contains the Average Power Factor ratio in 1/100ths. Valid + * values are 0 to 99. */ + ZB_ZCL_ATTR_METERING_READING_SNAPSHOT_TIME_ID, /**< @e ReadingSnapshotTime attribute represents the last time all of the + * @ref ZB_ZCL_ATTR_METERING_CURRENT_SUMMATION_DELIVERED_ID "CurrentSummationDelivered", + * @ref ZB_ZCL_ATTR_METERING_CURRENT_SUMMATION_RECEIVED_ID "CurrentSummationReceived", + * @ref ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_DELIVERED_ID "CurrentMaxDemandDelivered" and + * @ref ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_RECEIVED_ID "CurrentMaxDemandReceived" + * attributes that are supported by the device were updated. */ + ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_DELIVERED_TIME_ID, /**< @e CurrentMaxDemandDeliveredTime attribute represents the represents the time when + * @ref ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_DELIVERED_ID "CurrentMaxDemandDelivered" reading + * was captured. */ + ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_RECEIVED_TIME_ID, /**< @e CurrentMaxDemandReceivedTime attribute represents the time when + * @ref ZB_ZCL_ATTR_METERING_CURRENT_MAX_DEMAND_RECEIVED_ID "CurrentMaxDemandReceived reading + * was captured. */ + ZB_ZCL_ATTR_METERING_DEFAULT_UPDATE_PERIOD_ID, /**< @e DefaultUpdatePeriod attribute represents the interval (seconds) at which the + * @ref ZB_ZCL_ATTR_METERING_INSTANTANEOUS_DEMAND_ID "InstantaneousDemand" attribute is + * updated when not in fast poll mode. */ + ZB_ZCL_ATTR_METERING_FAST_POLL_UPDATE_PERIOD_ID, /**< @e FastPollUpdatePeriod attribute represents the interval (seconds) at which the + * @ref ZB_ZCL_ATTR_METERING_INSTANTANEOUS_DEMAND_ID "InstantaneousDemand" attribute is + * updated when in fast poll mode. */ + ZB_ZCL_ATTR_METERING_CURRENT_BLOCK_PERIOD_CONSUMPTION_DELIVERED_ID, /**< @e CurrentBlockPeriodConsumptionDelivered attribute represents the most recent summed + * value of Energy, Gas or Water delivered and consumed in the premises during the Block + * Tariff Period. */ + ZB_ZCL_ATTR_METERING_DAILY_CONSUMPTION_TARGET_ID, /**< @e DailyConsumptionTarget attribute is a daily target consumption amount that can be + * displayed to the consumer on a HAN device, with the intent that it can be used to compare + * to actual daily consumption. */ + ZB_ZCL_ATTR_METERING_CURRENT_BLOCK_ID, /**< @e CurrentBlock attribute is an 8-bit Enumeration which indicates the currently active + * block, when Block Tariffs are enabled. @see zb_zcl_metering_block_e */ + ZB_ZCL_ATTR_METERING_PROFILE_INTERVAL_PERIOD_ID, /**< @e ProfileIntervalPeriod attribute is currently included in the @e GetProfileResponse + * command payload, but does not appear in an attribute set. It represents the interval or + * time frame used to capture metered Energy, Gas, and Water consumption for profiling purposes. */ + /* 0x0010 attribute is deprecated */ + ZB_ZCL_ATTR_METERING_PRESET_READING_TIME_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_READ_INFO, 0x11), /**< @e PresetReadingTime attribute */ + ZB_ZCL_ATTR_METERING_SUMMATION_DELIVERED_PER_REPORT_ID, /**< @e SummationDeliveredPerReport attribute represents the summation increment per report + * from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_FLOW_RESTRICTION_ID, /**< @e FlowRestriction attribute represents the volume per minute limit set in the flow + * restrictor. This applies to water but not for gas. A setting of 0xFF indicates this + * feature is disabled. */ + ZB_ZCL_ATTR_METERING_SUPPLY_STATUS_ID, /**< @e SupplyStatus attribute represents the state of the supply at the customer's premises. + * @see zb_zcl_metering_supply_status_e */ + ZB_ZCL_ATTR_METERING_CURRENT_INLET_ENERGY_CARRIER_SUMMATION_ID, /**< @e CurrentInletEnergyCarrierSummation attribute is the current integrated volume of a + * given energy carrier measured on the inlet. */ + ZB_ZCL_ATTR_METERING_CURRENT_OUTLET_ENERGY_CARRIER_SUMMATION_ID, /**< @e CurrentOutletEnergyCarrierSummation attribute is the current integrated volume of a + * given energy carrier measured on the outlet. */ + ZB_ZCL_ATTR_METERING_INLET_TEMPERATURE_ID, /**< @e InletTemperature attribute is the temperature measured on the energy carrier inlet. */ + ZB_ZCL_ATTR_METERING_OUTLET_TEMPERATURE_ID, /**< @e OutletTemperature attribute is the temperature measured on the energy carrier outlet. */ + ZB_ZCL_ATTR_METERING_CONTROL_TEMPERATURE_ID, /**< @e ControlTemperature attribute is a reference temperature measured on the meter used to + * validate the Inlet/Outlet temperatures. */ + ZB_ZCL_ATTR_METERING_CURRENT_INLET_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentInletEnergyCarrierDemand attribute is the current absolute demand on the energy + * carrier inlet. */ + ZB_ZCL_ATTR_METERING_CURRENT_OUTLET_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentOutletEnergyCarrierDemand attribute is the current absolute demand on the energy + * carrier outlet. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_BLOCK_PERIOD_CONSUMPTION_DELIVERED_ID, /**< @e PreviousBlockPeriodConsumptionDelivered attribute represents the total value of Energy, + * Gas or Water delivered and consumed in the premises at the end of the previous Block Tariff + * period. */ + ZB_ZCL_ATTR_METERING_CURRENT_BLOCK_PERIOD_CONSUMPTION_RECEIVED_ID, /**< @e CurrentBlockPeriodConsumptionReceived attribute represents the most recent summed + * value of Energy, Gas or Water received by the energy supplier from the premises during + * the Block Tariff Period. */ + ZB_ZCL_ATTR_METERING_CURRENT_BLOCK_RECEIVED_ID, /**< @e CurrentBlockReceived attribute is an 8-bit Enumeration which indicates the currently + * active block, when Block Tariffs are enabled. */ + ZB_ZCL_ATTR_METERING_DFT_SUMMATION_RECEIVED_ID, /**< @e DFTSummationReceived attribute represents a snapshot of attribute + * @ref ZB_ZCL_ATTR_METERING_CURRENT_SUMMATION_RECEIVED_ID "CurrentSummationReceived" + * captured at the time indicated by the + * @ref ZB_ZCL_ATTR_METERING_DAILY_FREEZE_TIME_ID "DailyFreezeTime" attribute. */ + ZB_ZCL_ATTR_METERING_ACTIVE_REGISTER_TIER_DELIVERED_ID, /**< @e ActiveRegisterTierDelivered attribute indicates the current register tier that the + * energy consumed is being accumulated against. @see SE 1.4 spec, table D.98. */ + ZB_ZCL_ATTR_METERING_ACTIVE_REGISTER_TIER_RECEIVED_ID, /**< @e ActiveRegisterTierReceived attribute indicates the current register tier that the + * energy generated is being accumulated against. @see SE 1.4 spec, table D.101. */ + ZB_ZCL_ATTR_METERING_LAST_BLOCK_SWITCH_TIME_ID, /**< @e LastBlockSwitchTime attribute allows other devices to determine the time at which + * a meter switches from one block to another. */ + /* 0x0023 to 0x00FF reserved */ + + + /* TOU Information Attribute Set, table D.14 */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_TOU_INFORMATION, 0x00), /**< @e CurrentTierNSummationDelivered + * attributes represent the most recent summed value of Energy, Gas, or Water delivered to the premises at a + * specific price tier as defined by a TOU schedule or a real time pricing period. */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID, /**< @e CurrentTierNSummationReceived attributes represent the most recent summed value of Energy, Gas, or Water + * provided by the premises (i.e. received by the utility from the customer) at a specific price tier as defined + * by a TOU schedule or a real time pricing period. */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER2_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER2_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER3_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER3_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER4_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER4_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER5_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER5_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER6_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER6_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER7_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER7_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER8_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER8_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER9_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER9_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER10_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER10_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER11_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER11_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER12_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER12_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER13_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER13_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER14_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER14_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER15_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER15_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER16_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER16_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER17_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER17_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER18_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER18_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER19_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER19_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER20_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER20_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER21_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER21_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER22_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER22_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER23_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER23_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER24_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER24_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER25_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER25_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER26_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER26_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER27_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER27_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER28_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER28_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER29_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER29_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER30_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER30_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER31_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER31_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER32_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER32_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER33_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER33_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER34_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER34_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER35_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER35_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER36_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER36_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER37_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER37_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER38_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER38_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER39_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER39_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER40_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER40_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER41_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER41_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER42_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER42_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER43_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER43_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER44_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER44_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER45_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER45_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER46_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER46_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER47_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER47_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER48_SUMMATION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_CURRENT_TIER48_SUMMATION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_CURRENT_TIER1_SUMMATION_RECEIVED_ID */ + /* 0x0160 to 0x01FB reserved */ + ZB_ZCL_ATTR_METERING_CPP1_SUMMATION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_TOU_INFORMATION, 0xFC), /**< @e CPP1SummationDelivered attribute + * represents the most recent summed value of Energy, Gas, or Water delivered to the premises (i.e. + * delivered to the customer from the utility) while Critical Peak Price CPP1 was being applied. */ + /* 0x01FD reserved */ + ZB_ZCL_ATTR_METERING_CPP2_SUMMATION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_TOU_INFORMATION, 0xFE), /**< @e CPP2SummationDelivered attribute + * represents the most recent summed value of Energy, Gas, or Water delivered to the premises (i.e. + * delivered to the customer from the utility) while Critical Peak Price CPP2 was being applied. */ + /* 0x01FF reserved */ + + + /* Meter Status Attribute Set, table D.15. */ + ZB_ZCL_ATTR_METERING_STATUS_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_METER_STATUS, 0x00), /**< @e Status attribute provides indicators reflecting the current + * error conditions found by the metering device. Status depends on the device type. + * @see zb_zcl_metering_status_electricity_e + * @see zb_zcl_metering_status_gas_e + * @see zb_zcl_metering_status_water_e + * @see zb_zcl_metering_status_heat_cooling_e */ + ZB_ZCL_ATTR_METERING_REMAINING_BATTERY_LIFE_ID, /**< @e RemainingBatteryLife attribute represents the estimated remaining life of the battery in % of capacity. + * A setting of 0xFF indicates this feature is disabled. */ + ZB_ZCL_ATTR_METERING_HOURS_IN_OPERATION_ID, /**< @e HoursInOperation attribute is a counter that increments once every hour during operation. */ + ZB_ZCL_ATTR_METERING_HOURS_IN_FAULT_ID, /**< @e HoursInFault attribute is a counter that increments once every hour when the device is in operation + * with a fault detected. */ + ZB_ZCL_ATTR_METERING_EXTENDED_STATUS_ID, /**< @e ExtendedStatus attribute reflects the state of items in a meter that the standard Status attribute + * cannot show. The Extended Status BitMap is split into two groups of flags: general flags and metering + * type specific flags. + * @see zb_zcl_metering_extstatus_general_e + * @see zb_zcl_metering_extstatus_electricity_e + * @see zb_zcl_metering_extstatus_gas_e */ + ZB_ZCL_ATTR_METERING_REMAINING_BATTERY_LIFE_DAYS_ID, /**< @e RemainingBatteryLifeInDays attribute represents the estimated remaining life of the battery in days + * of capacity. The range is 0 - 0xFFFE, where 0xFFFF represents 'Invalid', 'Unused' and 'Disabled'. */ + ZB_ZCL_ATTR_METERING_CURRENT_METER_ID_ID, /**< @e CurrentMeterID attribute is the current id for the Meter. This could be the current firmware + * version supported on the meter. */ + ZB_ZCL_ATTR_METERING_AMBIENT_CONSUMPTION_INDICATOR_ID, /**< @e AmbientConsumptionIndicator attribute is an 8-bit enumeration which provides a simple indication + * (Low/Medium/High) of the amount of a commodity being consumed within the premises. + * @see @ref zb_zcl_metering_low_medium_high_status_e. */ + ZB_ZCL_ATTR_METERING_SERVICE_DISCONNECT_REASON_ID, /**< The Service Disconnect Reason attribute is an 8-bit enumeration which indicates why the supply + * to the premises has been disconnected */ + ZB_ZCL_ATTR_METERING_LINKY_MODE_OF_OPERATION_ID, /**< The @e LinkyModeOfOperation attribute is specific to Linky devices. It consists of a single flag + * (bit 0) which shall be set to FALSE (0) when in 'Simple' Mode and set to TRUE (1) when in + * Advanced Mode. Bits 1 to 7 are reserved. */ + /* 0x0208 to 0x02FF reserved */ + + + /* Formatting Attribute Set, table D.25 */ + ZB_ZCL_ATTR_METERING_UNIT_OF_MEASURE_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_FORMATTING, 0x00), /**< @e UnitOfMeasure attribute provides a label for + * the Energy, Gas, or Water being measured by the metering device. + * @see zb_zcl_metering_unit_of_measure_e */ + ZB_ZCL_ATTR_METERING_MULTIPLIER_ID, /**< @e Multiplier attribute provides a value to be multiplied against a raw or uncompensated sensor + * count of Energy, Gas, or Water being measured by the metering device. */ + ZB_ZCL_ATTR_METERING_DIVISOR_ID, /**< @e Divisor attribute provides a value to divide the results of applying the + * @ref ZB_ZCL_ATTR_METERING_MULTIPLIER_ID "Multiplier Attribute" against a raw or uncompensated + * sensor count of Energy, Gas, or Water being measured by the metering device. */ + ZB_ZCL_ATTR_METERING_SUMMATION_FORMATTING_ID, /**< @e SummationFormatting attribute provides a method to properly decipher the number of digits + * and the decimal location of the values found in the Summation Information Set of attributes. */ + ZB_ZCL_ATTR_METERING_DEMAND_FORMATTING_ID, /**< @e DemandFormatting attribute provides a method to properly decipher the number of digits and + * the decimal location of the values found in the Demand-related attributes. */ + ZB_ZCL_ATTR_METERING_HISTORICAL_CONSUMPTION_FORMATTING_ID, /**< @e HistoricalConsumptionFormatting attribute provides a method to properly decipher the number + * of digits and the decimal location of the values found in the Historical Consumption Set of + * attributes. */ + ZB_ZCL_ATTR_METERING_METERING_DEVICE_TYPE_ID, /**< @e MeteringDeviceType attribute provides a label for identifying the type of metering device + * present (Energy, Gas, Water, Thermal, Heat, Cooling, and mirrored metering devices). + * @see zb_zcl_metering_device_type_e */ + ZB_ZCL_ATTR_METERING_SITE_ID_ID, /**< @e SiteID attribute is a text string, known in the UK as the MPAN number for electricity, + * MPRN for gas and 'Stand Point' in South Africa. */ + ZB_ZCL_ATTR_METERING_METER_SERIAL_NUMBER_ID, /**< @e MeterSerialNumber attribute is used to provide a unique identification of the metering + * device. */ + ZB_ZCL_ATTR_METERING_ENERGY_CARRIER_UNIT_OF_MEASURE_ID, /**< @e EnergyCarrierUnitOfMeasure attribute specifies the unit of measure that the EnergyCarrier + * is measured in. */ + ZB_ZCL_ATTR_METERING_ENERGY_CARRIER_SUMMATION_FORMATTING_ID, /**< @e EnergyCarrierSummationFormatting attribute provides a method to properly decipher the number + * of digits and the decimal location of the values found in the Summation- related attributes. */ + ZB_ZCL_ATTR_METERING_ENERGY_CARRIER_DEMAND_FORMATTING_ID, /**< @e EnergyCarrierDemandFormatting attribute provides a method to properly decipher the number + * of digits and the decimal location of the values found in the Demand- related attributes. */ + ZB_ZCL_ATTR_METERING_TEMPERATURE_UNIT_OF_MEASURE_ID, /**< @e TemperatureUnitOfMeasure attribute specifies the unit of measure that temperatures are + * measured in. + * @see zb_zcl_metering_temperature_unit_of_measure_e */ + ZB_ZCL_ATTR_METERING_TEMPERATURE_FORMATTING_ID, /**< @e TemperatureFormatting attribute provides a method to properly decipher the number of digits + * and the decimal location of the values found in the Temperature-related attributes. */ + ZB_ZCL_ATTR_METERING_MODULE_SERIAL_NUMBER_ID, /**< @e ModuleSerialNumber attribute represents the serial number (unique identifier) of the + * meter module. */ + ZB_ZCL_ATTR_METERING_OPERATING_TARIFF_LABEL_DELIVERED_ID, /**< @e OperatingTariffLabelDelivered attribute is the meter's version of the @e TariffLabel attribute + * that is found within the Tariff Information attribute set of the Price Cluster. */ + ZB_ZCL_ATTR_METERING_OPERATING_TARIFF_LABEL_RECEIVED_ID, /**< @e OperatingTariffLabelReceived attribute is the meter's version of the @e ReceivedTariffLabel + * attribute that is found within the Tariff Information attribute set of the Price Cluster. */ + ZB_ZCL_ATTR_METERING_CUSTOMER_ID_NUMBER_ID, /**< @e CustomerIDNumber attribute provides a customer identification which may be used to confirm + * the customer at the premises. */ + ZB_ZCL_ATTR_METERING_ALTERNATIVE_UNIT_OF_MEASURE_ID, /**< @e AlternativeUnitOfMeasure attribute provides a base for the attributes in the Alternative + * Historical Consumption attribute set. */ + ZB_ZCL_ATTR_METERING_ALTERNATIVE_DEMAND_FORMATTING_ID, /**< @e AlternativeDemandFormatting attribute provides a method to properly decipher the number of + * digits and the decimal location of the values found in the Alternative Demand-related attributes. */ + ZB_ZCL_ATTR_METERING_ALTERNATIVE_CONSUMPTION_FORMATTING_ID, /**< @e AlternativeConsumptionFormatting attribute provides a method to properly decipher the + * number of digits and the decimal location of the consumption values found in the Alternative + * Historical Consumption Set of attributes. */ + /* 0x0313 to 0x03FF reserved */ + + + /* Historical Consumption Attribute Set, table D.29 */ + ZB_ZCL_ATTR_METERING_INSTANTANEOUS_DEMAND_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_HISTORICAL_CONSUMPTION, 0x00), /**< @e InstantaneousDemand attribute + * represents the current Demand of Energy, Gas, or Water delivered or received at the premises.*/ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_CONSUMPTION_DELIVERED_ID, /**< @e CurrentDayConsumptionDelivered attribute represents the summed value of Energy, + * Gas, or Water delivered to the premises since the Historical Freeze Time (HFT).*/ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_CONSUMPTION_RECEIVED_ID, /**< @e CurrentDayConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises since the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_CONSUMPTION_DELIVERED_ID, /**< @e PreviousDayConsumptionDelivered attribute represents the summed value of Energy, + * Gas, or Water delivered to the premises within the previous 24 hour period starting + * at the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_CONSUMPTION_RECEIVED_ID, /**< @e PreviousDayConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises within the previous 24 hour period starting + * at the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_CURRENT_PARTIAL_PROFILE_INTERVAL_START_TIME_DELIVERED_ID, /**< @e CurrentPartialProfileIntervalStartTimeDelivered attribute represents the start + * time of the current Load Profile interval being accumulated for commodity delivered. */ + ZB_ZCL_ATTR_METERING_CURRENT_PARTIAL_PROFILE_INTERVAL_START_TIME_RECEIVED_ID, /**< @e CurrentPartialProfileIntervalStartTimeReceived attribute represents the start + * time of the current Load Profile interval being accumulated for commodity received. */ + ZB_ZCL_ATTR_METERING_CURRENT_PARTIAL_PROFILE_INTERVAL_VALUE_DELIVERED_ID, /**< @e CurrentPartialProfileIntervalValueDelivered attribute represents the value of + * the current Load Profile interval being accumulated for commodity delivered. */ + ZB_ZCL_ATTR_METERING_CURRENT_PARTIAL_PROFILE_INTERVAL_VALUE_RECEIVED_ID, /**< @e CurrentPartialProfileIntervalValueReceived attribute represents the value of + * the current Load Profile interval being accumulated for commodity delivered. */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_PRESSURE_ID, /**< @e CurrentDayMaxPressure attribute is the maximum pressure reported during a day + * from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MIN_PRESSURE_ID, /**< @e CurrentDayMinPressure attribute is the minimum pressure reported during a day + * from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_PRESSURE_ID, /**< @e PreviousDayMaxPressure attribute is the maximum pressure reported during previous + * day from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MIN_PRESSURE_ID, /**< @e PreviousDayMinPressure attribute is the minimum pressure reported during previous + * day from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_DEMAND_ID, /**< @e CurrentDayMaxDemand attribute represents the maximum demand or rate of delivered + * value of Energy, Gas, or Water being utilized at the premises. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_DEMAND_ID, /**< @e PreviousDayMaxDemand attribute represents the maximum demand or rate of delivered + * value of Energy, Gas, or Water being utilized at the premises. */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_MAX_DEMAND_ID, /**< @e CurrentMonthMaxDemand attribute is the maximum demand reported during a month + * from the meter. For electricity, heat and cooling meters this is the maximum power + * reported in a month.*/ + ZB_ZCL_ATTR_METERING_CURRENT_YEAR_MAX_DEMAND_ID, /**< @e CurrentYearMaxDemand attribute is the maximum demand reported during a year + * from the meter. For electricity, heat and cooling meters this is the maximum power + * reported in a year.*/ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentDayMaxEnergyCarrierDemand attribute is the maximum energy carrier demand + * reported during a day from the meter. For heat and cooling meters this is the maximum + * flow rate on the inlet reported in a day. + * @note At the end of a day the meter will transfer the @e CurrentDayMaxEnergyCarrierDemand + * into @ref ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_ENERGY_CARRIER_DEMAND_ID "PreviousDayMaxEnergyCarrierDemand". */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_ENERGY_CARRIER_DEMAND_ID, /**< @e PreviousDayMaxEnergyCarrierDemand attribute is the maximum energy carrier demand + * reported during the previous day from the meter. */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_MAX_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentMonthMaxEnergyCarrierDemand attribute is the maximum energy carrier demand + * reported during a month from the meter. For heat and cooling meters this is the + * maximum flow rate on the inlet reported in a month. */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_MIN_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentMonthMinEnergyCarrierDemand attribute is the minimum energy carrier demand + * reported during a month from the meter. For heat and cooling meters this is the + * minimum flow rate on the inlet reported in a month. */ + ZB_ZCL_ATTR_METERING_CURRENT_YEAR_MAX_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentYearMaxEnergyCarrierDemand attribute is the maximum energy carrier demand + * reported during a year from the meter. For heat and cooling meters this is the maximum + * flow rate on the inlet reported in a year. */ + ZB_ZCL_ATTR_METERING_CURRENT_YEAR_MIN_ENERGY_CARRIER_DEMAND_ID, /**< @e CurrentYearMinEnergyCarrierDemand attribute is the minimum energy carrier demand + * reported during a year from the heat meter. For heat and cooling meters this is the + * minimum flow rate on the inlet reported in a year. */ + /* 0x0417 to 0x041F reserved */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_HISTORICAL_CONSUMPTION, 0x20), /**< @e PreviousDayNConsumptionDelivered + * attribute represents the summed value of Energy, Gas, or Water delivered to the + * premises within the previous 24 hour period starting at the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID, /**< @e PreviousDayNConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises within the previous 24 hour period starting + * at the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY3_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY3_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY4_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY4_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY5_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY5_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY6_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY6_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY7_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY7_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY8_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY8_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_CONSUMPTION_RECEIVED_ID */ + /* 0x042E to 0x042F reserved */ + ZB_ZCL_ATTR_METERING_CURRENT_WEEK_CONSUMPTION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_HISTORICAL_CONSUMPTION, 0x30), /**< @e CurrentWeekConsumptionDelivered + * attribute represents the summed value of Energy, Gas, or Water delivered to the premises + * since the Historical Freeze Time (HFT) on Monday to the last HFT read. */ + ZB_ZCL_ATTR_METERING_CURRENT_WEEK_CONSUMPTION_RECEIVED_ID, /**< @e CurrentWeekConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises since the Historical Freeze Time (HFT) on + * Monday to the last HFT read. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_DELIVERED_ID, /**< @e PreviousWeekNConsumptionDelivered attribute represents the summed value of Energy, + * Gas, or Water delivered to the premises within the previous week period starting at + * the Historical Freeze Time (HFT) on the Monday to the Sunday. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_RECEIVED_ID, /**< @e PreviousWeekNConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises within the previous week period starting at + * the Historical Freeze Time (HFT) on the Monday to the Sunday. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK2_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK2_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK3_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK3_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK4_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK4_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK5_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK5_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_CONSUMPTION_RECEIVED_ID */ + /* 0x043C to 0x043F reserved */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_CONSUMPTION_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_HISTORICAL_CONSUMPTION, 0x40), /**< @e CurrentMonthConsumptionDelivered + * attribute represents the summed value of Energy, Gas, or Water delivered to the premises + * since the Historical Freeze Time (HFT) on the 1 st of the month to the last HFT read. */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_CONSUMPTION_RECEIVED_ID, /**< @e CurrentMonthConsumptionReceived attribute represents the summed value of Energy, + * Gas, or Water received from the premises since the Historical Freeze Time (HFT) on the + * 1 st of the month to the last HFT read. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID, /**< @e PreviousMonthNConsumptionDelivered attribute represents the summed value of + * Energy, Gas, or Water delivered to the premises within the previous Month period + * starting at the Historical Freeze Time (HFT) on the 1 st of the month to the last + * day of the month.*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID, /**< @e PreviousMonthNConsumptionReceived attribute represents the summed value of + * Energy, Gas, or Water received from the premises within the previous month period + * starting at the Historical Freeze Time (HFT) on the 1 st of the month to the last + * day of the month.*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH2_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH2_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH3_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH3_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH4_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH4_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH5_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH5_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH6_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH6_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH7_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH7_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH8_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH8_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH9_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH9_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH10_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH10_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH11_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH11_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH12_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH12_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH13_CONSUMPTION_DELIVERED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_DELIVERED_ID */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH13_CONSUMPTION_RECEIVED_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_CONSUMPTION_RECEIVED_ID */ + ZB_ZCL_ATTR_METERING_HISTORICAL_FREEZE_TIME_ID, /**< @e HistoricalFreezeTime attribute represents the time of day, in Local Time, when + * Historical Consumption attributes and/or Alternative Historical Consumption + * attributes are captured (hour and minutes). */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_DEMAND_DELIVERED_ID, /**< @e CurrentDayMaxDemandDelivered represents the maximum demand or rate of delivered value of + * Energy, Gas, or Water being utilized at the premises since the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_DEMAND_DELIVERED_TIME_ID, /**< The @e CurrentDayMaxDemandDeliveredTime attribute represents the time when + * @e CurrentDayMaxDemandDelivered reading was captured. */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_DEMAND_RECEIVED_ID, /**< @e CurrentDayMaxDemandReceived represents the maximum demand or rate of received value of + * Energy, Gas, or Water being utilized by the utility from the premises sinc e the Historical + * Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_MAX_DEMAND_RECEIVED_TIME_ID, /**< The CurrentDayMaxDemandReceivedTime attribute represents the time CurrentDayMaxDemandReceived + * reading was captured */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_DEMAND_DELIVERED_ID, /**< @e PreviousDayMaxDemandDelivered represents the maximum demand or rate of delivered + * value of Energy, Gas, or Water that was utilized at the premises within the previous 24 + * hour period starting at the Historical Freeze Time (HFT) */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_DEMAND_DELIVERED_TIME_ID, /**< The @e PreviousDayMaxDemandDeliveredTime attribute represents the time when + * PreviousDayMaxDemandDelivered reading was captured. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_DEMAND_RECEIVED_ID, /**< @e PreviousDayMaxDemandReceived represents the maximum demand or rate of received value + * of Energy, Gas, or Water that was utilized by the utility from the premises within the + * previous 24 hour period starting at the Historical Freeze Time (HFT). + */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_MAX_DEMAND_RECEIVED_TIME_ID, /**< The @e PreviousDayMaxDem andReceivedTime attribute represents the time when + * @e PreviousDayMaxDemandReceived reading was captured. + */ + /* 0x045D to 0x04FF reserved */ + + + /* Load Profile Configuration Attribute Set, table D.30 */ + ZB_ZCL_ATTR_METERING_MAX_NUMBER_OF_PERIODS_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_LOAD_PROFILE_CONFIGURATION, 0x00), /**< @e MaxNumberOfPeriodsDelivered + * attribute represents the maximum number of intervals the device is capable of returning + * in one Get Profile Response command. It is required @e MaxNumberOfPeriodsDelivered fit + * within the default Fragmentation ASDU size of 128 bytes, or an optionally agreed upon + * larger Fragmentation ASDU size supported by both devices. + * @see SE spec, sub-clause 5.3.8. */ + /* 0x0501 to 0x05FF reserved */ + + + /* Supply Limit Attribute Set, table D.31 */ + ZB_ZCL_ATTR_METERING_CURRENT_DEMAND_DELIVERED_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_SUPPLY_LIMIT, 0x00), /**< @e CurrentDemandDelivered attribute represents + * the current Demand of Energy, Gas, or Water delivered at the premises. */ + ZB_ZCL_ATTR_METERING_DEMAND_LIMIT_ID, /**< @e DemandLimit attribute reflects the current supply demand limit set in the meter. This value can be + * compared to the @ref ZB_ZCL_ATTR_METERING_CURRENT_DEMAND_DELIVERED_ID "CurrentDemandDelivered" attribute to + * understand if limits are being approached or exceeded. A value of 0xFFFFFF indicates demand limiting + * is switched off.*/ + ZB_ZCL_ATTR_METERING_DEMAND_INTEGRATION_PERIOD_ID, /**< @e DemandIntegrationPeriod attribute is the number of minutes over which the + * @ref ZB_ZCL_ATTR_METERING_CURRENT_DEMAND_DELIVERED_ID "CurrentDemandDelivered" attribute is calculated. Valid + * range is 0x01 to 0xFF. 0x00 is a reserved value. */ + ZB_ZCL_ATTR_METERING_NUMBER_OF_DEMAND_SUBINTERVALS_ID, /**< @e NumberOfDemandSubintervals attribute represents the number of subintervals used within the + * @ref ZB_ZCL_ATTR_METERING_DEMAND_INTEGRATION_PERIOD_ID "DemandIntegrationPeriod". The subinterval + * duration (in minutes) is obtained by dividing the @ref ZB_ZCL_ATTR_METERING_DEMAND_INTEGRATION_PERIOD_ID + * "DemandIntegrationPeriod" by the @ref ZB_ZCL_ATTR_METERING_NUMBER_OF_DEMAND_SUBINTERVALS_ID "NumberOfDemandSubintervals". + * The @ref ZB_ZCL_ATTR_METERING_CURRENT_DEMAND_DELIVERED_ID "CurrentDemandDelivered" attribute is updated at the + * each of each subinterval. Valid range is 0x01 to 0xFF. 0x00 is a reserved value. */ + ZB_ZCL_ATTR_METERING_DEMAND_LIMIT_ARM_DURATION_ID, /**< @e DemandLimitArmDuration attribute defines the length of time, in seconds, that the supply shall be + * disconnected if the @ref ZB_ZCL_ATTR_METERING_DEMAND_LIMIT_ID "DemandLimit" attribute is enabled and + * the limit is exceeded.*/ + ZB_ZCL_ATTR_METERING_LOAD_LIMIT_SUPPLY_STATE_ID, /**< @e LoadLimitSupplyState attribute indicates the required status of the supply once device is in a load + * limit state. @see SE 1.4 spec, table D.68. */ + ZB_ZCL_ATTR_METERING_LOAD_LIMIT_COUNTER_ID, /**< @e LoadLimitCounter attribute is used for counting the number of times that the demand limit has + * exceeded the set threshold. */ + ZB_ZCL_ATTR_METERING_SUPPLY_TAMPER_STATE_ID, /**< @e SupplyTamperState attribute indicates the required status of the supply following the detection of a + * tamper event within the metering device. @see SE 1.4 spec, table D.68. */ + ZB_ZCL_ATTR_METERING_SUPPLY_DEPLETION_STATE_ID, /**< @e SupplyDepletionState attribute indicates the required status of the supply following detection of a + * depleted battery within the metering device. @see SE 1.4 spec, table D.68. */ + ZB_ZCL_ATTR_METERING_SUPPLY_UNCONTROLLED_FLOW_STATE_ID, /**< @e SupplyUncontrolledFlowState attribute indicates the required status of the supply following detection + * of an uncontrolled flow event within the metering device. @see SE 1.4 spec, table D.68. */ + /* 0x060A to 0x06FF reserved */ + + /*TODO: need to add set 0x07 - ZB_ZCL_METERING_SET_BLOCK_INFORMATION_DELIVERED*/ + /*FIXME: Does we need to use _ID suffix in attributes? */ + /*ZB_ZCL_METERING_SET_ALARMS attribute set*/ + ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_ALARMS, 0x00), /**< The AlarmMask attributes of the Alarm Attribute Set + * specify whether each of the alarms listed in the + * corresponding alarm group is enabled. When the bit number + * corresponding to the alarm number (minus the group offset) is set to 1, + * the alarm is enabled, else it is disabled. Bits not corresponding + * to a code in the respective table are reserved. + */ + ZB_ZCL_ATTR_METERING_ELECTRICITY_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_GENERIC_FLOW_PRESSURE_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_WATER_SPECIFIC_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_HEAT_AND_COOLING_SPECIFIC_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_GAS_SPECIFIC_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_EXTENDED_GENERIC_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + ZB_ZCL_ATTR_METERING_MANUFACTURER_ALARM_MASK_ID, /**< @copydoc ZB_ZCL_ATTR_METERING_GENERIC_ALARM_MASK_ID */ + + /*TODO: need to add set 0x09 */ + + /* Meter Billing Attribute Set, table D.44 */ + + /**< @e BillToDateDelivered provides a value for the costs in the current billing period.*/ + ZB_ZCL_ATTR_METERING_BILL_TO_DATE_DELIVERED = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_METER_BILLING, 0x00), + ZB_ZCL_ATTR_METERING_BILL_TO_DATE_TIMESTAMP_DELIVERED, /**< @e BillToDateTimeStampDelivered The UTC timestamp + * when the associated BillToDateDelivered attribute was last updated.*/ + ZB_ZCL_ATTR_METERING_PROJECTED_BILL_DELIVERED, /**< @e ProjectedBillDelivered provides a value indicating what the estimated state of the account + * will be at the end of the billing period based on past consumption.*/ + ZB_ZCL_ATTR_METERING_PROJECTED_BILL_TIME_STAMP_DELIVERED, /**< @e ProjectedBillTimeStampDelivered + * The UTC timestamp when the associated ProjectedBillDelivered attribute was last updated. */ + ZB_ZCL_ATTR_METERING_BILL_DELIVERED_TRAILING_DIGIT, /**< @e BillDeliveredTrailingDigit An 8-bit BitMap used to determine where the decimal point is located + * in the BillToDateDelivered and ProjectedBillDelivered attributes. */ + ZB_ZCL_ATTR_METERING_BILL_TO_DATE_RECEIVED = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_METER_BILLING, 0x10), + /**< @e BillToDateReceived provides a value for the costs in the current billing period. + * This attribute is measured in a base unit of Currency with the decimal point located + * as indicated by the BillReceivedTrailingDigit attribute */ + ZB_ZCL_ATTR_METERING_BILL_TO_DATE_TIMESTAMP_RECEIVED, /**< @e BillToDateTimeStampReceived The UTC timestamp + * when the associated BillToDateReceived attribute was last updated */ + ZB_ZCL_ATTR_METERING_PROJECTED_BILL_RECEIVED, /**< @e ProjectedBillReceived provides a value indicating what the estimated state of the account + * will be at the end of the billing period based on past generation.*/ + ZB_ZCL_ATTR_METERING_PROJECTED_BILL_TIME_STAMP_RECEIVED, /**< @e ProjectedBillTimeStampReceived + * The UTC timestamp when the associated ProjectedBillReceived attribute was last updated. */ + ZB_ZCL_ATTR_METERING_BILL_RECEIVED_TRAILING_DIGIT, /**< @e BillReceivedTrailingDigit + * An 8-bit BitMap used to determine where the decimal point is located + * in the BillToDateReceived and ProjectedBillReceived attributes.*/ + + /* Supply Control Attribute, table D.45 */ + + /**< @e ProposedChangeSupplyImplementationTime indicates the time + * at which a proposed change to the supply is to be implemented.*/ + ZB_ZCL_ATTR_METERING_PROPOSED_CHANGE_SUPPLY_IMPLEMENTATION_TIME = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_SUPPLY_CONTROL, 0x00), + ZB_ZCL_ATTR_METERING_PROPOSED_CHANGE_SUPPLY_STATUS, /**< @e ProposedChangeSupplyStatus indicates the proposed status of the supply + * once the change to the supply has be been implemented.*/ + /**< @e UncontrolledFlowThreshold indicates the threshold above which a flow meter (e.g. Gas or Water) + * shall detect an uncontrolled flow.*/ + ZB_ZCL_ATTR_METERING_UNCONTROLLED_FLOW_THRESHOLD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_SUPPLY_CONTROL, 0x10), + ZB_ZCL_ATTR_METERING_UNCONTROLLED_FLOW_THRESHOLD_UNIT_OF_MEASURE, /**< @e UncontrolledFlowThresholdUnitOfMeasure indicates the unit of measure + * used in conjunction with the Uncontrolled Flow Threshold attribute.*/ + ZB_ZCL_ATTR_METERING_UNCONTROLLED_FLOW_MULTIPLIER, /**< @e UncontrolledFlowMultiplier indicates the multiplier, + * to be used in conjunction with the Uncontrolled Flow Threshold and Uncontrolled Flow Divisor attributes, + * to determine the true flow threshold value.*/ + ZB_ZCL_ATTR_METERING_UNCONTROLLED_FLOW_DIVISOR, /**< @e UncontrolledFlowDivisor + * The Uncontrolled Flow Divisor attribute indicates the divisor, to be used in conjunction + * with the Uncontrolled Flow Threshold and Uncontrolled Flow Multiplier attributes, + * to determine the true flow threshold value.*/ + ZB_ZCL_ATTR_METERING_FLOW_STABILISATION_PERIOD, /**< @e FlowStabilisationPeriod indicates the time given to allow the flow to stabilize.*/ + ZB_ZCL_ATTR_METERING_FLOW_MEASUREMENT_PERIOD, /**< @e FlowMeasurementPeriodAttribute indicates the period + * over which the flow is measured and compared against the Uncontrolled Flow Threshold attribute.*/ + + /* Alternative Historical Consumption Attribute Set, table D.46 */ + /**< @e AlternativeInstantaneousDemand represents the current Demand delivered or received at the premises*/ + ZB_ZCL_ATTR_METERING_ALT_INSTANTANEOUS_DEMAND = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_ALTERNATIVE_HISTORICAL_CONSUMPTION, 0x00), + ZB_ZCL_ATTR_METERING_CURRENT_DAY_ALT_CONSUMPTION_DELIVERED, /**< @e CurrentDayAlternativeConsumptionDelivered represents the summed value + * delivered to the premises since the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_ALT_CONSUMPTION_RECEIVED, /**< @e CurrentDayAlternativeConsumptionReceived represents the summed value + * received from the premises since the Historical Freeze Time (HFT).*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_ALT_CONSUMPTION_DELIVERED, /**< @e PreviousDayAlternativeConsumptionDelivered represents the summed value + * delivered to the premises within the previous 24 hour period + * starting at the alternative Historical Freeze Time (HFT).*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_ALT_CONSUMPTION_RECEIVED, /**< @e PreviousDayAlternativeConsumptionReceived represents the summed value + * received to the premises within the previous 24 hour period + * starting at the alternative Historical Freeze Time (HFT).*/ + ZB_ZCL_ATTR_METERING_CURRENT_ALT_PARTIAL_PROFILE_INTERVAL_START_TIME_DELIVERED, /**< @e CurrentAlternativePartialProfileIntervalStartTimeDelivered represents the start time + * of the current Load Profile interval being accumulated for commodity delivered */ + ZB_ZCL_ATTR_METERING_CURRENT_ALT_PARTIAL_PROFILE_INTERVAL_START_TIME_RECEIVED, /**< @e CurrentAlternativePartialProfileIntervalStartTimeReceived represents the start time + * of the current Load Profile interval being accumulated for commodity received */ + ZB_ZCL_ATTR_METERING_CURRENT_ALT_PARTIAL_PROFILE_INTERVAL_VALUE_DELIVERED, /**< @e CurrentAlternativePartialProfileIntervalValueDelivered represents the value +* * of the current Load Profile interval being accumulated for commodity delivered.*/ + ZB_ZCL_ATTR_METERING_CURRENT_ALT_PARTIAL_PROFILE_INTERVAL_VALUE_RECEIVED, /**< @e CurrentAlternativePartialProfileIntervalValueReceived represents the value +* * of the current Load Profile interval being accumulated for commodity received .*/ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_ALT_MAX_PRESSURE, /**< @e CurrentDayAlternativeMaxPressure is the maximum pressure + * reported during a day from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_CURRENT_DAY_ALT_MIN_PRESSURE, /**< @e CurrentDayAlternativeMinPressure is the minimum pressure + * reported during a day from the water or gas meter. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_ALT_MAX_PRESSURE, /**< @e PreviousDayAlternativeMaxPressure represents the maximum pressure + * reported during previous day from the water or gas meter.*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_ALT_MIN_PRESSURE, /**< @e PreviousDayAlternativeMinPressure represents the minimum pressure + * reported during previous day from the water or gas meter.*/ + + ZB_ZCL_ATTR_METERING_CURRENT_DAY_ALT_MAX_DEMAND, /**< @e CurrentDayAlternativeMaxDemand represents the maximum demand or rate + * of delivered value of Energy, Gas, or Water being utilized at the premises.*/ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY_ALT_MAX_DEMAND, /**< @e PreviousDayAlternativeMaxDemand represents represents the maximum demand or rate + * of delivered value of Energy, Gas, or Water being utilized at the premises.*/ + + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_ALT_MAX_DEMAND, /**< @e CurrentMonthAlternativeMaxDemand is the maximum demand reported during a month from the meter. */ + ZB_ZCL_ATTR_METERING_CURRENT_YEAR_ALT_MAX_DEMAND, /**< @e CurrentYearAlternativeMaxDemand is the maximum demand reported during a year from the meter.*/ + + /**< @e PreviousDayNAlternativeConsumptionDelivered represents the summed value delivered to the premises + * within the previous 24 hour period starting at the Historical Freeze Time (HFT). */ + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_ALT_CONSUMPTION_DELIVERED = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_ALTERNATIVE_HISTORICAL_CONSUMPTION, 0x20), + ZB_ZCL_ATTR_METERING_PREVIOUS_DAY2_ALT_CONSUMPTION_RECEIVED, /**< @e PreviousDayNAlternativeConsumptionReceived + * represents the summed value received from the premises + * within the previous 24 hour period starting at the Historical Freeze Time (HFT).*/ + + /**< @e CurrentWeekAlternativeConsumptionDelivered represents the summed value + * delivered to the premises since the Historical Freeze Time (HFT) on Monday to the last HFT read. */ + ZB_ZCL_ATTR_METERING_CURRENT_WEEK_ALT_CONSUMPTION_DELIVERED = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_ALTERNATIVE_HISTORICAL_CONSUMPTION, 0x30), + ZB_ZCL_ATTR_METERING_CURRENT_WEEK_ALT_CONSUMPTION_RECEIVED, /**< @e CurrentWeekAlternativeConsumptionReceived represents the summed value + * received from the premises since the Historical Freeze Time (HFT) on Monday to the last HFT read */ + + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_ALT_CONSUMPTION_DELIVERED, /**< @e PreviousWeekNAlternativeConsumptionDelivered represents the summed value + * delivered to the premises within the previous week period + * starting at the Historical Freeze Time (HFT) on the Monday to the Sunday. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_WEEK_ALT_CONSUMPTION_RECEIVED, /**< @e PreviousWeekNAlternativeConsumptionReceived represents the summed value + * received from the premises within the previous week period + * starting at the Historical Freeze Time (HFT) on the Monday to the Sunday*/ + /**< @e CurrentMonthAlternativeConsumptionDelivered represents the summed value delivered to the premises + * since the Historical Freeze Time (HFT) on the 1st of the month to the last HFT read */ + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_ALT_CONSUMPTION_DELIVERED = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_ALTERNATIVE_HISTORICAL_CONSUMPTION, 0x40), + ZB_ZCL_ATTR_METERING_CURRENT_MONTH_ALT_CONSUMPTION_RECEIVED, /**< @e CurrentMonthAlternativeConsumptionReceived represents the summed value + * received from the premises since the Historical Freeze Time (HFT) + * on the 1st of the month to the last HFT read. */ + + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_ALT_CONSUMPTION_DELIVERED, /**< @e PreviousMonthNAlternativeConsumptionDelivered represents the summed value + * delivered to the premises within the previous Month period + * starting at the Historical Freeze Time (HFT) on the 1st of the month to the last day of the month. */ + ZB_ZCL_ATTR_METERING_PREVIOUS_MONTH_ALT_CONSUMPTION_RECEIVED, /**< @e PreviousMonthNAlternativeConsumptionReceived represents the summed value + * received from the premises within the previous month period + * starting at the Historical Freeze Time (HFT) on the 1st of the month to the last day of the month. */ + + /* ZB_ZCL_METERING_SET_FOUR_QUADRANT_ELECTRICITY attribute set */ + /*NOTE: the first attribute from this attribute set starts from 0x0D01 value instead of 0x0D00 */ + /*NOTE: attribute 0x0D04 in one spec it is ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q4_ID, + in another it is ZB_ZCL_ATTR_METERING_CURRENT_REACTIVE_SUMMATION_Q1_ID + NOTE: It is supposed that ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q1_ID = 0x0D00 + */ + ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q1_ID = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_METERING_SET_FOUR_QUADRANT_ELECTRICITY, 0x00), /**< This attribute represents the most + * recent summed value of Active Energy (kWh) + * delivered in the quadrant Q1. + */ + ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q2_ID, /**< This attribute represents the most + * recent summed value of Active Energy (kWh) + * delivered in the quadrant Q2. + */ + ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q3_ID, /**< This attribute represents the most + * recent summed value of Active Energy (kWh) + * delivered in the quadrant Q3. + */ + ZB_ZCL_ATTR_METERING_CURRENT_ACTIVE_SUMMATION_Q4_ID, /**< This attribute represents the most + * recent summed value of Active Energy (kWh) + * delivered in the quadrant Q4. + */ + ZB_ZCL_ATTR_METERING_CURRENT_REACTIVE_SUMMATION_Q1_ID, /**< This attribute represents the most recent + * summed value of Reactive Energy (kVarh) delivered + * in quadrant Q1. + */ + ZB_ZCL_ATTR_METERING_CURRENT_REACTIVE_SUMMATION_Q2_ID, /**< This attribute represents the most recent + * summed value of Reactive Energy (kVarh) delivered + * in quadrant Q2. + */ + ZB_ZCL_ATTR_METERING_CURRENT_REACTIVE_SUMMATION_Q3_ID, /**< This attribute represents the most recent + * summed value of Reactive Energy (kVarh) delivered + * in quadrant Q3. + */ + ZB_ZCL_ATTR_METERING_CURRENT_REACTIVE_SUMMATION_Q4_ID /**< This attribute represents the most recent + * summed value of Reactive Energy (kVarh) delivered + * in quadrant Q4. + */ +}; + + +/** @brief @e CurrentBlock attribute values + * @see @ref ZB_ZCL_ATTR_METERING_CURRENT_BLOCK_ID + * @see SE 1.4 spec, Table D.12. + */ +enum zb_zcl_metering_block_e +{ + ZB_ZCL_METERING_BLOCK_NOT_USED = 0x00, /**< No blocks in use */ + ZB_ZCL_METERING_BLOCK_1 = 0x01, /**< Block 1 */ + ZB_ZCL_METERING_BLOCK_2 = 0x02, /**< Block 2 */ + ZB_ZCL_METERING_BLOCK_3 = 0x03, /**< Block 3 */ + ZB_ZCL_METERING_BLOCK_4 = 0x04, /**< Block 4 */ + ZB_ZCL_METERING_BLOCK_5 = 0x05, /**< Block 5 */ + ZB_ZCL_METERING_BLOCK_6 = 0x06, /**< Block 6 */ + ZB_ZCL_METERING_BLOCK_7 = 0x07, /**< Block 7 */ + ZB_ZCL_METERING_BLOCK_8 = 0x08, /**< Block 8 */ + ZB_ZCL_METERING_BLOCK_9 = 0x09, /**< Block 9 */ + ZB_ZCL_METERING_BLOCK_10 = 0x0A, /**< Block 10 */ + ZB_ZCL_METERING_BLOCK_11 = 0x0B, /**< Block 11 */ + ZB_ZCL_METERING_BLOCK_12 = 0x0C, /**< Block 12 */ + ZB_ZCL_METERING_BLOCK_13 = 0x0D, /**< Block 13 */ + ZB_ZCL_METERING_BLOCK_14 = 0x0E, /**< Block 14 */ + ZB_ZCL_METERING_BLOCK_15 = 0x0F, /**< Block 15 */ + ZB_ZCL_METERING_BLOCK_16 = 0x10, /**< Block 16 */ + /* 0x11 to 0xFF reserved */ +}; + + +/** @brief @e SupplyStatus attribute values + * @see @ref ZB_ZCL_ATTR_METERING_SUPPLY_STATUS_ID + * @see SE 1.4 spec, table D.13. + */ +enum zb_zcl_metering_supply_status_e +{ + ZB_ZCL_SUPPLY_STATUS_OFF = 0x00, /**< Supply OFF */ + ZB_ZCL_SUPPLY_STATUS_ARMED = 0x01, /**< Supply OFF/ARMED */ + ZB_ZCL_SUPPLY_STATUS_ON = 0x02 /**< Supply ON */ + /* 0x03 to 0xFF reserved for future use */ +}; + + +/** @brief Bit mapping of the @e Status attribute (Electricity) + * @see @ref ZB_ZCL_ATTR_METERING_STATUS_ID + * @see SE spec, subclause 3.2.2.3.1, table D.16. + */ +enum zb_zcl_metering_status_electricity_e +{ + ZB_ZCL_METERING_ELECTRICITY_CHECK_METER = 1 << 0, /**< @e CheckMeter bit is set to true when a non fatal problem has been detected on the meter such as + * a measurement error, memory error, self check error. */ + ZB_ZCL_METERING_ELECTRICITY_LOW_BATTERY = 1 << 1, /**< @e LowBattery bit is set to true when the battery needs maintenance. */ + ZB_ZCL_METERING_ELECTRICITY_TAMPER_DETECT = 1 << 2, /**< @e TamperDetect bit is set to true if a tamper event has been detected. */ + ZB_ZCL_METERING_ELECTRICITY_POWER_FAILURE = 1 << 3, /**< @e PowerFailure bit is set to true during a power outage. */ + ZB_ZCL_METERING_ELECTRICITY_POWER_QUALITY = 1 << 4, /**< @e PowerQuality bit is set to true if a power quality event has been detected such as a low + * voltage, high voltage. */ + ZB_ZCL_METERING_ELECTRICITY_LEAK_DETECT = 1 << 5, /**< @e LeakDetect bit is set to true when a leak has been detected. */ + ZB_ZCL_METERING_ELECTRICITY_SERVICE_DISCONNECT_OPEN = 1 << 6, /**< @e ServiceDisconnectOpen bit is Set to true when the service has been disconnected to this premises. */ + ZB_ZCL_METERING_ELECTRICITY_RESERVED = 1 << 7 /**< Reserved bit */ +}; + + +/** @brief Bit mapping of the @e Status attribute (Gas) + * @see @ref ZB_ZCL_ATTR_METERING_STATUS_ID + * @see SE spec, subclause 3.2.2.3.1, table D.17. + */ +enum zb_zcl_metering_status_gas_e +{ + ZB_ZCL_METERING_GAS_CHECK_METER = 1 << 0, /**< @e CheckMeter bit is Set to true when a non fatal problem has been detected on the meter such as + * a measurement error, memory error, or self check error. */ + ZB_ZCL_METERING_GAS_LOW_BATTERY = 1 << 1, /**< @e LowBattery bit is set to true when the battery needs maintenance. */ + ZB_ZCL_METERING_GAS_TAMPER_DETECT = 1 << 2, /**< @e TamperDetect bit is set to true if a tamper event has been detected. */ + ZB_ZCL_METERING_GAS_RESERVED = 1 << 3, /**< Reserved bit */ + ZB_ZCL_METERING_GAS_LOW_PRESSURE = 1 << 4, /**< @e LowPressure bit is set to true when the pressure at the meter is below the meter's low + * pressure threshold value. */ + ZB_ZCL_METERING_GAS_LEAK_DETECT = 1 << 5, /**< @e LeakDetect bit is set to true when a leak has been detected. */ + ZB_ZCL_METERING_GAS_SERVICE_DISCONNECT = 1 << 6, /**< @e ServiceDisconnect bit is set to true when the service has been disconnected to this premises. + * Ex. The valve is in the closed position preventing delivery of gas. */ + ZB_ZCL_METERING_GAS_REVERSE_FLOW = 1 << 7 /**< @e ReverseFlow bit is set to true if flow detected in the opposite direction to normal (from + * consumer to supplier). */ +}; + + +/** @brief Bit mapping of the @e Status attribute (Water) + * @see @ref ZB_ZCL_ATTR_METERING_STATUS_ID + * @see SE 1.4 spec, subclause 3.2.2.3.1, table D.18. + */ +enum zb_zcl_metering_status_water_e +{ + ZB_ZCL_METERING_WATER_CHECK_METER = 1 << 0, /**< @e CheckMeter bit is Set to true when a non fatal problem has been detected on the meter such as + * a measurement error, memory error, or self check error. */ + ZB_ZCL_METERING_WATER_LOW_BATTERY = 1 << 1, /**< @e LowBattery bit is set to true when the battery needs maintenance. */ + ZB_ZCL_METERING_WATER_TAMPER_DETECT = 1 << 2, /**< @e TamperDetect bit set to true if a tamper event has been detected. */ + ZB_ZCL_METERING_WATER_PIPE_EMTPY = 1 << 3, /**< @e PipeEmpty bit is set to true when the service pipe at the meter is empty and there is no flow + * in either direction. */ + ZB_ZCL_METERING_WATER_LOW_PRESSURE = 1 << 4, /**< @e LowPressure bit is Set to true when the pressure at the meter is below the meter's low + * pressure threshold value. */ + ZB_ZCL_METERING_WATER_LEAK_DETECT = 1 << 5, /**< @e LeakDetect bit is set to true when a leak has been detected. */ + ZB_ZCL_METERING_WATER_SERVICE_DISCONNECT = 1 << 6, /**< @e ServiceDisconnect bit is set to true when the service has been disconnected to this premises. + * Ex. The valve is in the closed position preventing delivery of water. */ + ZB_ZCL_METERING_WATER_REVERSE_FLOW = 1 << 7 /**< @e ReverseFlow bit is Set to true if flow detected in the opposite direction to normal (from + * consumer to supplier). */ +}; + + +/** @brief Bit mapping of the @e Status attribute (Heat and Cooling) + * @see @ref ZB_ZCL_ATTR_METERING_STATUS_ID + * @see SE 1.4 spec, subclause 3.2.2.3.1, table D.19. + */ +enum zb_zcl_metering_status_heat_cooling_e +{ + ZB_ZCL_METERING_HCOOL_CHECK_METER = 1 << 0, /**< @e CheckMeter bit is Set to true when a non fatal problem has been detected on the meter such + * as a measurement error, memory error, or self check error. */ + ZB_ZCL_METERING_HCOOL_LOW_BATTERY = 1 << 1, /**< @e LowBattery bit is set to true when the battery needs maintenance. */ + ZB_ZCL_METERING_HCOOL_TAMPER_DETECT = 1 << 2, /**< @e TamperDetect bit is set to true if a tamper event has been detected. */ + ZB_ZCL_METERING_HCOOL_TEMPERATURE_SENSOR = 1 << 3, /**< @e TemperatureSensor bit is Set to true when an error is detected on a temperature sensor at + * this premises. */ + ZB_ZCL_METERING_HCOOL_BURST_DETECT = 1 << 4, /**< @e BurstDetect bit is set to true when a burst is detected on pipes at this premises. */ + ZB_ZCL_METERING_HCOOL_LEAK_DETECT = 1 << 5, /**< @e LeakDetect bit is set to true when a leak has been detected. */ + ZB_ZCL_METERING_HCOOL_SERVICE_DISCONNECT = 1 << 6, /**< @e ServiceDisconnect bit is Set to true when the service has been disconnected to this premises. + * Ex. The valve is in the closed position preventing delivery of heat or cooling. */ + ZB_ZCL_METERING_HCOOL_FLOW_SENSOR = 1 << 7 /**< @e FlowSensor bit is set to true when an error is detected on a flow sensor at this premises. */ +}; + + +/** @brief Bit mapping of the @e ExtendedStatus attribute (General Flags) + * @see @ref ZB_ZCL_ATTR_METERING_EXTENDED_STATUS_ID + * @see SE 1.4 spec, subclause D.3.2.2.3.5, table D.20 + */ +enum zb_zcl_metering_extstatus_general_e +{ + ZB_ZCL_METERING_METER_COVER_REMOVED = 1 << 0, /**< @e MeterCoverRemoved bit is set to true when the device detects the meter + * cover being removed. */ + ZB_ZCL_METERING_STRONG_MAGNETIC_FIELD_DETECTED = 1 << 1, /**< @e StrongMagneticFieldDetected bit is set to true when the device detects + * presence of a strong magnetic field */ + ZB_ZCL_METERING_BATTERY_FAILURE = 1 << 2, /**< @e BatteryFailure bit is set to true when the device detects that its battery + * has failed. */ + ZB_ZCL_METERING_PROGRAM_MEMORY_ERROR = 1 << 3, /**< @e ProgramMemoryError bit is set to true when the device detects an error + * within its program (non-volatile) memory. */ + ZB_ZCL_METERING_RAM_ERROR = 1 << 4, /**< @e RAMError bit is set to true when the device detects an instance of a + * Random Access Memory error within the device memory. */ + ZB_ZCL_METERING_NV_MEMORY_ERROR = 1 << 5, /**< @e NVMemoryError bit is set to true when the device detects an instance of a + * Non Volatile memory error within the device memory - this is a fatal meter + * error that will require the meter replacement */ + ZB_ZCL_METERING_MEASUREMENT_SYSTEM_ERROR = 1 << 6, /**< @e MeasurementSystemError bit is set to true when the device detects an error + * within its measurement system. */ + ZB_ZCL_METERING_WATCHDOG_ERROR = 1 << 7, /**< @e WatchdogError bit is set to true when the device has detected an instance + * of a watchdog reset event (following a catastrophic fault within the device). */ + ZB_ZCL_METERING_SUPPLY_DISCONNECT_FAILURE = 1 << 8, /**< @e SupplyDisconnectFailure bit is set to true when the device has detected + * that the valve has not closed as expected (for gas) or the contactor has not + * opened as expected (for electricity). */ + ZB_ZCL_METERING_SUPPLY_CONNECT_FAILURE = 1 << 9, /**< @e SupplyConnectFailure bit is set to true when the device has detected that + * the valve has not opened as expected (for gas) or the contactor has not closed + * as expected (for electricity). */ + ZB_ZCL_METERING_MEASUREMENT_SW_CHANGED = 1 << 10, /**< @e MeasurementSWChanged/Tampered bit is set to true when the device detects that + * its measurement software has changed. */ + ZB_ZCL_METERING_CLOCK_INVALID = 1 << 11, /**< @e ClockInvalid bit is set to true when the device detects that its internal clock + * is invalid. */ + ZB_ZCL_METERING_TEMPERATURE_EXCEEDED = 1 << 12, /**< @e TemperatureExceeded bit is set to true when the metering device's temperature + * exceeds a predefined limit. There are various reasons for temperature rise in + * metering devices. */ + ZB_ZCL_METERING_MOISTURE_DETECTED = 1 << 13 /**< @e MoistureDetected bit is set to true when a sensor has detected the presence of + * moisture e.g. moisture in a gas line which can cause a drop in gas pressure, or + * moisture detected in the sealed component area within a water meter. */ + /* bits 14-23 reserved */ +}; + + +/** @brief Bit mapping of the @e ExtendedStatus attribute (Electricity Meter specific Flags) + * @see @ref ZB_ZCL_ATTR_METERING_EXTENDED_STATUS_ID + * @see SE 1.4 spec, subclause D.3.2.2.3.5, table D.21 + */ +enum zb_zcl_metering_extstatus_electricity_e +{ + ZB_ZCL_METERING_ELECTRICITY_TERMINAL_COVER_REMOVED = 1L << 24, /**< @e TerminalCoverRemoved bit is set to true when the device detects that its + * terminal cover has been removed. */ + ZB_ZCL_METERING_ELECTRICITY_INCORRECT_POLARITY = 1L << 25, /**< @e IncorrectPolarity bit is set to true when the electricity meter detects + * incorrect polarity on the electricity supply. */ + ZB_ZCL_METERING_ELECTRICITY_CURRENT_WITH_NO_VOLTAGE = 1L << 26, /**< @e CurrentWithNoVoltage bit is set to true when the meter has been tampered + * with, to disconnect the measurement function from the supply. Electricity is + * still flowing but not being recorded. */ + ZB_ZCL_METERING_ELECTRICITY_LIMIT_THRESHOLD_EXCEEDED = 1L << 27, /**< @e LimitThresholdExceeded bit is set to true when the electricity meter detects + * that the load has exceeded the load limit threshold. */ + ZB_ZCL_METERING_ELECTRICITY_UNDER_VOLTAGE = 1L << 28, /**< @e UnderVoltage bit is set to true when the electricity meter indicates that + * the voltage measurement over the voltage measurement period is lower than the + * voltage threshold. */ + ZB_ZCL_METERING_ELECTRICITY_OVER_VOLTAGE = 1L << 29, /**< @e OverVoltage bit is set to true when the electricity meter indicates that the + * voltage measurement over the voltage measurement period is higher than the + * voltage threshold. */ + ZB_ZCL_METERING_ELECTRICITY_BIDIRECTION_OPERATION = 1L << 30, /** In (Maximum Current) - short circuit */ + ZB_ZCL_METERING_REASON_OFF_DUE_TO_OVERHEATING_OTHER = 0x06, /**< OFF due to overheating, + I < In (Maximum Current) - other */ +}; + + +/*! @brief If set, suppress leading zeros */ +#define ZB_ZCL_METERING_FORMATTING_SUPPRESS_ZERO(b) (((b) & 0x80)==0x80) + +/*! @brief Number of Digits to the right of the Decimal Point */ +#define ZB_ZCL_METERING_FORMATTING_LEFT(b) (((b)>>3) & 0x07) + +/*! @brief Number of Digits to the left of the Decimal Point */ +#define ZB_ZCL_METERING_FORMATTING_RIGHT(b) ((b) & 0x07) + +/*! @brief Set summation formatting */ +#define ZB_ZCL_METERING_FORMATTING_SET(suppress_zero, left, right) \ + ( ((suppress_zero) ? 0x80 : 0) | (((left) & 7)<<3) | ((right) & 7) ) + +/** @brief Default value for Status attribute */ +#define ZB_ZCL_METERING_STATUS_DEFAULT_VALUE 0x00 + +/** @brief Default value for Status attribute */ +#define ZB_ZCL_METERING_UNIT_OF_MEASURE_DEFAULT_VALUE 0x00 + +/** @brief Default value for Instantaneous Demand attribute */ +#define ZB_ZCL_METERING_INSTANTANEOUS_DEMAND_DEFAULT_VALUE 0x00 + + /** @brief Default value for DailyFreezeTime attribute */ +#define ZB_ZCL_METERING_DAILY_FREEZE_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for PowerFactor attribute */ +#define ZB_ZCL_METERING_POWER_FACTOR_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for DefaultUpdatePeriod attribute */ +#define ZB_ZCL_METERING_DEFAULT_UPDATE_PERIOD_DEFAULT_VALUE ((zb_uint8_t)0x1E) + +/** @brief Default value for FastPollUpdatePeriod attribute */ +#define ZB_ZCL_METERING_FAST_POLL_UPDATE_PERIOD_DEFAULT_VALUE ((zb_uint8_t)0x05) + +/** @brief Default value for PresetReadingTime attribute */ +#define ZB_ZCL_METERING_PRESET_READING_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for MaxNumberOfPeriodsDelivered attribute */ +#define ZB_ZCL_METERING_MAX_NUMBER_OF_PERIODS_DELIVERED_DEFAULT_VALUE ((zb_uint8_t)0x18) + +/** @brief Default value for GenericAlarmMask attribute */ +#define ZB_ZCL_METERING_GENERIC_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ElectricityAlarmMask attribute */ +#define ZB_ZCL_METERING_ELECTRICITY_ALARM_MASK_DEFAULT_VALUE ((zb_uint32_t)0xFFFFFFFF) + +/** @brief Default value for GenericFlowPressureAlarmMask attribute */ +#define ZB_ZCL_METERING_GENERIC_FLOW_PRESSURE_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for WaterSpecificAlarmMask attribute */ +#define ZB_ZCL_METERING_WATER_SPECIFIC_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for HeatAndCoolingSpecificAlarmMask attribute */ +#define ZB_ZCL_METERING_HEAT_AND_COOLING_SPECIFIC_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for GasSpecificAlarmMask attribute */ +#define ZB_ZCL_METERING_GAS_SPECIFIC_ALARM_MASK_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) +/** @} */ /* ZB_ZCL_METERING_SRV_ATTRS */ + + +/** @defgroup ZB_ZCL_METERING_CMDS Metering cluster commands + * @{ + */ + + +/** Metering cluster client command identifiers. + * @see SE spec, subclause D.3.3.3.1 + */ +typedef enum zb_zcl_metering_cli_cmd_e +{ + + /* (O) */ + ZB_ZCL_METERING_CLI_CMD_GET_PROFILE = 0x00, /**< @e GetProfile command */ + /* (O) */ + ZB_ZCL_METERING_CLI_CMD_REQUEST_MIRROR_RESPONSE, /**< The @e RequestMirrorResponse + * command allows the ESI to inform a + * sleepy Metering Device it has the + * ability to store and mirror its data. + */ + /* (O) */ + ZB_ZCL_METERING_CLI_CMD_MIRROR_REMOVED, /**on_off = src_ptr->on_off; \ + ZB_LETOH16(&((data_ptr)->on_time), &(src_ptr->on_time)); \ + ZB_LETOH16(&((data_ptr)->off_wait_time), &(src_ptr->off_wait_time)); \ + } \ +} + +/** @cond internals_doc */ +/** + * @name Inform User App about On/Off cluster command and change attributes. + * Internal structures and define-procedure for inform User App about On/Off + * cluster command and change attributes. + * @internal + * @{ + */ + +/** @brief Declare run Set Effect command for User Application +*/ +typedef struct zb_zcl_on_off_set_effect_value_param_s +{ + zb_uint8_t effect_id; /*!< Effect identify */ + zb_uint8_t effect_variant; /*!< Effect variant */ +} zb_zcl_on_off_set_effect_value_param_t; + +/*! Struct for invoke User App & continue after */ +typedef struct zb_zcl_on_off_effect_user_app_schedule_e +{ + zb_zcl_parsed_hdr_t cmd_info; /**< Parameters for continue command, + see @ref zb_zcl_parsed_hdr_s */ + zb_zcl_on_off_set_effect_value_param_t param; /**< User App command parameters, + see @ref zb_zcl_on_off_set_effect_value_param_s */ +} zb_zcl_on_off_effect_user_app_schedule_t; + +#define ZB_ZCL_ON_OFF_EFFECT_SCHEDULE_USER_APP(buffer, pcmd_info, effectId, effectVar) \ +{ \ + zb_zcl_on_off_effect_user_app_schedule_t* user_data = \ + ZB_BUF_GET_PARAM((buffer), zb_zcl_on_off_effect_user_app_schedule_t); \ + ZB_MEMMOVE(&(user_data->cmd_info), (pcmd_info), sizeof(zb_zcl_parsed_hdr_t)); \ + user_data->param.effect_id = (effectId); \ + user_data->param.effect_variant = (effectVar); \ + ZB_SCHEDULE_CALLBACK(zb_zcl_on_off_effect_invoke_user_app, (buffer)); \ +} + +/*! @} + * @endcond */ /* internals_doc */ + +/*! @} */ /* On/Off cluster commands */ + +/*! @cond internals_doc + @internal @name On/Off cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ON_OFF_ON_OFF_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_GLOBAL_SCENE_CONTROL(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ON_OFF_GLOBAL_SCENE_CONTROL, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_ON_TIME(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ON_OFF_ON_TIME, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_OFF_WAIT_TIME(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ON_OFF_OFF_WAIT_TIME, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/** @struct zb_zcl_on_off_attrs_s + * @brief On/Off cluster attributes + */ +typedef struct zb_zcl_on_off_attrs_s +{ + zb_uint8_t on_off; +} zb_zcl_on_off_attrs_t; + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_START_UP_ON_OFF(data_ptr) \ +{ \ + ZB_ZCL_ATTR_ON_OFF_START_UP_ON_OFF, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_ZCL_DECLARE_ON_OFF_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_ON_OFF_ATTRIB_LIST(attr_list, &attrs.on_off) + +/*! @internal Number of attributes mandatory for reporting in On/Off cluster */ +#define ZB_ZCL_ON_OFF_REPORT_ATTR_COUNT 1 + +/*! @internal Struct for invoke User App & continue after */ +typedef struct zb_on_off_user_app_schedule_e +{ + zb_zcl_parsed_hdr_t cmd_info; + zb_uint8_t new_value; + zb_bool_t is_run_timer; +} zb_on_off_user_app_schedule_t; + + +/*! @} + @endcond */ /* On/Off cluster internals */ + +/*! @} */ /* ZCL On/Off cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_on_off_init_server(void); +zb_void_t zb_zcl_on_off_init_client(void); +#define ZB_ZCL_CLUSTER_ID_ON_OFF_SERVER_ROLE_INIT zb_zcl_on_off_init_server +#define ZB_ZCL_CLUSTER_ID_ON_OFF_CLIENT_ROLE_INIT zb_zcl_on_off_init_client + +#endif /* ! defined ZB_ZCL_ON_OFF_H */ diff --git a/zboss/include/zcl/zb_zcl_on_off_switch_conf.h b/zboss/include/zcl/zb_zcl_on_off_switch_conf.h new file mode 100644 index 0000000000..03b04eae17 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_on_off_switch_conf.h @@ -0,0 +1,188 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: On/Off switch configuration definitoins +*/ + +#if ! defined ZB_ZCL_ON_OFF_SWITCH_CONF_H +#define ZB_ZCL_ON_OFF_SWITCH_CONF_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_OOSC + * @{ + * @details + * On/Off Switch Configuration cluster has no cluster-specific command support. Cluster + * attributes can be queried with @ref ZB_ZCL_COMMANDS "common commands". + * + * Sample switch config cluster attributes data + * @code + * zb_uint8_t attr_switch_type = ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_TOGGLE; + * zb_uint8_t attr_switch_actions = ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_DEFAULT_VALUE; + * + * ZB_ZCL_DECLARE_ON_OFF_SWITCH_CONFIGURATION_ATTRIB_LIST(switch_cfg_attr_list, &attr_switch_type, &attr_switch_actions); + * @endcode + * + * For more information see devices_generic sample + * + */ + +/*! @name On/off switch configuration cluster attributes + @{ +*/ + +/*! @brief On/off switch configuration cluster attribute identifiers + @see ZCL spec, subclause 3.9.2.2 +*/ +enum zb_zcl_on_off_switch_configuration_attr_e +{ + /*! Switch type attribute identifier (switch information) */ + ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_ID = 0x0000, + /*! Switch actions attribute identifier (switch settings) */ + ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_ID = 0x0010 +}; + +/*! @brief Permissible values for switch type attribute + @see ZCL spec, subclause 3.9.2.2.2 +*/ +enum zb_zcl_on_off_switch_configuration_switch_type_e +{ + /*! Toggle switch */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_TOGGLE = 0, + /*! Momentary switch */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_MOMENTARY = 1, + /*! Multifunction switch */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_MULTIFUNCTION = 2 +}; + +/*! @brief Maximal value for switch type attribute */ +#define ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_MAX_VALUE \ + (ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_MULTIFUNCTION) + +/* Switch type attribute has no default value */ + +/*! @brief Permissible values for switch actions attribute + @see ZCL spec, subclause 3.9.2.2.3.1 +*/ +enum zb_zcl_on_off_switch_configuration_switch_actions_e +{ + /*! @brief First type command pattern + + @li Send "On" on arriving to State2 from State1; + @li Send "Off" on arriving to State1 from State2. + */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_TYPE1 = 0, + /*! @brief Second type command pattern + + @li Send "On" on arriving to State1 from State2; + @li Send "Off" on arriving to State2 from State1. + */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_TYPE2 = 1, + /*! @brief Toggle command pattern + + Send "Toggle" on state change + */ + ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_TOGGLE = 2 +}; + +/*! @brief Maximal value for switch actions attribute */ +#define ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_MAX_VALUE \ + (ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_TOGGLE) + +/** @brief Default value for Switch actions attribute */ +#define ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_DEFAULT_VALUE \ + (ZB_ZCL_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_TYPE1) + +/*! @} */ /* On/off switch configuration cluster attributes */ + +/** @cond internals_doc + @internal @name On/off switch configuration cluster attribute structures + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ + } + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_ID(data_ptr) \ + { \ + ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ + } + +/** @internal Number of attributes mandatory for reporting on On/Off switch configuration cluster */ +#define ZB_ZCL_ON_OFF_SWITCH_CONFIG_REPORT_ATTR_COUNT 0 + +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for ON/OFF Swith configuration cluster + @param attr_list - attribute list name + @param switch_type - pointer to variable to store switch type attribute value + @param switch_actions - pointer to variable to store switch action attribute value +*/ +#define ZB_ZCL_DECLARE_ON_OFF_SWITCH_CONFIGURATION_ATTRIB_LIST(attr_list, switch_type, switch_actions) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_TYPE_ID, (switch_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_ON_OFF_SWITCH_CONFIGURATION_SWITCH_ACTIONS_ID, (switch_actions)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} + @endcond */ /* On/off switch configuration cluster attribute structures */ + + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_on_off_switch_config_init_server(void); +zb_void_t zb_zcl_on_off_switch_config_init_client(void); +#define ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG_SERVER_ROLE_INIT zb_zcl_on_off_switch_config_init_server +#define ZB_ZCL_CLUSTER_ID_ON_OFF_SWITCH_CONFIG_CLIENT_ROLE_INIT zb_zcl_on_off_switch_config_init_client + +#endif /* ! defined ZB_ZCL_ON_OFF_SWITCH_CONF_H */ diff --git a/zboss/include/zcl/zb_zcl_ota_upgrade.h b/zboss/include/zcl/zb_zcl_ota_upgrade.h new file mode 100644 index 0000000000..d539a147d0 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_ota_upgrade.h @@ -0,0 +1,2167 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: OTA Upgrade cluster defintions +*/ + +#if ! defined ZB_ZCL_OTA_UPGRADE_H +#define ZB_ZCL_OTA_UPGRADE_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +#if defined ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE || defined ZB_USE_OSIF_OTA_ROUTINES || defined DOXYGEN + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_OTA_UPGRADE + * @{ + * @details + * All commands in the cluster have only request form, and carry no payload. + */ + +/** @brief Hook on Write attribute + * send Check-in if change Check-in interval & Check-in remain time > new check-in interval */ +/* zb_void_t zb_zcl_ota_upgrade_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); */ + +/*! @name OTA File Header format + Structures for representation OTA File Header + @{ +*/ + +/*! @brief Structure representsation of OTA File Header, + * see OTA spec 6.3.2 */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_file_header_s +{ + zb_uint32_t file_id; /**< OTA upgrade file identifier*/ + zb_uint16_t header_version; /**< OTA Header version */ + zb_uint16_t header_length; /**< OTA Header length */ + zb_uint16_t fc; /**< OTA Header Field control */ + zb_uint16_t manufacturer_code; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint16_t stack_version; /**< Zigbee Stack version */ + zb_char_t header_string[32]; /**< OTA Header string */ + zb_uint32_t total_image_size; /**< Total Image size (including header) */ + + /* Optional fields are moved to additional structure zb_zcl_ota_upgrade_file_header_optional_t */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_file_header_t; + +#define ZB_ZCL_OTA_FILE_IS_FILE_SPECIFIC(head) \ + (((head)->fc) & ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FC_DEVICE_SPECIFIC) + +/** + Optional parts of the OTA file header + */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_file_header_optional_s +{ + zb_uint8_t credential_version; /**< Security credential version */ + zb_ieee_addr_t dst_addr; /**< Upgrade file destination */ + zb_uint16_t min_hw_version; /**< Minimum hardware version */ + zb_uint16_t max_hw_version; /**< Maximum hardware version */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_file_header_optional_t; + +/** @cond internals_doc */ +#define ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FULL_SIZE \ + (sizeof(zb_zcl_ota_upgrade_file_header_t) + 2*sizeof(zb_uint16_t)+sizeof(zb_ieee_addr_t)) +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Default OTA Upgrade File Identifier, see spec 6.3.2.1 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FILE_ID 0x0BEEF11E + +/** @brief Default OTA Upgrade File Version, see spec 6.3.2.2 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FILE_VERSION 0x0100 + +/*! @brief OTA File header - fc fields structure + @see OTA spec, OTA Upgrade Cluster 6.3.2.4 +*/ +enum zb_zcl_ota_upgrade_file_header_fc_e +{ + /*! @brief Security Credential Version Present */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FC_CREDENTIAL_VER = 1 << 0, + /*! @brief Device Specific File */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FC_DEVICE_SPECIFIC = 1 << 1, + /*! @brief Hardware Versions Present */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_FC_HW_VER = 1 << 2, +}; + +/** @brief Special Manufacturer Code, see spec 6.3.2.5 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_HEADER_MANUFACTURE_CODE_WILD_CARD 0xffff + +/*! @brief OTA File header - Image Type Values + @see OTA spec, OTA Upgrade Cluster 6.3.2.6 +*/ +enum zb_zcl_ota_upgrade_file_header_image_type_e +{ + /*! @brief Manufacturer Specific - maximum value */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_IMAGE_MANUF_SPEC_MAX = 0xffbf, + /*! @brief Security credential */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_IMAGE_SECURITY_CRED = 0xffc0, + /*! @brief Configuration */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_IMAGE_CONFIG = 0xffc1, + /*! @brief Log */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_IMAGE_LOG = 0xffc2, + /*! @brief Wild card value */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_IMAGE_WILD_CARD = 0xffff, +}; + +/** @brief OTA Upgrade File Version, App release, see spec 6.3.2.7 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_APP_RELEASE(ver) (((ver) >>24) & 0xff) + +/** @brief OTA Upgrade File Version, App build, see spec 6.3.2.7 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_APP_BUILD(ver) (((ver) >>16) & 0xff) + +/** @brief OTA Upgrade File Version, Stack release, see spec 6.3.2.7 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_STACK_RELEASE(ver) (((ver) >>8) & 0xff) + +/** @brief OTA Upgrade File Version, Stack build, see spec 6.3.2.7 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_STACK_BUILD(ver) ((ver) & 0xff) + +/** @brief OTA Upgrade File Version, make file verston, see spec 6.3.2.7 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_MAKE_VERSION(app_rel, app_build, stack_rel, stack_build) \ + ((app_rel) << 24 | (app_build) << 16 | (stack_rel) << 8 | (stack_build)) + +/* + OTA Upgrade Spec (6.3.2.7 File Version) has dome recommendations about versioning (at least to + divide version to 4 parts - Stack Build, Stack Release, Application Build and Application + Release), but does not specify comparing method. Looks like we do not have any limitations and + may upgrade/downgrade any f/w (except re-installation), so this comparing is simply: + ver1 != ver2 + Only one possible limitation now is NVRAM, but if dataset ids are not overlapped, it is also ok. + Any additional comparsion logic may be implemented on the application level. + */ +/** @brief Compare 2 OTA versions and deside if it is needed to do upgrade */ +#define ZB_ZCL_OTA_UPGRADE_VERSION_CMP(ver1, ver2) \ + ( (ver1) != (ver2) ) + +/*! @brief OTA File header - Zigbee Stack version + @see OTA spec, OTA Upgrade Cluster 6.3.2.8 +*/ +enum zb_zcl_ota_upgrade_file_header_stack_version_e +{ + /*! @brief Zigbee 2006 */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_STACK_2006 = 0x0000, + /*! @brief Zigbee 2007 */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_STACK_2007 = 0x0001, + /*! @brief Zigbee Pro */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_STACK_PRO = 0x0002, + /*! @brief Zigbee IP */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_STACK_IP = 0x0003, +}; + +/*! @brief OTA File header - Security Credential Version + @see OTA spec, OTA Upgrade Cluster 6.3.2.11 +*/ +enum zb_zcl_ota_upgrade_file_header_security_version_e +{ + /*! @brief SE 1.0 */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_SECURITY_VER_SE1_0 = 0x00, + /*! @brief SE 1.1 */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_SECURITY_VER_SE1_1 = 0x01, + /*! @brief SE 2.0 */ + ZB_ZCL_OTA_UPGRADE_FILE_HEADER_SECURITY_VER_SE2_0 = 0x02, +}; + +/** @brief OTA Upgrade HW Version Get Version, see spec 6.3.2.13 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_HW_VERSION(ver) (((ver) >>8) & 0xff) + +/** @brief OTA Upgrade HW Version Get Revision, see spec 6.3.2.13 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_GET_HW_REVISION(ver) ((ver) & 0xff) + +/** @brief OTA Upgrade Make HW Version, see spec 6.3.2.13 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_MAKE_HW_VERSION(ver, rev) \ + ((ver) << 8 | (rev)) + +/** @brief Default value of OTA Upgrade HW Version */ +#define ZB_ZCL_OTA_UPGRADE_FILE_HW_VERSION_DEF_VALUE 0xffff +/** @brief Default value of OTA Upgrade destination address */ +#define ZB_ZCL_OTA_UPGRADE_FILE_DEST_ADDRESS_DEF_VALUE { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } + +/*! @} +*/ + +/*! @name OTA File Sub-elementformat + Structures for representation OTA File Sub-element + @{ +*/ + +/*! @brief Structure representsation of OTA File Sub-element, + * see OTA spec 6.3.3 */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_sub_element_s +{ + zb_uint16_t tag_id; /** Tag ID*/ + zb_uint32_t length; /** length */ + zb_uint8_t value[1]; /** data variable, length - see 'length' field */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_sub_element_t; + + +/*! @brief OTA File header - Tag Identifiers + @see OTA spec, OTA Upgrade Cluster 6.3.4 +*/ +enum zb_zcl_ota_upgrade_sub_element_tags_e +{ + /*! @brief */ + ZB_ZCL_OTA_UPGRADE_FILE_TAG_UPGRADE_IMAGE = 0x0000, + /*! @brief ECDSA Signature */ + ZB_ZCL_OTA_UPGRADE_FILE_TAG_ECDSA = 0x0001, + /*! @brief ECDSA Signature Certificate */ + ZB_ZCL_OTA_UPGRADE_FILE_TAG_ECDSA_CERT = 0x0002, + /*! @brief Manufacturer Specific Use - minimum */ + ZB_ZCL_OTA_UPGRADE_FILE_TAG_MANUF_MIN = 0xf000, + /*! @brief Manufacturer Specific Use - maximum */ + ZB_ZCL_OTA_UPGRADE_FILE_TAG_MANUF_MAX = 0xffff, +}; + +/*! @brief Structure representsation of OTA ECDSA Signature, + * see OTA spec 6.3.5 */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_ecdsa_s +{ + zb_uint16_t tag_id; /** Tag ID*/ + zb_uint32_t length; /** length */ + zb_ieee_addr_t address; /** address */ + zb_uint8_t value[42]; /** data variable */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_ecdsa_t; + +/** @brief Special Manufacturer Code, see spec 6.3.5 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_TAG_ID 0x0001 + +/** @brief Special Manufacturer Code, see spec 6.3.5 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_LENGTH 0x00000032 + + +/*! @brief Structure representsation of OTA ECDSA Signature, + * see OTA spec 6.3.6 */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_ecdsa_signing_s +{ + zb_uint16_t tag_id; /** Tag ID*/ + zb_uint32_t length; /** length */ + zb_uint8_t certificate[48]; /** data variable, length - see 'length' field */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_ecdsa_signing_t; + +/** @brief Special Manufacturer Code, see spec 6.3.6 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_SIGNING_TAG_ID 0x0002 + +/** @brief Special Manufacturer Code, see spec 6.3.6 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_SIGNING_LENGTH 0x00000030 + + +/*! @brief Structure representsation of OTA ECDSA Certificate, + * see OTA spec 6.3.7 */ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_ecdsa_certificate_s +{ + zb_uint16_t tag_id; /** Tag ID*/ + zb_uint32_t length; /** length */ + zb_uint8_t hash[16]; /** hash */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_ecdsa_ertificate_t; + +/** @brief Special Manufacturer Code, see spec 6.3.7 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_CERTIFICATE_TAG_ID 0x0003 + +/** @brief Special Manufacturer Code, see spec 6.3.7 */ +#define ZB_ZCL_OTA_UPGRADE_ECDSA_CERTIFICATE_LENGTH 0x00000010 + + +/*! @} +*/ + +/* Cluster ZB_ZCL_CLUSTER_ID_OTA_UPGRADE */ + +/*! @name OTA Upgrade cluster attributes + @{ +*/ + +/*! @brief Maximum size data for Query Image Block Request */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_DATA_SIZE_MAX 64 + +/*! @brief Callback function for send next data portion + * + */ +typedef zb_ret_t (*zb_zcl_ota_upgrade_next_data_ind_t)(zb_uint8_t index, + zb_zcl_parsed_hdr_t *zcl_header, + zb_uint32_t offset, + zb_uint8_t size, + zb_uint8_t** data); + +#if defined ZB_HA_ENABLE_OTA_UPGRADE_SERVER || defined DOXYGEN + +/** @brief Initialize OTA Upgrade cluster - server part + * For server clear custom data and registry next data indication + * + * @param endpoint - destination endpoint + * @param next_data_ind_cb - callback to be called on received image block + * For client initiate search Upgrade server */ +zb_void_t zb_zcl_ota_upgrade_init_server(zb_uint8_t endpoint, zb_zcl_ota_upgrade_next_data_ind_t next_data_ind_cb); + +/*! @brief Structure representsation of Data for insert OTA file to upgrade mechanism */ +typedef struct zb_zcl_ota_upgrade_server_insert_file_s +{ + zb_uint8_t endpoint; /**< Endpoint */ + zb_uint8_t index; /**< Index of table, index must be less value is set when create attribute */ + zb_uint8_t *ota_file; /**< OTA file, place in memory, see OTA spec 6.3.2 + @note OTA file must saved in memory until call zb_zcl_ota_upgrade_remove_file*/ + zb_uint8_t notify_on; /**< Flag to control Image notification after the file is inserted */ + zb_uint32_t upgrade_time; /**< Upgrade time for this OTA file */ + +} zb_zcl_ota_upgrade_server_insert_file_t; + +/*! @brief Insert upgrade OTA file into Server upgrade table + * + * @param param - buffer with @ref zb_zcl_ota_upgrade_server_insert_file_s structure + * + * @note OTA file must be saved in memory until call zb_zcl_ota_upgrade_remove_file +*/ +zb_ret_t zb_zcl_ota_upgrade_insert_file(zb_uint8_t param); + +#define ZB_ZCL_OTA_UPGRADE_INSERT_FILE(buf, ep, i, file, upgrade_tm, notify, ret_code) \ +{ \ + zb_zcl_ota_upgrade_server_insert_file_t *file_data = \ + ZB_BUF_GET_PARAM(buf, zb_zcl_ota_upgrade_server_insert_file_t); \ + file_data->endpoint = (ep); \ + file_data->index = (i); \ + file_data->ota_file = (file); \ + file_data->upgrade_time = (upgrade_tm); \ + file_data->notify_on = (notify); \ + (ret_code) = zb_zcl_ota_upgrade_insert_file(buf); \ +} + +/*! @brief Structure representsation of Data for insert OTA file to upgrade mechanism */ +typedef struct zb_zcl_ota_upgrade_server_remove_file_s +{ + zb_uint8_t endpoint; /**< Endpoint */ + zb_uint8_t index; /**< Index of table, index must be less value is set when create attribute */ + +} zb_zcl_ota_upgrade_server_remove_file_t; + +/*! @brief Remove upgrade file from Server upgrade table + * + * @param param - buffer with @ref zb_zcl_ota_upgrade_server_remove_file_s structure + * + * @note After calling this command OTA file may be removed from memory +*/ +zb_ret_t zb_zcl_ota_upgrade_remove_file(zb_uint8_t param); + +#define ZB_ZCL_OTA_UPGRADE_REMOVE_FILE(buf, ep, i, ret_code) \ +{ \ + zb_zcl_ota_upgrade_server_remove_file_t *file_data = \ + ZB_BUF_GET_PARAM(buf, zb_zcl_ota_upgrade_server_remove_file_t); \ + file_data->endpoint = (ep); \ + file_data->index = (i); \ + (ret_code) = zb_zcl_ota_upgrade_remove_file(buf); \ +} + +/*! @brief Structure representsation of OTA file on server side */ +typedef struct zb_zcl_ota_upgrade_data_s +{ + zb_zcl_ota_upgrade_file_header_t *file_header; + zb_uint32_t upgrade_time; + +} zb_zcl_ota_upgrade_data_t; + +/*! @brief Structure representsation of server side variables */ +typedef struct zb_zcl_ota_upgrade_server_variable_s +{ + zb_uint8_t *query_jitter; /**< QueryJitter */ + //zb_uint8_t data_size; /**< DataSize */ + //zb_uint8_t *ota_image_data; /**< OTAImageData */ + zb_uint32_t *current_time; /**< CurrentTime */ + //zb_uint32_t upgrade_time; /**< UpgradeTime */ + + // custom data + zb_uint8_t table_length; /**< Length of server table with upgrade image data */ + zb_zcl_ota_upgrade_data_t *table; /**< Server table with upgrade image data */ + +} zb_zcl_ota_upgrade_server_variable_t; + +/*! @brief Default value for DataSize, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_DATA_SIZE_DEF_VALUE 0xff + +/*! @brief Minimum value for QueryJitter, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_JITTER_MIN_VALUE 0x01 +/*! @brief Maximum value for QueryJitter, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_JITTER_MAX_VALUE 0x64 +/*! @brief Default value for QueryJitter, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_JITTER_DEF_VALUE 0x32 + +/*! @brief Default value for currentTime, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_CURRENT_TIME_DEF_VALUE 0xffffffff + +/*! @brief Default value for UpgradeTime, OTA spec */ +#define ZB_ZCL_OTA_UPGRADE_UPGRADE_TIME_DEF_VALUE 0xffffffff + +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_srv_query_img_param_s +{ + zb_zcl_parsed_hdr_t zcl_parsed_hdr; + zb_zcl_addr_t *zcl_addr; + zb_uint16_t image_type; + zb_uint16_t manufacturer_code; + zb_uint32_t version; + zb_uint8_t *table_idx; +} + ZB_PACKED_STRUCT zb_zcl_ota_upgrade_srv_query_img_param_t; + +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_srv_upgrade_started_param_s +{ + zb_zcl_addr_t *zcl_addr; + zb_uint16_t image_type; + zb_uint32_t version; +} + ZB_PACKED_STRUCT zb_zcl_ota_upgrade_srv_upgrade_started_param_t; + +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_srv_upgrade_aborted_param_s +{ + zb_zcl_addr_t *zcl_addr; + zb_uint16_t image_type; + zb_uint32_t version; +} + ZB_PACKED_STRUCT zb_zcl_ota_upgrade_srv_upgrade_aborted_param_t; + +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_srv_upgrade_end_param_s +{ + zb_zcl_addr_t *zcl_addr; + zb_uint32_t *upgrade_time; + zb_uint8_t status; + zb_uint16_t image_type; + zb_uint32_t version; +} + ZB_PACKED_STRUCT zb_zcl_ota_upgrade_srv_upgrade_end_param_t; + +#endif /* defined ZB_HA_ENABLE_OTA_UPGRADE_SERVER || defined DOXYGEN */ + +#if defined ZB_HA_ENABLE_OTA_UPGRADE_CLIENT || defined DOXYGEN + +/** @brief Initialize OTA Upgrade cluster - client part + * For server clear custom data + * For client initiate search Upgrade server + @param param - empty buffer +*/ +zb_void_t zb_zcl_ota_upgrade_init_client(zb_uint8_t param); + +/** @brief Start OTA Upgrade client with pre-defined OTA Upgrade Server attributes + * (without Service Discovery) + * + * @param server_ep - OTA Upgrade server endpoint + * @param server_addr - OTA Upgrade server short address + * @return RET_OK on success or RET_ERROR on error +*/ +zb_ret_t zb_zcl_ota_upgrade_start_client(zb_uint8_t server_ep, zb_uint16_t server_addr); + +/** @brief Stop process OTA Upgrade / OTA query new images + * Client stop schedule OTA command & clear OTA status*/ +zb_void_t zb_zcl_ota_upgrade_stop_client(void); + +/*! @brief Resume process OTA Upgrade if it was previously suspended by the application + * + * @param param - buffer to be resumed + * @param upgrade_status - application upgrade status @see zb_zcl_ota_upgrade_status_e + */ +zb_void_t zb_zcl_ota_upgrade_resume_client(zb_uint8_t param, zb_uint8_t upgrade_status); + +/*! @brief Set Freqency request server about new upgrade file (minutes) + * @param endpoint - endpoint of the OTA cluster + * @param interval - new interval value (in minutes) + */ +zb_void_t zb_zcl_ota_upgrade_set_query_interval(zb_uint8_t endpoint, zb_uint16_t interval); + +/*! @brief Clear attribute after upgrade + * + * @param endpoint - endpoint + * + *@note After colling this command OTA file may be removed from memory +*/ +zb_void_t zb_zcl_ota_upgrade_file_upgraded(zb_uint8_t endpoint); + +/*! @brief Structure representsation of client side variables */ +typedef struct zb_zcl_ota_upgrade_client_variable_s +{ + // custom data + zb_uint32_t download_file_size; + zb_uint16_t timer_query; + zb_uint16_t timer_counter; + zb_uint16_t hw_version; + zb_uint8_t max_data_size; + zb_uint8_t img_block_req_sent; + zb_uint8_t pending_img_block_resp; +} zb_zcl_ota_upgrade_client_variable_t; + +#endif /* defined ZB_HA_ENABLE_OTA_UPGRADE_CLIENT || defined DOXYGEN */ + +/*! @brief OTA Upgrade cluster attribute identifiers + @see OTA spec, OTA Upgrade Cluster 6.7, +*/ +enum zb_zcl_ota_upgrade_attr_e +{ + /** @brief UpgradeServerID attribute, OTA spec 6.7.1 */ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ID = 0x0000, + /** @brief FileOffset attribute, OTA spec 6.7.2 */ + ZB_ZCL_ATTR_OTA_UPGRADE_FILE_OFFSET_ID = 0x0001, + /** @brief CurrentFileVersion attribute, OTA spec 6.7.3 */ + ZB_ZCL_ATTR_OTA_UPGRADE_FILE_VERSION_ID = 0x0002, + /** @brief CurrentZigbeeStackVersion attribute, OTA spec 6.7.4 */ + ZB_ZCL_ATTR_OTA_UPGRADE_STACK_VERSION_ID = 0x0003, + /** @brief DownloadedFileVersion attribute, OTA spec 6.7.5 */ + ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_FILE_VERSION_ID = 0x0004, + /** @brief DownloadedZigbeeStackVersion attribute, OTA spec 6.7.6 */ + ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_STACK_VERSION_ID = 0x0005, + /** @brief ImageUpgradeStatus attribute, OTA spec 6.7.7 */ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STATUS_ID = 0x0006, + /** @brief Manufacturer ID attribute, OTA spec 6.7.8 */ + ZB_ZCL_ATTR_OTA_UPGRADE_MANUFACTURE_ID = 0x0007, + /** @brief Image Type ID attribute, OTA spec 6.7.9 */ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_TYPE_ID = 0x0008, + /** @brief MinimumBlockReque attribute, OTA spec 6.7.10 */ + ZB_ZCL_ATTR_OTA_UPGRADE_MIN_BLOCK_REQUE_ID = 0x0009, + /** @brief Image Stamp attribute, OTA spec 6.7.11 */ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STAMP_ID = 0x000a, + /** This attribute indicates what behavior the client device supports for activating + * a fully downloaded but not installed upgrade image. */ + ZB_ZCL_ATTR_OTA_UPGRADE_UPGRADE_ACTIVATION_POLICY_ID = 0x000b, + /** This attribute indicates what behavior the client device supports for activating + * a fully downloaded image when the OTA server cannot be reached. */ + ZB_ZCL_ATTR_OTA_UPGRADE_UPGRADE_TIMEOUT_POLICY_ID = 0x000c, + + + /*! @brief OTA server endpoint custom attribute */ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID = 0xfff3, + /*! @brief OTA server addr custom attribute */ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID = 0xfff2, + /*! @brief DownloadedFileSize custom attribute */ + ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID = 0xfff1, + /*! @brief Server variables- see OTA spec 6.8 + * and Custom data */ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID = 0xfff0, +}; + +/*! @brief Default value for UpgradeServerID attribute, OTA spec 6.7.1 */ +#define ZB_ZCL_OTA_UPGRADE_SERVER_DEF_VALUE { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } +/*! @brief Default value for FileOffset attribute, OTA spec 6.7.2 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_OFFSET_DEF_VALUE 0xffffffff +/*! @brief Default value for CurrentFileVersion attribute, OTA spec 6.7.3 */ +#define ZB_ZCL_OTA_UPGRADE_FILE_VERSION_DEF_VALUE 0xffffffff +/*! @brief Default value for CurrentZigbeeStackVersion attribute, OTA spec 6.7.4 */ +#define ZB_ZCL_OTA_UPGRADE_STACK_VERSION_DEF_VALUE 0xffff +/*! @brief Default value for DownloadedFileVersion attribute, OTA spec 6.7.5 */ +#define ZB_ZCL_OTA_UPGRADE_DOWNLOADED_FILE_VERSION_DEF_VALUE 0xffffffff +/*! @brief Default value for DownloadedZigbeeStackVersion attribute, OTA spec 6.7.6 */ +#define ZB_ZCL_OTA_UPGRADE_DOWNLOADED_STACK_DEF_VALUE 0xffff +/*! @brief Default value for ImageUpgradeStatus attribute, OTA spec 6.7.7 */ +#define ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_DEF_VALUE 0x00 +/*! @brief Maximum value for MinimumBlockReque attribute, OTA spec 6.7.11 */ +#define ZB_ZCL_OTA_UPGRADE_IMAGE_STAMP_MIN_VALUE 0x0256 + +/*! @brief Default value for OTA server endpoint custom attribute */ +#define ZB_ZCL_OTA_UPGRADE_SERVER_ENDPOINT_DEF_VALUE 0xff +/*! @brief Default value for OTA server addr custom attribute */ +#define ZB_ZCL_OTA_UPGRADE_SERVER_ADDR_DEF_VALUE 0xffff + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.7.7 +*/ +enum zb_zcl_ota_upgrade_image_status_e +{ + /*! @brief Normal */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_NORMAL = 0x00, + /*! @brief Download in progress */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_DOWNLOADING = 0x01, + /*! @brief Download complete */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_DOWNLOADED = 0x02, + /*! @brief Waiting to upgrade */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_WAITING_UPGRADE = 0x03, + /*! @brief Count down */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_COUNT_DOWN = 0x04, + /*! @brief Wait for more */ + ZB_ZCL_OTA_UPGRADE_IMAGE_STATUS_WAIT_FOR_MORE = 0x05, +}; + +/*! @brief Default Freqency request server about new upgrade file (minutes) */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_TIMER_COUNT_DEF (24*60) + +/*! @brief Timer interval for Query timer */ +#define ZB_ZCL_OTA_UPGRADE_QUERY_TIMER_INTERVAL \ + 60l * ZB_TIME_ONE_SECOND + +/*! @brief Maximum value of nextImageQuery interval */ +#define ZB_ZCL_OTA_UPGRADE_MAX_INTERVAL 60 + +/*! @brief Resend buffer delay */ +#define ZB_ZCL_OTA_UPGRADE_RESEND_BUFFER_DELAY ZB_TIME_ONE_SECOND * 45 + +/*! @cond internals_doc + @name OTA Upgrade cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ID, \ + ZB_ZCL_ATTR_TYPE_IEEE_ADDR, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_FILE_OFFSET_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_FILE_OFFSET_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_FILE_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_FILE_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_STACK_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_STACK_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_FILE_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_FILE_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_STACK_VERSION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_STACK_VERSION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STATUS_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_MANUFACTURE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_MANUFACTURE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_TYPE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_MIN_BLOCK_REQUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_MIN_BLOCK_REQUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STAMP_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STAMP_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in OTA Upgrade cluster */ +#define ZB_ZCL_OTA_UPGRADE_REPORT_ATTR_COUNT 0 + +/*! @} + * @ + @endcond endcond */ /* OTA Upgrade cluster internals */ + +/** @brief Declare attribute list for OTA Upgrade cluster - client side + @param attr_list - attribute list name + @param upgrade_server - pointer to variable to store UpgradeServerID attribute + @param file_offset - pointer to variable to store FileOffset attribute + @param file_version - pointer to variable to store CurrentFileVersion attribute + @param stack_version - pointer to variable to store CurrentZigbeeStackVersion attribute + @param downloaded_file_ver - pointer to variable to store DownloadedFileVersion attribute + @param downloaded_stack_ver - pointer to variable to store DownloadedZigbeeStackVersion attribute + @param image_status - pointer to variable to store ImageUpgradeStatus attribute + @param manufacturer - pointer to variable to store Manufacturer ID attribute + @param image_type - pointer to variable to store Image Type ID attribute + @param min_block_reque - pointer to variable to store MinimumBlockReque attribute + @param image_stamp - pointer to variable to store Image Stamp attribute + @param server_addr - server short address + @param server_ep - server endpoint + @param hardware_version - (const) hardware version + @param max_data_size - (const) maximum data size Query Block Image commands + @param query_timer - (const) query timer count +*/ +#define ZB_ZCL_DECLARE_OTA_UPGRADE_ATTRIB_LIST(attr_list, \ + upgrade_server, file_offset, file_version, stack_version, downloaded_file_ver, \ + downloaded_stack_ver, image_status, manufacturer, image_type, min_block_reque, image_stamp, \ + server_addr, server_ep, hardware_version, max_data_size, query_timer) \ + zb_zcl_ota_upgrade_client_variable_t client_var_##attr_list = \ + {0, query_timer, 1, hardware_version, max_data_size, 0, 0}; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ID , (upgrade_server)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_FILE_OFFSET_ID , (file_offset)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_FILE_VERSION_ID , (file_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_STACK_VERSION_ID , (stack_version)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_FILE_VERSION_ID , (downloaded_file_ver)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_DOWNLOADED_STACK_VERSION_ID, (downloaded_stack_ver)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STATUS_ID , (image_status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_MANUFACTURE_ID , (manufacturer)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_TYPE_ID , (image_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_MIN_BLOCK_REQUE_ID , (min_block_reque)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_IMAGE_STAMP_ID , (image_stamp)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ADDR_ID , (server_addr)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_ENDPOINT_ID , (server_ep)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_CLIENT_DATA_ID, &(client_var_##attr_list)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @brief Declare attribute list for OTA Upgrade cluster - server side + @param attr_list - attribute list name + @param query_jitter - (8bit) pointer to variable to store QueryJitter value + @param current_time - (32bit) pointer to variable to store CurrentTime + @param length - (const) length of server table with upgrade image data +*/ +#define ZB_ZCL_DECLARE_OTA_UPGRADE_ATTRIB_LIST_SERVER(attr_list, \ + query_jitter, current_time, length) \ + zb_zcl_ota_upgrade_data_t table_##attr_list[length]; \ + zb_zcl_ota_upgrade_server_variable_t server_var_##attr_list = { \ + query_jitter, /* 0, 0,*/ current_time, /*ZB_ZCL_OTA_UPGRADE_UPGRADE_TIME_DEF_VALUE,*/ \ + length, table_##attr_list }; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_OTA_UPGRADE_SERVER_DATA_ID, &(server_var_##attr_list)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* OTA Upgrade cluster attributes */ + +/*! @name OTA Upgrade cluster commands + @{ +*/ + +/*! @brief OTA Upgrade cluster client to server command identifiers + @see OTA spec, OTA Upgrade Cluster, 6.10.1 +*/ +enum zb_zcl_ota_upgrade_cmd_e +{ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_ID = 0x01, /**< "Query Next Image Request" command */ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_ID = 0x03, /**< "Image Block Request" command */ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_PAGE_ID = 0x04, /**< "Image Page Request" command */ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_ID = 0x06, /**< "Upgrade End Request" command */ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_ID = 0x08, /**< "Query Specific File Request" command */ +}; + +/*! @brief OTA Upgrade cluster server to client command identifiers + @see OTA spec, OTA Upgrade Cluster, 6.10.1 +*/ +enum zb_zcl_ota_upgrade_resp_cmd_e +{ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_NOTIFY_ID = 0x00, /**< "Image Notify" command */ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_RESP_ID = 0x02, /**< "Query Next Image Response" command */ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_RESP_ID = 0x05, /**< "Image Block Response" command */ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_RESP_ID = 0x07, /**< "Upgrade End Response" command */ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_RESP_ID = 0x09, /**< "Query Specific File Response" command */ + + ZB_ZCL_CMD_OTA_UPGRADE_INTERNAL_ABORT_ID = 0xf9, /**< ZBOSS internal command */ +}; + +/** @cond internals_doc */ +/* OTA Upgrade cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_NOTIFY_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_RESP_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_RESP_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_RESP_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_RESP_ID + +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_PAGE_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_ID + +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_SERVER_ROLE_RECEIVED_CMD_LIST \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_ID, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_ID +/*! @} + * @endcond */ /* internals_doc */ + + +/************************* Query Next Image Request **************************/ + +/*! @brief Structure representsation of Query Next Image Request command payload + @see OTA spec, OTA Upgrade Cluster 6.10.4.1 +*/typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_query_next_image_s +{ + zb_uint8_t fc; /**< Field Control, see @ref zb_zcl_ota_upgrade_image_notify_payload_type_e */ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint16_t hw_version; /**< Hardware version */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_query_next_image_t; + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.10.4.1.2 +*/ +enum zb_zcl_ota_upgrade_query_next_image_fc_e +{ + /*! @brief Hardware Version Present */ + ZB_ZCL_OTA_UPGRADE_QUERY_NEXT_IMAGE_HW_VERSION = 1 << 0, +}; + +/*! @brief Send "Query Next Image Request" command, see OTA spec 6.10.4 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param fc - Field Control, see @ref zb_zcl_ota_upgrade_image_notify_payload_type_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param hw_version - Hardware version + @param aps_secured - APS security +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_QUERY_NEXT_IMAGE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + fc, manufacturer, image_type, file_version, hw_version, aps_secured) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (fc)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (file_version)); \ + if( (fc) & ZB_ZCL_OTA_UPGRADE_QUERY_NEXT_IMAGE_HW_VERSION ) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (hw_version)); \ + } \ + ZB_ZCL_FINISH_N_SEND_PACKET_NEW((buffer), ptr, addr, dst_addr_mode, \ + dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb, aps_secured, \ + ZB_FALSE, 0); \ +} + +/** @brief Macro for getting "Query Next Image Request" command, see OTA spec 6.10.4 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_query_next_image_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_QUERY_NEXT_IMAGE_REQ(data_ptr, buffer, status) \ +{ \ + zb_zcl_ota_upgrade_query_next_image_t *src_ptr = \ + (zb_zcl_ota_upgrade_query_next_image_t*)zb_buf_begin((buffer)); \ + zb_uint8_t expected_payload_len = sizeof(zb_zcl_ota_upgrade_query_next_image_t); \ + \ + if (!(src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_NEXT_IMAGE_HW_VERSION)) \ + { \ + expected_payload_len -= sizeof(zb_uint16_t); \ + } \ + \ + if (zb_buf_len((buffer)) != expected_payload_len) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->fc = src_ptr->fc; \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + if( src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_NEXT_IMAGE_HW_VERSION ) \ + { \ + ZB_HTOLE16(&((data_ptr)->hw_version), &(src_ptr->hw_version)); \ + } \ + else \ + { \ + (data_ptr)->hw_version = 0; \ + } \ + } \ +} + +/************************* Image Block Request **************************/ + +/*! @brief Structure representsation of Image Block Request command payload + @see OTA spec, OTA Upgrade Cluster 6.10.6.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_image_block_s +{ + zb_uint8_t fc; /**< Field Control, see @ref zb_zcl_ota_upgrade_image_block_fc_e */ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint32_t file_offset; /**< File offset */ + zb_uint8_t data_size_max; /**< Maximum data size */ + + zb_ieee_addr_t node_addr; /**< Request node address*/ + zb_uint16_t block_delay; /**< BlockRequestDelay */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_image_block_t; + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.10.6.1.2 +*/ +enum zb_zcl_ota_upgrade_image_block_fc_e +{ + /*! @brief Request node’s IEEE address Present */ + ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_IEEE_PRESENT = 1 << 0, + /*! @brief BlockRequestDelay present */ + ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_DELAY_PRESENT = 1 << 1, +}; + +/*! @brief Send "Image Block Request" command, see OTA spec 6.10.6 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param fc - Field Control, see @ref zb_zcl_ota_upgrade_image_block_fc_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param file_offset - File offset + @param data_size_max - Maximum data size + @param node_addr - Request node address + @param block_delay - BlockRequestDelay + @param current_delay - Delay current send (millisec) +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_BLOCK_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + fc, manufacturer, image_type, file_version, file_offset, data_size_max, \ + node_addr, block_delay, current_delay) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (fc)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (file_offset)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (data_size_max)); \ + if( (fc) & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_IEEE_PRESENT) \ + { \ + ZB_ZCL_PACKET_PUT_DATA_IEEE(ptr, (node_addr)); \ + } \ + if( (fc) & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_DELAY_PRESENT) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (block_delay)); \ + } \ + ZB_ZCL_FINISH_PACKET_O((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT_SCHEDULE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb, \ + current_delay); \ +} + +/** @brief Macro for getting "Image Block Request" command, see OTA spec 6.10.6 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_image_block_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_IMAGE_BLOCK_REQ(data_ptr, buffer, status) \ +{ \ + zb_zcl_ota_upgrade_image_block_t *src_ptr = \ + (zb_zcl_ota_upgrade_image_block_t*)zb_buf_begin((buffer)); \ + \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ota_upgrade_image_block_t) - \ + ( !(src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_IEEE_PRESENT) ? sizeof(zb_ieee_addr_t) : 0) - \ + ( !(src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_DELAY_PRESENT) ? sizeof(zb_uint16_t) : 0) ) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->fc = src_ptr->fc; \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE32(&((data_ptr)->file_offset), &(src_ptr->file_offset)); \ + (data_ptr)->data_size_max = src_ptr->data_size_max; \ + if( src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_IEEE_PRESENT) \ + { \ + ZB_IEEE_ADDR_COPY((data_ptr)->node_addr, (src_ptr)->node_addr); \ + } \ + if( src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_BLOCK_DELAY_PRESENT) \ + { \ + ZB_HTOLE16(&((data_ptr)->block_delay), &(src_ptr->block_delay)); \ + } \ + } \ +} + +/************************* Image Page Request **************************/ + +/*! @brief Structure representsation of Image Page Request command payload + @see OTA spec, OTA Upgrade Cluster 6.10.7.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_image_page_s +{ + zb_uint8_t fc; /**< Field Control, see @ref zb_zcl_ota_upgrade_image_page_fc_e */ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint32_t file_offset; /**< File offset */ + zb_uint8_t data_size_max; /**< Maximum data size */ + zb_uint16_t page_size; /**< Page size */ + zb_uint16_t response_spacing; /**< Response Spacing */ + + zb_ieee_addr_t node_addr; /**< Request node address */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_image_page_t; + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.10.7.1.2 +*/ +enum zb_zcl_ota_upgrade_image_page_fc_e +{ + /*! @brief Request node's IEEE address Present */ + ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_PAGE_IEEE_PRESENT = 1 << 0, +}; + +/*! @brief Send "Image Page Request" command, see OTA spec 6.10.7 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param fc - Field Control, see @ref zb_zcl_ota_upgrade_image_page_fc_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param file_offset - File offset + @param data_size_max - Maximum data size + @param page_size - Page size + @param response_spacing - Response Spacing + @param node_addr - Request node address +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_PAGE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + fc, manufacturer, image_type, file_version, file_offset, data_size_max, \ + page_size, response_spacing, node_addr) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_PAGE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (fc)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (file_offset)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (data_size_max)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (page_size), (response_spacing)); \ + if( (fc) & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_PAGE_IEEE_PRESENT) \ + { \ + ZB_ZCL_PACKET_PUT_DATA_IEEE(ptr, (node_addr)); \ + } \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb); \ +} + +/** @brief Macro for getting "Image Page Request" command, see OTA spec 6.10.7 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_image_page_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_IMAGE_PAGE_REQ(data_ptr, buffer, status) \ +{ \ + zb_zcl_ota_upgrade_image_page_t *src_ptr = \ + (zb_zcl_ota_upgrade_image_page_t*)zb_buf_begin((buffer)); \ + \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ota_upgrade_image_page_t) - \ + ((src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_PAGE_IEEE_PRESENT) ? sizeof(zb_ieee_addr_t) : 0) ) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->fc = src_ptr->fc; \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE32(&((data_ptr)->file_offset), &(src_ptr->file_offset)); \ + (data_ptr)->data_size_max = src_ptr->data_size_max; \ + ZB_HTOLE16(&((data_ptr)->page_size), &(src_ptr->page_size)); \ + ZB_HTOLE16(&((data_ptr)->response_spacing), &(src_ptr->response_spacing)); \ + if( src_ptr->fc & ZB_ZCL_OTA_UPGRADE_QUERY_IMAGE_PAGE_IEEE_PRESENT) \ + { \ + ZB_IEEE_ADDR_COPY((data_ptr)->node_addr, (src_ptr)->node_addr); \ + } \ + } \ +} + +/************************* Upgrade End Request **************************/ + +/*! @brief Structure representsation of Upgrade End Request command payload + @see OTA spec, OTA Upgrade Cluster 6.10.9.1 +*/typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_upgrade_end_s +{ + zb_uint8_t status; /**< Status */ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_upgrade_end_t; + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.10.9.1.2 +*/ +/*! @brief Send "Upgrade End Request" command, see OTA spec 6.10.9 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param status - Status, see @ref zb_zcl_status_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_UPGRADE_END_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + status, manufacturer, image_type, file_version) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (file_version)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb); \ +} + +/** @brief Macro for getting "Upgrade End Request" command, see OTA spec 6.10.9 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_upgrade_end_s. + * @param buffer containing the packet (by pointer). + * @param status_ - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_UPGRADE_END_REQ(data_ptr, buffer, status_) \ +{ \ + zb_zcl_ota_upgrade_upgrade_end_t *src_ptr = \ + (zb_zcl_ota_upgrade_upgrade_end_t*)zb_buf_begin((buffer)); \ + \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ota_upgrade_upgrade_end_t) ) \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + } \ +} + +/************************* Query Specific File Request **************************/ + +/*! @brief Structure representsation of Query Specific File Request command payload + @see OTA spec, OTA Upgrade Cluster 6.10.11.1 +*/typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_query_specific_file_s +{ + zb_ieee_addr_t node_addr; /**< Node address */ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint16_t stack_version; /**< Zigbee stack version */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_query_specific_file_t; + +/*! @brief Send "Query Specific File Request" command, see OTA spec 6.10.11 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param node_addr - Node address + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param stack_version - Zigbee stack version +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_QUERY_SPECIFIC_FILE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + node_addr, manufacturer, image_type, file_version, stack_version) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_ID); \ + ZB_ZCL_PACKET_PUT_DATA_IEEE(ptr, (node_addr)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (file_version)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (stack_version)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb); \ +} + +/** @brief Macro for getting "Query Specific File Request" command, see OTA spec 6.10.11 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_query_specific_file_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_QUERY_SPECIFIC_FILE_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ota_upgrade_query_specific_file_t) ) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ota_upgrade_query_specific_file_t *src_ptr = \ + (zb_zcl_ota_upgrade_query_specific_file_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_IEEE_ADDR_COPY((data_ptr)->node_addr, (src_ptr)->node_addr); \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE16(&((data_ptr)->stack_version), &(src_ptr->stack_version)); \ + } \ +} + +/******************************* Image Notify ******************************/ + +/*! @brief Structure representsation of Image Notify response command payload + @see OTA spec, OTA Upgrade Cluster 6.10.3.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_image_notify_s +{ + zb_uint8_t payload_type; /** Payload type, see @ref zb_zcl_ota_upgrade_image_notify_payload_type_e */ + zb_uint8_t query_jitter; /** Query jitter */ + zb_uint16_t manufacturer; /** Manufacturer code */ + zb_uint16_t image_type; /** Image type */ + zb_uint32_t file_version; /** File version */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_image_notify_t; + +/*! @brief OTA Image Upgrade Status Attribute Values + @see OTA spec, OTA Upgrade Cluster 6.10.3.2 +*/ +enum zb_zcl_ota_upgrade_image_notify_payload_type_e +{ + /*! @brief Query jitter */ + ZB_ZCL_OTA_UPGRADE_IMAGE_NOTIFY_PAYLOAD_JITTER = 0x00, + /*! @brief Query jitter and manufacturer code */ + ZB_ZCL_OTA_UPGRADE_IMAGE_NOTIFY_PAYLOAD_JITTER_CODE = 0x01, + /*! @brief Query jitter, manufacturer code, and image type */ + ZB_ZCL_OTA_UPGRADE_IMAGE_NOTIFY_PAYLOAD_JITTER_CODE_IMAGE = 0x02, + /*! @brief Query jitter, manufacturer code, image type, and new file version */ + ZB_ZCL_OTA_UPGRADE_IMAGE_NOTIFY_PAYLOAD_JITTER_CODE_IMAGE_VER = 0x03, +}; + +/*! @brief Send Image Notify command, see OTA spec 6.10.3 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param payload_type - Payload type + @param query_jitter - Query jitter + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_NOTIFY_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + payload_type, query_jitter, manufacturer, image_type, file_version) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A( \ + ptr, ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, (def_resp)); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_NOTIFY_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (payload_type)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (query_jitter)); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (file_version)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, cb); \ +} + + +#define ZB_ZCL_OTA_UPGRADE_GET_IMAGE_NOTIFY_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) <= sizeof(zb_uint8_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ota_upgrade_image_notify_t *src_ptr = \ + (zb_zcl_ota_upgrade_image_notify_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->payload_type = src_ptr->payload_type; \ + (data_ptr)->query_jitter = src_ptr->query_jitter; \ + switch ( src_ptr->payload_type ) \ + { \ + case 0x03: \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version));\ + /* FALLTHROUGH */ \ + case 0x02: \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + /* FALLTHROUGH */ \ + case 0x01: \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer));\ + /* FALLTHROUGH */ \ + default: \ + break; \ + } \ + } \ +} + + + + +/******************************* Query Next Image Response ******************************/ + +/*! @brief Structure representsation of Query Next Image Response command payload + @see OTA spec, OTA Upgrade Cluster 6.10.5.1 +*/typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_query_next_image_res_s +{ + zb_uint8_t status; /** Status, see @ref zb_zcl_status_e */ + zb_uint16_t manufacturer; /** Manufacturer code */ + zb_uint16_t image_type; /** Image type */ + zb_uint32_t file_version; /** File version */ + zb_uint32_t image_size; /** Image size */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_query_next_image_res_t; + + +/*! @brief Send Query Next Image Response command, see OTA spec 6.10.5 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param status - Status, see @ref zb_zcl_status_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param image_size - Image size +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_QUERY_NEXT_IMAGE_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + status, manufacturer, image_type, file_version, image_size) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_NEXT_IMAGE_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + if( (status) == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (image_size)); \ + } \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/** @brief Macro for getting Query Next Image Response command, see OTA spec 6.10.5 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_query_next_image_res_s. + * @param buffer containing the packet (by pointer). + * @param status_ - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_QUERY_NEXT_IMAGE_RES(data_ptr, buffer, status_)\ +{ \ + zb_zcl_ota_upgrade_query_next_image_res_t *src_ptr = \ + (zb_zcl_ota_upgrade_query_next_image_res_t*)zb_buf_begin((buffer)); \ + \ + if (zb_buf_len((buffer)) != ( (src_ptr->status)==ZB_ZCL_STATUS_SUCCESS ? \ + sizeof(zb_zcl_ota_upgrade_query_next_image_res_t) : sizeof(zb_uint8_t))) \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + TRACE_MSG(TRACE_ZLL1, "ERROR: buf_len %i", (FMT__H, zb_buf_len((buffer)))); \ + } \ + else \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + if( src_ptr->status == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE32(&((data_ptr)->image_size), &(src_ptr->image_size)); \ + } \ + } \ +} + +/******************************* Image Block Response ******************************/ + +/*! @brief Structure representsation of Image Block Response command payload + @see OTA spec, OTA Upgrade Cluster 6.10.8.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_image_block_res_s +{ + /** Status, see @ref zb_zcl_status_e */ + zb_uint8_t status; + ZB_PACKED_PRE union + { + ZB_PACKED_PRE struct + { + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint32_t file_offset; /**< File offset */ + zb_uint8_t data_size; /**< Data size */ + zb_uint8_t *image_data; /**< Image data */ + + } ZB_PACKED_STRUCT success; /**< Success response. */ + + ZB_PACKED_PRE struct + { + zb_uint32_t current_time; /**< Current time */ + zb_uint32_t request_time; /**< Request time */ + zb_uint16_t delay; /**< BlockRequestDelay */ + + } ZB_PACKED_STRUCT wait_for_data; /**< Wait for data */ + + } response; /**< response data */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_image_block_res_t; + +/*! @brief Send Image Block Response command - success status, see OTA spec 6.10.8 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param file_offset - File offset + @param data_size - data size + @param image_data - image data +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_BLOCK_SUCCESS_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + manufacturer, image_type, file_version, file_offset, data_size, image_data) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_STATUS_SUCCESS); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (file_offset)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (data_size)); \ + ZB_ASSERT(image_data != NULL); \ + ZB_ZCL_PACKET_PUT_DATA_N(ptr, (image_data), (data_size)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/*! @brief Send Image Block Response command - wait for data status, see OTA spec 6.10.8 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param current_time - Current time + @param request_time - Request time + @param delay - BlockRequestDelay +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_BLOCK_WAIT_FOR_DATA_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + current_time, request_time, delay) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_STATUS_WAIT_FOR_DATA); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (current_time), (request_time)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (delay)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/*! @brief Send Image Block Response command - abort status, see OTA spec 6.10.8 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_IMAGE_BLOCK_ABORT_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_IMAGE_BLOCK_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, ZB_ZCL_STATUS_ABORT); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/** @brief Macro for getting Image Block Response command, see OTA spec 6.10.8 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_image_block_res_s. + * @param buffer containing the packet (by pointer). + * @param status_ - variable to put parse status to (see @ref zb_zcl_parse_status_t). + * + * @note File data is placed in buffer, payload saves pointer to data only! + */ +#define ZB_ZCL_OTA_UPGRADE_GET_IMAGE_BLOCK_RES(data_ptr, buffer, status_) \ +{ \ + zb_zcl_ota_upgrade_image_block_res_t *src_ptr = \ + (zb_zcl_ota_upgrade_image_block_res_t*)zb_buf_begin((buffer)); \ + \ + if (zb_buf_len((buffer)) != sizeof(zb_uint8_t) + \ + ((src_ptr->status)==ZB_ZCL_STATUS_SUCCESS ? \ + sizeof(src_ptr->response.success) - sizeof(zb_uint8_t*)+ \ + src_ptr->response.success.data_size : 0) + \ + ((src_ptr->status)==ZB_ZCL_STATUS_WAIT_FOR_DATA ? \ + sizeof(src_ptr->response.wait_for_data) : 0) ) \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + if( src_ptr->status == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_HTOLE16(&((data_ptr)->response.success.manufacturer), \ + &(src_ptr->response.success.manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->response.success.image_type), \ + &(src_ptr->response.success.image_type)); \ + ZB_HTOLE32(&((data_ptr)->response.success.file_version), \ + &(src_ptr->response.success.file_version)); \ + ZB_HTOLE32(&((data_ptr)->response.success.file_offset), \ + &(src_ptr->response.success.file_offset)); \ + (data_ptr)->response.success.data_size = \ + src_ptr->response.success.data_size; \ + /*ZB_MEMCPY((data_ptr)->response.success.image_data, */ \ + /* src_ptr->response.success.image_data, */ \ + /* src_ptr->response.success.data_size); */ \ + (data_ptr)->response.success.image_data = \ + (zb_uint8_t*)(&(src_ptr->response.success.image_data)); \ + } \ + if( src_ptr->status == ZB_ZCL_STATUS_WAIT_FOR_DATA) \ + { \ + ZB_HTOLE32(&((data_ptr)->response.wait_for_data.current_time), \ + &(src_ptr->response.wait_for_data.current_time)); \ + ZB_HTOLE32(&((data_ptr)->response.wait_for_data.request_time), \ + &(src_ptr->response.wait_for_data.request_time)); \ + ZB_HTOLE16(&((data_ptr)->response.wait_for_data.delay), \ + &(src_ptr->response.wait_for_data.delay)); \ + } \ + } \ +} + +/******************************* Upgrade End Response ******************************/ + +/*! @brief Structure representsation of Upgrade End Response command payload + @see OTA spec, OTA Upgrade Cluster 6.10.10.1 +*/ +typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_upgrade_end_res_s +{ + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint32_t current_time; /**< Current time */ + zb_uint32_t upgrade_time; /**< Upgrade time */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_upgrade_end_res_t; + + +/*! @brief Send Upgrade End Response command, see OTA spec 6.10.10 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param current_time - Current time + @param upgrade_time - Upgrade time +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_UPGRADE_END_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + manufacturer, image_type, file_version, current_time, upgrade_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_UPGRADE_END_RESP_ID); \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (current_time)); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (upgrade_time)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/** @brief Macro for getting Upgrade End Response command, see OTA spec 6.10.10 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_upgrade_end_res_s. + * @param buffer containing the packet (by pointer). + * @param status_ - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_UPGRADE_END_RES(data_ptr, buffer, status_) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_ota_upgrade_upgrade_end_res_t) ) \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_ota_upgrade_upgrade_end_res_t *src_ptr = \ + (zb_zcl_ota_upgrade_upgrade_end_res_t*)zb_buf_begin((buffer)); \ + (status_) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE16(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE32(&((data_ptr)->current_time), &(src_ptr->current_time)); \ + ZB_HTOLE32(&((data_ptr)->upgrade_time), &(src_ptr->upgrade_time)); \ + } \ +} + +/******************************* Query Specific File Response ******************************/ + +/*! @brief Structure representsation of Query Specific File Response command payload + @see OTA spec, OTA Upgrade Cluster 6.10.12.1 +*/typedef ZB_PACKED_PRE struct zb_zcl_ota_upgrade_query_specific_file_res_s +{ + zb_uint8_t status; /** Status, see @ref zb_zcl_status_e */ + zb_uint16_t manufacturer; /** Manufacturer code */ + zb_uint16_t image_type; /** Image type */ + zb_uint32_t file_version; /** File version */ + zb_uint32_t image_size; /** Image size */ + +} ZB_PACKED_STRUCT zb_zcl_ota_upgrade_query_specific_file_res_t; + + +/*! @brief Send Query Specific File Response command, see OTA spec 6.10.12 + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequence + @param status - Status, see @ref zb_zcl_status_e + @param manufacturer - Manufacturer code + @param image_type - Image type + @param file_version - File version + @param image_size - Image size +*/ +#define ZB_ZCL_OTA_UPGRADE_SEND_QUERY_SPECIFIC_FILE_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, \ + status, manufacturer, image_type, file_version, image_size) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, \ + ZB_ZCL_CMD_OTA_UPGRADE_QUERY_SPECIFIC_FILE_RESP_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + if( (status) == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_ZCL_PACKET_PUT_2DATA16_VAL(ptr, (manufacturer), (image_type)); \ + ZB_ZCL_PACKET_PUT_2DATA32_VAL(ptr, (file_version), (image_size)); \ + } \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, NULL); \ +} + +/** @brief Macro for getting Query Specific File Response command, see OTA spec 6.10.12 + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_ota_upgrade_query_specific_file_res_s. + * @param buffer containing the packet (by pointer). + * @param status_ - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_OTA_UPGRADE_GET_QUERY_SPECIFIC_FILE_RES(data_ptr, buffer, status_) \ +{ \ + zb_zcl_ota_upgrade_query_specific_file_res_t *src_ptr = \ + (zb_zcl_ota_upgrade_query_specific_file_res_t*)zb_buf_begin((buffer)); \ + if (zb_buf_len((buffer)) != ( (src_ptr->status)==ZB_ZCL_STATUS_SUCCESS ? \ + sizeof(zb_zcl_ota_upgrade_query_specific_file_res_t) : sizeof(zb_uint8_t) ) ) \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (status_) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->status = src_ptr->status; \ + if( src_ptr->status == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_HTOLE32(&((data_ptr)->manufacturer), &(src_ptr->manufacturer)); \ + ZB_HTOLE32(&((data_ptr)->image_type), &(src_ptr->image_type)); \ + ZB_HTOLE32(&((data_ptr)->file_version), &(src_ptr->file_version)); \ + ZB_HTOLE32(&((data_ptr)->image_size), &(src_ptr->image_size)); \ + } \ + } \ +} + +/*! @} */ /* OTA Upgrade cluster commands */ + + + +#if defined ZB_HA_ENABLE_OTA_UPGRADE_CLIENT || defined DOXYGEN + +/** @brief Declare User Application about upgrade status +*/ +typedef struct zb_zcl_ota_upgrade_value_param_s +{ + zb_uint8_t upgrade_status; /**< Upgrade status, see @ref zb_zcl_ota_upgrade_status_e */ + union + { + struct zb_zcl_ota_upgrade_start_s + { + zb_uint16_t manufacturer; /**< Manufacturer code */ + zb_uint16_t image_type; /**< Image type */ + zb_uint32_t file_version; /**< File version */ + zb_uint32_t file_length; /**< File length */ + } start; /**< Parameters for start load upgrade file */ + struct zb_zcl_ota_upgrade_receive_s + { + zb_uint32_t file_offset; /**< File offset */ + zb_uint8_t data_length; /**< Data length */ + zb_uint8_t *block_data; /**< Block data */ + } receive; /**< Parameters for receive part upgrade file */ + + } upgrade; /**< Upgrade data */ + +} zb_zcl_ota_upgrade_value_param_t; + +/** @brief Possible statuses of OTA upgrade + */ +enum zb_zcl_ota_upgrade_status_e +{ + ZB_ZCL_OTA_UPGRADE_STATUS_START, + ZB_ZCL_OTA_UPGRADE_STATUS_APPLY, + ZB_ZCL_OTA_UPGRADE_STATUS_RECEIVE, + ZB_ZCL_OTA_UPGRADE_STATUS_FINISH, + ZB_ZCL_OTA_UPGRADE_STATUS_ABORT, + ZB_ZCL_OTA_UPGRADE_STATUS_CHECK, // ask user app about received file + ZB_ZCL_OTA_UPGRADE_STATUS_OK, // user app return value + ZB_ZCL_OTA_UPGRADE_STATUS_ERROR, // user app return value + ZB_ZCL_OTA_UPGRADE_STATUS_REQUIRE_MORE_IMAGE, // user app return value + ZB_ZCL_OTA_UPGRADE_STATUS_BUSY, // user app return value. + // Application is responsible for resuming OTA Upgrade process when it + // return that error code to the OTA cluster */ + ZB_ZCL_OTA_UPGRADE_STATUS_SERVER_NOT_FOUND, // Notify an application that OTA Upgrade server not found +}; + +/** @cond internals_doc */ +#define ZB_ZCL_OTA_UPGRADE_START_USER_APP(buffer, \ + manufacturer_, image_type_, file_version_, file_length_, result) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_START_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_START; \ + value->upgrade.start.manufacturer = (manufacturer_); \ + value->upgrade.start.image_type = (image_type_); \ + value->upgrade.start.file_version = (file_version_); \ + value->upgrade.start.file_length = (file_length_); \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + result = value->upgrade_status; \ + } \ +} + +// NOTE file data place`s in buffer, payload saves pointer to data only! +#define ZB_ZCL_OTA_UPGRADE_RECEIVE_USER_APP(buffer, \ + file_offset_, data_length_, block_data_, result) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_RECEIVE_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_RECEIVE; \ + value->upgrade.receive.file_offset = (file_offset_); \ + value->upgrade.receive.data_length = (data_length_); \ + value->upgrade.receive.block_data = (block_data_); \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + result = value->upgrade_status; \ + } \ +} + +#define ZB_ZCL_OTA_UPGRADE_FINISH_USER_APP(buffer, result) \ +{ \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_FINISH_USER_APP", (FMT__0)); \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_ERROR; \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_FINISH; \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + if (user_app_data->status == RET_OK) \ + { \ + result = value->upgrade_status; \ + } \ + }else \ + { \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_OK; \ + } \ +} \ + +#define ZB_ZCL_OTA_UPGRADE_APPLY_USER_APP(buffer, result) \ +{ \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_APPLY_USER_APP", (FMT__0)); \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_ERROR; \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_APPLY; \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + if (user_app_data->status == RET_OK) \ + { \ + result = value->upgrade_status; \ + } \ + }else \ + { \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_OK; \ + } \ +} \ + +/* NK:WARNING: Implicit passing "param" to device_cb! + TODO: Fix all cases! Use ZB_REF_FROM_BUF instead. */ +#define ZB_ZCL_OTA_UPGRADE_ABORT_USER_APP(buffer) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_ABORT_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_ABORT; \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + } \ +} + +#define ZB_ZCL_OTA_UPGRADE_CHECK_USER_APP(buffer, result) \ +{ \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_CHECK_USER_APP", (FMT__0)); \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_ERROR; \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_CHECK; \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + if (user_app_data->status == RET_OK) \ + { \ + result = value->upgrade_status; \ + } \ + }else \ + { \ + result = ZB_ZCL_OTA_UPGRADE_STATUS_OK; \ + } \ +} \ + +#define ZB_ZCL_OTA_UPGRADE_SERVER_NOT_FOUND_USER_APP(buffer) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_OTA_UPGRADE_SERVER_NOT_FOUND_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM(buffer, zb_zcl_device_callback_param_t); \ + zb_zcl_ota_upgrade_value_param_t *value = \ + &(user_app_data->cb_param.ota_value_param); \ + value->upgrade_status = ZB_ZCL_OTA_UPGRADE_STATUS_SERVER_NOT_FOUND; \ + user_app_data->device_cb_id = ZB_ZCL_OTA_UPGRADE_VALUE_CB_ID; \ + user_app_data->endpoint = get_endpoint_by_cluster(ZB_ZCL_CLUSTER_ID_OTA_UPGRADE, ZB_ZCL_CLUSTER_CLIENT_ROLE); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + } \ +} + +zb_void_t zb_zcl_ota_upgrade_set_ota_status(zb_uint8_t endpoint, zb_uint8_t status); + +zb_uint8_t zb_zcl_ota_upgrade_get_ota_status(zb_uint8_t endpoint); + +zb_void_t zb_zcl_ota_upgrade_send_upgrade_end_req(zb_uint8_t param, zb_uint8_t status); + +zb_void_t zb_zcl_ota_restart_after_rejoin(zb_uint8_t endpoint); + +void zb_zcl_ota_set_file_size(zb_uint8_t endpoint, zb_uint32_t size); + +zb_uint8_t zb_zcl_ota_upgrade_get8(zb_uint8_t endpoint, zb_uint16_t attr_id); + +zb_uint16_t zb_zcl_ota_upgrade_get16(zb_uint8_t endpoint, zb_uint16_t attr_id); + +zb_uint32_t zb_zcl_ota_upgrade_get32(zb_uint8_t endpoint, zb_uint16_t attr_id); +/*! @} + * @endcond */ /* internals_doc */ + +zb_ret_t zb_zcl_check_value_ota_upgrade(zb_uint16_t attr_id, zb_uint8_t endpoint, zb_uint8_t *value); + +/*! @brief Abort OTA Upgrade process + * + * @param endpoint - endpoint for OTA Upgrade + * @param param - buffer to be aborted + */ +zb_void_t zcl_ota_abort(zb_uint8_t endpoint, zb_uint8_t param); + +#ifdef ZB_ZCL_SUPPORT_CLUSTER_WWAH +void zcl_ota_abort_and_set_tc(zb_uint8_t param); +#endif + +#endif /* defined ZB_HA_ENABLE_OTA_UPGRADE_CLIENT || defined DOXYGEN */ + +#if defined ZB_ENABLE_HA +zb_uint8_t zb_zcl_get_cmd_list_ota_upgrade(zb_bool_t is_client_generated, zb_uint8_t **cmd_list); +#endif /* defined ZB_ENABLE_HA */ + +#endif /* defined ZB_ZCL_SUPPORT_CLUSTER_OTA_UPGRADE || defined DOXYGEN */ +/*! @} */ /* ZCL OTA Upgrade cluster definitions */ + +#ifdef ZB_HA_ENABLE_OTA_UPGRADE_CLIENT +#define ZCL_OTA_MAX_RESEND_RETRIES 3 + +typedef struct zb_zcl_ota_upgrade_cli_ctx_s +{ + zb_zcl_parsed_hdr_t cmd_info_2; + zb_zcl_ota_upgrade_image_block_res_t payload_2; + zb_uint_t resend_retries; + zb_uint8_t ota_restart_after_rejoin; +} zb_zcl_ota_upgrade_cli_ctx_t; +#endif + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_ota_upgrade_init_srv(void); +zb_void_t zb_zcl_ota_upgrade_init_cli(void); + +/** + * Sends Query Next Image Response. + * Should be used only in the following case: + * If application can't return a table index immediately from user app callback + * (which is called by query_next_image_handler()) + * then it should return RET_BLOCKED status and should call zb_zcl_ota_upgrade_send_query_next_image_response(). + * If there is no image available application should call this function with image_present parameter + * set to ZB_FALSE. + * + * @param zcl_parsed_hdr - the header of the Query Next Image packet + * @param image_present - whether the image is present + * @param table_idx - a table index of the image if image_present is ZB_TRUE + * + * @return nothing + */ +void zb_zcl_ota_upgrade_send_query_next_image_response(zb_zcl_parsed_hdr_t *zcl_parsed_hdr, zb_bool_t image_present, zb_uindex_t table_idx); + +/** + * Sends Image Block Response + * Should be used only in the following case: + * If application can't return a pointer to the requested block immediately on request + * it should return RET_BLOCKED status and should call zb_zcl_ota_upgrade_send_image_block_response() + * If there is no block available application should call this function with block_present parameter + * set to ZB_FALSE. + * + * @param zcl_header - the header of the request packet + * @param table_idx - the index of requested block image + * @param block_present - whether the block is present + * @param offset - an offset in the image + * @param data_size - size of the provided block + * @param data - a pointer to the requested data + * + * @return nothing + */ +void zb_zcl_ota_upgrade_send_image_block_response(zb_zcl_parsed_hdr_t *zcl_header, zb_uindex_t table_idx, + zb_bool_t block_present, + zb_uint32_t offset, zb_uint8_t data_size, + zb_uint8_t* data); + +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_SERVER_ROLE_INIT zb_zcl_ota_upgrade_init_srv +#define ZB_ZCL_CLUSTER_ID_OTA_UPGRADE_CLIENT_ROLE_INIT zb_zcl_ota_upgrade_init_cli + +#endif /* ! defined ZB_ZCL_OTA_UPGRADE_H */ diff --git a/zboss/include/zcl/zb_zcl_poll_control.h b/zboss/include/zcl/zb_zcl_poll_control.h new file mode 100644 index 0000000000..e19a5216ff --- /dev/null +++ b/zboss/include/zcl/zb_zcl_poll_control.h @@ -0,0 +1,699 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Poll Control cluster defintions +*/ + +#if ! defined ZB_ZCL_POLL_CONTROL_H +#define ZB_ZCL_POLL_CONTROL_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_POLL_CONTROL + * @{ + * @details + * All commands in the cluster have only request form, and carry no payload. + * + * For more information see 5.51.2_poll_control_commands sample + */ + +/** + * @brief Hook on Write attribute + * + * send Check-in if change Check-in interval & Check-in remain time > new check-in interval + * + * @param endpoint - endpoint number + * @param attr_id - ID of attribute being written + * @param new_value - pointer to new value of attribute + */ +void zb_zcl_poll_control_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); + +#if defined ZB_HA_ENABLE_POLL_CONTROL_SERVER || defined DOXYGEN + +/*! @brief Schedule poll control process on given endpoint + * First check-in will occur after one check-in interval + * @param param - buffer for check-in command + * @param endpoint - endpoint to start poll control process on */ +void zb_zcl_poll_control_start(zb_uint8_t param, zb_uint8_t endpoint); + + +/** + * @brief Stop Poll control processing + * + * Checking already scheduled will be canceled + * @return reference to buffer which was previously reserved for check-in. + * It must be reused or explicitly freed. + */ +zb_uint8_t zb_zcl_poll_control_stop(void); + + +/*! @brief Start Poll Control process on Server side + * @param param - buffer for Poll Process +*/ +void zb_zcl_poll_control_start_check_in(zb_uint8_t param); + +/** + @brief Register callback for Poll control cluster. + + This callback will be called when check-in command is sent. + + @param cb - pointer to callback + */ +void zb_zcl_poll_controll_register_cb(zb_callback_t cb); + + +#endif /* defined ZB_HA_ENABLE_POLL_CONTROL_SERVER || defined DOXYGEN */ + +/* Cluster ZB_ZCL_CLUSTER_ID_POLL_CONTROL */ + +/*! @name Poll Control cluster attributes + @{ +*/ + +/*! @brief Poll Control cluster attribute identifiers + @see HA spec, Poll Control Cluster 9.5.4.1 +*/ +enum zb_zcl_poll_control_attr_e +{ + /*! @brief Check-in Interval attribute, HA spec 9.5.4.1.1 */ + ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_ID = 0x0000, + /*! @brief Long Poll Interval attribute, HA spec 9.5.4.1.2 */ + ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_ID = 0x0001, + /*! @brief Short Poll Interval attribute, HA spec 9.5.4.1.3 */ + ZB_ZCL_ATTR_POLL_CONTROL_SHORT_POLL_INTERVAL_ID = 0x0002, + /*! @brief Fast Poll Timeout attribute, HA spec 9.5.4.1. */ + ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_ID = 0x0003, + /*! @brief Check-in Interval Min attribute, HA spec 9.5.4.1.4 */ + ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_MIN_ID = 0x0004, + /*! @brief Long Poll Interval Min attribute, HA spec 9.5.4.1.5 */ + ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_ID = 0x0005, + /*! @brief Fast Poll Timeout Max attribute, HA spec 9.5.4.1.6 */ + ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_ID = 0x0006, + + /*! @brief Status Data - custom non-spec parameters */ + ZB_ZCL_ATTR_POLL_CONTROL_STATUS_DATA_ID = 0xefff, + /*! @brief Status Data - custom non-spec parameters for server side */ + ZB_ZCL_ATTR_POLL_CONTROL_ADDR_DATA_ID = 0xeffe, +}; + +/** @brief Value for stop Check-in process for Check-in Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_CHECKIN_INTERVAL_NO_CHECK_IN_VALUE 0x0000 + +/** @brief Default value for Check-in Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_CHECKIN_INTERVAL_DEFAULT_VALUE 0x3840 + +/** @brief Maximum value for Check-in Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_CHECKIN_INTERVAL_MAX_VALUE 0x6e0000 + +/** @brief Minimum value for Long Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_VALUE 0x04 + +/** @brief Default value for Long Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_LONG_POLL_INTERVAL_DEFAULT_VALUE 0x0014 + +/** @brief Maximum value for Long Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_LONG_POLL_INTERVAL_MAX_VALUE 0x6e0000 + +/** @brief Minimum value for Short Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_SHORT_POLL_INTERVAL_MIN_VALUE 0x01 + +/** @brief Default value for Short Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_SHORT_POLL_INTERVAL_DEFAULT_VALUE 0x02 + +/** @brief Maximum value for Short Poll Interval attribute */ +#define ZB_ZCL_POLL_CONTROL_SHORT_POLL_INTERVAL_MAX_VALUE 0xffff + +/** @brief Minimum value for Fast Poll Timeout attribute */ +#define ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_MIN_VALUE 0x01 + +/** @brief Default value for Fast Poll Timeout attribute */ +#define ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_DEFAULT_VALUE 0x0028 + +/** @brief Maximum value for Fast Poll Timeout attribute */ +#define ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_VALUE 0xffff + +/** @brief Default value for CheckinIntervalMin attribute */ +#define ZB_ZCL_POLL_CONTROL_CHECKIN_INTERVAL_MIN_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for LongPollIntervalMin attribute */ +#define ZB_ZCL_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_DEFAULT_VALUE ((zb_uint32_t)0) + +/** @brief Default value for FastPollTimeoutMax attribute */ +#define ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_DEFAULT_VALUE ((zb_uint16_t)0) + +/*! @cond internals_doc + @internal @name Poll Control cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_SHORT_POLL_INTERVAL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_SHORT_POLL_INTERVAL_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_MIN_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_MIN_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_STATUS_DATA_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_STATUS_DATA_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POLL_CONTROL_ADDR_DATA_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POLL_CONTROL_ADDR_DATA_ID, \ + ZB_ZCL_ATTR_TYPE_NULL, \ + ZB_ZCL_ATTR_ACCESS_INTERNAL, \ + (zb_voidp_t) data_ptr \ +} + + +/*! @brief Structure representsation of Client Status attributes */ +typedef ZB_PACKED_PRE struct zb_zcl_poll_control_client_status_s +{ + /** Client is In Poll Mode */ + zb_bool_t is_poll_mode; + /** Client Fast Poll timeout*/ + zb_uint16_t fast_poll_timeout; + +} ZB_PACKED_STRUCT zb_zcl_poll_control_client_status_t; + + +#define ZB_ZCL_POLL_CTRL_INVALID_ADDR 0xFFFF +#define ZB_ZCL_POLL_INVALID_EP 0xFF +/*! @brief Address information that is used for sending check-in command */ +/* Currently not only address info is stored - also status information */ +typedef struct zb_zcl_poll_control_srv_cfg_data_s +{ + /** Short address of the Poll cotrol client */ + zb_uint16_t poll_addr; + /** Endpoint number of the Poll cotrol client */ + zb_uint8_t poll_ep; + /** Flag to check if check-in command is being sent currently */ + zb_bitfield_t sending_cmd:4; + /** Flag to determine fast poll mode / long poll mode */ + zb_bitfield_t fast_poll_mode:1; +} +zb_zcl_poll_control_srv_cfg_data_t; + +/** @brief Default value for Fast Poll Timeout for Client command */ +#define ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_CLIENT_DEFAULT_VALUE 0x00f0 + +/*! @internal Number of attributes mandatory for reporting in Poll Control cluster */ +#define ZB_ZCL_POLL_CONTROL_REPORT_ATTR_COUNT 0 + +/*! @} + @endcond */ /* Poll Control cluster internals */ + +/** @brief Declare attribute list for Poll Control cluster - server side + @param attr_list - attribute list name + @param checkin_interval - pointer to variable to store Check-in Interval attribute + @param long_poll_interval - pointer to variable to store Long Poll Interval attribute + @param short_poll_interval - pointer to variable to store Short Poll Interval attribute + @param fast_poll_timeout - pointer to variable to store Fast Poll Timeout attribute + @param checkin_interval_min - pointer to variable to store Check-in Interval Min attribute + @param long_poll_interval_min- pointer to variable to store Long Poll Interval Min attribute + @param fast_poll_timeout_max - pointer to variable to store Fast Poll Timeout Max attribute +*/ +#define ZB_ZCL_DECLARE_POLL_CONTROL_ATTRIB_LIST(attr_list, \ + checkin_interval, long_poll_interval, short_poll_interval, fast_poll_timeout, \ + checkin_interval_min, long_poll_interval_min, fast_poll_timeout_max) \ + zb_zcl_poll_control_srv_cfg_data_t srv_cfg_data_ctx_##attr_list = \ + { ZB_ZCL_POLL_CTRL_INVALID_ADDR, ZB_ZCL_POLL_INVALID_EP, 0, 0 }; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_ID, (checkin_interval)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_ID, (long_poll_interval)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_SHORT_POLL_INTERVAL_ID, (short_poll_interval)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_ID, (fast_poll_timeout)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_CHECKIN_INTERVAL_MIN_ID, (checkin_interval_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_LONG_POLL_INTERVAL_MIN_ID, (long_poll_interval_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_FAST_POLL_TIMEOUT_MAX_ID, (fast_poll_timeout_max)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_ADDR_DATA_ID, &(srv_cfg_data_ctx_##attr_list)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @brief Declare attribute list for Poll Control cluster - client side + @param attr_list - attribute list name +*/ +#define ZB_ZCL_DECLARE_POLL_CONTROL_ATTRIB_LIST_CLIENT(attr_list) \ + zb_zcl_poll_control_client_status_t client_status_data_ctx_##attr_list = \ + { ZB_FALSE, ZB_ZCL_POLL_CONTROL_FAST_POLL_TIMEOUT_CLIENT_DEFAULT_VALUE }; \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POLL_CONTROL_STATUS_DATA_ID, \ + (&(client_status_data_ctx_##attr_list))) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Poll Control cluster attributes */ + +/*! @name Poll Control cluster commands + @{ +*/ + +/*! @brief Poll Control cluster command identifiers + @see HA spec, Poll Control Cluster, 9.5.4.3 +*/ +enum zb_zcl_poll_control_cmd_e +{ + ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_ID = 0x00 /**< "Check-in" command. HA spec 9.5.4.4 */ +}; + +/*! @brief Poll Control cluster response command identifiers + @see HA spec, Poll Control Cluster, 9.5.5.2 +*/ +enum zb_zcl_poll_control_resp_cmd_e +{ + ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_RESPONSE_ID = 0x00, /**< "Check-in response" command, HA spec 9.5.5.3 */ + ZB_ZCL_CMD_POLL_CONTROL_FAST_POLL_STOP_ID = 0x01, /**< "Fast Poll Stop" command, HA spec 9.5.5.4 */ + ZB_ZCL_CMD_POLL_CONTROL_SET_LONG_POLL_INTERVAL_ID = 0x02, /**< "Set Long Poll Interval" command, HA spec 9.5.5.5 */ + ZB_ZCL_CMD_POLL_CONTROL_SET_SHORT_POLL_INTERVAL_ID = 0x03, /**< "Set Short Poll Interval" command, HA spec 9.5.5.6 */ +}; + +/** @cond internals_doc */ +/* Poll control cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_SERVER_ROLE_GENERATED_CMD_LIST ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_ID + +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_POLL_CONTROL_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_RESPONSE_ID, \ + ZB_ZCL_CMD_POLL_CONTROL_FAST_POLL_STOP_ID, \ + ZB_ZCL_CMD_POLL_CONTROL_SET_LONG_POLL_INTERVAL_ID, \ + ZB_ZCL_CMD_POLL_CONTROL_SET_SHORT_POLL_INTERVAL_ID + +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_POLL_CONTROL_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/******************************* Check-in ******************************/ + +/*! @brief Send Check-in command, see HA spec 9.5.4.4 + @param _buffer - to put packet to + @param _dst_addr - destinition address + @param _dst_addr_mode - addressing mode + @param _dst_ep - destination endpoint + @param _local_ep - source endpoint + @param _prfl_id - profile identifier + @param _cb - callback for getting command send status +*/ +#define ZB_ZCL_POLL_CONTROL_SEND_CHECK_IN_REQ( \ + _buffer, _dst_addr, _dst_addr_mode, _dst_ep, _local_ep, _prfl_id, _cb) \ +{ \ + zb_uint8_t* _ptr = ZB_ZCL_START_PACKET(_buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(_ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_ID); \ + ZB_ZCL_FINISH_PACKET((_buffer), _ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + _buffer, _dst_addr, _dst_addr_mode, _dst_ep, _local_ep, _prfl_id, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, _cb); \ +} + +/*! @brief Parameters to pass to device callback for incoming check in */ +typedef struct zb_zcl_poll_control_check_in_cli_param_s +{ + zb_uint16_t fast_poll_timeout; + zb_uint16_t short_addr; + zb_uint8_t ep; +} +zb_zcl_poll_control_check_in_cli_param_t; + +/** @cond internals_doc */ +#define ZB_ZCL_POLL_CONTROL_CLI_CALL_USER_APP( \ + _buffer, _short_addr, _ep, _fast_poll_timeout, _result) \ +{ \ + TRACE_MSG(TRACE_ZCL1, "ZB_ZCL_POLL_CONTROL_CLI_CALL_USER_APP", (FMT__0)); \ + if (ZCL_CTX().device_cb) \ + { \ + zb_zcl_device_callback_param_t *user_app_data = \ + ZB_BUF_GET_PARAM((_buffer), zb_zcl_device_callback_param_t); \ + zb_zcl_poll_control_check_in_cli_param_t *value = \ + &(user_app_data->cb_param.checkin_cli_param); \ + value->fast_poll_timeout = (_fast_poll_timeout); \ + value->short_addr = (_short_addr); \ + value->ep = (_ep); \ + user_app_data->device_cb_id = ZB_ZCL_POLL_CONTROL_CHECK_IN_CLI_CB_ID; \ + user_app_data->endpoint = (_ep); \ + user_app_data->status = RET_OK; \ + (ZCL_CTX().device_cb)(param); \ + _result = user_app_data->status; \ + } \ + else \ + { \ + _result = RET_OK; \ + } \ +} +/*! @} + * @endcond */ /* internals_doc */ + +/******************************* Check-in response ******************************/ + +/*! @brief Structure representsation of Check-in response command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_poll_control_check_in_res_s +{ + /** Start Fast Polling */ + zb_uint8_t is_start; + /** Fast Poll Timeout */ + zb_uint16_t timeout; +} ZB_PACKED_STRUCT zb_zcl_poll_control_check_in_res_t; + +/*! @brief Send "Check-in response" command, see HA spec 9.5.5.3 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param is_start - Start Fast Polling + @param timeout - Fast Poll Timeout +*/ +#define ZB_ZCL_POLL_CONTROL_SEND_CHECK_IN_RES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + is_start, timeout) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_POLL_CONTROL_CHECK_IN_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (is_start)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (timeout)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, cb); \ +} + +/** @brief Macro for getting Check-in response command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_poll_control_check_in_res_s. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_POLL_CONTROL_GET_CHECK_IN_RES(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_poll_control_check_in_res_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_poll_control_check_in_res_t *src_ptr = \ + (zb_zcl_poll_control_check_in_res_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (data_ptr)->is_start = src_ptr->is_start; \ + ZB_HTOLE16(&((data_ptr)->timeout), &(src_ptr->timeout)); \ + } \ +} + +/******************************* Fast Poll Stop ******************************/ + +/*! @brief Send "Fast Poll Stop" command, see HA spec 9.5.5.4 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback +*/ +#define ZB_ZCL_POLL_CONTROL_SEND_FAST_POLL_STOP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_POLL_CONTROL_FAST_POLL_STOP_ID); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, cb); \ +} + +/******************************* Set Long Poll Interval ******************************/ + +/*! @brief Structure representsation of Set Long Poll Interval command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_poll_control_set_long_poll_interval_req_s +{ + /** New Long Poll Interval */ + zb_uint32_t interval; +} ZB_PACKED_STRUCT zb_zcl_poll_control_set_long_poll_interval_t; + + +/*! @brief Send "Set Long Poll Interval" command, see HA spec 9.5.5.5 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param interval - New Long Poll Interval +*/ +#define ZB_ZCL_POLL_CONTROL_SEND_SET_LONG_POLL_INTERVAL_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, interval) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_POLL_CONTROL_SET_LONG_POLL_INTERVAL_ID); \ + ZB_ZCL_PACKET_PUT_DATA32_VAL(ptr, (interval)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, cb); \ +} + +/** @brief Macro for getting "Set Long Poll Interval" command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_poll_control_set_long_poll_interval_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_POLL_CONTROL_GET_SET_LONG_POLL_INTERVAL_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_poll_control_set_long_poll_interval_t)) \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_poll_control_set_long_poll_interval_t *src_ptr = \ + (zb_zcl_poll_control_set_long_poll_interval_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE32(&((data_ptr)->interval), &(src_ptr->interval)); \ + } \ +} + +/******************************* Set Short Poll Interval ******************************/ + +/*! @brief Structure representsation of Set Short Poll Interval command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_poll_control_set_short_poll_interval_req_s +{ + /** New Short Poll Interval */ + zb_uint16_t interval; +} ZB_PACKED_STRUCT zb_zcl_poll_control_set_short_poll_interval_t; + + +/*! @brief Send "Set Short Poll Interval" command, see HA spec 9.5.5.6 + @param buffer to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback + @param interval - New Short Poll Interval +*/ +#define ZB_ZCL_POLL_CONTROL_SEND_SET_SHORT_POLL_INTERVAL_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, interval) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, (def_resp)) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_POLL_CONTROL_SET_SHORT_POLL_INTERVAL_ID); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (interval)); \ + ZB_ZCL_FINISH_PACKET((buffer), ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, \ + ZB_ZCL_CLUSTER_ID_POLL_CONTROL, cb); \ +} + +/** @brief Macro for getting "Set Short Poll Interval" command + * @attention Assumes that ZCL header already cut. + * @param data_ptr - pointer to a variable of type @ref + * zb_zcl_poll_control_set_short_poll_interval_t. + * @param buffer containing the packet (by pointer). + * @param status - variable to put parse status to (see @ref zb_zcl_parse_status_t). + */ +#define ZB_ZCL_POLL_CONTROL_GET_SET_SHORT_POLL_INTERVAL_REQ(data_ptr, buffer, status) \ +{ \ + if (zb_buf_len((buffer)) != sizeof(zb_zcl_poll_control_set_short_poll_interval_t))\ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + zb_zcl_poll_control_set_short_poll_interval_t *src_ptr = \ + (zb_zcl_poll_control_set_short_poll_interval_t*)zb_buf_begin((buffer)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&((data_ptr)->interval), &(src_ptr->interval)); \ + } \ +} + +#if defined ZB_HA_ENABLE_POLL_CONTROL_SERVER || defined DOXYGEN + +/** + * @brief Set client address information. This address is used to + * send Check-in command. If address information is NOT sent, + * check-in command will be sent assuming binding with client is + * created + * @param local_ep - local endpoint number, is used to find particular attribute + * @param addr - poll control client short address + * @param ep - poll control client end point + * @return RET_ERROR if addr is not a TC (WWAH requirement). + * RET_OK otherwise. + */ +zb_ret_t zb_zcl_poll_control_set_client_addr(zb_uint8_t local_ep, zb_uint16_t addr, zb_uint8_t ep); +#endif + +/** + @brief Force to go long polling + @param endpoint - Endpoint, implementing Poll control cluster +*/ +void zb_zcl_poll_control_stop_fast_poll(zb_uint8_t endpoint); + +/** + @brief Function is used by Poll control client to set Fast poll + timeout value. This value is included into Check-in response + command + @param ep - local endpoint number, running Poll control client + @param fast_poll_timeout - Fast poll timeout value (in quarterseconds) +*/ +void zb_zcl_set_fast_poll_timeout(zb_uint8_t ep, zb_uint16_t fast_poll_timeout); + + +#ifdef ZB_USE_NVRAM +/** + @brief Save to NVRAM Poll Control dataset + @param param + @note ignore param, set it to 0 +*/ +void zb_zcl_poll_control_save_nvram(zb_uint8_t param); +#endif + +/*! @} */ /* Poll Control cluster commands */ + +/*! @} */ /* ZCL Poll Control cluster definitions */ + +#if defined ZB_ENABLE_HA + +zb_uint8_t zb_zcl_get_cmd_list_poll_control(zb_bool_t is_client_generated, zb_uint8_t **cmd_list); + +#endif /* defined ZB_ENABLE_HA */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_poll_control_init_server(void); +void zb_zcl_poll_control_init_client(void); +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_SERVER_ROLE_INIT zb_zcl_poll_control_init_server +#define ZB_ZCL_CLUSTER_ID_POLL_CONTROL_CLIENT_ROLE_INIT zb_zcl_poll_control_init_client + +#endif /* ! defined ZB_ZCL_POLL_CONTROL_H */ diff --git a/zboss/include/zcl/zb_zcl_power_config.h b/zboss/include/zcl/zb_zcl_power_config.h new file mode 100644 index 0000000000..75dbf76e19 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_power_config.h @@ -0,0 +1,732 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Power Configuration cluster defintions +*/ + +#if ! defined ZB_ZCL_POWER_CONFIG_H +#define ZB_ZCL_POWER_CONFIG_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_POWER_CONFIG + * @{ + */ + +/** + * @brief Hook on Write attribute + * @param endpoint - endpoint number + * @param attr_id - ID of attribute being written + * @param new_value - pointer to new value of attribute + */ +zb_void_t zb_zcl_power_config_write_attr_hook(zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); + +/* Cluster ZB_ZCL_CLUSTER_ID_POWER_CONFIG */ + +/*! @name Power Configuration cluster attributes + @{ +*/ + +/*! @brief Power Configuration cluster attribute identifiers + @see ZCL spec, Power Configuration Cluster 3.3.2.2 +*/ +enum zb_zcl_power_config_attr_e +{ + /** @brief MainsVoltage attribute, ZCL spec 3.3.2.2.1.1 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_ID = 0x0000, + /** @brief MainsFrequency attribute, ZCL spec 3.3.2.2.1.2 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_FREQUENCY_ID = 0x0001, + /** @brief MainsAlarmMask attribute, ZCL spec 3.3.2.2.2.1 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_ALARM_MASK_ID = 0x0010, + /** @brief MainsVoltageMinThreshold attribute, ZCL spec 3.3.2.2.2.2 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD = 0x0011, + /** @brief MainsVoltageMaxThreshold attribute, ZCL spec 3.3.2.2.2.3 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD = 0x0012, + /** @brief MainsVoltageDwellTripPoint attribute, ZCL spec 3.3.2.2.2.4 */ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_DWELL_TRIP_POINT = 0x0013, + + /** @brief BatteryVoltage attribute, ZCL spec 3.3.2.2.3.1 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID = 0x0020, + /*! @brief BatteryPercentageRemaining attribute, ZCL spec 3.3.2.2.3.2 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID = 0x0021, + + /** The BatteryManufacturer attribute is a maximum of 16 bytes in length + * and specifies the name of the battery manufacturer as a character string. */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_MANUFACTURER_ID = 0x0030, + /** @brief BatterySize attribute, ZCL spec 3.3.2.2.4.2 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_SIZE_ID = 0x0031, + /** The BatteryAHrRating attribute is 16 bits in length and specifies + * the Ampere-hour rating of the battery, measured in units of 10mAHr. */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_A_HR_RATING_ID = 0x0032, + /** @brief BatteryQuantity attribute, ZCL spec 3.3.2.2.4.4 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_QUANTITY_ID = 0x0033, + /** @brief BatteryRatedVoltage attribute, ZCL spec 3.3.2.2.4.5 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_RATED_VOLTAGE_ID = 0x0034, + /** @brief BatteryAlarmMask attribute, ZCL spec 3.3.2.2.4.6 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_MASK_ID = 0x0035, + /** @brief BatteryVoltageMinThreshold attribute, ZCL spec 3.3.2.2.4.7 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_MIN_THRESHOLD_ID = 0x0036, + /*! @brief BatteryVoltageThreshold1 attribute, ZCL spec 3.3.2.2.4.8 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD1_ID = 0x0037, + /*! @brief BatteryVoltageThreshold2 attribute, ZCL spec 3.3.2.2.4.8 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD2_ID = 0x0038, + /*! @brief BatteryVoltageThreshold3 attribute, ZCL spec 3.3.2.2.4.8 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD3_ID = 0x0039, + + /*! @brief BatteryPercentageMinThreshold attribute, ZCL spec 3.3.2.2.4.9 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_MIN_THRESHOLD_ID = 0x003a, + + /*! @brief BatteryPercentageThreshold1 attribute, ZCL spec 3.3.2.2.4.10 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD1_ID = 0x003b, + /*! @brief BatteryPercentageThreshold2 attribute, ZCL spec 3.3.2.2.4.10 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD2_ID = 0x003c, + /*! @brief BatteryPercentageThreshold3 attribute, ZCL spec 3.3.2.2.4.10 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD3_ID = 0x003d, + + /*! @brief BatteryAlarmState attribute, ZCL spec 3.3.2.2.4.11 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_STATE_ID = 0x003e, + + /*! @brief Battery Information 2 attribute set, ZCL spec 3.3.2.2.5 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_VOLTAGE_ID = 0x0040, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_PERCENTAGE_REMAINING_ID = 0x0041, + + /*! @brief Battery Settings 2 attribute set, ZCL spec 3.3.2.2.6 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_MANUFACTURER_ID = 0x0050, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_SIZE_ID = 0x0051, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_A_HR_RATING_ID = 0x0052, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_QUANTITY_ID = 0x0053, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_RATED_VOLTAGE_ID = 0x0054, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_ALARM_MASK_ID = 0x0055, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_VOLTAGE_MIN_THRESHOLD_ID = 0x0056, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_VOLTAGE_THRESHOLD1_ID = 0x0057, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_VOLTAGE_THRESHOLD2_ID = 0x0058, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_VOLTAGE_THRESHOLD3_ID = 0x0059, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_PERCENTAGE_MIN_THRESHOLD_ID = 0x005a, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_PERCENTAGE_THRESHOLD1_ID = 0x005b, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_PERCENTAGE_THRESHOLD2_ID = 0x005c, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_PERCENTAGE_THRESHOLD3_ID = 0x005d, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY2_ALARM_STATE_ID = 0x005e, + + /*! @brief Battery Information 3 attribute set, ZCL spec 3.3.2.2.7 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_VOLTAGE_ID = 0x0060, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_PERCENTAGE_REMAINING_ID = 0x0061, + + /*! @brief Battery Settings 3 attribute set, ZCL spec 3.3.2.2.8 */ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_MANUFACTURER_ID = 0x0070, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_SIZE_ID = 0x0071, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_A_HR_RATING_ID = 0x0072, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_QUANTITY_ID = 0x0073, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_RATED_VOLTAGE_ID = 0x0074, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_ALARM_MASK_ID = 0x0075, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_VOLTAGE_MIN_THRESHOLD_ID = 0x0076, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_VOLTAGE_THRESHOLD1_ID = 0x0077, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_VOLTAGE_THRESHOLD2_ID = 0x0078, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_VOLTAGE_THRESHOLD3_ID = 0x0079, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_PERCENTAGE_MIN_THRESHOLD_ID = 0x007a, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_PERCENTAGE_THRESHOLD1_ID = 0x007b, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_PERCENTAGE_THRESHOLD2_ID = 0x007c, + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_PERCENTAGE_THRESHOLD3_ID = 0x007d, + + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY3_ALARM_STATE_ID = 0x007e, + /** @cond internals_doc */ + /* Custom attribures */ + ZB_ZCL_ATTR_POWER_CONFIG_CUSTOM_BATTERY_VOLTAGE_SHARP_ID = 0x8020 + /*! @} + * @endcond */ /* internals_doc */ +}; + +/** + * @brief Power Configuration MainsAlarmMask value + * see ZCL spec 3.3.2.2.4.7 + */ +enum zb_zcl_power_config_mains_alarm_mask_e +{ + /** @brief MainsAlarmMask - Mains Voltage too low */ + ZB_ZCL_POWER_CONFIG_MAINS_ALARM_MASK_VOLTAGE_LOW = 0x01, + /** @brief MainsAlarmMask - Mains Voltage too high */ + ZB_ZCL_POWER_CONFIG_MAINS_ALARM_MASK_VOLTAGE_HIGH = 0x02, + /** @brief MainsAlarmMask - Mains power supply lost/unavailable */ + ZB_ZCL_POWER_CONFIG_MAINS_ALARM_MASK_VOLTAGE_UNAVAIL = 0x04, + +}; + +/** @brief Default value for MainsAlarmMask attribute */ +#define ZB_ZCL_POWER_CONFIG_MAINS_ALARM_MASK_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for MainsVoltageMinThreshold attribute */ +#define ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for MainsVoltageMaxThreshold attribute */ +#define ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for MainsDwellTripPoint attribute */ +#define ZB_ZCL_POWER_CONFIG_MAINS_DWELL_TRIP_POINT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief BatteryVoltage attribute invalid value */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_VOLTAGE_INVALID 0xff + +/** @brief Power Configuration BatteryPercentageRemaining attribute unknown value */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_REMAINING_UNKNOWN 0xff + +/** @brief Default value for BatteryRemainingHA attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_REMAINING_HA_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for BatteryManufacturer attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_MANUFACTURER_DEFAULT_VALUE {0} + +/** @brief BatterySize attribute default value */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_DEFAULT_VALUE 0xff + +/** @brief BatteryAlarmMask attribute default value */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_MASK_DEFAULT_VALUE 0x00 + +/** @brief Default value for BatteryVoltageMinThreshold attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_VOLTAGE_MIN_THRESHOLD_DEFAULT_VALUE ((zb_uint8_t)0x0000) + +/** @brief Default value for BatteryVoltageThreshold1 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD1_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryVoltageThreshold2 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD2_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryVoltageThreshold3 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD3_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryPercentageMinThreshold attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_PERCENTAGE_MIN_THRESHOLD_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryPercentageThreshold1 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD1_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryPercentageThreshold2 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD2_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryPercentageThreshold3 attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD3_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for BatteryAlarmState attribute */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_DEFAULT_VALUE ((zb_uint32_t)0x00000000) + +/** @brief Mains attribute set the least significant nibble*/ +#define ZB_ZCL_POWER_CONFIG_MAINS_ATTRIBUTE_SET 0 + +/** @brief Battery attribute set the least significant nibble*/ +#define ZB_ZCL_POWER_CONFIG_BATTERY_ATTRIBUTE_SET 0 + +/** @brief Battery Source 2 attribute set the least significant nibble*/ +#define ZB_ZCL_POWER_CONFIG_BATTERY_SOURCE_2_ATTRIBUTE_SET 0x20 + +/** @brief Battery Source 3 attribute set the least significant nibble*/ +#define ZB_ZCL_POWER_CONFIG_BATTERY_SOURCE_3_ATTRIBUTE_SET 0x40 + +/** + * @brief Power Configuration BatterySize value + * see ZCL spec 3.3.2.2.4.2 + */ +enum zb_zcl_power_config_battery_size_e +{ + /** @brief BatterySize - no battery*/ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_NO_BATTERY = 0, + /** @brief BatterySize - built in */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_BUILT_IN = 1, + /** @brief BatterySize - other */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_OTHER = 2, + /** @brief BatterySize - AA */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_AA = 3, + /** @brief BatterySize - AAA */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_AAA = 4, + /** @brief BatterySize - C */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_C = 5, + /** @brief BatterySize - D */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_D = 6, + /** @brief BatterySize - CR2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_CR2 = 7, + /** @brief BatterySize - CR123A */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_CR123A = 8, + /** @brief BatterySize - unknown */ + ZB_ZCL_POWER_CONFIG_BATTERY_SIZE_UNKNOWN = 0xff, +}; + +/** + * @brief Power Configuration BatteryAlarmMask value + * see ZCL spec 3.3.2.2.4.7 + */ +enum zb_zcl_power_config_battery_alarm_mask_e +{ + /** @brief BatteryAlarmMask - Battery voltage too low */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_MASK_VOLTAGE_LOW = 0, + /** @brief BatteryAlarmMask - Alarm1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_MASK_ALARM1 = 1, + /** @brief BatteryAlarmMask - Alarm2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_MASK_ALARM2 = 2, + /** @brief BatteryAlarmMask - Alarm3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_MASK_ALARM3 = 3, +}; + +/*! @brief Power Configuration Alarm Code for Alarm + @see ZCL spec 3.3.2.2.4.7, Table 3-25 +*/ +enum zb_zcl_power_config_battery_alarm_code_e +{ + /** @brief MainsVoltageAlarmCode - MainsVoltageMinThreshold reached for Mains Voltage**/ + ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_ALARM_CODE_MIN_THRESHOLD = 0x00, + /** @brief MainsVoltageAlarmCode - MainsVoltageMaxThreshold reached for Mains Voltage**/ + ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_ALARM_CODE_MAX_THRESHOLD = 0x01, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE1_MIN_THRESHOLD = 0x10, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE1_VOLTAGE1 = 0x11, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE1_VOLTAGE2 = 0x12, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE1_VOLTAGE3 = 0x13, + + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE2_MIN_THRESHOLD = 0x20, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE2_VOLTAGE1 = 0x21, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE2_VOLTAGE2 = 0x22, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE2_VOLTAGE3 = 0x23, + + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE3_MIN_THRESHOLD = 0x30, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE3_VOLTAGE1 = 0x31, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE3_VOLTAGE2 = 0x32, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_SOURCE3_VOLTAGE3 = 0x33, + /** @brief Mains power supply lost/unavailable (i.e., device is running on battery) */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_CODE_MAINS_POWER_SUPPLY_LOST_UNAVAILABLE = 0x3a, +}; + + +/*! @brief Power Configuration BatteryAlarmState + @see ZCL spec 3.3.2.2.4.11, Table 3-26 +*/ +enum zb_zcl_power_config_battery_alarm_state_e +{ + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE1_MIN_THRESHOLD = 1 << 0, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE1_VOLTAGE1 = 1 << 1, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE1_VOLTAGE2 = 1 << 2, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 1 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE1_VOLTAGE3 = 1 << 3, + + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE2_MIN_THRESHOLD = 1 << 10, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE2_VOLTAGE1 = 1 << 11, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE2_VOLTAGE2 = 1 << 12, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 2 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE2_VOLTAGE3 = 1 << 13, + + /* use 1l to exclude overflow at 16-bit CPU: force 32-bit enum */ + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE3_MIN_THRESHOLD = 1l << 20, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold1 or + * BatteryPercentageMinThreshold1 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE3_VOLTAGE1 = 1l << 21, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold2 or + * BatteryPercentageMinThreshold2 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE3_VOLTAGE2 = 1l << 22, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold3 or + * BatteryPercentageMinThreshold3 reached for Battery Source 3 */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_SOURCE3_VOLTAGE3 = 1l << 23, + /** @brief Mains power supply lost/unavailable (i.e., device is running on battery) */ + ZB_ZCL_POWER_CONFIG_BATTERY_ALARM_STATE_MAINS_POWER_SUPPLY_LOST_UNAVAILABLE = 1l << 30, +}; + +/** @cond internals_doc */ +/*! @internal @name Power Configuration cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_FREQUENCY_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_FREQUENCY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_ALARM_MASK_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_ALARM_MASK_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_MAINS_DWELL_TRIP_POINT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_MAINS_DWELL_TRIP_POINT, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_VOLTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_SIZE_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_SIZE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_QUANTITY_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_QUANTITY_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_RATED_VOLTAGE_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_RATED_VOLTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/* DA: HA12 change */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_MASK_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_ALARM_MASK_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_MIN_THRESHOLD_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_VOLTAGE_MIN_THRESHOLD_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_PERCENTAGE_REMAINING_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD1_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_VOLTAGE_THRESHOLD1_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD2_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_VOLTAGE_THRESHOLD2_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD3_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_VOLTAGE_THRESHOLD3_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_MIN_THRESHOLD_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_PERCENTAGE_MIN_THRESHOLD_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD1_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_PERCENTAGE_THRESHOLD1_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD2_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_PERCENTAGE_THRESHOLD2_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD3_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_PERCENTAGE_THRESHOLD3_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_STATE_ID(data_ptr, bat_num) \ +{ \ + ZB_ZCL_ATTR_POWER_CONFIG_BATTERY##bat_num##_ALARM_STATE_ID, \ + ZB_ZCL_ATTR_TYPE_32BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Power + * Configuration cluster for 1 battery pack */ +#undef ZB_ZCL_POWER_CONFIG_REPORT_ATTR_COUNT +#define ZB_ZCL_POWER_CONFIG_REPORT_ATTR_COUNT 2 /* Voltage + Alarm State */ +/*! @internal Number of attributes mandatory for reporting in Power + * Configuration cluster for 2 Battery packs included */ +#define ZB_ZCL_POWER_CONFIG_BAT_PACK_2_REPORT_ATTR_COUNT 4 /* Voltage + Voltage 2 + Alarm State + + * Alarm State 2 */ +/*! @internal Number of attributes mandatory for reporting in Power + * Configuration cluster for 3 Battery packs included */ +#define ZB_ZCL_POWER_CONFIG_BAT_PACK_3_REPORT_ATTR_COUNT 6 /* Voltage + Voltage 2 + Voltage 3 + + * Alarm State + Alarm State 2 + Alarm State 3*/ + +/*! @internal Alarm Code for Power Configuration cluster */ +#define ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD_ALARM_CODE 0x00 +#define ZB_ZCL_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD_ALARM_CODE 0x01 + +/*! @} */ /* Power Configuration cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Power Configuration cluster - server side + @param attr_list - attribute list name + @param voltage - pointer to variable to store BatteryVoltage attribute + @param size - pointer to variable to store BatterySize attribute + @param quantity - pointer to variable to store BatteryQuantity attribute + @param rated_voltage - pointer to variable to store BatteryRatedVoltage attribute + @param alarm_mask - pointer to variable to store BatteryAlarmMask attribute + @param voltage_min_threshold - pointer to variable to store BatteryVoltageMinThreshold attribute +*/ +#define ZB_ZCL_DECLARE_POWER_CONFIG_ATTRIB_LIST(attr_list, \ + voltage, size, quantity, rated_voltage, alarm_mask, voltage_min_threshold) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID, (voltage)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_SIZE_ID, (size)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_QUANTITY_ID, (quantity)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_RATED_VOLTAGE_ID, (rated_voltage)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_MASK_ID, (alarm_mask )) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_MIN_THRESHOLD_ID, (voltage_min_threshold)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @cond internals_doc */ +#define ZB_ZCL_POWER_CONFIG_MAINS_ATTRIB_LIST(voltage, frequency, alarm_mask, \ + voltage_min_threshold, voltage_max_threshold, \ + dwell_trip_point) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_ID, (voltage)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_FREQUENCY_ID, (frequency)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_ALARM_MASK_ID, (alarm_mask)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MIN_THRESHOLD, (voltage_min_threshold)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_VOLTAGE_MAX_THRESHOLD, (voltage_max_threshold)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_POWER_CONFIG_MAINS_DWELL_TRIP_POINT, (dwell_trip_point)) +/*! @} + * @endcond */ /* internals_doc */ + + +/** @brief Declare attribute list for Power Configuration cluster - server side (Mains + attribute set) + @param attr_list - attribure list name + @param voltage - pointer to variable to store MainsVoltage attribute + @param frequency - pointer to variable to store MainsFrequency attribute + @param alarm_mask - pointer to variable to store BatteryAlarmMask attribute + @param voltage_min_threshold - pointer to variable to store MainsVoltageMinThreshold attribute + @param voltage_max_threshold - pointer to variable to store MainsVoltageMaxThreshold attribute + @param dwell_trip_point - pointer to variable to store MainsVoltageDwellTripPoint attribute +*/ +#define ZB_ZCL_DECLARE_POWER_CONFIG_MAINS_ATTRIB_LIST(attr_list, voltage, frequency, alarm_mask, \ + voltage_min_threshold, voltage_max_threshold, \ + dwell_trip_point) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_POWER_CONFIG_MAINS_ATTRIB_LIST(voltage, frequency, alarm_mask, \ + voltage_min_threshold, voltage_max_threshold, \ + dwell_trip_point) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @cond internals_doc */ +#define ZB_ZCL_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(bat_num, \ + voltage, size, quantity, rated_voltage, alarm_mask, voltage_min_threshold, \ + remaining, threshold1, threshold2, threshold3, min_threshold, percent_threshold1, \ + percent_threshold2, percent_threshold3, alarm_state) \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_ID(voltage, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_SIZE_ID(size, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_QUANTITY_ID(quantity, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_RATED_VOLTAGE_ID(rated_voltage, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_MASK_ID(alarm_mask, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_MIN_THRESHOLD_ID(voltage_min_threshold, bat_num), \ + /* ext attribute */ \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_REMAINING_ID(remaining, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD1_ID(threshold1, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD2_ID(threshold2, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_VOLTAGE_THRESHOLD3_ID(threshold3, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_MIN_THRESHOLD_ID(min_threshold, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD1_ID(percent_threshold1, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD2_ID(percent_threshold2, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_PERCENTAGE_THRESHOLD3_ID(percent_threshold3, bat_num), \ + ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_POWER_CONFIG_BATTERY_ALARM_STATE_ID(alarm_state, bat_num), \ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Power Configuration cluster - server side (Battery attribute + list extended) + @param attr_list - attribute list name + @param voltage - pointer to variable to store BatteryVoltage attribute + @param size - pointer to variable to store BatterySize attribute + @param quantity - pointer to variable to store BatteryQuantity attribute + @param rated_voltage - pointer to variable to store BatteryRatedVoltage attribute + @param alarm_mask - pointer to variable to store BatteryAlarmMask attribute + @param voltage_min_threshold - pointer to variable to store BatteryVoltageMinThreshold attribute + + @param remaining - pointer to variable to store BatteryPercentageRemaining attribute + @param threshold1 - pointer to variable to store BatteryVoltageThreshold1 attribute + @param threshold2 - pointer to variable to store BatteryVoltageThreshold2 attribute + @param threshold3 - pointer to variable to store BatteryVoltageThreshold3 attribute + @param min_threshold - pointer to variable to store BatteryPercentageMinThreshold attribute + @param percent_threshold1 - pointer to variable to store BatteryPercentageThreshold1 attribute + @param percent_threshold2 - pointer to variable to store BatteryPercentageThreshold2 attribute + @param percent_threshold3 - pointer to variable to store BatteryPercentageThreshold3 attribute + @param alarm_state - pointer to variable to store BatteryAlarmState attribute +*/ +#define ZB_ZCL_DECLARE_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(attr_list, \ + voltage, size, quantity, rated_voltage, alarm_mask, voltage_min_threshold, \ + remaining, threshold1, threshold2, threshold3, min_threshold, percent_threshold1, \ + percent_threshold2, percent_threshold3, alarm_state) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_POWER_CONFIG_BATTERY_ATTRIB_LIST_EXT(, \ + voltage, size, quantity, rated_voltage, alarm_mask, voltage_min_threshold, \ + remaining, threshold1, threshold2, threshold3, min_threshold, percent_threshold1, \ + percent_threshold2, percent_threshold3, alarm_state) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Power Configuration cluster attributes */ + +/*! @name Power Configuration cluster commands + @{ +*/ + +/*! @} */ /* Power Configuration cluster commands */ + +/*! @} */ /* ZCL Power Configuration cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_power_config_init_server(void); +zb_void_t zb_zcl_power_config_init_client(void); +#define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_SERVER_ROLE_INIT zb_zcl_power_config_init_server +#define ZB_ZCL_CLUSTER_ID_POWER_CONFIG_CLIENT_ROLE_INIT zb_zcl_power_config_init_client + +#endif /* ! defined ZB_ZCL_POWER_CONFIG_H */ diff --git a/zboss/include/zcl/zb_zcl_price.h b/zboss/include/zcl/zb_zcl_price.h new file mode 100644 index 0000000000..fdee40a2ea --- /dev/null +++ b/zboss/include/zcl/zb_zcl_price.h @@ -0,0 +1,4457 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Price cluster defintions +*/ + +#ifndef ZB_ZCL_PRICE_H +#define ZB_ZCL_PRICE_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_PRICE + * @{ + * @details + * The Price Cluster provides the mechanism for communicating Gas, Energy, or + * Water pricing information within the premises. + */ + +/* Cluster ZB_ZCL_CLUSTER_ID_PRICE */ + +/** @defgroup ZB_ZCL_PRICE_ATTRS Price cluster attributes + * @{ + */ + +/** @defgroup ZB_ZCL_PRICE_SRV_ATTRIBUTES_GROUP Price cluster server attributes + * @{ + * @details + * For convenience, the attributes defined in this cluster are arranged into sets + * of related attributes; each set can contain up to 256 attributes. Attribute + * identifiers are encoded such that the most significant Octet specifies the + * attribute set and the least significant Octet specifies the attribute within + * the set. + */ + +/** @brief Price Cluster General server attributes + * @see SE spec, Table D-73 + */ +enum zb_zcl_price_srv_attr_set_e +{ + ZB_ZCL_PRICE_SET_TIER_LABEL = 0x00, /**< Provides a method for utilities to assign a label to the Price Tier. */ + ZB_ZCL_PRICE_SET_BLOCK_THRESHOLD = 0x01, /**< Provides remote access to the Price server Block Thresholds. */ + ZB_ZCL_PRICE_SET_BLOCK_PERIOD = 0x02, /**< Provides remote access to the Price server Block Threshold period. */ + ZB_ZCL_PRICE_SET_COMMODITY = 0x03, /**< Represents items that are associated with a particular commodity. */ + ZB_ZCL_PRICE_SET_BLOCK_PRICE_INFORMATION = 0x04, /**< Provides remote access to the block prices. */ + ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION = 0x05, /**< Represents extended price information. */ + ZB_ZCL_PRICE_SET_TARIFF_INFORMATION = 0x06, /**< Represents items that are associated with a particular Price Tariff. */ + ZB_ZCL_PRICE_SET_BILLING_INFORMATION = 0x07, /**< Provides remote access to the Price server Billing information. */ + ZB_ZCL_PRICE_SET_CREDIT_PAYMENT = 0x08, /**< Provides a method for the HAN (IHD) to understand the current status + * of the credit-only payment made to the energy supplier. */ + + /* reserved 0x09 - 0x7F */ + + ZB_ZCL_PRICE_SET_RECEIVED_TIER_LABEL = 0x80, /**< Provides a method for utilities to assing a label to Received Price Tiers. */ + ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_THRESHOLD = 0x81, /**< Provides remote access to the Price server ReceivedBlockThresholds. */ + ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PERIOD = 0x82, /**< Provides remote access to the Price server Received Block Threshold period. */ + + /* reserved 0x83 */ + + ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PRICE_INFORMATION = 0x84, /**< @copydetails ZB_ZCL_PRICE_SET_BLOCK_PRICE_INFORMATION_GROUP */ + ZB_ZCL_PRICE_SET_RECEIVED_EXTENDED_PRICE_INFORMATION = 0x85, /**< @copydetails ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION_GROUP */ + ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION = 0x86, /**< @copydetails ZB_ZCL_PRICE_SET_TARIFF_INFORMATION_GROUP */ + ZB_ZCL_PRICE_SET_RECEIVED_BILLING_INFORMATION = 0x87, /**< @copydetails ZB_ZCL_PRICE_SET_BILLING_INFORMATION_GROUP */ + + /* reserved 0x88 - 0xFF */ +}; + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_TIER_LABEL_GROUP Tier Label + * @{ + */ + +/** @brief Tier Label (Delivered) Attributes Set + * @see SE spec, D.4.2.2.1 + */ +enum zb_zcl_price_set_tier_label_e +{ + /** The TierNPriceLabel attributes provide a method for utilities to assign a + * label to the Price Tier declared within the Publish Price command. + */ + ZB_ZCL_ATTR_PRICE_SRV_TIER1_PRICE_LABEL = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_TIER_LABEL, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_TIER2_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER16_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER17_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER18_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER19_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER20_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER21_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER22_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER23_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER24_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER25_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER26_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER27_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER28_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER29_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER30_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER31_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER32_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER33_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER34_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER35_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER36_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER37_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER38_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER39_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER40_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER41_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER42_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER43_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER44_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER45_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER46_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER47_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_TIER48_PRICE_LABEL, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIERN_PRICE_LABEL_GNR(tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER ## tierN ## _PRICE_LABEL, \ + ZB_ZCL_ATTR_TYPE_OCTET_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_TIER_LABEL_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_BLOCK_THRESHOLD_GROUP Block Threshold + * @{ + * @details + * The following set of attributes provides remote access to the Price server + * Block Thresholds. Block Threshold values are crossed when the + * CurrentBlockPeriodConsumptionDelivered attribute value is greater than a + * BlockNThreshold attribute. The number of block thresholds is indicated by + * the Number of Block Thresholds field in the associated Publish Price command. + * The number of blocks is one greater than the number of thresholds. + */ + +/** @brief Block Threshold (Delivered) Attributes Set + * @see SE spec, D.4.2.2.2 + */ +enum zb_zcl_set_block_threshold_e +{ + /** Attributes Block1Threshold through Block15Threshold represent the block + * threshold values for a given period (typically the billing cycle). + */ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK1_THRESHOLD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_BLOCK_THRESHOLD, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_BLOCK15_THRESHOLD, + + /** Where a single set of thresholds is used, the BlockThresholdCount + * attribute indicates the number of applicable BlockNThresholds. Where more + * than one set of thresholds is used, each set will be accompanied by an + * appropriate TierNBlockThresholdCount attribute + */ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_THRESHOLD_COUNT, + + /** Attributes Tier1Block1Threshold through Tier15Block15Threshold represent + * the block threshold values applicable to a specific TOU tier for a given + * period (typically the billing cycle). + */ + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK15_THRESHOLD, + + /** The TierNBlockThresholdCount attributes hold the number of block + * thresholds applicable to a given tier. + */ + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK_THRESHOLD_COUNT, + + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK1_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK15_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK_THRESHOLD_COUNT, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_BLOCKN_THRESHOLD_GNR(blockN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK ## blockN ## _THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_48BIT, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_BLOCK_THRESHOLD_COUNT_GNR(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_THRESHOLD_COUNT, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIERN_BLOCKM_THRESHOLD_GNR(blockN, tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER ## tierN ## _BLOCK ## blockN ## _THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIERN_BLOCK_THRESHOLD_COUNT_GNR(tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER ## tierN ## _BLOCK_THRESHOLD_COUNT, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_BLOCK_THRESHOLD_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_BLOCK_PERIOD_GROUP Block Period + * @{ + * @details + * This set of attributes provides remote access to the Price server + * Block Threshold period (typically the billing cycle) information. + */ + +/** @brief Block Period (Delivered) Attributes Set + * @see SE spec, D.4.2.2.3 + */ +enum zb_zcl_price_set_block_period_e +{ + /** The StartOfBlockPeriod attribute represents the start time of the current + * block tariff period. + */ + ZB_ZCL_ATTR_PRICE_SRV_START_OF_BLOCK_PERIOD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_BLOCK_PERIOD, 0x00), + + /** The BlockPeriodDuration attribute represents the current block tariff + * period duration in units defined by the BlockPeriodDurationType attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION, + + /** ThresholdMultiplier provides a value to be multiplied against Threshold + * attributes. + */ + ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_MULTIPLIER, + + /** ThresholdDivisor provides a value to divide the result of applying + * the ThresholdMultiplier attribute to Block Threshold values to derive + * values That can be compared against the CurrentBlockPeriodConsumptionDelivered + * attribute within the Metering cluster. + */ + ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_DIVISOR, + + /** The BlockPeriodDurationType attribute indicates the timebase used for the + * BlockPeriodDuration attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION_TYPE, + /* reserved 0x0205 - 0x02FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_START_OF_BLOCK_PERIOD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_START_OF_BLOCK_PERIOD, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_MULTIPLIER(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_MULTIPLIER, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_DIVISOR(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_THRESHOLD_DIVISOR, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION_TYPE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION_TYPE, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @brief @e BlockPeriodDurationType attribute values + * @see SE spec, table D-105. + * @see ZB_ZCL_ATTR_PRICE_SRV_BLOCK_PERIOD_DURATION_TYPE + */ +typedef enum zb_zcl_price_block_period_duration_type_e +{ + ZB_ZCL_PRICE_BLOCK_PERIOD_DURATION_TYPE_MINUTES = 0x00, /**< minutes (default) */ + ZB_ZCL_PRICE_BLOCK_PERIOD_DURATION_TYPE_DAYS = 0x01, /**< days */ + ZB_ZCL_PRICE_BLOCK_PERIOD_DURATION_TYPE_WEEKS = 0x02, /**< weeks */ + ZB_ZCL_PRICE_BLOCK_PERIOD_DURATION_TYPE_MONTHS = 0x03, /**< months */ +} zb_zcl_price_block_period_duration_type_t; + +/** @} */ /* end of ZB_ZCL_PRICE_SET_BLOCK_PERIOD_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_COMMODITY_GROUP Commodity + * @{ + * @details + * This set of attributes represents items that are associated with a + * particular commodity. + */ + +/** Values and Descriptions for the CalorificValueUnit Attribute + * @see SE spec, subclause D.4.2.2.4.6 + */ +typedef enum zb_zcl_price_calorific_value_unit_values_e +{ + ZB_ZCL_PRICE_CALORIFIC_VALUE_UNIT_MJ_M3 = 0x01, /**< MJ/m3 */ + ZB_ZCL_PRICE_CALORIFIC_VALUE_UNIT_MJ_KG, /**< MJ/kg */ +} zb_zcl_price_calorific_value_unit_values_t; + + +/** @brief Commodity Attributes Set + * @see SE spec, D.4.2.2.4 + */ +enum zb_zcl_price_set_commodity_e +{ + /** CommodityType provides a label for identifying the type of pricing server + * present. + */ + ZB_ZCL_ATTR_PRICE_SRV_COMMODITY_TYPE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_COMMODITY, 0x00), + + /** The value of the Standing Charge is a daily fixed charge associated with + * supplying the commodity, measured in base unit of Currency with the decimal + * point located as indicated by the Trailing Digits field of a Publish Price + * command or PriceTrailingDigit attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_STANDING_CHARGE, + + /** The conversion factor is used for gas meter and takes into account changes + * in the volume of gas based on temperature and pressure. + */ + ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR, + + /** An 8-bit BitMap used to determine where the decimal point is located in + * the ConversionFactor attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR_TRAILING_DIGIT, + + /** The amount of heat generated when a given mass of fuel is completely burned. + */ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE, + + /** This attribute defines the unit for the CalorificValue. + */ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_UNIT, + + /** An 8-bit BitMap used to determine where the decimal point is located in + * the CalorificValue attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_TRAILING_DIGIT, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_COMMODITY_TYPE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_COMMODITY_TYPE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_STANDING_CHARGE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_STANDING_CHARGE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR_TRAILING_DIGIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CONVERSION_FACTOR_TRAILING_DIGIT, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_UNIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_UNIT, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_TRAILING_DIGIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CALORIFIC_VALUE_TRAILING_DIGIT, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_COMMODITY_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_BLOCK_PRICE_INFORMATION_GROUP Block Price Information + * @{ + * @details + * This attributes set provide remote access to the block prices. + * The Block Price Information attribute set supports Block and combined + * Tier-Block pricing, the number of blocks is one greater than the number of + * block thresholds defined in the Pricing cluster + */ + +/** @brief Block Price Information (Delivered) Attributes Set + * @see SE spec, D.4.2.2.5 + */ +enum zb_zcl_price_set_block_price_information_e +{ + /** Attributes PriceNoTierBlock1 through PriceTier15Block16 represent the + * price of Energy, Gas, or Water delivered to the premises (i.e. delivered + * to the customer from the utility) at a specific price tier as defined by + * a TOU schedule, Block Threshold or a real time pricing period. + */ + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK1_PRICE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_BLOCK_PRICE_INFORMATION, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER1_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER2_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER3_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER4_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER5_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER6_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER7_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER8_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER9_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER10_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER11_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER12_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER13_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER14_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_TIER15_BLOCK16_PRICE, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCKN_PRICE_GNR(blockN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_NO_TIER_BLOCK ## blockN ## _PRICE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIERN_BLOCKM_PRICE_GNR(tierN, blockM, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER ## tierN ## _BLOCK ## blockM ## _PRICE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_BLOCK_PRICE_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION_GROUP Extended Price Information + * @{ + * @details + * In case of TOU charging only, the price server allows support for up to 48 + * TOU rates. To reduce the number of attributes, Tier1Block1Price through + * Tier15Block1Price attributes are reused to represent rates for tiers 1 to 15. + * Rates for tiers 16 to 48 are provided in the extended price information set. + */ + +/** @brief Extended Price Information (Delivered) Attributes Set + * @see SE spec, D.4.2.2.6 + */ +enum zb_zcl_price_set_extended_price_information_e +{ + /* reserved 0x0500 - 0x050E */ + + /** Attributes PriceTier16 through PriceTier48 represent the price of Energy, + * Gas, or Water delivered to the premises (i.e. delivered to the customer + * from the utility) at a specific price tier. + */ + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER16 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION, 0x0F), + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER17, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER18, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER19, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER20, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER21, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER22, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER23, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER24, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER25, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER26, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER27, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER28, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER29, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER30, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER31, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER32, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER33, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER34, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER35, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER36, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER37, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER38, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER39, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER40, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER41, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER42, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER43, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER44, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER45, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER46, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER47, + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER48, + /* reserved 0x0530 - 0x05FD */ + + /** Attribute CPP1 Price represents the price of Energy, Gas, or Water + * delivered to the premises (i.e. delivered to the customer from the utility) + * while Critical Peak Pricing 'CPP1' is being applied. + */ + ZB_ZCL_ATTR_PRICE_SRV_CPP1_PRICE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION, 0x0FE), + + /** Attribute CPP2 Price represents the price of Energy, Gas, or Water + * delivered to the premises (i.e. delivered to the customer from the utility) + * while Critical Peak Pricing 'CPP2' is being applied. + */ + ZB_ZCL_ATTR_PRICE_SRV_CPP2_PRICE, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIERN_GNR(tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TIER ## tierN, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CPPN_PRICE_GNR(cppN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CPP ## cppN ## _PRICE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_EXTENDED_PRICE_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_TARIFF_INFORMATION_GROUP Tariff Information + * @{ + * @details + * This set of attributes represents items that are associated with a + * particular Price Tariff. + * @note The terms tier and rate are used + * interchangeably here, but do define the same thing. + */ + +/** @brief Tariff Information (Delivered) Attributes Set + * @see SE spec, D.4.2.2.7 + */ +enum zb_zcl_price_set_tariff_information_e +{ + /* reserved 0x0600 - 0x060F */ + + /** The TariffLabel attribute provides a method for utilities to assign a + * label to an entire set of tariff information. + */ + ZB_ZCL_ATTR_PRICE_SRV_TARIFF_LABEL = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_TARIFF_INFORMATION, 0x10), + + /** An 8-bit integer which indicates the number of price tiers used while this + * tariff is active. + */ + ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_PRICE_TIERS_IN_USE, + + /** An 8-bit integer which indicates the total number of block thresholds used + * in the currently active tariff. + */ + ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE, + + /** An 8-bit enumeration indicating how the mixed TOU / Block charging is to + * be applied. + */ + ZB_ZCL_ATTR_PRICE_SRV_TIER_BLOCK_MODE, + /* reserved 0x0614 */ + + /** An 8-bit enumeration identifying the base unit of measure. + */ + ZB_ZCL_ATTR_PRICE_SRV_UNIT_OF_MEASURE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_TARIFF_INFORMATION, 0x15), + + /** An unsigned 16-bit integer containing identifying information concerning + * the local unit of currency used in the Price cluster. + */ + ZB_ZCL_ATTR_PRICE_SRV_CURRENCY, + + /** An 8-bit BitMap used to determine where the decimal point is located for + * prices provided in the Standing Charge attribute and the Price Matrix command. + */ + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TRAILING_DIGIT, + /* reserved 0x0618 */ + + /** An 8-bit enumeration identifying the resolution period for Block Tariff. + */ + ZB_ZCL_ATTR_PRICE_SRV_TARIFF_RESOLUTION_PERIOD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_TARIFF_INFORMATION, 0x19), + /* reserved 0x061A - 0x061F */ + + /** Used to calculate the amount of carbon dioxide (CO2) produced from energy use. + */ + ZB_ZCL_ATTR_PRICE_SRV_CO2 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_TARIFF_INFORMATION, 0x20), + + /** This attribute is an 8-bit enumeration which defines the unit for the CO2 attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_CO2_UNIT, + + /** An 8-bit Bit-Map used to determine where the decimal point is located in + * the CO2 attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_CO2_TRAILING_DIGIT, + /* reserved 0x628 - 0x06FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TARIFF_LABEL(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TARIFF_LABEL, \ + ZB_ZCL_ATTR_TYPE_OCTET_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_PRICE_TIERS_IN_USE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_PRICE_TIERS_IN_USE, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIER_BLOCK_MODE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER_BLOCK_MODE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @see SE spec, table D-82. */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TIER_BLOCK_MODE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TIER_BLOCK_MODE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @see @ref zb_zcl_metering_unit_of_measure_e */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_UNIT_OF_MEASURE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_UNIT_OF_MEASURE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CURRENCY(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CURRENCY, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_PRICE_TRAILING_DIGIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_PRICE_TRAILING_DIGIT, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @brief @e TariffResolutionPeriod attribute values + * @see SE spec, Table D-107 + * @see @ref ZB_ZCL_ATTR_PRICE_SRV_TARIFF_RESOLUTION_PERIOD + */ +typedef enum zb_zcl_price_tariff_resolution_period_e +{ + ZB_ZCL_ATTR_PRICE_TARIFF_RESOLUTION_PERIOD_NOT_DEFINED = 0x00, /**< Not defined */ + ZB_ZCL_ATTR_PRICE_TARIFF_RESOLUTION_PERIOD_BLOCK_PERIOD, /**< Block Period */ + ZB_ZCL_ATTR_PRICE_TARIFF_RESOLUTION_PERIOD_1DAY, /**< 1 Day */ +} zb_zcl_price_tariff_resolution_period_t; + +/** @cond internals_doc */ + +/** @see @ref zb_zcl_price_tariff_resolution_period_t. */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_TARIFF_RESOLUTION_PERIOD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_TARIFF_RESOLUTION_PERIOD, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CO2(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CO2, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @brief @e CO2Unit attribute values + * @see SE spec, Table D-83. + * @see ZB_ZCL_ATTR_PRICE_SRV_CO2_UNIT + */ +typedef enum zb_zcl_price_co2_unit_e +{ + ZB_ZCL_ATTR_PRICE_CO2_UNIT_KG_PER_KWH = 0x01, /**< kg per kWh */ + ZB_ZCL_ATTR_PRICE_CO2_UNIT_KG_PER_GALLON_OF_GASOLINE = 0x02, /**< kg per Gallon of Gasoline */ + ZB_ZCL_ATTR_PRICE_CO2_UNIT_KG_PER_THERM_OF_NATURAL_GAS = 0x03, /**< kg per Therm of Natural Gas */ +} zb_zcl_price_co2_unit_t; + +/** @cond internals_doc */ + +/** @see @ref zb_zcl_price_co2_unit_t */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CO2_UNIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CO2_UNIT, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CO2_TRAILING_DIGIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CO2_TRAILING_DIGIT, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_TARIFF_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_BILLING_INFORMATION_GROUP Billing Information + * @{ + * @details + * This set of attributes provides remote access to the Price server + * Billing information. + */ + +/** @brief Billing Information (Delivered) Attributes Set + * @see SE spec, D.4.2.2.8 + */ +enum zb_zcl_price_set_billing_information_e +{ + /** The CurrentBillingPeriodStart attribute represents the start time of the + * current billing period. + */ + ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_START = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_BILLING_INFORMATION, 0x00), + + /** The CurrentBillingPeriodDuration attribute represents the current billing + * period duration in minutes. + */ + ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_DURATION, + + /** The LastBillingPeriodStart attribute represents the start time of the last + * billing period. + */ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_START, + + /** The LastBillingPeriodDuration attribute is the duration of the last + * billing period in minutes (start to end of last billing period). + */ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_DURATION, + + /** The LastBillingPeriodConsolidatedBill attribute is an amount for the cost + * of the energy supplied from the date of the LastBillingPeriodStart + * attribute and until the duration of the LastBillingPeriodDuration attribute + * expires, measured in base unit of Currency with the decimal point located + * as indicated by the Trailing Digits attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_CONSOLIDATED_BILL, + /* reserved 0x0705 - 0x07FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_START(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_START, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CURRENT_BILLING_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_START(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_START, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_CONSOLIDATED_BILL(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_LAST_BILLING_PERIOD_CONSOLIDATED_BILL, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_BILLING_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_CREDIT_PAYMENT_GROUP Credit Payment + * @{ + * @details + * The Credit Payments Attribute set provides a method for the HAN (IHD) to + * understand the current status of the credit-only payment made to the energy + * supplier. These payments are for a credit meter only and do not cover any + * Prepayment Top up or payment. This attribute set is used to display the bill + * on the IHD should this service be required. Devices that require this information + * should use standard ZCL commands to read this information. + */ + +/** @brief Credit Payment Attributes Set + * @see SE spec, D.2.2.9 + */ +enum zb_zcl_price_set_credit_payment_e +{ + /** The CreditPaymentDueDate attribute indicates the date and time when the + * next credit payment is due to be paid by the consumer to the supplier. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DUE_DATE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x00), + + /** The CreditPaymentStatus attribute indicates the current status of the last payment. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_STATUS, + + /** This is the total of the consolidated bill amounts accumulated since the + * last payment. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_OVER_DUE_AMOUNT, + /* reserved 0x0803 - 0x0809 */ + + /** The PaymentDiscount attribute indicates the discount that the energy + * supplier has applied to the consolidated bill. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x0A), + + /** The PaymentDiscountPeriod attribute indicates the period for which this + * discount shall be applied for. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_PERIOD, + /* reserved 0x080C - 0x080F */ + + /** The CreditPayment attributes indicate the amount paid by the consumer to + * the energy supplier. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_1 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x10), + + /** The CreditPaymentDate attributes indicate the last time the consumer made + * a payment to the energy supplier. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_1, + + /** The CreditPaymentRef attributes indicate the reference number given to the + * payment by the energy supplier. + */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_1, + /* reserved 0x0813 - 0x081F */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_2 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x20), + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_2, + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_2, + /* reserved 0x0823 - 0x082F */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_3 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x30), + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_3, + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_3, + /* reserved 0x0833 - 0x083F */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_4 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x40), + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_4, + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_4, + /* reserved 0x0843 - 0x084F */ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_5 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_CREDIT_PAYMENT, 0x50), + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_5, + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_5, + /* reserved 0x0853 - 0x08FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DUE_DATE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DUE_DATE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @brief @e CreditPaymentStatus attribute values + * @see SE spec, Table D-86. + * @see ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_STATUS + */ +typedef enum zb_zcl_price_credit_payment_status_e +{ + ZB_ZCL_PRICE_CREDIT_PAYMENT_PENDING = 0x00, /**< Pending */ + ZB_ZCL_PRICE_CREDIT_PAYMENT_RECEIVED = 0x01, /**< Received/Paid */ + ZB_ZCL_PRICE_CREDIT_PAYMENT_PAID = ZB_ZCL_PRICE_CREDIT_PAYMENT_RECEIVED, /**< @copydoc ZB_ZCL_PRICE_CREDIT_PAYMENT_RECEIVED */ + ZB_ZCL_PRICE_CREDIT_PAYMENT_OVERDUE = 0x02, /**< Overdue */ + ZB_ZCL_PRICE_CREDIT_PAYMENT_2PAYMENTS_OVERDUE = 0x03, /**< 2 Payments overdue */ + ZB_ZCL_PRICE_CREDIT_PAYMENT_3PAYMENTS_OVERDUE = 0x04, /**< 3 Payments overdue */ + /* reserved 0x05 - 0xFF */ +} zb_zcl_price_credit_payment_status_t; + + +/** @cond internals_doc */ + +/** @see @ref zb_zcl_price_credit_payment_status_t */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_STATUS(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_STATUS, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_OVER_DUE_AMOUNT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_OVER_DUE_AMOUNT, \ + ZB_ZCL_ATTR_TYPE_S32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT, \ + ZB_ZCL_ATTR_TYPE_S32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_PERIOD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_PERIOD, \ + ZB_ZCL_ATTR_TYPE_S32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_N(paymentN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_ ## paymentN, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_N(paymentN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_DATE_ ## paymentN, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_N(paymentN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_CREDIT_PAYMENT_REF_ ## paymentN, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_CREDIT_PAYMENT_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_TIER_LABEL_GROUP Tier Label + * @{ + */ + +/** @brief Received Tier Label Attributes Set + * @see SE spec, D.4.2.2.10 + */ +enum zb_zcl_price_set_received_tier_label +{ + /** The ReceivedTierNPriceLabel attributes provide a method for utilities to + * assign a label to Received Price Tiers. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER1_PRICE_LABEL = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_TIER_LABEL, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER2_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER3_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER4_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER5_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER6_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER7_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER8_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER9_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER10_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER11_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER12_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER13_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER14_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER15_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER16_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER17_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER18_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER19_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER20_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER21_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER22_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER23_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER24_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER25_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER26_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER27_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER28_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER29_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER30_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER31_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER32_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER33_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER34_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER35_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER36_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER37_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER38_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER39_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER40_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER41_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER42_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER43_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER44_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER45_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER46_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER47_PRICE_LABEL, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER48_PRICE_LABEL, + /* reserved 0x8030 - 0x80FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIERN_PRICE_LABEL_GNR(tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER ## tierN ## _PRICE_LABEL, \ + ZB_ZCL_ATTR_TYPE_OCTET_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_TIER_LABEL_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_THRESHOLD_GROUP Received Block Threshold + * @{ + * @details + * This set of attributes provides remote access to the Price server + * ReceivedBlockThresholds. The number of block thresholds is indicated by the + * NumberOfBlockThresholds field in the associated PublishTariffInformation + * command. The number of blocks is one greater than the number of thresholds. + */ + +/** @brief Received Block Threshold Attributes Set + * @see SE spec, D.4.2.2.11 + */ +enum zb_zcl_price_set_received_block_threshold_e +{ + /** The format of these attributes is the same as for the 'Delivered' Block Thresholds + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK1_THRESHOLD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_THRESHOLD, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK2_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK3_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK4_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK5_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK6_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK7_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK8_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK9_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK10_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK11_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK12_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK13_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK14_THRESHOLD, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK15_THRESHOLD, + /* reserved 0x810F - 0x81FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCKN_THRESHOLD_GNR(blockN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK ## blockN ## _THRESHOLD, \ + ZB_ZCL_ATTR_TYPE_48BIT, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_THRESHOLD_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PERIOD_GROUP Received Block Period + * @{ + * @details + * This set of attributes provides remote access to the Price server + * Received Block Threshold period (typically the billing cycle) information. + */ + +/** @brief Received Block Period Attributes Set + * @see SE spec, D.4.2.2.12 + */ +enum zb_zcl_price_set_received_block_period_e +{ + /** The format of this attribute is the same as for the 'Delivered' + * StartOfBlockPeriod attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_START_OF_BLOCK_PERIOD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PERIOD, 0x00), + + /** The format of this attribute is the same as for the 'Delivered' + * BlockPeriodDuration attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK_PERIOD_DURATION, + + /** The format of this attribute is the same as for the 'Delivered' + * ThresholdMultiplier attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_MULTIPLIER, + + /** The format of this attribute is the same as for the 'Delivered' + * ThresholdDivisor attribute + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_DIVISOR, + /* reserved 0x8204 - 0x82FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_START_OF_BLOCK_PERIOD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_START_OF_BLOCK_PERIOD, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_BLOCK_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_MULTIPLIER(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_MULTIPLIER, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_DIVISOR(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_THRESHOLD_DIVISOR, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PERIOD_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PRICE_INFORMATION_GROUP Received Block Price Information + * @{ + */ + +/** @brief Received Block Price Information Attributes Set + * @see SE spec, D.4.2.2.13 + */ +enum zb_zcl_price_set_received_block_price_information_e +{ + /** The format and use of these attributes is the same as for the + * 'Delivered' TierNBlockNPrice attributes. + */ + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK1_PRICE = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PRICE_INFORMATION, 0x00), + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER1_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER2_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER3_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER4_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER5_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER6_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER7_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER8_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER9_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER10_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER11_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER12_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER13_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER14_BLOCK16_PRICE, + + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK1_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK2_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK3_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK4_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK5_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK6_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK7_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK8_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK9_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK10_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK11_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK12_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK13_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK14_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK15_PRICE, + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER15_BLOCK16_PRICE, +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCKN_PRICE_GNR(blockN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RX_NO_TIER_BLOCK ## blockN ## _PRICE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RX_TIERN_BLOCKM_PRICE_GNR(tierN, blockM, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RX_TIER ## tierN ## _BLOCK ## blockM ## _PRICE, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_BLOCK_PRICE_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_EXTENDED_PRICE_INFORMATION_GROUP Received Extended Price Information + * @{ + * @details + * In case of TOU charging only, the price server shall support up to 48 TOU + * rates. To reduce the number of attributes, RxTierNBlock1Price attributes + * are reused to represent rates for tiers 1 to 15. Rates for tiers 16 to 48 + * are provided in the Received Extended Price Information Set. + */ + +/** @brief Received Extended Price Information Attributes Set + * @see SE spec, D.4.2.2.14 + */ +enum zb_zcl_price_set_received_extended_price_information_e +{ + /* reserved 0x8500 - 0x850E */ + + /** The format and use of these attributes is the same as for the + * 'Delivered' PriceTierN attributes. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER16 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_EXTENDED_PRICE_INFORMATION, 0x0F), + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER17, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER18, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER19, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER20, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER21, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER22, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER23, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER24, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER25, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER26, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER27, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER28, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER29, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER30, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER31, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER32, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER33, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER34, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER35, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER36, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER37, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER38, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER39, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER40, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER41, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER42, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER43, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER44, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER45, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER46, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER47, + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER48, + /* reserved 0x8530 - 0x85FF */ +}; + +/** @brief Default value for Tier1_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER1_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x00} + +/** @brief Default value for Tier2_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER2_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x32 ,0x00} + +/** @brief Default value for Tier3_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER3_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x33 ,0x00} + +/** @brief Default value for Tier4_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER4_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x34 ,0x00} + +/** @brief Default value for Tier5_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER5_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x35 ,0x00} + +/** @brief Default value for Tier6_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER6_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x36 ,0x00} + +/** @brief Default value for Tier7_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER7_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x37 ,0x00} + +/** @brief Default value for Tier8_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER8_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x38 ,0x00} + +/** @brief Default value for Tier9_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER9_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x39 ,0x00} + +/** @brief Default value for Tier10_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER10_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x30, 0x00} + +/** @brief Default value for Tier11_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER11_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x31, 0x00} + +/** @brief Default value for Tier12_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER12_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x32, 0x00} + +/** @brief Default value for Tier13_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER13_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x33, 0x00} + +/** @brief Default value for Tier14_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER14_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x34, 0x00} + +/** @brief Default value for Tier15_PriceLabel attribute */ +#define ZB_ZCL_PRICE_SRV_TIER15_PRICE_LABEL_DEFAULT_VALUE {0x54, 0x49, 0x45, 0x52, 0x20, 0x31 ,0x35, 0x00} + +/** @brief Default value for ConversionFactor attribute */ +#define ZB_ZCL_PRICE_SRV_CONVERSION_FACTOR_DEFAULT_VALUE ((zb_uint32_t)0x10000000) + +/** @brief Default value for ConversionFactorTrailingDigit attribute */ +#define ZB_ZCL_PRICE_SRV_CONVERSION_FACTOR_TRAILING_DIGIT_DEFAULT_VALUE ((zb_uint8_t)0x70) + +/** @brief Default value for CalorificValue attribute */ +#define ZB_ZCL_PRICE_SRV_CALORIFIC_VALUE_DEFAULT_VALUE ((zb_uint32_t)0x2625A00) + +/** @brief Default value for CalorificValueUnit attribute */ +#define ZB_ZCL_PRICE_SRV_CALORIFIC_VALUE_UNIT_DEFAULT_VALUE ((zb_uint8_t)0x1) + +/** @brief Default value for CalorificValueTrailingDigit attribute */ +#define ZB_ZCL_PRICE_SRV_CALORIFIC_VALUE_TRAILING_DIGIT_DEFAULT_VALUE ((zb_uint8_t)0x60) +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIERN_GNR(tierN, data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_PRICE_TIER ## tierN, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_EXTENDED_PRICE_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION_GROUP Received Tariff Information + * @{ + * @details + * The following set of attributes represents items that are associated with a + * particular Received Price Tariff. + */ + +/** @brief Received Tariff Information Attributes Set + * @see SE spec, D.4.2.2.15 + */ +enum zb_zcl_price_set_received_tariff_information_e +{ + /* reserved 0x8600 - 0x860F */ + + /** The format and use of this attribute is the same as for the + * 'Delivered' TariffLabel attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_LABEL = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION, 0x10), + + /** The format and use of this attribute is the same as for the + * 'Delivered' NumberOfPriceTiersInUse attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_PRICE_TIERS_IN_USE, + + /** The format and use of this attribute is the same as for the + * 'Delivered' NumberOfBlockThresholdsInUse attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE, + + /** The format and use of this attribute is the same as for the + * 'Delivered' TierBlockMode attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER_BLOCK_MODE, + /* reserved 0x8614 */ + + /** An 8-bit enumeration identifying the resolution period for Block Tariff. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_RESOLUTION_PERIOD = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION, 0x15), + /* reserved 0x8616 - 0x8624 */ + + /** The format and use of this attribute is the same as for the + * 'Delivered' CO2 attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2 = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION, 0x25), + + /** The format and use of this attribute is the same as for the + * 'Delivered' CO2Unit attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_UNIT, + + /** The format and use of this attribute is the same as for the + * 'Delivered' CO2TrailingDigit attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_TRAILING_DIGIT, + /* reserved 0x8528 - 0x85FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_LABEL(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_LABEL, \ + ZB_ZCL_ATTR_TYPE_OCTET_STRING, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_PRICE_TIERS_IN_USE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_PRICE_TIERS_IN_USE, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_NUMBER_OF_BLOCK_THRESHOLDS_IN_USE, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @see SE spec, table D-82. */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER_BLOCK_MODE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TIER_BLOCK_MODE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @see @ref zb_zcl_price_tariff_resolution_period_t. */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_RESOLUTION_PERIOD(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_TARIFF_RESOLUTION_PERIOD, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @see @ref zb_zcl_price_co2_unit_t */ +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_UNIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_UNIT, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_TRAILING_DIGIT(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CO2_TRAILING_DIGIT, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_TARIFF_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_SET_RECEIVED_BILLING_INFORMATION_GROUP Received Billing Information + * @{ + * @details + * The following set of attributes represents items that are associated with + * particular Received Billing information. + */ + +/** @brief Received Billing Information Attributes Set + * @see SE spec, D.4.2.2.16 + */ +enum zb_zcl_price_set_received_billing_information +{ + /** The format and use of this attribute is the same as for the + * 'Delivered' CurrentBillingPeriodStart attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_START = ZB_ZCL_ATTR_SET_WITH_ATTR_ID(ZB_ZCL_PRICE_SET_RECEIVED_BILLING_INFORMATION, 0x00), + + /** The format and use of this attribute is the same as for the + * 'Delivered' CurrentBillingPeriodDuration attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_DURATION, + + /** The format and use of this attribute is the same as for the + * 'Delivered' LastBillingPeriodStart attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_START, + + /** The format and use of this attribute is the same as for the + * 'Delivered' LastBillingPeriodDuration attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_DURATION, + + /** The format and use of this attribute is the same as for the + * 'Delivered' LastBillingPeriodConsolidatedBill attribute. + */ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_CONSOLIDATED_BILL, + /* reserved 0x8705 - 0x87FF */ +}; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_START(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_START, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_CURRENT_BILLING_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_START(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_START, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_DURATION(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_DURATION, \ + ZB_ZCL_ATTR_TYPE_U24, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_CONSOLIDATED_BILL(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_SRV_RECEIVED_LAST_BILLING_PERIOD_CONSOLIDATED_BILL, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @} */ /* end of ZB_ZCL_PRICE_SET_RECEIVED_BILLING_INFORMATION_GROUP */ + + +/******************************************************************************/ + +/** @def ZB_ZCL_DECLARE_PRICE_SRV_ATTRIB_LIST + * @brief Declare server-side Price cluster attributes + * @param attr_list - Attribute list name. + * @param commodity_type - pointer to variable to store @ref ZB_ZCL_ATTR_PRICE_SRV_COMMODITY_TYPE "CommodityType" attribute value. +*/ +#define ZB_ZCL_DECLARE_PRICE_SRV_ATTRIB_LIST(attr_list, commodity_type) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_PRICE_SRV_COMMODITY_TYPE, (commodity_type)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* end of ZB_ZCL_PRICE_SRV_ATTRIBUTES_GROUP */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_CLIENT_ATTRIBUTES_GROUP Price cluster client attributes + * @{ + */ + +/** @brief Price Cluster client attributes */ +typedef enum zb_zcl_price_cli_attr_e +{ + /** @e PriceIncreaseRandomizeMinutes attribute represents the maximum amount + * of time to be used when randomizing the response to a price increase. + */ + ZB_ZCL_ATTR_PRICE_CLI_PRICE_INCREASE_RANDOMIZE_MINUTES = 0x0000, + + /** @e PriceDecreaseRandomizeMinutes attribute represents the maximum number + * of minutes to be used when randomizing the response to a price decrease. + */ + ZB_ZCL_ATTR_PRICE_CLI_PRICE_DECREASE_RANDOMIZE_MINUTES = 0x0001, + + /** @e CommodityType attribute provides a label for identifying the type of pricing client present. + */ + ZB_ZCL_ATTR_PRICE_CLI_COMMODITY_TYPE = 0x0002, +} zb_zcl_price_cli_attr_t; + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_CLI_PRICE_INCREASE_RANDOMIZE_MINUTES(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_CLI_PRICE_INCREASE_RANDOMIZE_MINUTES, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_CLI_PRICE_DECREASE_RANDOMIZE_MINUTES(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_CLI_PRICE_DECREASE_RANDOMIZE_MINUTES, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) (data_ptr) \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_PRICE_CLI_COMMODITY_TYPE(data_ptr) \ +{ \ + ZB_ZCL_ATTR_PRICE_CLI_COMMODITY_TYPE, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) (data_ptr) \ +} + +/** @endcond */ /* internals_doc */ + +/** @def ZB_ZCL_DECLARE_PRICE_CLI_ATTRIB_LIST + * @brief Declare client-side Price cluster attributes + * @param attr_list - Attribute list name + * @param inc_rand_min - pointer to variable to store @ref ZB_ZCL_ATTR_PRICE_CLI_PRICE_INCREASE_RANDOMIZE_MINUTES "PriceIncreaseRandomizeMinutes" attribute value. + * @param dec_rand_min - pointer to variable to store @ref ZB_ZCL_ATTR_PRICE_CLI_PRICE_DECREASE_RANDOMIZE_MINUTES "PriceDecreaseRandomizeMinutes" attribute value. + * @param commodity_type - pointer to variable to store "CommodityType" attribute value. + */ +#define ZB_ZCL_DECLARE_PRICE_CLI_ATTRIB_LIST(attr_list, inc_rand_min, dec_rand_min, commodity_type) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_PRICE_CLI_PRICE_INCREASE_RANDOMIZE_MINUTES, (inc_rand_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_PRICE_CLI_PRICE_DECREASE_RANDOMIZE_MINUTES, (dec_rand_min)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_PRICE_CLI_COMMODITY_TYPE, (commodity_type)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* end of ZB_ZCL_PRICE_CLIENT_ATTRIBUTES_GROUP */ + +/** @} */ /* end of ZB_ZCL_PRICE_ATTRS */ + + +/******************************************************************************/ + +/** @defgroup ZB_ZCL_PRICE_CLUSTER_COMMANDS Price cluster commands + * @{ + */ + +/** @brief Price cluster client command identifiers. + * @see SE spec, subclause D.4.2.3. + */ +typedef enum zb_zcl_price_client_cmd_e +{ + /** GetCurrentPrice command initiates a PublishPrice command for the current time. + * @see SE spec, subclause D.4.2.3.2. + * @see zb_zcl_price_get_current_price_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CURRENT_PRICE = 0x00, + + /** GetScheduledPrices command initiates a PublishPrice command for available + * price events. + * @see zb_zcl_price_get_scheduled_prices_payload_s + * @see SE spec, subclause D.4.2.3.3. */ + ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES = 0x01, + + /** PriceAcknowledgement command provides the ability to acknowledge a + * previously sent PublishPrice command. + * @see SE spec, subclause D.4.2.3.4. + * @see zb_zcl_price_ack_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK = 0x02, + + /** GetBlockPeriod(s) command. + * This command initiates a PublishBlockPeriod command for the currently + * scheduled block periods. + * @see SE spec, subclause D.4.2.3.5. + * @see zb_zcl_price_get_block_period_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_BLOCK_PERIOD = 0x03, + + /** GetConversionFactor command. + * This command initiates a PublishConversionFactor command(s) for scheduled + * conversion factor updates. + * @see SE spec, subclause D.4.2.3.6 + * @see zb_zcl_price_get_conversion_factor_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CONVERSION_FACTOR = 0x04, + + /** GetCalorificValue command. + * This command initiates a PublishCalorificValue command(s) for scheduled + * calorific value updates. + * @see SE spec, subclause D.4.2.3.7. + * @see zb_zcl_price_client_get_calorific_value_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CALORIFIC_VALUE = 0x05, + + /** GetTariffInformation command. + * This command initiates PublishTariffInformation command(s) for scheduled + * tariff updates. + * @see SE spec, subclause D.4.2.3.8. + * @see zb_zcl_price_get_tariff_information_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_TARIFF_INFORMATION = 0x06, + + /** GetPriceMatrix command. + * This command initiates a PublishPriceMatrix command for the scheduled Price + * Matrix updates. + * @see SE spec, subclause D.4.2.3.9. + * @see zb_zcl_price_get_price_matrix_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_PRICE_MATRIX = 0x07, + + /** GetBlockThresholds command. + * This command initiates a PublishBlockThreshold command for the scheduled + * Block Threshold updates. + * @see SE spec, subclause D.4.2.3.10. + * @see zb_zcl_price_get_block_thresholds_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_BLOCK_THRESHOLDS = 0x08, + + /** GetCO2Value command. + * This command initiates PublishCO2Value command(s) for scheduled CO2 + * conversion factor updates. + * @see SE spec, subclause D.4.2.3.11. + * @see zb_zcl_price_get_co2_value_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CO2_VALUE = 0x09, + + /** GetTierLabels command. + * This command allows a client to retrieve the tier labels associated with a + * given tariff; this command initiates a PublishTierLabels command from + * the server. + * @see SE spec, subclause D.4.2.3.12. + * @see zb_zcl_price_get_tier_labels_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_TIER_LABELS = 0x0A, + + /** GetBillingPeriod command. + * This command initiates one or more PublishBillingPeriod commands for + * currently scheduled billing periods. + * @see SE spec, subclause D.4.2.3.13. + * @see zb_zcl_price_get_billing_period_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_BILLING_PERIOD = 0x0B, + + /** GetConsolidatedBill command. + * This command initiates one or more PublishConsolidatedBill commands with + * the requested billing information. + * @see SE spec, subclause D.4.2.3.14. + * @see zb_zcl_price_get_consolidated_bill_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CONSOLIDATED_BILL = 0x0C, + + /** CPPEventResponse command. + * The CPPEventResponse command is sent from a Client (IHD) to the ESI to + * notify it of a Critical Peak Pricing event authorization. + * + * @note The CPPEventResponse command in current revision of SE specification + * is provisional and not certifiable. This feature may change before reaching + * certifiable status in a future revision of SE specification. + * + * @see SE spec, subclause D.4.2.3.15. + * @see zb_zcl_price_cpp_event_response_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_CPP_EVENT_RESPONSE = 0x0D, + + /** GetCreditPayment command. + * This command initiates PublishCreditPayment commands for the requested + * credit payment information. + * @see SE spec, subclause D.4.2.3.16. + * @see zb_zcl_price_get_credit_payment_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CREDIT_PAYMENT = 0x0E, + + /** GetCurrencyConversion command. + * This command initiates a PublishCurrencyConversion command for the currency + * conversion factor updates. + * @see SE spec, subclause D.4.2.3.17. + * @see zb_zcl_price_publish_currency_conversion_payload_s + */ + ZB_ZCL_PRICE_CLI_CMD_GET_CURRENCY_CONVERSION = 0x0F, + + /** GetTariffCancellation command. + * This command initiates the return of the last CancelTariff command held on + * the associated server. + * @see SE spec, subclauseD.4.2.3.18. + * @note This command has no payload. + */ + ZB_ZCL_PRICE_CLI_CMD_GET_TARIFF_CANCELLATION = 0x10, + + /* reserved 0x11 - 0xFF */ +} zb_zcl_price_client_cmd_t; + +/** @brief Price cluster server command identifiers + * @see SE spec, subclause D.4.2.4. + */ +typedef enum zb_zcl_price_server_cmd_e +{ + /** PublishPrice command. + * The Publish Price command is generated in response to receiving a + * GetCurrentPrice command, in response to a GetScheduledPrices command, + * and when an update to the pricing information is available from the + * commodity provider. + * @see SE spec, subclause D.4.2.4.1. + * @see zb_zcl_price_publish_price_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE = 0x00, + + /** PublishBlockPeriod command. + * The Publish Block Period command is generated in response to receiving a + * GetBlockPeriod(s) command (see sub-clause D.4.2.3.5) or when an update + * to the block tariff schedule is available from the commodity provider. + * @see SE spec, subclause D.4.2.4.2. + * @see zb_zcl_price_publish_block_period_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BLOCK_PERIOD = 0x01, + + /** PublishConversionFactor command. + * The PublishConversionFactor command is sent in response to a + * GetConversionFactor command or if a new conversion factor is available. + * @see SE spec, subclause D.4.2.4.3. + * @see zb_zcl_price_publish_conversion_factor_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CONVERSION_FACTOR = 0x02, + + /** PublishCalorificValue command. + * The PublishCalorificValue command is sent in response to a + * GetCalorificValue command or if a new calorific value is available. + * @see SE spec, subclause D.4.2.4.4. + * @see zb_zcl_price_publish_calorific_value_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CALORIFIC_VALUE = 0x03, + + /** PublishTariffInformation command. + * The PublishTariffInformation command is sent in response to a + * GetTariffInformation command or if new tariff information is available + * (including Price Matrix and Block Thresholds). + * @see SE spec, subclause D.4.2.4.5. + * @see zb_zcl_price_publish_tariff_information_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TARIFF_INFORMATION = 0x04, + + /** PublishPriceMatrix command. + * The PublishPriceMatrix command is used to publish the Block Price + * Information Set (up to 15 tiers x 15 blocks) and + * the Extended Price Information Set (up to 48 tiers). + * The PublishPriceMatrix command is sent in response to + * a GetPriceMatrix command. + * @see SE spec, subclause D.4.2.4.6. + * @see zb_zcl_price_publish_price_matrix_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE_MATRIX = 0x05, + + /** PublishBlockThresholds command. + * The PublishBlockThresholds command is sent in response to + * a GetBlockThresholds command. + * @see SE spec, subclause D.4.2.4.7. + * @see zb_zcl_price_publish_block_thresholds_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BLOCK_THRESHOLDS = 0x06, + + /** PublishCO2Value command. + * The PublishCO2Value command is sent in response to a GetCO2Value command or + * if a new CO2 conversion factor is available. + * @see SE spec, subclause D.4.2.4.8. + * @see zb_zcl_price_publish_co2_value_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CO2_VALUE = 0x07, + + /** PublishTierLabels command. + * The PublishTierLabels command is generated in response to receiving a + * GetTierLabels command or when there is a tier label change. + * @see SE spec, subclause D.4.2.4.9. + * @see zb_zcl_price_publish_tier_labels_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TIER_LABELS = 0x08, + + /** PublishBillingPeriod command. + * The PublishBillingPeriod command is generated in response to receiving a + * GetBillingPeriod(s) command or when an update to the Billing schedule is + * available from the commodity supplier. + * @see SE spec, subclause D.4.2.4.10. + * @see zb_zcl_price_publish_billing_period_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BILLING_PERIOD = 0x09, + + /** PublishConsolidatedBill command. + * The PublishConsolidatedBill command is used to make consolidated billing + * information from previous billing periods available to other end devices. + * This command is issued in response to a GetConsolidatedBill command or + * if new billing information is available. + * @see SE spec, subclause D.4.2.4.11. + * @see zb_zcl_price_publish_consolidated_bill_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CONSOLIDATED_BILL = 0x0A, + + /** PublishCPPEvent command. + * The PublishCPPEvent command is sent from an ESI to its Price clients to + * notify them of a Critical Peak Pricing (CPP) event. + * + * @note The CPPEventResponse command in current revision of SE specification + * is provisional and not certifiable. This feature may change before reaching + * certifiable status in a future revision of SE specification. + * + * @see SE spec, subclause D.4.2.4.12. + * @see zb_zcl_price_publish_cpp_event_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CPP_EVENT = 0x0B, + + /** PublishCreditPayment command. + * The PublishCreditPayment command is used to update the credit payment + * information when available. + * @see SE spec, subclause D.4.2.4.13. + * @see zb_zcl_price_publish_credit_payment_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CREDIT_PAYMENT = 0x0C, + + /** PublishCurrencyConversion command. + * The PublishCurrencyConversion command is sent in response to a + * GetCurrencyConversion command or when a new currency becomes available. + * @see SE spec, subclause D.4.2.4.14. + * @see zb_zcl_price_publish_currency_conversion_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CURRENCY_CONVERSION = 0x0D, + + /** CancelTariff command. + * The CancelTariff command indicates that all data associated with a + * particular tariff instance should be discarded. + * @see SE spec, subclause D.4.2.4.15. + * @see zb_zcl_price_cancel_tariff_payload_s + */ + ZB_ZCL_PRICE_SRV_CMD_CANCEL_TARIFF = 0x0E, + + /* reserved 0x0F - 0xFF */ +} zb_zcl_price_server_cmd_t; + +/* PRICE cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_PRICE_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE, \ + ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TIER_LABELS + +#define ZB_ZCL_CLUSTER_ID_PRICE_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_PRICE_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_PRICE_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_PRICE_CLI_CMD_GET_CURRENT_PRICE, \ + ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES, \ + ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK, \ + ZB_ZCL_PRICE_CLI_CMD_GET_TIER_LABELS + +#define ZB_ZCL_CLUSTER_ID_PRICE_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_PRICE_CLIENT_ROLE_GENERATED_CMD_LIST + + +/** @brief @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE "PublishPrice" command payload. + * @see SE spec, subclause D.4.2.3.1.1. + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_price_payload_s +{ + /** Unique identifier for the commodity provider. */ + zb_uint32_t provider_id; /* (M) */ + + /** Commodity provider-specific information regarding + * the current billing rate. + */ + zb_uint8_t rate_label[13]; /* (M) */ + + /** Unique identifier generated by the commodity provider + * allows devices to determine which pricing information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** UTC Time field containing the current time as determined + * by the device. + */ + zb_uint32_t current_time; /* (M) */ + + /** Field identifying the commodity as well as this base units of measure. + * @see enum zb_zcl_metering_unit_of_measure_e + */ + zb_uint8_t unit_of_measure; /* (M) */ + + /** Field identifying information concerning the local unit of + * currency used in the price field. + * @see ISO-4217 + */ + zb_uint16_t currency; /* (M) */ + + /** Determines where the decimal point is located in the price field */ + zb_bitfield_t price_trailing_digit:4; /* (M) */ + + /** Indicates the current price tier as chosen by the commodity provider */ + zb_bitfield_t price_tier:4; /* (M) */ + + /** Represents the maximum number of price tiers available. */ + zb_bitfield_t number_of_price_tiers:4; /* (M) */ + + /** Indicates the register tier used with the + * current Price Tier (@ref price_tier). + */ + zb_bitfield_t register_tier:4; /* (M) */ + + /** Denotes the time at which the signal becomes valid. + * Value 0x00000000 is a special time denoting "now". + */ + zb_uint32_t start_time; /* (M) */ + + /** Denotes amount of time in minutes after Start Time (@ref start_time) + * during which the price signal is valid. + */ + zb_uint16_t duration_in_minutes; /* (M) */ + + /** Contains the price of the commodity measured in base unit of + * Currency per Unit of Measure (@ref currency per @ref unit_of_measure) + * with the decimal point located as indicated by + * the Price Trailing Digit field (@ref price_trailing_digit) when + * the commodity is delivered to premises. + */ + zb_uint32_t price; /* (M) */ + + /* Optional fields. */ + + /** Gives the ratio of the price denoted in the Price field (@ref price) + * to the "normal" price, chosen by the commodity provider. + */ + zb_uint8_t price_ratio; /* (O) */ + + /** Contains the price of the commodity measured in base unit of + * Currency per Unit of Measure (@ref currency per @ref unit_of_measure) + * with the decimal point located as indicated by + * the Price Trailing Digit field (@ref price_trailing_digit) when + * the commodity is received from premises. + */ + zb_uint32_t generation_price; /* (O) */ + + /** Gives the ratio of the price denoted in the Generation Price + * field (@ref price) to the "normal" price, + * chosen by the commodity provider. + */ + zb_uint8_t generation_price_ratio; /* (O) */ + + /** Provides mechanism to describe an alternative measure of the cost + * of the energy consumed. + */ + zb_uint32_t alternate_cost_delivered; /* (O) */ + + /** Identifies the unit for Alternate Cost Delivered field + * (@ref alternate_cost_delivered) + */ + zb_uint8_t alternate_cost_unit; /* (O) */ + + /** Determines where the decimal point is located in + * the alternate cost field. + */ + zb_uint8_t alternate_cost_trailing_digit; /* (O) */ + + /** Indicates the number of block thresholds available. */ + zb_uint8_t number_of_block_thresholds; /* (O) */ + + /** Identifies additional control options (PriceAcknowledgement policy and + * total number of tier flag). + */ + zb_uint8_t price_control; /* (O) */ + + /** Specifies the total number of generation tiers applicable in the + * current tariff. + */ + zb_uint8_t number_of_generation_tiers; /* (O) */ + + /** Specifies the current generation tier. */ + zb_uint8_t generation_tier; /* (O) */ + + /** Indicates a maximum number of tier available. + * @see number_of_generation_tiers + */ + zb_uint8_t extended_number_of_price_tiers; /* (O) */ + + /** Indicates the current price tier. + * @see price_tier + */ + zb_uint8_t extended_price_tier; /* (O) */ + + /** Indicates the register tier used with the + * current Price Tier (@ref register_tier). + */ + zb_uint8_t extended_register_tier; /* (O) */ + +} ZB_PACKED_STRUCT zb_zcl_price_publish_price_payload_t; + + +/** @def ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_SIZE_IS_VALID + * @brief Returns 'true' if payload is in range [min_payload_size, max_payload_size] + */ +#define ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_SIZE_IS_VALID(size) \ + (size <= sizeof(zb_zcl_price_publish_price_payload_t)) \ + && (size > (sizeof(zb_zcl_price_publish_price_payload_t) \ + - ZB_SIZEOF_FIELD(zb_zcl_price_publish_price_payload_t, rate_label))) + +/** @def ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_EXPECTED_SIZE + * @brief Returns actual size of payload. + * @details PublishPrice packet payload doesn't have fixed length because of 'rate_label' + * field. This macro can be used to check payload size of incomming packet. + */ +#define ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_EXPECTED_SIZE(pl) \ + (sizeof(*(pl)) \ + - (ZB_ZCL_STRING_CONST_SIZE((pl)->rate_label) - ZB_ZCL_GET_STRING_LENGTH((pl)->rate_label))) + +/** @def ZB_ZCL_PRICE_DEFAULT_PRICE_CONTROL_VALUE + * @brief Controls PriceAck policy for outcoming PublishPrice packets. + * SE devices can enable this field (refer @ref zb_zcl_price_publish_price_payload_t::price_control) + * if they want to receive @ref ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK "PriceAcknowledgement" command as + * response to @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE "PublishPrice" command, but this behavior + * is valid only for SE version >= 1.1. + * SE 1.2 is used, so this field is set to 1 by default. + */ +#define ZB_ZCL_PRICE_DEFAULT_PRICE_CONTROL_VALUE 0x01 + +/** @def ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_INIT + * @brief Macro for initializing @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE "PublishPrice" Command payload. + * @see @ref zb_zcl_price_publish_price_payload_t + * @par Example + * @code{C} + * zb_zcl_price_publish_price_payload_t pl = ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_INIT; + * @endcode + */ +#define ZB_ZCL_PRICE_PUBLISH_PRICE_PAYLOAD_INIT \ + (zb_zcl_price_publish_price_payload_t) \ +{ \ + .price_ratio = 0xFF, \ + .generation_price = 0xFFFFFFFF, \ + .generation_price_ratio = 0xFF, \ + .alternate_cost_delivered = 0xFFFFFFFF, \ + .alternate_cost_unit = 0xFF, \ + .alternate_cost_trailing_digit = 0xFF, \ + .number_of_block_thresholds = 0xFF, \ + .price_control = ZB_ZCL_PRICE_DEFAULT_PRICE_CONTROL_VALUE, \ + .number_of_generation_tiers = 0x00, \ + .generation_tier = 0x00, \ + .extended_number_of_price_tiers = 0x00, \ + .extended_price_tier = 0x00, \ + .extended_register_tier = 0x00, \ +} + +/** @brief @ref ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK "PriceAcknowledgement" Command payload + * @see SE spec, D.4.2.3.4.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_ack_payload_s +{ + /** Unique identifier for the commodity provider. */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. + * allows devices to determine which pricing information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** @e UTCTime field containing the current time as determined + * by the device. + */ + zb_uint32_t current_time; /* (M) */ + + /** Identifies additional control options (PriceAcknowledgement policy and + * total number of tier flag). + */ + zb_uint8_t price_control; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_ack_payload_t; + + +/** @cond internals_doc */ + +/** Check if @ref ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK "PriceAcknowledgement" Command payload is valid + */ +#define ZB_ZCL_PRICE_ACK_PAYLOAD_SIZE_IS_VALID(size) \ + ((size) == sizeof(zb_zcl_price_ack_payload_t)) + +/** @ref zb_zcl_price_ack_payload_t initializer */ +#define ZB_ZCL_PRICE_ACK_PAYLOAD_INIT (zb_zcl_price_ack_payload_t) {0} + +/** Initialize @ref zb_zcl_price_ack_payload_t from + * @ref zb_zcl_price_publish_price_payload_t values. + */ +#define ZB_ZCL_PRICE_ACK_PAYLOAD_INIT_FROM_PUBLISH_PRICE_PAYLOAD(pl) \ + (zb_zcl_price_ack_payload_t) { \ + .provider_id = (pl)->provider_id, \ + .issuer_event_id = (pl)->issuer_event_id, \ + .current_time = zb_get_utc_time(), \ + .price_control = (pl)->price_control, \ + } + +/** @endcond */ /* internals_doc */ + + +/** @brief @ref ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES "GetScheduledPrices" Command Payload Format + * @see SE spec, D.4.2.3.3.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_scheduled_prices_payload_s +{ + /** @e StartTime represents the minimum ending time for any scheduled or + * currently active pricing events to be resent. + * @note Value 0x00000000 will be replaced with the current time stamp. + */ + zb_uint32_t start_time; + + /** @e NumberOfEvents represents the maximum number of events to be sent. + * @note Value 0 indicates no maximum limit. + */ + zb_uint8_t number_of_events; +} ZB_PACKED_STRUCT zb_zcl_price_get_scheduled_prices_payload_t; + + +/** @def ZB_ZCL_PRICE_GET_SCHEDULED_PRICES_PAYLOAD_INIT + * @brief Macro for initializing @ref ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES "GetScheduledPrices" Command payload + */ +#define ZB_ZCL_PRICE_GET_SCHEDULED_PRICES_PAYLOAD_INIT \ + (zb_zcl_price_get_scheduled_prices_payload_t) {0} + +/** @def ZB_ZCL_PRICE_GET_SCHEDULED_PRICES_PAYLOAD_SIZE_IS_VALID + * @brief Check if @ref ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES "GetScheduledPrices" Command payload is valid + */ +#define ZB_ZCL_PRICE_GET_SCHEDULED_PRICES_PAYLOAD_SIZE_IS_VALID(size) \ + ((size) == sizeof(zb_zcl_price_get_scheduled_prices_payload_t)) + +/** @brief @ref ZB_ZCL_PRICE_CLI_CMD_GET_CURRENT_PRICE "GetCurrentPrice" Command Payload Format */ +typedef zb_uint8_t zb_zcl_price_get_current_price_payload_t; + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_BLOCK_PERIOD "GetBlockPeriod" command payload + * @see SE spec, subclause D.4.2.3.5 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_block_period_payload_s +{ + /** UTC Timestamp representing the minimum ending time for any scheduled or currently block period + * events to be resent. + */ + zb_uint32_t start_time; /* (M) */ + + /** An 8-bit Integer which indicates the maximum number of Publish Block Period commands + * that can be sent. + */ + zb_uint8_t number_of_events; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. The least significant + * nibble represents an enumeration of the tariff type. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_price_client_get_block_period_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_CONVERSION_FACTOR "GetConversionFactor" command payload. + * @see SE spec, subclause D.4.2.3.6.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_conversion_factor_payload_s +{ + /** UTC Timestamp indicating the earliest start time of values to be returned by the corresponding + * @e PublishConversionFactor command. + * */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of values to be returned by the + * corresponding @e PublishCalorificValue command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit integer which represents the maximum number of @e PublishConversionFactor commands that + * the client is willing to receive in response to this command. A value of 0 indicates no maximum + * limit. + */ + zb_uint8_t number_of_commands; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_conversion_factor_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_CALORIFIC_VALUE "GetCalorificValue" command payload + * @see SE spec, subclause D.4.2.3.7 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_client_get_calorific_value_payload_s +{ + /** UTC Timestamp indicating the earliest start time of values to be returned by the + * corresponding @e PublishCalorificValue command. + * */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of values to be returned by the + * corresponding @e PublishCalorificValue command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit Integer which represents the maximum number of @e PublishCalorificValue commands that the + * client is willing to receive in response to this command. A value of 0 indicates no maximum limit + */ + zb_uint8_t number_of_commands; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_client_get_calorific_value_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_TARIFF_INFORMATION "GetTariffInformation" command payload + * @see SE spec, subclause D.4.2.3.8.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_tariff_information_payload_s +{ + /** UTC Timestamp indicating the earliest start time of tariffs to be returned by the + * corresponding @e PublishTariffInformation command. + */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of tariffs to be returned by the + * corresponding @e PublishTariffInformation command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit integer which represents the maximum number of @e PublishTariffInformation commands that + * the client is willing to receive in response to this command. A value of 0 would indicate all + * available @e PublishTariffInformation commands shall be returned. + */ + zb_uint8_t number_of_commands; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. The least significant + * nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_tariff_information_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_PRICE_MATRIX "GetPriceMatrix" command payload + * @see SE spec, subclause D.4.2.3.9 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_price_matrix_payload_s +{ + /** @e IssuerTariffID indicates the tariff to which the requested Price Matrix belongs. */ + zb_uint32_t issuer_tariff_id; +} ZB_PACKED_STRUCT zb_zcl_price_get_price_matrix_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_BLOCK_THRESHOLDS "GetBlockThresholds" command payload + * @see SE spec, subclause D.4.2.3.10 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_block_thresholds_payload_s +{ + /** @e IssuerTariffID indicates the tariff to which the requested Block + * Thresholds belong. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_block_thresholds_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_CO2_VALUE "GetCO2Value" command payload + * @see SE spec, subclause D.4.2.3.11.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_co2_value_payload_s +{ + /** UTC Timestamp indicating the earliest start time of values to be returned by the corresponding + * @e PublishCO2Value command. The first returned @e PublishCO2Value command shall be the instance + * which is active or becomes active at or after the stated @e EarliestStartTime. If more than one + * instance is requested, the active and scheduled instances shall be sent with ascending ordered + * @e StartTime. + */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of values to be returned by the + * corresponding @e PublishCO2Value command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit Integer which represents the maximum number of @e PublishCO2Value commands that the + * client is willing to receive in response to this command. A value of 0 would indicate all + * available @e PublishCO2Value commands shall be returned. + */ + zb_uint8_t number_of_commands; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. The least significant + * nibble represents an enumeration of the tariff type. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_co2_value_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_TIER_LABELS "GetTierLabels" command payload + * @see SE spec, subclause D.4.2.3.12.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_tier_labels_payload_s +{ + /** Unique identifier generated by the commodity supplier. This is used to + * identify the tariff that the labels apply to. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_tier_labels_payload_t; + +#define ZB_ZCL_PRICE_GET_TIER_LABELS_PAYLOAD_SIZE_IS_VALID(size) \ + ((size) == sizeof(zb_zcl_price_get_tier_labels_payload_t)) + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_BILLING_PERIOD "GetBillingPeriod" command payload + * @see SE spec, subclause D.4.2.3.13.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_billing_period_payload_s +{ + /** UTC Timestamp indicating the earliest start time of billing periods to be + * returned by the corresponding @e PublishBillingPeriod command. + */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of billing + * periods to be returned by the corresponding @e PublishBillingPeriod command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit Integer which indicates the maximum number of @e PublishBillingPeriod commands + * that the client is willing to receive in response to this command. + */ + zb_uint8_t number_of_commands; /* (M) */ + + /** An 8-bit bitmap identifying the @e TariffType of the requested @e BillingPeriod information. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_billing_period_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_CONSOLIDATED_BILL "GetConsolidatedBill" command payload + * @see SE spec, subclause D.4.2.3.14.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_consolidated_bill_payload_s +{ + /** UTC Timestamp indicating the earliest start time of billing information to be + * returned by the corresponding @e PublishConsolidatedBill command. + */ + zb_uint32_t earliest_start_time; /* (M) */ + + /** A 32-bit integer representing the minimum @e IssuerEventID of billing information + * to be returned by the corresponding @e PublishConsolidatedBill command. + */ + zb_uint32_t min_issuer_event_id; /* (M) */ + + /** An 8-bit Integer which indicates the maximum number of @e PublishConsolidatedBill + * commands that can be sent. A value of 0 would indicate all available @e PublishConsolidatedBill + * commands shall be returned. + */ + zb_uint8_t number_of_commands; /* (M) */ + + /** An 8-bit bitmap identifying the @e TariffType of the requested @e BillingPeriod information. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_consolidated_bill_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_CPP_EVENT_RESPONSE "CPPEventResponse" command payload + * @see SE spec, subclause D.4.2.3.15.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_cpp_event_response_payload_s +{ + /** Unique identifier generated by the commodity provider. When new information is provided that + * replaces older information for the same time period, this field allows devices + * to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** An 8-bit enumeration identifying the status of the CPP event. This field shall contain the + * 'Accepted' or 'Rejected' values + * @see SE spec, Table D-113 + * @see zb_zcl_price_cpp_event_status_t + */ + zb_uint8_t cpp_auth; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_cpp_event_response_payload_t; + + +/** @ref ZB_ZCL_PRICE_CLI_CMD_GET_CREDIT_PAYMENT "GetCreditPayment" command payload + * @see SE spec, subclause D.4.2.3.16.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_get_credit_payment_payload_s +{ + /** UTC timestamp indicating the latest @e CreditPaymentDate of records to be returned + * by the corresponding @e PublishCreditPayment commands. The first returned + * @e PublishCreditPayment command shall be the most recent record with its + * @e CreditPaymentDate equal to or older than the @e LatestEndTime provided. + */ + zb_uint32_t latest_end_time; /* (M) */ + + /** An 8-bit integer that represents the maximum number of @e PublishCreditPayment + * commands that the client is willing to receive in response to this command. + */ + zb_uint8_t number_of_commands; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_get_credit_payment_payload_t; + + +/** Block Period Control Field BitMap + * @see SE spec, Table D-104 + * @see zb_zcl_price_publish_block_period_payload_s::block_period_control + */ +typedef enum zb_zcl_price_block_period_control_field_bitmap_e +{ + ZB_ZCL_PRICE_CONTROL_PRICE_ACKNOWLEDGEMENT_REQUIRED = 1 << 0, /**< 1=Price Acknowledgement required,@n + * 0=Price Acknowledgement not required + */ + ZB_ZCL_PRICE_CONTROL_REPEATING_BLOCK = 1 << 1, /**< 1=Repeating Block, @n + * 0=Non Repeating Block + */ +} zb_zcl_price_block_period_control_field_t; + + +/** @brief Block Period Duration Control Enumeration + * @see SE spec, Table D-106 + */ +typedef enum zb_zcl_price_block_period_duration_control_e +{ + ZB_ZCL_PRICE_DURATION_START_OF_TIMEBASE = 0x00, /**< Start of Timebase */ + ZB_ZCL_PRICE_DURATION_END_OF_TIMEBASE, /**< End of Timebase */ + ZB_ZCL_PRICE_DURATION_NOT_SPECIFIED /**< Not Specified */ +} zb_zcl_price_block_period_duration_control_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BLOCK_PERIOD "PublishBlockPeriod" command payload + * @see SE spec, subclause D.4.2.4.2.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_block_period_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity provider. + * This field allows differentiation in deregulated markets where multiple + * commodity providers may be available. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new block period + * information is provided that replaces older information for the same period, + * this field allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the block tariff period starts. + */ + zb_uint32_t block_period_start_time; /* (M) */ + + /** An unsigned 24-bit field to denote the block tariff period . + */ + zb_uint24_t block_period_duration; /* (M) */ + + /** Identifies additional control options for the block period event. A value of + * 0x00 indicates field not used. + */ + zb_uint8_t block_period_control; + + /** An 8-bit bitmap where the least significant nibble is an enumerated sub-field + * indicating the time base used for the duration, and the most significant nibble + * is an enumerated sub-field providing duration control. + * @see zb_zcl_price_block_period_duration_type_e + */ + zb_uint8_t block_period_duration_type; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ + + /** An 8-bit enumeration identifying the resolution period for the block tariff. + * @see SE spec, Table D-107 + * @see zb_zcl_price_tariff_resolution_period_t + */ + zb_uint8_t tariff_resolution_period; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_block_period_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CONVERSION_FACTOR "PublishConversionFactor" comamdn payload + * @see SE spec, subclause D.4.2.4.3.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_conversion_factor_payload_s +{ + + /** Unique identifier generated by the commodity provider. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the value becomes valid. + * The value remains valid until replaced by a newer one. + */ + zb_uint32_t start_time; /* (M) */ + + /** @see SE spec, subclause D.4.2.2.4.3 */ + zb_uint32_t conversion_factor; /* (M) */ + + /** @see SE spec, subclause D.4.2.2.4.4 */ + zb_uint8_t conversion_factor_trailing_digit; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_conversion_factor_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CALORIFIC_VALUE "PublishCalorificValue" command payload + * @see SE spec, subclause D.4.2.4.4. + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_calorific_value_payload_s +{ + + /** Unique identifier generated by the commodity provider. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the value becomes valid. + * The value remains valid until replaced by a newer one. + */ + zb_uint32_t start_time; /* (M) */ + + /** @see sub-clause D.4.2.2.4.5 + */ + zb_uint32_t calorific_value; /* (M) */ + + /** @see sub-clause D.4.2.2.4.6 + */ + zb_uint8_t calorific_value_unit; /* (M) */ + + /** @see sub-clause D.4.2.2.4.7 + */ + zb_uint8_t calorific_value_trailing_digit; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_calorific_value_payload_t; + + +/** Tariff Type Enumeration + * @see SE spec, Table D-108 + */ +typedef enum zb_zcl_price_tariff_type_e +{ + ZB_ZCL_PRICE_TARIFF_TYPE_DELIVERED = 0x00, /**< Delivered Tariff */ + ZB_ZCL_PRICE_TARIFF_TYPE_RECEIVED, /**< Received Tariff */ + ZB_ZCL_PRICE_TARIFF_TYPE_DELIVERED_AND_RECEIVED, /**< Delivered and Received Tariff */ +} zb_zcl_price_tariff_type_t; + + +/** Tariff Charging Scheme Enumeration + * @see SE spec, Table D-109 + */ +typedef enum zb_zcl_price_tariff_charging_scheme_e +{ + ZB_ZCL_PRICE_TOU_TARIFF = 0x00, /**< TOU Tariff */ + ZB_ZCL_PRICE_BLOCK_TARIFF, /**< Block Tariff */ + ZB_ZCL_PRICE_BLOCK_TOU_TARIFF_COMMON, /**< Block/TOU Tariff with common thresholds */ + ZB_ZCL_PRICE_BLOCK_TOU_TARIFF_INDIVIDUAL, /**< Block/TOU Tariff with individual thresholds per tier */ +} zb_zcl_price_tariff_charging_scheme_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TARIFF_INFORMATION "PublishTariffInformation" command payload + * @see SE spec, subclause D.4.2.4.5.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_tariff_information_payload_s +{ + + + /** A unique identifier for the commodity supplier. */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** Unique identifier generated by the commodity supplier. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ + + /** A UTC Time field to denote the time at which the price signal becomes valid. + */ + zb_uint32_t start_time; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type, + * the most significant nibble represents an enumeration specifying the charging + * scheme. + * @see SE spec, Table D-108 and Table D-109 + * @see zb_zcl_price_tariff_type_t + * @see zb_zcl_price_tariff_charging_scheme_e + */ + zb_uint8_t tariff_type_charging_scheme; /* (M) */ + + /** The format and use of this field is the same as for the @e TariffLabel attribute + * or @e ReceivedTariffLabel attribute + */ + zb_uint8_t tariff_label[25]; /* (M) */ + + /** The format and use of this field is the same as for the @e NumberOfPriceTiersInUse + * attribute or @e ReceivedNumberOfPriceTiersInUse attribute + */ + zb_uint8_t number_of_price_tiers_in_use; /* (M) */ + + /** The format and use of this field is the same as for the @e NumberOfBlockThresholdsInUse + * attribute or @e ReceivedNumberOfBlockThresholdsInUse attribute + */ + zb_uint8_t number_of_block_thresholds_in_use; /* (M) */ + + /** The format and use of this field is the same as for the @e UnitOfMeasure attribute + */ + zb_uint8_t unit_of_measure; /* (M) */ + + /** The format and use of this field is the same as for the @e Currencyattribute + */ + zb_uint16_t currency; /* (M) */ + + /** The format and use of this field is the same as for the @e PriceTrailingDigit + * attribute + */ + zb_uint8_t price_trailing_digit; /* (M) */ + + /** The format and use of this field is the same as for the @e StandingCharge + * attribute. A value of 0xFFFFFFFF indicates the field is not used + */ + zb_uint32_t standing_charge; /* (M) */ + + /** The format and use of this field is the same as for the @e TierBlockMode + * attribute or @e ReceivedTierBlockMode attribute + */ + zb_uint8_t tier_block_mode; /* (M) */ + + /** @e BlockThresholdMultiplier provides a value to be multiplied against Threshold + * parameter(s). If present, this attribute must be applied to all @e BlockThreshold + * values to derive values that can be compared against the @e CurrentBlockPeriodConsumptionDelivered + * attribute within the Metering cluster. This parameter must be used in conjunction + * with the @e BlockThresholdDivisor parameter(s). + */ + zb_uint24_t block_threshold_multiplier; /* (M) */ + + /** @e BlockThresholdDivisor provides a value to divide the result of applying the + * @e ThresholdMultiplier attribute to @e BlockThreshold values to derive values that + * can be compared against the @e CurrentBlockPeriodConsumptionDelivered attribute + * within the Metering cluster. This attribute must be used in conjunction with + * the @e BlockThresholdMultiplier parameter(s). In case no divisor is defined, + * this field shall be set to 1. + */ + zb_uint24_t block_threshold_devisor; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_tariff_information_payload_t; + + +/** PublishPriceMatrix and PublishBlockThresholds Sub-Payload Control Bitmap + * @see SE spec, Table D-110 + * @see SE spec, Table D-111 + * @see zb_zcl_price_publish_matrix_type_e + * @see zb_zcl_price_publish_block_thresholds_type_e + */ +enum zb_zcl_price_sub_payload_control_bitmap_e +{ + ZB_ZCL_PRICE_SUB_PAYLOAD_TYPE = 0, /**< 0-bit of bitfield */ +}; + + +/** PublishPriceMatrix Sub-Payload Control values. + * @see SE spec, Table D-110 + * @see zb_zcl_price_sub_payload_control_bitmap_e + */ +typedef enum zb_zcl_price_publish_matrix_type_e +{ + ZB_ZCL_PRICE_BLOCK_TOU_BASED_INFORMATION = 0x00, /**< The information stored in the + * sub payload is Block only or Block/TOU based + */ + ZB_ZCL_PRICE_TOU_BASED_INFORMATION = 0x01, /**< The information stored in the sub + * payload is TOU based. + */ +} zb_zcl_price_publish_matrix_type_t; + + +/** PriceMatrix Sub-Payload + * @see SE spec, subclause D.4.2.4.6.2.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_price_matrix_sub_payload_s +{ + /** The @e Tier/Block ID specifies the TOU Tier or the TOU Tier and Block that + * the subsequent @e Price field in the command applies to + */ + zb_uint8_t tier_block_id; /* (M) */ + + /** This field holds the price information for the Block/TOU or TOU identified + * by the previous @e Tier/Block @e ID field. + */ + zb_uint32_t price; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_price_matrix_sub_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_PRICE_MATRIX "PublishPriceMatrix" command payload + * @see SE spec, subclause D.4.2.4.6.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_price_matrix_payload_s +{ + /** A unique identifier for the commodity supplier. */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the price signal becomes valid. + */ + zb_uint32_t start_time; /* (M) */ + + + /** Unique identifier generated by the commodity supplier. This must match the + * @e IssuerTariffID sent in the related @e PublishTariffInformation command. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ + + /** The @e CommandIndex is used to count the payload fragments in the case that + * an entire payload does not fit into one message. The @e CommandIndex starts + * at 0 and is incremented for each fragment belonging to the same command. + */ + zb_uint8_t command_index; /* (M) */ + + /** In the case that an entire payload does not fit into one message, the + * @e TotalNumberOfCommands field indicates the total number of sub-commands + * in the message. + */ + zb_uint8_t total_number_of_commands; /* (M) */ + + /** An 8-bit bitmap, the least significant bit of which specifies the information + * type stored in the sub payload. The remaining bits are reserved. + */ + zb_uint8_t sub_payload_control; /* (M) */ + + /** @see zb_zcl_price_price_matrix_sub_payload_s + */ + zb_zcl_price_price_matrix_sub_payload_t *price_matrix_sub_payload; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_price_matrix_payload_t; + + +/** PublishBlockThresholds Sub-Payload Control values + * @see SE spec, Table D-111 + * @see zb_zcl_price_sub_payload_control_bitmap_e + */ +typedef enum zb_zcl_price_publish_block_thresholds_type_e +{ + ZB_ZCL_PRICE_SPECIFIC_TOU_TIER = 0x00, /**< Block Thresholds supplied + * apply to a specific TOU tier + */ + ZB_ZCL_PRICE_ALL_TOU_TIER = 0X01, /**< Block Thresholds supplied apply to + * all TOU tiers or when Block Only charging + * is in operation + */ +} zb_zcl_price_publish_block_thresholds_type_t; + + +/** BlockThreshold Sub-Payload Format + * @see SE spec, subclause D.4.2.4.7.2.1 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_block_threshold_sub_payload_s +{ + /** The Tier/NumberOfBlockThresholds field is an 8 bitmap. The format of the + * bitmap is decided by bit0 of the sub-payload control field. + * @n If Bit0 of the Sub-Payload Control field is 0, then the least significant + * nibble represents a value specifying the number of thresholds to follow in + * the command. The most significant nibble represents the Tier that the subsequent + * block threshold values apply to. + * @n If Bit0 of the Sub-Payload Control field is 1, then the most significant + * nibble is unused and should be set to 0. + * @n Valid values for the NumberOfBlockThresholds sub-field are 0 to 15 + * reflecting no block in use (0) to block 15(15). + * Valid values for the Tiers sub-field are from 0 to 15 reflecting no tier to tier + * fifteen. + */ + zb_uint8_t tier_number_of_block_thresholds; + + /** The Block Thresholds represent the threshold values applicable to an + * individual block period and, where applicable, to a particular tier. + */ + zb_uint48_t block_threshold[15]; +} ZB_PACKED_STRUCT zb_zcl_price_block_threshold_sub_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BLOCK_THRESHOLDS "PublishBlockThresholds" command payload + * @see SE spec, subclause D.4.2.4.7.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_block_thresholds_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this + * field allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the price signal becomes valid. + */ + zb_uint32_t start_time; /* (M) */ + + /** Unique identifier generated by the commodity supplier. This must match the + * @e IssuerTariffID sent in the related @e PublishTariffInformation command. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ + + /** The @e CommandIndex is used to count the payload fragments in the case where + * the entire payload does not fit into one message. The @e CommandIndex starts + * at 0 and is incremented for each fragment belonging to the same command. + */ + zb_uint8_t command_index; /* (M) */ + + /** In the case where the entire payload does not fit into one message, the + * @e TotalNumberOfCommands field indicates the total number of sub-commands + * in the message. + */ + zb_uint8_t total_number_of_commands; /* (M) */ + + /** The Sub-Payload Control bitmap specifies the usage of the information contained + * within the Block Threshold Sub-Payload. + * @see zb_zcl_price_publish_block_thresholds_sub_payload_control_bitmap_e + */ + zb_uint8_t sub_payload_control; /* (M) */ + + /** The BlockThreshold Sub-Payload consists of multiple sets of data which + * consist of a @e TierID, @e BlockThresholdCount and the threshold values + * associated with the stated Tier. + * @see zb_zcl_price_block_threshold_sub_payload_t + */ + zb_zcl_price_block_threshold_sub_payload_t *block_threshold_sub_payload; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_block_thresholds_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CO2_VALUE "PublishCO2Value" command payload + * @see SE spec, subclause D.4.2.4.8.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_co2_value_payload_s +{ + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the @e CO2 value becomes valid. + */ + zb_uint32_t start_time; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ + + /** The format and use of this field is the same as for the @e CO2 attribute or + * @e ReceivedCO2 attribute . A value of 0xFFFFFFFF indicates field not used. + */ + zb_uint32_t co2_value; /* (M) */ + + /** The format and use of this field is the same as for the @e CO2Unit attribute + * or @e ReceivedCO2Unit attribute. A value of 0xFF indicates field not used. + */ + zb_uint8_t co2_value_unit; /* (M) */ + + /** The format and use of this field is the same as for the @e CO2TrailingDigit + * attribute or @e ReceivedCO2TrailingDigit attribute. + * A value of 0xFF indicates field not used. + */ + zb_uint8_t co2_value_trailing_digit; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_co2_value_payload_t; + + +/** @see SE spec, subclause D.4.2.4.9.2 + * @see zb_zcl_price_publish_tier_labels_payload_t::tier_labels + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_tier_labels_sub_payload_s +{ + /** The tier number that the associated @e TierLabel applies to. */ + zb_uint8_t tier_id; /* (M) */ + + /** Octet String field capable of storing a 12 character string (the first + * character indicates the string length, represented in hexadecimal format) + * encoded in the UTF-8 format. + */ + zb_uint8_t tier_label[13]; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_tier_labels_sub_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TIER_LABELS "PublishTierLabels" command payload + * @see SE spec, subclause D.4.2.4.9.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_tier_labels_payload_s +{ + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** Unique identifier generated by the commodity supplier. This is used to + * identify the tariff that the labels apply to. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ + + /** The @e CommandIndex is used to count the payload fragments in the case where + * the entire payload does not fit into one message. The @e CommandIndex starts + * at 0 and is incremented for each fragment belonging to the same command. + */ + zb_uint8_t command_index; /* (M) */ + + /** In the case where the entire payload does not fit into one message, the + * @e TotalNumberOfCommands field indicates the total number of sub-commands + * in the message. + */ + zb_uint8_t total_number_of_commands; /* (M) */ + + /** The number of @e TierID/Tier Label sets contained within the command. + */ + zb_uint8_t number_of_labels; /* (M) */ + + /** @see zb_zcl_price_publish_tier_labels_sub_payload_t */ + zb_zcl_price_publish_tier_labels_sub_payload_t *tier_labels; + +} ZB_PACKED_STRUCT zb_zcl_price_publish_tier_labels_payload_t; + + +/** Check if @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TIER_LABELS "PublishTierLabels" command payload size is valid + * @param size - size of received data payload + */ +#define ZB_ZCL_PRICE_PUBLISH_TIER_LABELS_PAYLOAD_SIZE_IS_VALID(size) \ + ((size >= (sizeof(zb_zcl_price_publish_tier_labels_payload_t)-sizeof(zb_void_t *)) ? ZB_TRUE : ZB_FALSE)) + + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_BILLING_PERIOD "PublishBillingPeriod" command payload + * @see SE spec, D.4.2.4.10 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_billing_period_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information is + * provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the billing period starts. + */ + zb_uint32_t billing_period_start_time; /* (M) */ + + /** An unsigned 24-bit field to denote the billing period duration. The + * duration units are defined by the @e BillingPeriodDurationType field. + */ + zb_uint24_t billing_period_duration; /* (M) */ + + /** An 8-bit bitmap where the least significant nibble is an enumerated + * sub-field indicating the time base used for the duration, and the most + * significant nibble is an enumerated sub-field providing duration control. + * @see zb_zcl_price_block_period_duration_type_t + * @see zb_zcl_price_block_period_duration_control_t + */ + zb_uint8_t billing_period_duration_type; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see zb_zcl_price_block_period_duration_control_t + */ + zb_uint8_t tariff_type; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_billing_period_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CONSOLIDATED_BILL "PublishConsolidatedBill" command payload + * @see SE spec, subclause D.4.2.4.11.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_consolidated_bill_payload_s +{ + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field containing the start time of the related billing period. + */ + zb_uint32_t billing_period_start_time; /* (M) */ + + /** An unsigned 24-bit field denoting the duration of the related billing period. + */ + zb_uint24_t billing_period_duration; /* (M) */ + + /** An 8-bit bitmap where the least significant nibble is an enumerated sub-field + * indicating the time base used for the duration, and the most significant nibble + * is an enumerated sub-field providing duration control. + * @see SE spec, Table D-105, Table D-106 + */ + zb_uint8_t billing_period_duration_type; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ + + /** An unsigned 32-bit field containing the consolidated bill value for the + * stated billing period. + */ + zb_uint32_t consolidated_bill; /* (M) */ + + /** An unsigned 16-bit field containing identifying information concerning the + * local unit of currency used in the @e ConsolidatedBill field. + */ + zb_uint16_t currency; /* (M) */ + + /** An 8-bit field used to determine where the decimal point is located in the + * @e ConsolidatedBill field. + */ + zb_uint8_t bill_trailing_digit; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_consolidated_bill_payload_t; + + +/** CPP Auth Enumeration + * @see SE spec, Table D-112 + */ +typedef enum zb_zcl_price_cpp_price_tier_e +{ + ZB_ZCL_PRICE_CPP_PRICE_TIER_CPP1 = 0, /**< CPP1 */ + ZB_ZCL_PRICE_CPP_PRICE_TIER_CPP2 = 1, /**< CPP2 */ +} zb_zcl_price_cpp_price_tier_t; + + +/** CPP Auth Enumeration + * @see SE spec, Table D-113 + */ +typedef enum zb_zcl_price_cpp_event_status_e +{ + ZB_ZCL_PRICE_CPP_EVENT_STATUS_PENDING = 0, /**< Pending */ + ZB_ZCL_PRICE_CPP_EVENT_STATUS_ACCEPTED, /**< Accepted */ + ZB_ZCL_PRICE_CPP_EVENT_STATUS_REJECTED, /**< Rejected */ + ZB_ZCL_PRICE_CPP_EVENT_STATUS_FORCED, /**< Forced */ +} zb_zcl_price_cpp_event_status_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CPP_EVENT "PublishCPPEvent" command payload + * @see SE spec, subclause D.4.2.4.12.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_cpp_event_payload_s +{ + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the CPP event begins. A start + * date/time of 0x00000000 shall indicate that the command should be executed + * immediately. + */ + zb_uint32_t start_time; /* (M) */ + + + /** Defines the duration of the CPP event. + */ + zb_uint16_t duration_in_minutes; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff published in this command. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ + + /** An 8-bit enumeration identifying the price tier associated with this CPP event. + * The price(s) contained in the active price matrix for that price tier will override + * the normal pricing scheme. + * @see zb_zcl_price_cpp_price_tier_t + */ + zb_uint8_t cpp_price_tier; /* (M) */ + + /** An 8-bit enumeration identifying the status of the CPP event. + * @see zb_zcl_price_cpp_event_status_t + */ + zb_uint8_t cpp_auth; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_cpp_event_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CREDIT_PAYMENT "PublishCreditPayment" command payload. + * @see SE spec, subclause D.4.2.4.13.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_credit_payment_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this field + * allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field containing the time that the next credit payment is due. */ + zb_uint32_t credit_payment_due_date; /* (M) */ + + /** An unsigned 32-bit field denoting the current amount this is overdue from + * the consumer. This field should be provided in the same currency as used in + * the Price cluster. + */ + zb_uint32_t credit_payment_overdue_amount; /* (M) */ + + /** An 8-bit enumeration identifying the current credit payment status. + */ + zb_uint8_t credit_payment_status; /* (M) */ + + /** An unsigned 32-bit field denoting the last credit payment. This field should + * be provided in the same currency as used in the Price cluster. + */ + zb_uint32_t credit_payment; /* (M) */ + + /** A @e UTCTime field containing the time at which the last credit payment + * was made. + */ + zb_uint32_t credit_payment_date; /* (M) */ + + /** An string of between 0-20 octets used to denote the last credit payment + * reference used by the energy supplier. + */ + zb_uint8_t credit_payment_ref[21]; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_credit_payment_payload_t; + + +/** Currency Change Control Enumeration + * @see SE spec, Table D-114 + */ +typedef enum zb_zcl_price_currency_change_control_e +{ + ZB_ZCL_PRICE_CLEAR_BILLING_INFORMATION = 1 << 0, /**< 1 = Clear Billing Information + * @n 0 = Do Not Clear Billing Information + */ + ZB_ZCL_PRICE_CONVERT_BILLING_INFORMATION = 1 << 1, /**< 1 = Convert Billing Information using the New Currency + * @n 0 = Do Not Convert Billing Information + */ + ZB_ZCL_PRICE_CLEAR_OLD_CONSUMPTION_DATA = 1 << 2, /**< 1 = Clear Old Consumption Data + * @n 0 = Do Not Clear Old Consumption Data + */ + ZB_ZCL_PRICE_CONVERT_OLD_CONSUMPTION_DATA = 1 << 3, /**< 1 = Convert Old Consumption Data using the New Currency + * @n 0 = Do Not Convert Old Consumption Data + */ +} zb_zcl_price_currency_cghange_control_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_CURRENCY_CONVERSION "PublishCurrencyConversion" command payload. + * @see SE spec, subclause D.4.2.4.14.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_publish_currency_conversion_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity provider. When new information + * is provided that replaces older information for the same time period, this + * field allows devices to determine which information is newer. + */ + zb_uint32_t issuer_event_id; /* (M) */ + + /** A @e UTCTime field to denote the time at which the new currency becomes valid. + */ + zb_uint32_t start_time; /* (M) */ + + /** An unsigned 16-bit field containing identifying information concerning the + * old local unit of currency used in the Price cluster. + */ + zb_uint16_t old_currency; /* (M) */ + + /** An unsigned 16-bit field containing identifying information concerning the + * new local unit of currency used in the Price cluster. The value of the @e NewCurrency + * field should match the values defined by ISO 4217. + */ + zb_uint16_t new_currency; /* (M) */ + + /** The format and use of this field is the same as for the @e ConversionFactor + * attribute as defined in D.4.2.2.4.3. + */ + zb_uint32_t conversion_factor; /* (M) */ + + /** The format and use of this field is the same as for the + * @e ConversionFactorTrailingDigit attribute as defined in D.4.2.2.4.4. + */ + zb_uint8_t conversion_factor_trailing_digit; /* (M) */ + + /** A 32-bit mask that denotes the functions that are required to be carried + * out on processing of this command. + */ + zb_uint32_t currency_change_control_flags; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_publish_currency_conversion_payload_t; + + +/** @ref ZB_ZCL_PRICE_SRV_CMD_CANCEL_TARIFF "CancelTariff" command payload + * @see SE spec, subclause D.4.2.4.15.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_price_cancel_tariff_payload_s +{ + + /** An unsigned 32-bit field containing a unique identifier for the commodity + * provider. + */ + zb_uint32_t provider_id; /* (M) */ + + /** Unique identifier generated by the commodity Supplier. All parts of a tariff + * instance shall have the same @e IssuerTariffID. + */ + zb_uint32_t issuer_tariff_id; /* (M) */ + + /** An 8-bit bitmap identifying the type of tariff to be cancelled by this command. + * The least significant nibble represents an enumeration of the tariff type. + * The most significant nibble is reserved. + * @see SE spec, Table D-108 + * @see zb_zcl_price_tariff_type_t + */ + zb_uint8_t tariff_type; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_price_cancel_tariff_payload_t; + + +/** @cond internals_doc */ +/** @def ZB_ZCL_PRICE_GET_REQUESTOR_RX_ON_WHEN_IDLE + * @brief Macro for getting Requestor RX on When Idle state. + * @param x - zb_zcl_price_get_current_price_payload_t value. + */ +#define ZB_ZCL_PRICE_GET_REQUESTOR_RX_ON_WHEN_IDLE(x) ZB_CHECK_BIT_IN_BIT_VECTOR(x, 0) + +/** @def ZB_ZCL_PRICE_SET_REQUESTOR_RX_ON_WHEN_IDLE + * @brief Macro for setting Requestor RX on When Idle state. + * @param x - zb_zcl_price_get_current_price_payload_t value. + */ +#define ZB_ZCL_PRICE_SET_REQUESTOR_RX_ON_WHEN_IDLE(x) ZB_SET_BIT_IN_BIT_VECTOR(x, 0) +/** @endcond */ /* internals_doc */ + +/** @def ZB_ZCL_PRICE_SEND_CMD_GET_CURRENT_PRICE + * @brief Macro for sending @ref ZB_ZCL_PRICE_CLI_CMD_GET_CURRENT_PRICE "GetCurrentPrice" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _rx_on_when_idle - Helps to determine publishing + * policy for the server, (see SE spec, subclause D.4.2.3.2.1.1) + */ +#define ZB_ZCL_PRICE_SEND_CMD_GET_CURRENT_PRICE( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _rx_on_when_idle) \ + zb_zcl_price_send_cmd_get_current_price( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _rx_on_when_idle, NULL) + +/** @def ZB_ZCL_PRICE_SEND_CMD_GET_SCHEDULED_PRICES + * @brief Macro for sending @ref ZB_ZCL_PRICE_CLI_CMD_GET_SCHEDULED_PRICES "GetScheduledPrices" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _payload - Packet payload (@ref + * zb_zcl_price_get_scheduled_prices_payload_t). + */ +#define ZB_ZCL_PRICE_SEND_CMD_GET_SCHEDULED_PRICES( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload) \ + zb_zcl_price_send_cmd_get_scheduled_prices( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + +/** @def ZB_ZCL_PRICE_SEND_CMD_PUBLISH_PRICE + * @brief Macro for sending @ref ZB_ZCL_PRICE_SEND_CMD_PUBLISH_PRICE "PublishPrice" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _payload - Packet payload (@ref zb_zcl_price_publish_price_payload_t). + */ +#define ZB_ZCL_PRICE_SEND_CMD_PUBLISH_PRICE( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload) \ + zb_zcl_price_send_cmd_publish_price( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + + +/** @def ZB_ZCL_PRICE_SEND_CMD_GET_TIER_LABELS + * @brief Macro for sending @ref ZB_ZCL_PRICE_CLI_CMD_GET_TIER_LABELS "GetTierLabels" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _payload - Packet payload (ref to @ref zb_zcl_price_get_tier_labels_payload_t). + */ +#define ZB_ZCL_PRICE_SEND_CMD_GET_TIER_LABELS(_param, _dst_addr, _dst_addr_mode, \ + _dst_ep, _src_ep, _payload) \ + zb_zcl_price_send_cmd_get_tier_labels(_param, _dst_addr, _dst_addr_mode, \ + _dst_ep, _src_ep, _payload, NULL) + + +/** @def ZB_ZCL_PRICE_SEND_CMD_PUBLISH_TIER_LABELS + * @brief Macro for sending @ref ZB_ZCL_PRICE_SRV_CMD_PUBLISH_TIER_LABELS "PublishTierLabels" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _payload - Packet payload (ref to @ref zb_zcl_price_publish_tier_labels_payload_t). + */ +#define ZB_ZCL_PRICE_SEND_CMD_PUBLISH_TIER_LABELS(_param, _dst_addr, _dst_addr_mode, \ + _dst_ep, _src_ep, _payload) \ + zb_zcl_price_send_cmd_publish_tier_labels(_param, _dst_addr, _dst_addr_mode, \ + _dst_ep, _src_ep, _payload, NULL) + + +/** @cond internals_doc */ +/** @def ZB_ZCL_PRICE_SEND_CMD_PRICE_ACK + * @brief Macro for sending @ref ZB_ZCL_PRICE_CLI_CMD_PRICE_ACK "PriceAcknowledgement" command. + * @param _param - Reference to buffer. + * @param _dst_addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _src_ep - Current endpoint. + * @param _payload - Packet payload (@ref zb_zcl_price_ack_payload_t). + */ +#define ZB_ZCL_PRICE_SEND_CMD_PRICE_ACK( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload) \ + zb_zcl_price_send_cmd_price_ack( \ + _param, _dst_addr, _dst_addr_mode, _dst_ep, _src_ep, _payload, NULL) + + +zb_void_t zb_zcl_price_send_cmd_publish_price(zb_uint8_t param, const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, + const zb_zcl_price_publish_price_payload_t *payload, + zb_callback_t cb); + +zb_void_t zb_zcl_price_send_cmd_get_current_price(zb_uint8_t param, const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, zb_uint8_t rx_on_when_idle, + zb_callback_t cb); + +zb_void_t zb_zcl_price_send_cmd_price_ack(zb_uint8_t param, const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, + zb_uint8_t dst_ep, zb_uint8_t src_ep, + const zb_zcl_price_ack_payload_t *payload, + zb_callback_t cb); + +zb_void_t zb_zcl_price_send_cmd_get_scheduled_prices(zb_uint8_t param, const zb_addr_u *dst_addr, + enum zb_aps_addr_mode_e dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, + const zb_zcl_price_get_scheduled_prices_payload_t *payload, + zb_callback_t cb); + + +zb_void_t zb_zcl_price_send_cmd_get_tier_labels(zb_uint8_t param, zb_addr_u *dst_addr, + zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, + zb_zcl_price_get_tier_labels_payload_t *payload, + zb_callback_t cb); + + +zb_void_t zb_zcl_price_send_cmd_publish_tier_labels(zb_uint8_t param, zb_addr_u *dst_addr, + zb_aps_addr_mode_t dst_addr_mode, zb_uint8_t dst_ep, + zb_uint8_t src_ep, + zb_zcl_price_publish_tier_labels_payload_t *payload, + zb_callback_t cb); + +/** @endcond */ /* internals_doc */ + + +/** @} */ /* end of ZB_ZCL_PRICE_CLUSTER_COMMANDS */ + +/** @cond internals_doc */ +/*** Internal handler for Price Cluster commands */ + +zb_void_t zb_zcl_price_init_server(void); +zb_void_t zb_zcl_price_init_client(void); +#define ZB_ZCL_CLUSTER_ID_PRICE_SERVER_ROLE_INIT zb_zcl_price_init_server +#define ZB_ZCL_CLUSTER_ID_PRICE_CLIENT_ROLE_INIT zb_zcl_price_init_client + +/** @endcond */ /* internals_doc */ + +/** @} */ /* Price cluster */ +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* ! defined ZB_ZCL_PRICE_H */ diff --git a/zboss/include/zcl/zb_zcl_rel_humidity_measurement.h b/zboss/include/zcl/zb_zcl_rel_humidity_measurement.h new file mode 100644 index 0000000000..4d09974cca --- /dev/null +++ b/zboss/include/zcl/zb_zcl_rel_humidity_measurement.h @@ -0,0 +1,178 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Relative Humidity Measurement cluster defintions +*/ + +#ifndef ZB_ZCL_REL_HUMIDITY_MEASUREMENT_H +#define ZB_ZCL_REL_HUMIDITY_MEASUREMENT_H 1 + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_WATER_CONTENT_MEASUREMENT + * @{ + */ + +/* Cluster ZB_ZCL_WATER_CONTENT_MEASUREMENT */ + +/*! @name Water Content Measurement cluster attributes + @{ +*/ + +/*! @brief Water Content Measurement cluster attribute identifiers + @see ZCL specification revision 7, Relative Humidity MeasuremenWater Content Measurement Cluster 4.7.2.1 +*/ +enum zb_zcl_rel_humidity_measurement_attr_e +{ + /** @brief MeasuredValue, ZCL specification revision 7 subsection 4.7.2.1.1 MeasuredValue Attribute */ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID = 0x0000, + /** @brief MinMeasuredValue, ZCL specification revision 7 subsection 4.7.2.1.2 MinMeasuredValue Attribute*/ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID = 0x0001, + /** @brief MaxMeasuredValue, ZCL specification revision 7 subsection 4.7.2.1.3 MaxMeasuredValue Attribute*/ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_ID = 0x0002, + /** The Tolerance attribute SHALL indicate the magnitude of the + * possible error that is associated with MeasuredValue, using + * the same units and resolution. + * @brief Tolerance, ZCL specification revision 7 subsection 4.7.2.1.4 Tolerance Attribute + */ + ZB_ZCL_ATTR_REL_HUMIDITY_TOLERANCE_ID = 0x0003, +}; + +/** @brief MeasuredValue attribute unknown value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_UNKNOWN 0xFFFF + +/** @brief MinMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_MIN_VALUE 0x0000 + +/** @brief MinMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_MAX_VALUE 0x270F + +/** @brief MinMeasuredValue attribute undefined value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_UNDEFINED 0xFFFF + +/** @brief MaxMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_MIN_VALUE 0x0001 + +/** @brief MaxMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_MAX_VALUE 0x2710 + +/** @brief MaxMeasuredValue attribute value not defined */ +#define ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_UNDEFINED 0xFFFF + +/** @brief Default value for MeasurementValue attribute */ +#define ZB_ZCL_REL_HUMIDITY_MEASUREMENT_VALUE_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for MeasurementMinValue attribute */ +#define ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for MeasurementMaxValue attribute */ +#define ZB_ZCL_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @cond internals_doc */ +/*! @internal @name Relative Humidity Measurement cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_ZCL_REL_HUMIDITY_MEASUREMENT_REPORT_ATTR_COUNT 1 + +/*! @} */ /* Relative Humidity Measurement cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Relative Humidity Measurement cluster - server side + @param attr_list - attribute list name + @param value - pointer to variable to store MeasuredValue attribute + @param min_value - pointer to variable to store MinMeasuredValue attribute + @param max_value - pointer to variable to store MAxMeasuredValue attribute +*/ +#define ZB_ZCL_DECLARE_REL_HUMIDITY_MEASUREMENT_ATTRIB_LIST(attr_list, \ + value, min_value, max_value) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_VALUE_ID, (value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MIN_VALUE_ID, (min_value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_REL_HUMIDITY_MEASUREMENT_MAX_VALUE_ID, (max_value)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Relative Humidity Measurement cluster attributes */ + +/*! @name Relative Humidity Measurement cluster commands + @{ +*/ + +/*! @} */ /* Relative Humidity Measurement cluster commands */ + +/*! @} */ /* ZCL Relative Humidity Measurement cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_rel_humidity_init_server(void); +zb_void_t zb_zcl_rel_humidity_init_client(void); +#define ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT_SERVER_ROLE_INIT zb_zcl_rel_humidity_init_server +#define ZB_ZCL_CLUSTER_ID_REL_HUMIDITY_MEASUREMENT_CLIENT_ROLE_INIT zb_zcl_rel_humidity_init_client + +#endif /* ZB_ZCL_REL_HUMIDITY_MEASUREMENT_H */ diff --git a/zboss/include/zcl/zb_zcl_reporting.h b/zboss/include/zcl/zb_zcl_reporting.h new file mode 100644 index 0000000000..7f31ff3635 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_reporting.h @@ -0,0 +1,317 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Zigbee cluster library definitions for reporting functionality +*/ + +#ifndef ZB_ZCL_REPORTING_H +#define ZB_ZCL_REPORTING_H 1 + +#if !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** + * @addtogroup ZB_ZCL_REPORTING + * @{ + * @details + * ZCL attribute reporting being described in ZCL spec, subclauses 2.4.7 through 2.4.11, and + * subclauses covering clusters with reportable attributes. + * + * API for attribute reporting configuring and configuration details reading documented in: @ref + * cfg_reporting_cmd, and @ref report_attr_cmd respectively. + * + * Since all events related to attribute reporting are being handled internally, application can + * be provided with information on attribute report receipt event, and attribute report not + * received within predefined interval event. To handle these events, application may set + * "report attribute" and "no reporting" callbacks with @ref ZB_ZCL_SET_REPORT_ATTR_CB() and + * @ref ZB_ZCL_SET_NO_REPORTING_CB() macros respectively. + * + * @par Example + * @snippet light_sample/dimmable_light/bulb.c zb_zcl_set_report_attr_cb + * @snippet light_sample/dimmable_light/bulb.c zb_zcl_set_report_attr_cb_example + * @par + * + * For more information see light_sample/dimmable_light sample + */ + +/* Boundary and default values are defined by application profile */ + +/*! Default value for minimum reporting interval */ +#define ZB_ZCL_MIN_REPORTING_INTERVAL_DEFAULT 0x0005 + +/*! Default value for maximum reporting interval */ +#define ZB_ZCL_MAX_REPORTING_INTERVAL_DEFAULT 0x0000 + +union zb_zcl_attr_var_u +{ + zb_uint8_t u8; + zb_int8_t s8; + zb_uint16_t u16; + zb_int16_t s16; + zb_uint24_t u24; + zb_int24_t s24; + zb_uint32_t u32; + zb_int32_t s32; + zb_uint48_t u48; + zb_uint8_t data_buf[4]; +}; + +/** @cond internals_doc */ + +/** @brief Structure for storing Reporting information */ +typedef struct zb_zcl_reporting_info_s +{ + zb_uint8_t direction; /*!< Direction: report is send or received */ + zb_uint8_t ep; /*!< Endpoint number */ + zb_uint16_t cluster_id; /*!< Cluster ID for reporting */ + zb_uint8_t cluster_role; + zb_uint16_t attr_id; /*!< Attribute ID for reporting */ + zb_uint8_t flags; /*!< Flags to inform status of reporting */ + zb_time_t run_time; /*!< Time to run next reporting activity */ + union + { + struct + { + zb_uint16_t min_interval; /*!< Actual minimum reporting interval */ + zb_uint16_t max_interval; /*!< Actual maximum reporting interval */ + union zb_zcl_attr_var_u delta; /*!< Actual reportable change */ + union zb_zcl_attr_var_u reported_value; /*!< The last reported value */ + zb_uint16_t def_min_interval; /*!< Default minimum reporting interval */ + zb_uint16_t def_max_interval; /*!< Default maximum reporting interval */ + } + send_info; /*!< send_info is stored on cluster server side (as usual) and describes how + attribute should be reported */ + struct + { + zb_uint16_t timeout; /*!< Timeout period */ + } + recv_info; /*!< recv_info is stored on cluster client side (as usual) and describes how + attribute report is received */ + } + u; + + struct + { + zb_uint16_t short_addr; /*!< Destinition short address */ + zb_uint8_t endpoint; /*!< Destinition endpoint */ + zb_uint16_t profile_id; /*!< Profile id */ + } + dst; +} +zb_zcl_reporting_info_t; + +#if defined ZB_USE_NVRAM + +/* FIXME: Dataset is not aligned (21 bytes)! Fix align and use u48 instead of u32 for delta! */ + +/** @brief Structure for storing Reporting information to NVRAM */ +typedef ZB_PACKED_PRE struct zb_zcl_reporting_info_nvram_s +{ + zb_uint8_t direction; /*!< Direction: report is send or received */ + zb_uint8_t ep; /*!< Endpoint number */ + zb_uint16_t cluster_id; /*!< Cluster ID for reporting */ + zb_uint8_t cluster_role; /*!< Cluster role */ + zb_uint16_t attr_id; /*!< Attribute ID for reporting */ + zb_uint8_t flags; /*!< Flags to inform status of reporting */ + + zb_uint16_t min_interval; /*!< Minimum reporting interval or timeout for client*/ + zb_uint16_t max_interval; /*!< Maximum reporting interval */ + /* FIXME: Should be U48 here! Leave it as is to do not perform migration! U32 delta is enough for + * the most cases... */ + zb_uint32_t delta; /*!< Reportable change */ + + zb_uint16_t short_addr_dest; /*!< Destinition short address */ + zb_uint8_t endpoint_dest; /*!< Destinition endpoint */ + zb_uint16_t profile_id_dest; /*!< Profile id */ + zb_uint8_t align[3]; +} ZB_PACKED_STRUCT zb_zcl_reporting_info_nvram_t; + +#endif /* defined ZB_USE_NVRAM */ + +typedef struct zb_zcl_reporting_ctx_s +{ + zb_uint16_t min_interval; + zb_uint16_t max_interval; + zb_uint16_t timeout; + + zb_uint8_t buf_ref; +} +zb_zcl_reporting_ctx_t; + +/** @endcond */ /* internals_doc */ + +/** @brief Informs application that some attribute value was not reported during defined time + interval + @param ep - endpoint number + @param cluster_id - cluster ID + @param attr_id - attribute ID +*/ +typedef void (*zb_zcl_no_reporting_cb_t)( + zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t attr_id); + +/** @brief Informs application about received attribute report + @param addr - source address + @param ep - source endpoint number + @param cluster_id - cluster ID + @param attr_id - attribute ID + @param value - pointer to reported data value +*/ + +typedef void (*zb_zcl_report_attr_cb_t)( + zb_zcl_addr_t *addr, zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint16_t attr_id, zb_uint8_t attr_type, zb_uint8_t *value); +/** @cond internals_doc */ + +/** Enumeration of reporting info flag values */ +typedef enum zb_zcl_reporting_flags_e +{ + ZB_ZCL_REPORTING_SLOT_BUSY = 0x01, /*!< Reporting info slot is busy */ + ZB_ZCL_REPORT_ATTR = 0x01 << 1, /*!< Current attribute should be reported */ + ZB_ZCL_REPORT_IS_ALLOWED = 0x01 << 2, /*!< Reporting for attribute is allowed if + * min_interval timeout condition is met */ + ZB_ZCL_REPORTING_STOP = 0x01 << 3, /*!< Stop reporting this attribute */ + ZB_ZCL_REPORT_TIMER_STARTED = 0x01 << 4, + ZB_ZCL_REPORT_IS_SENT = 0x01 << 5, + ZB_ZCL_REPORT_IS_FIRST = 0x01 << 6, /*!< First report for this attribute */ +} +zb_zcl_reporting_flags_t; + +#define ZB_ZCL_SET_REPORTING_FLAG(rep_info, f) ((rep_info)->flags |= (zb_uint8_t)(f)) + +#define ZB_ZCL_CLR_REPORTING_FLAG(rep_info, f) ((rep_info)->flags &= (zb_uint8_t)(f^0xFF)) + +#define ZB_ZCL_GET_REPORTING_FLAG(rep_info, f) ((rep_info)->flags & (zb_uint8_t)(f)) + +#define ZB_ZCL_CLR_ALL_REPORTING_FLAGS(rep_info) ((rep_info)->flags = 0) + + +/*! @internal min_interval zero value */ +#define ZB_ZCL_MIN_INTERVAL_ZERO 0x0000 + +/*! @internal Check, if min_interval should be taken into account */ +#define ZB_ZCL_MIN_INTERVAL_SPECIFIED \ + (ZCL_CTX().reporting_ctx.min_interval != ZB_ZCL_MIN_INTERVAL_ZERO) + +/** @endcond */ /* internals_doc */ + +/** @brief If Maximum reporting interval is set to value 0xFFFF,reporting is not needed for current + attribute +*/ +#define ZB_ZCL_REPORTING_NOT_NEEDED 0xFFFF + +/** @cond internals_doc */ + +#define ZB_ZCL_TIMEOUT_ZERO 0x0000 + +#define ZB_ZCL_INVALID_TIMEOUT 0xFFFF + +#define ZB_ZCL_UNDEFINED_REPORTING_SLOT 0xFF +#define ZB_ZCL_MAX_REPORTING_SLOTS_BY_EP (ZB_ZCL_UNDEFINED_REPORTING_SLOT / ZB_ZCL_MAX_EP_NUMBER) + +/************************** Reporting functions declarations **********************************/ + +#ifdef ZB_ZCL_ENABLE_DEFAULT_REPORT_ATTR_PROCESSING +zb_void_t zb_zcl_report_attr_cmd_handler(zb_uint8_t param); +#endif + +void zb_zcl_report_received(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +zb_ret_t zb_zcl_put_reporting_info(zb_zcl_reporting_info_t* rep_info_ptr, zb_bool_t override); + +zb_ret_t zb_zcl_put_reporting_info_from_req(zb_zcl_configure_reporting_req_t *config_rep_req, + zb_zcl_attr_addr_info_t* attr_addr_info); + +void zb_zcl_init_reporting_info(void); + +zb_zcl_reporting_info_t* zb_zcl_find_reporting_info( zb_uint8_t ep, + zb_uint16_t cluster_id, + zb_uint8_t cluster_role, + zb_uint16_t attr_id); + +zb_zcl_reporting_info_t* zb_zcl_get_next_reporting_info( + zb_zcl_reporting_info_t *rep_info_init, zb_uint8_t is_manuf_spec); + +zb_void_t zb_zcl_reporting_cb(zb_uint8_t param); + +zb_void_t zb_zcl_save_reported_value(zb_zcl_reporting_info_t *rep_info, zb_zcl_attr_t* attr_desc); + +void zb_zcl_mark_attr_for_reporting(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +/** @endcond */ /* internals_doc */ + +/** @brief Start attribute reporting + @param ep - endpoint number + @param cluster_id - cluster ID + @param cluster_role - cluster role + @param attr_id - attribute ID + @return RET_OK if reporting is successfully started \n + RET_DOES_NOT_EXIST if reporting can't be configured with given parameters (i.e cluster not present) +*/ +zb_ret_t zb_zcl_start_attr_reporting(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +/** @brief Stop attribute reporting + @param ep - endpoint number + @param cluster_id - cluster ID + @param cluster_role - cluster role + @param attr_id - attribute ID + @return RET_OK if reporting is successfully stopped \n + RET_DOES_NOT_EXIST if reporting was not set up with given parameters +*/ +zb_ret_t zb_zcl_stop_attr_reporting(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +/** @brief Check if an atrtibute is configured for reporting or not + @param ep - endpoint number + @param cluster_id - cluster ID + @param cluster_role - cluster role + @param attr_id - attribute ID + @return ZB_TRUE if attribute is reported +*/ +zb_bool_t zcl_is_attr_reported(zb_uint8_t ep, zb_uint16_t cluster_id, zb_uint8_t cluster_role, zb_uint16_t attr_id); + +/* TODO: Document */ +zb_ret_t zb_zcl_put_reporting_info(zb_zcl_reporting_info_t* rep_info_ptr, zb_bool_t override); + +/** @} */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#endif /* !(defined ZB_ZCL_DISABLE_REPORTING) || defined(DOXYGEN) */ + +#endif /* ZB_ZCL_REPORTING_H */ diff --git a/zboss/include/zcl/zb_zcl_scenes.h b/zboss/include/zcl/zb_zcl_scenes.h new file mode 100644 index 0000000000..507eaece16 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_scenes.h @@ -0,0 +1,1712 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Scenes cluster definitoins +*/ + +#ifndef ZB_ZCL_SCENES_H +#define ZB_ZCL_SCENES_H 1 + +/** @cond DOXYGEN_ZCL_SECTION */ + +/*! @defgroup ZB_ZCL_SCENES ZCL Scenes cluster + @ingroup ZB_ZCL_CLUSTERS + @addtogroup ZB_ZCL_SCENES + ZCL Scenes cluster definitions + @{ +*/ + +/* ZB_ZCL_CLUSTER_ID_SCENES = 0x0005 */ + +/*! @name Scenes cluster attributes + @{ +*/ + +/*! @brief Scene cluster attribute identifiers + @see ZCL specification, subclause 3.7.2.2 + */ +enum zb_zcl_scene_attr_e +{ + /*! Number of scenes currently in the device's scene table */ + ZB_ZCL_ATTR_SCENES_SCENE_COUNT_ID = 0x0000, + /*! Scene ID of the scene last invoked */ + ZB_ZCL_ATTR_SCENES_CURRENT_SCENE_ID = 0x001, + /*! @brief Group ID of the scene last invoked + + Can hold 0x0000 if the scene last invoked is not associated with a group + */ + ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_ID = 0x002, + /*! @brief Indicates whether the state of the device corresponds to + that associated with the CurrentScene and CurrentGroup attributes + @li TRUE indicates that these attributes are valid + @li FALSE indicates that they are not valid + */ + ZB_ZCL_ATTR_SCENES_SCENE_VALID_ID = 0x003, + /* TODO Remove default value for Name support attribute when scene name + support will be provided + */ + /*! @brief Indicates support for scene names + + The most significant bit of the NameSupport attribute indicates whether or + not scene names are supported + @li 1 indicates that they are supported + @li 0 indicates that they are not supported + @note Currently scene names are not supported + */ + ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID = 0x004, + /*! @brief specifies the IEEE address of the device that last configured the + scene table + + The value 0xffffffffffffffff indicates that the device has not been + configured, or that the address of the device that last configured the + scenes cluster is not known + @attention The attribute is not supported! + */ + ZB_ZCL_ATTR_SCENES_LAST_CONFIGURED_BY_ID = 0x005 +}; + +/** @brief Mask to extract Name support bit */ +#define ZB_ZCL_SCENES_NAME_SUPPORT_BIT_MASK 0x80 + +/*! Maximal permissible value for Current group attribute */ +#define ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_MAX_VALUE 0xfff7 +/*! Maximal number of scene table records */ +#define ZB_ZCL_MAX_SCENE_TABLE_RECORDS 16 + +/** @brief Default value for Scene count attribute */ +#define ZB_ZCL_SCENES_SCENE_COUNT_DEFAULT_VALUE 0 + +/** @brief Default value for Current scene attribute */ +#define ZB_ZCL_SCENES_CURRENT_SCENE_DEFAULT_VALUE 0 + +/** @brief Default value for Current group attribute */ +#define ZB_ZCL_SCENES_CURRENT_GROUP_DEFAULT_VALUE 0 + +/** @brief Default value for Scene valid attribute */ +#define ZB_ZCL_SCENES_SCENE_VALID_DEFAULT_VALUE 0 + +/* + * TODO: Remove default value for Scenes.NameSupport attribute when scene names + * will be supported. + */ +/** @brief Default value for Name support attribute + + Actually Name support attribute has no default value (see ZCL spec, + subclause 3.7.2.2.1.5), but the Stack does not support scene names, the default value for the attribute can be declared until name support will be added +*/ +#define ZB_ZCL_SCENES_NAME_SUPPORT_DEFAULT_VALUE 0 + +#if defined ZB_ENABLE_ZLL || defined DOXYGEN + +/** @brief Global Scene - group identifier + see ZLL spec 6.5.1.3.1*/ +#define ZB_ZCL_SCENE_GLOBAL_SCENE_GROUP_ID 0x00 + +/** @brief Global Scene - scene identifier + see ZLL spec 6.5.1.3.1*/ +#define ZB_ZCL_SCENE_GLOBAL_SCENE_ID 0x00 + +#endif /*defined ZB_ENABLE_ZLL || defined DOXYGEN*/ + + +/*! @brief Fixed-size part of the Scene table */ +typedef ZB_PACKED_PRE struct zb_zcl_scene_table_record_fixed_s +{ + /*! @brief Group identifier for the scene + + Can be zero if the scene is not associated with any group @attention Since + value of 0xffff is not appropriate as a group identifier, it is being used + as a free record marker in a form of @ref ZB_ZCL_SCENES_FREE_SCENE_TABLE_RECORD + macro + */ + zb_uint16_t group_id; + /*! @brief Scene transition time */ + zb_uint16_t transition_time; + /*! @brief Scene identifier */ + zb_uint8_t scene_id; + /*! @brief Field set length + + Actual length of the field sets. While the maximal length of the field + sets is known, its actual length should be figured out in order to finish reading at + a proper point. E. g.: as stated in ZCL spec, subclause 3.7.2.4.1.1, it is + not mandatory for a field set to be included in the command for every + cluster on the endpoint that has a defined field set. This field can provide + and actual length of the field sets thus being able to read + only the info required. + */ + zb_uint8_t field_sets_length; + zb_uint8_t transition_time_100ms; +} ZB_PACKED_STRUCT zb_zcl_scene_table_record_fixed_t; + +/*! @brief Declares a "free record" marker for a scene table + Used as a value of a group_id field in a corresponding table record +*/ +#define ZB_ZCL_SCENES_FREE_SCENE_TABLE_RECORD 0xffff + +/** @brief Default value for scene transition time */ +#define ZB_ZCL_SCENES_TRANSITION_TIME_DEFAULT_VALUE 0 + +/*! @brief Common part of the field set definition */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_fieldset_common_s +{ + zb_uint16_t cluster_id; /*!< Cluster identifier */ + zb_uint8_t fieldset_length; /*!< Length of the field set's variable part */ +} ZB_PACKED_STRUCT zb_zcl_scenes_fieldset_common_t; + +/*! @brief Declares Scenes attribute list + @param attr_list Attribute list name + @param scene_count @ref ZB_ZCL_ATTR_SCENES_SCENE_COUNT_ID placeholder + @param current_scene @ref ZB_ZCL_ATTR_SCENES_CURRENT_SCENE_ID placeholder + @param current_group @ref ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_ID placeholder + @param scene_valid @ref ZB_ZCL_ATTR_SCENES_SCENE_VALID_ID placeholder + @param name_support @ref ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID placeholder +*/ +#define ZB_ZCL_DECLARE_SCENES_ATTRIB_LIST( \ + attr_list, \ + scene_count, \ + current_scene, \ + current_group, \ + scene_valid, \ + name_support) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SCENES_SCENE_COUNT_ID, (scene_count)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SCENES_CURRENT_SCENE_ID, (current_scene)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_ID, (current_group)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SCENES_SCENE_VALID_ID, (scene_valid)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID, (name_support)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @cond internals_doc */ +/** @brief Removes All scenes corresponding to a group identifiers in a whole device. + @param param - buffer to get data from. + @param group_id - group identifier for which all scenes must be removed. +*/ +zb_void_t zb_zcl_scenes_remove_all_scenes_in_all_endpoints_by_group_id(zb_uint8_t param, zb_uint16_t group_id); +zb_void_t zb_zcl_scenes_remove_all_scenes_in_all_endpoints(zb_uint8_t param); +/*! @} + * @endcond */ /* internals_doc */ + +/*! @} */ /* Scenes cluster attributes */ + +/** @cond internals_doc */ +/*! @name Scenes cluster internals + Internal structures for Scenes cluster + @internal + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SCENES_SCENE_COUNT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SCENES_SCENE_COUNT_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SCENES_CURRENT_SCENE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SCENES_CURRENT_SCENE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SCENES_CURRENT_GROUP_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SCENES_SCENE_VALID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SCENES_SCENE_VALID_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SCENES_NAME_SUPPORT_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! @} */ /* Scenes cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/*! @name Scenes cluster commands + @{ +*/ + +/*! @brief Command identifiers for Scenes Cluster + @see ZCL spec, subclause 3.7.2.4 +*/ +enum zb_zcl_scenes_cmd_e +{ + /** Add scene command */ + ZB_ZCL_CMD_SCENES_ADD_SCENE = 0x00, + /** View scene command */ + ZB_ZCL_CMD_SCENES_VIEW_SCENE = 0x01, + /** Remove scene command */ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE = 0x02, + /** Remove all scenes command */ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES = 0x03, + /** Store scene command */ + ZB_ZCL_CMD_SCENES_STORE_SCENE = 0x04, + /** Recall scene command */ + ZB_ZCL_CMD_SCENES_RECALL_SCENE = 0x05, + /** Get scene membership command */ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP = 0x06, + /** The Enhanced Add Scene command allows a scene to be added using a finer scene + * transition time than the Add Scene command. */ + ZB_ZCL_CMD_SCENES_ENHANCED_ADD_SCENE = 0x40, + /** The Enhanced View Scene command allows a scene to be retrieved using + * a finer scene transition time than the View Scene command. */ + ZB_ZCL_CMD_SCENES_ENHANCED_VIEW_SCENE = 0x41, + /** The Copy Scene command allows a device to efficiently copy scenes from + * one group/scene identifier pair to another group/scene identifier pair. */ + ZB_ZCL_CMD_SCENES_COPY_SCENE = 0x42, +}; + +/*! @brief Command response identifiers for Scenes Cluster + @see ZCL spec, subclause 3.7.2.5 +*/ +enum zb_zcl_scenes_cmd_resp_e +{ + /** Add scene response */ + ZB_ZCL_CMD_SCENES_ADD_SCENE_RESPONSE = 0x00, + /** View scene response */ + ZB_ZCL_CMD_SCENES_VIEW_SCENE_RESPONSE = 0x01, + /** Remove scene response */ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE_RESPONSE = 0x02, + /** Remove all scenes response */ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES_RESPONSE = 0x03, + /** Store scene response */ + ZB_ZCL_CMD_SCENES_STORE_SCENE_RESPONSE = 0x04, + /** Get scene membership response */ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP_RESPONSE = 0x06, + /** The Enhanced Add Scene Response command allows a device to respond + * to an Enhanced Add Scene command.*/ + ZB_ZCL_CMD_SCENES_ENHANCED_ADD_SCENE_RESPONSE = 0x40, + /** The Enhanced View Scene Response command allows a device to respond + * to an Enhanced View Scene command using a finer scene transition time + * that was available in the ZCL. */ + ZB_ZCL_CMD_SCENES_ENHANCED_VIEW_SCENE_RESPONSE = 0x41, + /** The Copy Scene Response command allows a device to respond + * to a Copy Scene command.*/ + ZB_ZCL_CMD_SCENES_COPY_SCENE_RESPONSE = 0x42, +}; + +/** @cond internals_doc */ +/* Scenes cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_SCENES_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_SCENES_ADD_SCENE_RESPONSE, \ + ZB_ZCL_CMD_SCENES_VIEW_SCENE_RESPONSE, \ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE_RESPONSE, \ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES_RESPONSE, \ + ZB_ZCL_CMD_SCENES_STORE_SCENE_RESPONSE, \ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP_RESPONSE + +#define ZB_ZCL_CLUSTER_ID_SCENES_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_SCENES_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_SCENES_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_SCENES_ADD_SCENE, \ + ZB_ZCL_CMD_SCENES_VIEW_SCENE, \ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE, \ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES, \ + ZB_ZCL_CMD_SCENES_STORE_SCENE, \ + ZB_ZCL_CMD_SCENES_RECALL_SCENE, \ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP + +#define ZB_ZCL_CLUSTER_ID_SCENES_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_SCENES_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** + * Inform User App about Scene cluster Add Scene command. + * + */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_add_scene_req_s +{ + zb_uint16_t group_id; /**< Scene group identifier */ + zb_uint8_t scene_id; /**< Scene identifier */ + zb_uint16_t transition_time; /**< Scene transition time */ + /*! @brief Scene name + + Has zero length (for compatibility) as unsupported attribute. + */ + zb_uint8_t scene_name[1]; +} ZB_PACKED_STRUCT zb_zcl_scenes_add_scene_req_t; + + +/*! @brief Start filling Add scene command frame + + Fills the constant-structure part of the command payload only. + + Command can contain no fieldsets defining empty scene. The new scene can be + used, for example, for storing fieldsets with Store scene command. + @note According to a 3.7.2.4.2. subclause of ZCL spec, the command shall be + addressed to a single device (not a group). + @param buffer to put packet to + @param cmd_struct_ptr - pointer to the place variable-structure part of the + command payload (fieldsets) should be placed. + @param dis_default_resp - enable/disable default response + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store + @param transition_time - scene transition time +*/ +#define ZB_ZCL_SCENES_INIT_ADD_SCENE_REQ( \ + buffer, \ + cmd_struct_ptr, \ + dis_default_resp, \ + group_id, \ + scene_id, \ + transition_time) \ + { \ + cmd_struct_ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + cmd_struct_ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + cmd_struct_ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_ADD_SCENE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_struct_ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (scene_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_struct_ptr, (transition_time)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, 0); \ + } + +/*! @brief Sends Add scene command + + @note According to a 3.7.2.4.2. subclause of ZCL spec, the command shall be + addressed to a single device (not a group). + @param buffer - with prepared command payload + @param cmd_struct_ptr - pointer to the place variable-structure part of the + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status +*/ +#define ZB_ZCL_SCENES_SEND_ADD_SCENE_REQ( \ + buffer, \ + cmd_struct_ptr, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback) \ + { \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_struct_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Adds fieldset into the buffer for sending command + @param cmd_struct_ptr - pointer to the place in the buffer to put data to + @param cluster identifier the fieldset under consideration belongs to + @param fs_length - summary length of the attributes in the fieldset + @attention The order of the attribute values in the fieldset is significant +*/ +#define ZB_ZCL_SCENES_INIT_FIELDSET(cmd_struct_ptr, cluster, fs_length) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL((cmd_struct_ptr), (cluster)); \ + ZB_ZCL_PACKET_PUT_DATA8((cmd_struct_ptr), (fs_length)); \ + } + + +/** @brief Parse common part of Add Scene command + @param buffer containing Store scene command payload + @param cmd_struct_ptr - pointer to the request representation structure of type zb_zcl_scenes_add_scene_req_t or NULL pointer if payload size is + too small + @attention The macro changes content of the buffer + @note The macro ignores scene name in the buffer, and, if it has non-zero + size, skips it and directly sets length of the scene name to zero in the + command representation structure +*/ +#define ZB_ZCL_SCENES_GET_ADD_SCENE_REQ_COMMON(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_add_scene_req_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_add_scene_req_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->transition_time); \ + (void)zb_buf_cut_left( \ + (buffer), \ + sizeof(zb_zcl_scenes_add_scene_req_t) + \ + (cmd_struct_ptr)->scene_name[0]); \ + (cmd_struct_ptr)->scene_name[0] = 0; \ + } \ + } + +/** @brief Parses fieldset description + @param buffer containing fieldset + @param cmd_struct_ptr - pointer to the fieldset description representation + structure (of type @ref zb_zcl_scenes_fieldset_common_s) or NULL pointer if + payload size is too small + @param content_length - variable to contain size of the fieldset content + left unprocessed + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_ADD_SCENE_REQ_NEXT_FIELDSET_DESC( \ + buffer, \ + cmd_struct_ptr, \ + content_length) \ + { \ + if (sizeof(zb_zcl_scenes_fieldset_common_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = (zb_zcl_scenes_fieldset_common_t *)zb_buf_begin(buffer); \ + (content_length) = sizeof(zb_zcl_scenes_fieldset_common_t) + \ + ( (zb_zcl_scenes_fieldset_common_t*) \ + (cmd_struct_ptr))->fieldset_length; \ + if ((content_length) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + (content_length) = 0; \ + } \ + else \ + { \ + /* Cludgy: decoding cluster_id in the fieldset directly */ \ + ZB_ZCL_HTOLE16_INPLACE((cmd_struct_ptr)); \ + (void)zb_buf_cut_left((buffer), (content_length)); \ + } \ + } \ + } + +/** @brief Copies parsed fieldset description into designated memory area + @param src_data_ptr - pointer to the memory area containing parsed fieldset + description + @param dst_data_ptr - pointer to the memory area to put fieldset description + to + @param content_length - remaining length of the unprocessed fieldset content +*/ +#define ZB_ZCL_SCENES_GET_ADD_SCENE_REQ_STORE_FIELDSET_COMMON( \ + src_data_ptr, \ + dst_data_ptr, \ + content_length) \ + { \ + ZB_MEMCPY( \ + (dst_data_ptr), \ + (src_data_ptr), \ + sizeof(zb_zcl_scenes_fieldset_common_t)); \ + ((zb_zcl_scenes_fieldset_common_t*)(dst_data_ptr))->fieldset_length = 0; \ + content_length -= sizeof(zb_zcl_scenes_fieldset_common_t); \ + } + +/*! @brief View scene command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_view_scene_req_s +{ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_view_scene_req_t; + +/*! @brief Send View Scene command + + @note According to a 3.7.2.4.2. subclause of ZCL spec, the command shall be + addressed to a single device (not a group). + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_VIEW_SCENE_REQ( \ + buffer, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_VIEW_SCENE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.ViewScene command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_view_scene_req_s) or NULL pointer if payload size is + too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_VIEW_SCENE_REQ(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_view_scene_req_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_view_scene_req_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/*! @brief Remove scene command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_remove_scene_req_s +{ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_remove_scene_req_t; + +/*! @brief Send Remove scene command + + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_addr_mode - addressing mode. Either @ref + ZB_APS_ADDR_MODE_16_ENDP_PRESENT or @ref + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT will fit + @param dst_ep - destination endpoint (if sendting to a particular device) + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_REMOVE_SCENE_REQ( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.RemoveScene command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_remove_scene_req_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_REMOVE_SCENE_REQ(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_remove_scene_req_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_remove_scene_req_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/*! @brief Remove all scenes command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_remove_all_scenes_req_s +{ + zb_uint16_t group_id; /*!< Scene group identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_remove_all_scenes_req_t; + +/*! @brief Send Remove all scenes command + + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_addr_mode - addressing mode. Either @ref + ZB_APS_ADDR_MODE_16_ENDP_PRESENT or @ref + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT will fit + @param dst_ep - destination endpoint (if sendting to a particular device) + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_REMOVE_ALL_SCENES_REQ( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.RemoveScene command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_remove_scene_req_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_REMOVE_ALL_SCENES_REQ(buffer, cmd_struct_ptr) \ + { \ + if ( sizeof(zb_zcl_scenes_remove_all_scenes_req_t) \ + > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_remove_all_scenes_req_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/*! @brief Store scene command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_store_scene_req_s +{ + zb_uint16_t group_id; /*!< Group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_store_scene_req_t; + +/*! @brief Send Store Scene command + + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_addr_mode - addressing mode. Either @ref + ZB_APS_ADDR_MODE_16_ENDP_PRESENT or @ref + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT will fit + @param dst_ep - destination endpoint (if sendting to a particular device) + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_STORE_SCENE_REQ( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_STORE_SCENE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parse Store Scene command + @param buffer containing Store scene command payload + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_store_scene_req_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_STORE_SCENE_REQ(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_store_scene_req_t) != zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + ZB_ZCL_HTOLE16_INPLACE(zb_buf_begin((buffer))); \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_store_scene_req_t*)zb_buf_begin(buffer); \ + (void)zb_buf_cut_left( \ + (buffer), \ + sizeof(zb_zcl_scenes_store_scene_req_t)); \ + } \ + } + +/*! @brief Recall scene command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_recall_scene_req_s +{ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_recall_scene_req_t; + +/*! @brief Recall scene command transition_time payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_recall_scene_transition_time_req_s +{ + zb_uint16_t transition_time; /*!< Scene group identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_recall_scene_transition_time_req_t; + +/*! @brief Send Recall scene command + + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_addr_mode - addressing mode. Either @ref + ZB_APS_ADDR_MODE_16_ENDP_PRESENT or @ref + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT will fit + @param dst_ep - destination endpoint (if sendting to a particular device) + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_RECALL_SCENE_REQ( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL \ + (ptr \ + , dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_RECALL_SCENE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Move to Level payload length macro */ +#define ZB_ZCL_SCENES_RECALL_SCENE_REQ_TRANSITION_TIME_PAYLOAD_LEN \ + sizeof(zb_zcl_scenes_recall_scene_transition_time_req_t) + +/** @internal Macro for getting Move to Color command */ +#define ZB_ZCL_SCENES_GET_RECALL_SCENE_CMD_TRANSITION_TIME(data_buf, req_transition_time, status) \ +{ \ + zb_zcl_scenes_recall_scene_transition_time_req_t *req_transition_time_ptr; \ + (req_transition_time_ptr) = ZB_BUF_LEN(data_buf) >= \ + ZB_ZCL_SCENES_RECALL_SCENE_REQ_TRANSITION_TIME_PAYLOAD_LEN ? \ + (zb_zcl_scenes_recall_scene_transition_time_req_t*)ZB_BUF_BEGIN(data_buf) : NULL; \ + if (req_transition_time_ptr) \ + { \ + ZB_HTOLE16(&(req_transition_time).transition_time, &(req_transition_time_ptr->transition_time)); \ + status = ZB_TRUE; \ + (void)zb_buf_cut_left(data_buf, ZB_ZCL_SCENES_RECALL_SCENE_REQ_TRANSITION_TIME_PAYLOAD_LEN); \ + } \ + else \ + { \ + status = ZB_FALSE; \ + } \ +} + +/** @brief Move to Level payload length macro */ +#define ZB_ZCL_SCENES_RECALL_SCENE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_scenes_recall_scene_req_t) + +/** @brief Parse Recall Scene command + @param buffer containing Store scene command payload + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_recall_scene_req_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_RECALL_SCENE_REQ(buffer, cmd_struct_ptr) \ +{ \ + zb_zcl_scenes_recall_scene_req_t *recall_scene_req_ptr; \ + (recall_scene_req_ptr) = zb_buf_len(buffer) >= \ + ZB_ZCL_SCENES_RECALL_SCENE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_scenes_recall_scene_req_t*)zb_buf_begin(buffer) : NULL; \ + if (recall_scene_req_ptr) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(zb_buf_begin((buffer))); \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_recall_scene_req_t*)zb_buf_begin(buffer); \ + (void)zb_buf_cut_left( \ + (buffer), \ + sizeof(zb_zcl_scenes_recall_scene_req_t)); \ + } \ + else \ + { \ + cmd_struct_ptr = NULL; \ + } \ +} + +/*! @brief Get scene membership command payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_get_scene_membership_req_s +{ + zb_uint16_t group_id; /*!< Scene group identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_get_scene_membership_req_t; + +/*! @brief Send Remove all scenes command + + The command can be sent to device or group of devices either + @param buffer to put packet to + @param dst_addr - address to send packet to + @param dst_addr_mode - addressing mode. Either @ref + ZB_APS_ADDR_MODE_16_ENDP_PRESENT or @ref + ZB_APS_ADDR_MODE_16_GROUP_ENDP_NOT_PRESENT will fit + @param dst_ep - destination endpoint (if sendting to a particular device) + @param ep - sending endpoint + @param prof_id - profile identifier + @param dis_default_resp - enable/disable default response + @param callback for getting command send status + @param group_id - group identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_GET_SCENE_MEMBERSHIP_REQ( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + dis_default_resp, \ + callback, \ + group_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL( \ + ptr, \ + dis_default_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ( \ + ptr, \ + ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + dst_addr_mode, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.GetSceneMembership command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_get_scene_membership_req_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_GET_SCENE_MEMBERSHIP_REQ(buffer, cmd_struct_ptr) \ + { \ + if ( sizeof(zb_zcl_scenes_get_scene_membership_req_t) \ + > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_get_scene_membership_req_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/*! @brief Add scene response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_add_scene_res_s +{ + zb_uint8_t status; /*!< Add scene status */ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_add_scene_res_t; + +/*! @brief Send Add Scene response + + @param buffer to put packet to + @param seq_num - ZCL sequence number + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status + @param status of the corresponding Add scene command execution. Appropriate + values (defined in @ref zb_zcl_status_e enumeration)are: + @li @ref ZB_ZCL_STATUS_SUCCESS for successfull result + @li @ref ZB_ZCL_STATUS_INSUFF_SPACE if the scene table is full + @li @ref ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + Group Table + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_ADD_SCENE_RES( \ + buffer, \ + seq_num, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback, \ + status, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_ADD_SCENE_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.AddSceneResponse command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_add_scene_res_s) or NULL pointer if payload size is + too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_ADD_SCENE_RES(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_add_scene_res_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_add_scene_res_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/** @brief Mandatory part of the Scenes.ViewSceneResponse payload */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_view_scene_res_fixed_size_s +{ + zb_uint8_t status; /*!< Command execution status */ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ + /** @brief Scene transition time + @attention Valid if status is @ref ZB_ZCL_STATUS_SUCCESS only + */ + zb_uint16_t transition_time; + /** @brief Scene name field. + + Since scene names are not supported, will contain only zero length byte on + formation. If received packet with scene name filled from some other + stack, the fields will be skipped during packet parsing, and length byte + will be set to zero. + @attention Valid if status is @ref ZB_ZCL_STATUS_SUCCESS only + */ + zb_uint8_t scene_name[1]; +} ZB_PACKED_STRUCT zb_zcl_scenes_view_scene_res_fixed_size_t; + +/*! @brief Start filling View scene response frame + + Fills the mandatory part of the View scene response payload. + + @param buffer to put packet to + @param cmd_struct_ptr - pointer to the place variable-structure part of the + command payload (fieldsets) should be placed. + @param seq_num - ZCL sequence number + @param status of the command execution. Appropriate values (defined in @ref + zb_zcl_status_e enumeration) are: + @li ZB_ZCL_STATUS_SUCCESS for successfull result + @li ZB_ZCL_STATUS_INSUFF_SPACE if fieldsets don't fit into packet + @li ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_INIT_VIEW_SCENE_RES( \ + buffer, \ + cmd_struct_ptr, \ + seq_num, \ + status, \ + group_id, \ + scene_id) \ + { \ + cmd_struct_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL( \ + cmd_struct_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + cmd_struct_ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_VIEW_SCENE_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_struct_ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (scene_id)); \ + } + +/*! @brief Sends View scene response + + @param buffer with prepared command payload + @param cmd_struct_ptr - pointer to the place variable-structure part of the + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status +*/ +#define ZB_ZCL_SCENES_SEND_VIEW_SCENE_RES( \ + buffer, \ + cmd_struct_ptr, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback) \ + { \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_struct_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Adds transition time into Scenes.ViewSceneResponse payload. + @param cmd_struct_ptr - pointer to the place in buffer to put data to + @param trans_time - transition time to put +*/ +#define ZB_ZCL_SCENES_ADD_TRANSITION_TIME_VIEW_SCENE_RES( \ + cmd_struct_ptr, \ + trans_time) \ + ZB_ZCL_PACKET_PUT_DATA16((cmd_struct_ptr), &(trans_time)) + +/** @brief Adds scene name into Scenes.ViewSceneResponse payload. + + Since the Stack does not support scene names, the define puts only zero scene name length byte + to preserve payload format. + @param cmd_struct_ptr - pointer to the place in buffer to put data to + @param scene_name - scene name to put (currently ignored) +*/ +#define ZB_ZCL_SCENES_ADD_SCENE_NAME_VIEW_SCENE_RES( \ + cmd_struct_ptr, \ + scene_name) \ + ZB_ZCL_PACKET_PUT_DATA8((cmd_struct_ptr), 0) + +/* TODO Fix possible issue with buffer length */ + +/** @brief Parses comon part of the Scenes.ViewSceneResponse + @param buffer containing data + @param response_ptr - pointer to the extracted data +*/ +#define ZB_ZCL_SCENES_GET_VIEW_SCENE_RES_COMMON(buffer, response_ptr) \ + { \ + if (zb_buf_len((buffer)) < \ + (2 * sizeof(zb_uint8_t) + sizeof(zb_uint16_t))) \ + { \ + (response_ptr) = NULL; \ + } \ + else \ + { \ + (response_ptr) = \ + (zb_zcl_scenes_view_scene_res_fixed_size_t*) \ + zb_buf_begin((buffer)); \ + ZB_ZCL_HTOLE16_INPLACE(&((response_ptr)->group_id)); \ + if ((response_ptr)->status == ZB_ZCL_STATUS_SUCCESS) \ + { \ + ZB_ZCL_HTOLE16_INPLACE(&((response_ptr)->transition_time)); \ + (void)zb_buf_cut_left((buffer), sizeof(zb_zcl_scenes_view_scene_res_fixed_size_t) + \ + (response_ptr)->scene_name[0]); \ + (response_ptr)->scene_name[0] = 0; \ + } \ + else \ + { \ + (void)zb_buf_cut_left( \ + (buffer), \ + (2 * sizeof(zb_uint8_t) + sizeof(zb_uint16_t))); \ + } \ + } \ + } + + +/*! @brief Remove scene response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_remove_scene_res_s +{ + zb_uint8_t status; /** Command execution status */ + zb_uint16_t group_id; /** Scene group identifier */ + zb_uint8_t scene_id; /** Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_remove_scene_res_t; + +/*! @brief Send Remove Scene response + + @param buffer to put packet to + @param seq_num - ZCL sequence number + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status + @param status of the corresponding Add scene command execution. Appropriate + values (defined in @ref zb_zcl_status_e enumeration)are: + @li @ref ZB_ZCL_STATUS_SUCCESS for successfull result + @li @ref ZB_ZCL_STATUS_NOT_FOUND if the scene is not present in the scene table + @li @ref ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + Group Table + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_REMOVE_SCENE_RES( \ + buffer, \ + seq_num, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback, \ + status, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_REMOVE_SCENE_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.RemoveSceneResponse command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_remove_scene_res_s) or NULL pointer if payload + size is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_REMOVE_SCENE_RES(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_remove_scene_res_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_remove_scene_res_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/** @brief Remove all scenes response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_remove_all_scenes_res_s +{ + zb_uint8_t status; /** Command execution status */ + zb_uint16_t group_id; /** Group identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_remove_all_scenes_res_t; + +/*! @brief Send Remove all scenes response + + @param buffer to put packet to + @param seq_num - ZCL sequence number + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status + @param status of the corresponding Add scene command execution. Appropriate + values (defined in @ref zb_zcl_status_e enumeration)are: + @li @ref ZB_ZCL_STATUS_SUCCESS for successfull result + @li @ref ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + Group Table + @param group_id - group identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_REMOVE_ALL_SCENES_RES( \ + buffer, \ + seq_num, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback, \ + status, \ + group_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_REMOVE_ALL_SCENES_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.RemoveAllScenesResponse command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_remove_all_scenes_res_s) or NULL pointer if payload + size is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_REMOVE_ALL_SCENES_RES(buffer, cmd_struct_ptr) \ + { \ + if ( sizeof(zb_zcl_scenes_remove_all_scenes_res_t) \ + > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_remove_all_scenes_res_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/** @brief Store scene response payload structure */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_store_scene_res_s +{ + zb_uint8_t status; /*!< Command execution status */ + zb_uint16_t group_id; /*!< Scene group identifier */ + zb_uint8_t scene_id; /*!< Scene identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_store_scene_res_t; + +/*! @brief Send Store scene response + + @param buffer to put packet to + @param seq_num - ZCL sequence number + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status + @param status of the corresponding Add scene command execution. Appropriate + values (defined in @ref zb_zcl_status_e enumeration)are: + @li @ref ZB_ZCL_STATUS_SUCCESS for successfull result + @li ZB_ZCL_STATUS_INSUFF_SPACE if fieldsets don't fit into packet + @li @ref ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + Group Table + @param group_id - group identifier for the scene to store + @param scene_id - scene identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_SEND_STORE_SCENE_RES( \ + buffer, \ + seq_num, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback, \ + status, \ + group_id, \ + scene_id) \ + { \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_STORE_SCENE_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (group_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (scene_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.StoreScene command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_store_scene_res_s) or NULL pointer if payload size + is too small + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_STORE_SCENE_RES(buffer, cmd_struct_ptr) \ + { \ + if (sizeof(zb_zcl_scenes_store_scene_res_t) > zb_buf_len((buffer))) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_store_scene_res_t*)zb_buf_begin(buffer); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->group_id); \ + } \ + } + +/** @brief Scene table capacity: at least one scene can be added + + Exact number is unknown +*/ +#define ZB_ZCL_SCENES_CAPACITY_ONE_MORE ((zb_uint8_t)0xfe) + +/** @brief Scene table capacity unknown */ +#define ZB_ZCL_SCENES_CAPACITY_UNKNOWN ((zb_uint8_t)0xff) + +/** @brief Get scene membership response fixed-structure payload part + representation */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_get_scene_membership_res_mandatory_s +{ + /** @brief Command execution status + + Appropriate values are: + @li ZB_ZCL_STATUS_SUCCESS - successfully executed + @li ZB_ZCL_STATUS_INVALID_FIELD - group is not present in the Group Table + see @ref zb_zcl_status_e enumeration + */ + zb_uint8_t status; + /** @brief Scene table capacity + + Permitted values are: + @li 0..0xfd direct scene table capacity + @li @ref ZB_ZCL_SCENES_CAPACITY_ONE_MORE at least one more scene can be added + @li @ref ZB_ZCL_SCENES_CAPACITY_UNKNOWN scene table capacity is unknown + */ + zb_uint8_t capacity; + zb_uint16_t group_id; /**< Group identifier */ +} ZB_PACKED_STRUCT zb_zcl_scenes_get_scene_membership_res_mandatory_t; + +/** @brief Get scene membership response optional payload part + representation */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_get_scene_membership_res_optional_s +{ + /** @brief Number of scenes in the response. + @note Valid if status has ZB_ZCL_STATUS_SUCCESS value only. + */ + zb_uint8_t scene_count; + /** @brief Array of scenes corresponding to the group identifier. + + Array contains strictly @ref scene_count elements. + @note Valid if status has ZB_ZCL_STATUS_SUCCESS value only. + */ + zb_uint8_t scene_list[1]; +} ZB_PACKED_STRUCT zb_zcl_scenes_get_scene_membership_res_optional_t; + +/** @brief Get scene membership response */ +typedef ZB_PACKED_PRE struct zb_zcl_scenes_get_scene_membership_res_s +{ + /** @brief Mandatory payload part */ + zb_zcl_scenes_get_scene_membership_res_mandatory_t mandatory; + /** @brief Optional payload part */ + zb_zcl_scenes_get_scene_membership_res_optional_t optional; +} ZB_PACKED_STRUCT zb_zcl_scenes_get_scene_membership_res_t; + +/** @brief Start filling Get scene membership response frame + + Fills the mandatory part of the Get scene membership scene response payload. + + @param buffer to put packet to + @param cmd_struct_ptr - pointer to the place variable-structure part of the + command payload (fieldsets) should be placed. + @param seq_num - ZCL sequence number + @param cap_ptr - pointer to the capacity fields of the response + @param status of the command execution. Appropriate values (defined in @ref + zb_zcl_status_e enumeration) are: + @li ZB_ZCL_STATUS_SUCCESS for successfull result + @li ZB_ZCL_STATUS_INVALID_FIELD if the group is not present in the + @param capacity of the scene table + @param group_id - group identifier for the scene to store +*/ +#define ZB_ZCL_SCENES_INIT_GET_SCENE_MEMBERSHIP_RES( \ + buffer, \ + cmd_struct_ptr, \ + seq_num, \ + cap_ptr, \ + status, \ + capacity, \ + group_id) \ + { \ + cmd_struct_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL( \ + cmd_struct_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER( \ + cmd_struct_ptr, \ + seq_num, \ + ZB_ZCL_CMD_SCENES_GET_SCENE_MEMBERSHIP_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (status)); \ + (cap_ptr) = (cmd_struct_ptr); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (capacity)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_struct_ptr, (group_id)); \ + } + +/** @brief Appends Scene count value to Get scene membership response + constant-structure payload part + @note Should not be used if command status is not ZB_ZCL_STATUS_SUCCESS + @param cmd_struct_ptr - pointer to the memory area SceneCount value should be put to + @param scene_count - number of scenes in the scene list +*/ +#define ZB_ZCL_SCENES_ADD_SCENE_COUNT_GET_SCENE_MEMBERSHIP_RES( \ + cmd_struct_ptr, \ + scene_count) \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (scene_count)) + +/** @brief Appends a scene identifier to the Scene list in Get scene membership + response payload + @note Should be preceded with @ref + ZB_ZCL_SCENES_ADD_SCENE_COUNT_GET_SCENE_MEMBERSHIP_RES macro invocation. + @param cmd_struct_ptr - pointer to the memory area scene identifier should + be put to + @param scene_id - scene identifier +*/ +#define ZB_ZCL_SCENES_ADD_SCENE_ID_GET_SCENE_MEMBERSHIP_RES( \ + cmd_struct_ptr, \ + scene_id) \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_struct_ptr, (scene_id)) + +/*! @brief Sends Get scene membership response + + @param buffer with prepared command payload + @param cmd_struct_ptr - pointer to the place directly after the payload + @param dst_addr - address to send packet to + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prof_id - profile identifier + @param callback for getting command send status +*/ +#define ZB_ZCL_SCENES_SEND_GET_SCENE_MEMBERSHIP_RES( \ + buffer, \ + cmd_struct_ptr, \ + dst_addr, \ + dst_ep, \ + ep, \ + prof_id, \ + callback) \ + { \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_struct_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, \ + dst_addr, \ + ZB_APS_ADDR_MODE_16_ENDP_PRESENT, \ + dst_ep, \ + ep, \ + prof_id, \ + ZB_ZCL_CLUSTER_ID_SCENES, \ + callback); \ + } + +/** @brief Parses Scenes.RemoveAllScenesResponse command payload + @param buffer to get data from + @param cmd_struct_ptr - pointer to the request representation structure (of + type @ref zb_zcl_scenes_get_scene_membership_res_s) or NULL pointer if + payload size is too small to contain mandatory part + @attention The macro changes content of the buffer +*/ +#define ZB_ZCL_SCENES_GET_GET_SCENE_MEMBERSHIP_RES(buffer, cmd_struct_ptr) \ + { \ + if (zb_buf_len((buffer)) < \ + sizeof(zb_zcl_scenes_get_scene_membership_res_t)) \ + { \ + (cmd_struct_ptr) = NULL; \ + } \ + else \ + { \ + (cmd_struct_ptr) = \ + (zb_zcl_scenes_get_scene_membership_res_t*)zb_buf_begin((buffer)); \ + ZB_ZCL_HTOLE16_INPLACE(&(cmd_struct_ptr)->mandatory.group_id); \ + } \ + } + +/** @cond internals_doc */ + +zb_uint8_t zb_zcl_scenes_process_store_scene(zb_uint8_t param, zb_zcl_scenes_store_scene_req_t* req, const zb_zcl_parsed_hdr_t *cmd_info); + +zb_uint8_t zb_zcl_scenes_process_recall_scene(zb_uint8_t param, zb_zcl_scenes_recall_scene_req_t* req, const zb_zcl_parsed_hdr_t *cmd_info); + +zb_uint8_t zb_zcl_scenes_process_remove_all_scenes(zb_uint8_t param, zb_zcl_scenes_remove_all_scenes_req_t* req, const zb_zcl_parsed_hdr_t *cmd_info); + +/** @endcond */ + +/*! @} */ /* Scenes cluster commands */ + +/*! @} */ /* ZCL Scenes cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_scenes_init_server(void); +zb_void_t zb_zcl_scenes_init_client(void); +#define ZB_ZCL_CLUSTER_ID_SCENES_SERVER_ROLE_INIT zb_zcl_scenes_init_server +#define ZB_ZCL_CLUSTER_ID_SCENES_CLIENT_ROLE_INIT zb_zcl_scenes_init_client + +#endif /* ZB_ZCL_SCENES_H */ diff --git a/zboss/include/zcl/zb_zcl_shade_config.h b/zboss/include/zcl/zb_zcl_shade_config.h new file mode 100644 index 0000000000..de8a3c94ab --- /dev/null +++ b/zboss/include/zcl/zb_zcl_shade_config.h @@ -0,0 +1,293 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Shade Configuration cluster defintions +*/ + +#ifndef ZB_ZCL_SHADE_CONFIG_H +#define ZB_ZCL_SHADE_CONFIG_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Logically most opened value */ +#define ZB_ZCL_SHADE_CONFIG_LOGICALLY_MOST_OPENED 0 + +/* Logically most closed value */ +#define ZB_ZCL_SHADE_CONFIG_LOGICALLY_MOST_CLOSED 0xffff + +/** @defgroup ZB_ZCL_SHADE_CONFIG ZCL Shade Configuration cluster + @ingroup ZB_ZCL_CLUSTERS + @addtogroup ZB_ZCL_SHADE_CONFIG + @{ +*/ + +/** @name Shade Configuration cluster attributes + @{ +*/ + +/** @brief Shade Configuration cluster information attribute set identifiers + @see ZCL spec, subclause 7.2.2.2.1 +*/ +enum zb_zcl_shade_config_info_attr_e +{ + /** The PhysicalClosedLimit attribute indicates the most closed (numerically lowest) + * position that the shade can physically move to. */ + ZB_ZCL_ATTR_SHADE_CONFIG_PHYSICAL_CLOSED_LIMIT_ID = 0x0000, + /** The MotorStepSize attribute indicates the angle the shade motor moves for one step, + * measured in 1/10ths of a degree. */ + ZB_ZCL_ATTR_SHADE_CONFIG_MOTOR_STEP_SIZE_ID = 0x0001, + /** @brief Status attribute */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_ID = 0x0002 +}; + +/** @brief Bit values for Status attribute + * @see ZCL spec, subclause 7.2.2.2.1.3 + */ +enum zb_zcl_shade_config_status_type_e +{ + /** Shade operational value */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_SHADE_OPERATIONAL = 0x00, + /** Shade Adjusting value */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_SHADE_ADJUSTING = 0x01, + /** Shade Direction value */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_SHADE_DIRECTION = 0x02, + /** Forward Direction of Motor value */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_FORWARD_DIRECTION_OF_MOTOR = 0x03, + /** Reserved values */ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_RESERVED = 0x04 +}; + +/** @cond internals_doc */ +/** @internal Set bits from conf_var variable to type_value */ +#define ZB_ZCL_SET_BIT(conf_var, type_value) \ +{ \ + (conf_var) = (conf_var) | (type_value); \ +} + +/** @internal Get type_value bits from conf_var variable */ +#define ZB_ZCL_GET_BIT(conf_var, type_value) ((conf_var) & (type_value)) + +/** @internal Clear type_value bits in conf_var variable */ +#define ZB_ZCL_CLR_BIT(conf_var, type_value) \ +{ \ + (conf_var) = (conf_var) & ~(type_value); \ +} +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Sets bits of Status parameter + @param type_value - bit to set + @param conf_var - config variable +*/ +#define ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_SET(conf_var, type_value) \ + ZB_ZCL_SET_BIT(conf_var, type_value) + +/** @brief Gets bit value of Status parameter + @param type_value - bit value to check + @param conf_var - config variable +*/ +#define ZB_ZCL_ATTR_SHADE_CONFIG_GET_STATUS_BIT_VAL(conf_var, type_value) \ + ZB_ZCL_GET_BIT(conf_var, type_value) + + +/** @brief Clear bit of Status parameter + @param type_value - bit to clear + @param conf_var - config variable +*/ +#define ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_CLEAR(conf_var, type_value) \ + ZB_ZCL_CLR_BIT(conf_var, type_value) + + +/** @brief Shade cluster settings attribute set identifiers + @see ZCL spec, subclause 7.2.2.2.2 +*/ +enum zb_zcl_shade_config_settings_attr_e +{ + /** @brief ClosedLimit attribute */ + ZB_ZCL_ATTR_SHADE_CONFIG_CLOSED_LIMIT_ID = 0x0010, + /** @brief Mode attribute */ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_ID = 0x0011 +}; + +/** @brief Permissible values for Mode attribute + @see ZCL spec, subclause 7.2.2.2.2.2 */ +enum zb_zcl_shade_config_mode_e +{ + /** Normal value */ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_NORMAL = 0x00, + /** Configure value */ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_CONFIGURE = 0x01, + /** Reserved values */ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_RESERVED = 0x02 +}; + +/** @cond internals_doc */ +typedef struct zb_zcl_shade_set_value_param_s +{ + zb_uint16_t new_value; + zb_bool_t is_config; +} zb_zcl_shade_set_value_param_t; + +typedef struct zb_zcl_shade_get_value_param_s +{ + zb_uint16_t ret_value; +} zb_zcl_shade_get_value_param_t; +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Shade Configuration Status attribute default value */ +#define ZB_ZCL_SHADE_CONFIG_STATUS_DEFAULT_VALUE 0x00 + +/** @brief ClosedLimit attribute default value */ +#define ZB_ZCL_SHADE_CONFIG_CLOSED_LIMIT_DEFAULT_VALUE 0x0001 + +/** @brief Zero Point attribute default value */ +#define ZB_ZCL_SHADE_CONFIG_ZERO_POINT_DEFAULT_VALUE 0x0000 + +/** @brief Mode attribute default value */ +#define ZB_ZCL_SHADE_CONFIG_MODE_DEFAULT_VALUE ZB_ZCL_ATTR_SHADE_CONFIG_MODE_NORMAL + +/** @brief Declare attribute list for Shade Configuration cluster + @param attr_list - attribute list name + @param status - pointer to variable to store Status attribute value + @param closed_limit - pointer to variable to store ClosedLimit attribute value + @param mode - pointer to variable to store Mode attribute value +*/ +#define ZB_ZCL_DECLARE_SHADE_CONFIG_ATTRIB_LIST(attr_list, status, closed_limit, mode) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_ID, (status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SHADE_CONFIG_CLOSED_LIMIT_ID, (closed_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_SHADE_CONFIG_MODE_ID, (mode)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* Shade Configuration cluster attributes */ + +/* Descriptors for server side */ + +/** @cond internals_doc */ +/** @name Shade Configuration cluster internals + Internal structures for Shade Configuration cluster + @internal + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SHADE_CONFIG_STATUS_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SHADE_CONFIG_CLOSED_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SHADE_CONFIG_CLOSED_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_SHADE_CONFIG_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/** Number of attributes mandatory for reporting in Shade Configuration cluster */ +#define ZB_ZCL_SHADE_CONFIG_REPORT_ATTR_COUNT 0 + + +/** Macro for setting Mode attribute + @param ep - endpoint id + @param mode_val - mode value +*/ + +/** @brief Shade Configuration cluster command identifiers + @see ZCL spec, subclause ? +*/ +/*enum zb_zcl_shade_config_cmd_e +{ + +};*/ + +/** Mandatory commands defines */ + +/*! @internal Setting Shade Mode value macro: + @param ep - endpoint where setting + @param mode_val - Shade Mode value +*/ + +#define ZB_ZCL_SHADE_SET_MODE(ep, mode_val) \ +{ \ + zb_uint8_t mode = (mode_val); \ + ZB_ZCL_SET_ATTRIBUTE((ep), \ + ZB_ZCL_CLUSTER_ID_SHADE_CONFIG, \ + ZB_ZCL_ATTR_SHADE_CONFIG_MODE_ID, \ + &mode, \ + ZB_FALSE); \ +} + +/** @} */ /* Shade Configuration cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @name Shade Configuration cluster commands + @{ +*/ + + +/** @} */ /* Shade Configuration cluster commands */ + +/** @} */ /* ZCL Shade Configuration cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_shade_config_init_server(void); +void zb_zcl_shade_config_init_client(void); +#define ZB_ZCL_CLUSTER_ID_SHADE_CONFIG_SERVER_ROLE_INIT zb_zcl_shade_config_init_server +#define ZB_ZCL_CLUSTER_ID_SHADE_CONFIG_CLIENT_ROLE_INIT zb_zcl_shade_config_init_client + +#endif /* ZB_ZCL_SHADE_CONFIG_H */ diff --git a/zboss/include/zcl/zb_zcl_temp_measurement.h b/zboss/include/zcl/zb_zcl_temp_measurement.h new file mode 100644 index 0000000000..f3290a20bb --- /dev/null +++ b/zboss/include/zcl/zb_zcl_temp_measurement.h @@ -0,0 +1,206 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Temperature Measurement cluster defintions +*/ + +#if ! defined ZB_ZCL_TEMP_MEASUREMENT_H +#define ZB_ZCL_TEMP_MEASUREMENT_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_TEMP_MEASUREMENT + * @{ + * @details + * All commands in the cluster have only request form, and carry no payload. + */ + + +/* Cluster ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT */ + +/*! @name Temperature Measurement cluster attributes + @{ +*/ + +/*! @brief Temperature Measurement cluster attribute identifiers + @see ZCL spec, Temperature Measurement Cluster 4.4.2.2.1 +*/ +enum zb_zcl_temp_measurement_attr_e +{ + /*! @brief MeasuredValue, ZCL spec 4.4.2.2.1.1 */ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID = 0x0000, + /*! @brief MinMeasuredValue, ZCL spec 4.4.2.2.1.2 */ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID = 0x0001, + /*! @brief MaxMeasuredValue, ZCL spec 4.4.2.2.1.3 */ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID = 0x0002, + /*! @brief Tolerance, ZCL spec 4.4.2.2.1.4 */ +#ifndef ZB_DISABLE_TEMP_MEASUREMENT_TOLERANCE_ID + ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID = 0x0003, +#else + ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID = 0xF003, +#endif +}; + +/** @brief MeasuredValue attribute unknown value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_UNKNOWN ((zb_int16_t)0x8000) + +/** @brief MinMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_MIN_VALUE ((zb_int16_t)0x954d) + +/** @brief MinMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_MAX_VALUE 0x7ffe + +/** @brief MinMeasuredValue attribute invalid value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_INVALID ((zb_int16_t)0x8000) + +/** @brief MaxMeasuredValue attribute minimum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_MIN_VALUE ((zb_int16_t)0x954e) + +/** @brief MaxMeasuredValue attribute maximum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_MAX_VALUE 0x7fff + +/** @brief MaxMeasuredValue attribute invalid value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_INVALID ((zb_int16_t)0x8000) + + + /* (See: Table 4.13 Temperature Measurement Information Attribute Set) */ + +/** @brief Tolerance attribute minimum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_MIN_VALUE 0x0000 + +/** @brief Tolerance attribute maximum value */ +#define ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_MAX_VALUE 0x0800 + +/** @brief Default value for Value attribute */ +#define ZB_ZCL_TEMP_MEASUREMENT_VALUE_DEFAULT_VALUE ((zb_int16_t)0xFFFF) + +/** @brief Default value for MinValue attribute */ +#define ZB_ZCL_TEMP_MEASUREMENT_MIN_VALUE_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for MaxValue attribute */ +#define ZB_ZCL_TEMP_MEASUREMENT_MAX_VALUE_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @cond internals_doc */ +/*! @internal @name Temperature Measurement cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Temperature Measurement cluster */ +#define ZB_ZCL_TEMP_MEASUREMENT_REPORT_ATTR_COUNT 1 + +/*! Write attribute hook is used to set min/max temperature values */ +zb_void_t zb_zcl_temp_measurement_write_attr_hook( + zb_uint8_t endpoint, zb_uint16_t attr_id, zb_uint8_t *new_value); + +/*! @} */ /* Temperature Measurement cluster internals */ +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief Declare attribute list for Temperature Measurement cluster - server side + @param attr_list - attribute list name + @param value - pointer to variable to store MeasuredValue attribute + @param min_value - pointer to variable to store MinMeasuredValue attribute + @param max_value - pointer to variable to store MAxMeasuredValue attribute + @param tolerance - pointer to variable to store Tolerance attribute +*/ +#define ZB_ZCL_DECLARE_TEMP_MEASUREMENT_ATTRIB_LIST(attr_list, \ + value, min_value, max_value, tolerance) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TEMP_MEASUREMENT_VALUE_ID, (value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TEMP_MEASUREMENT_MIN_VALUE_ID, (min_value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TEMP_MEASUREMENT_MAX_VALUE_ID, (max_value)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TEMP_MEASUREMENT_TOLERANCE_ID, (tolerance)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Temperature Measurement cluster attributes */ + +/*! @name Temperature Measurement cluster commands + @{ +*/ + +/*! @} */ /* Temperature Measurement cluster commands */ + +/*! @} */ /* ZCL Temperature Measurement cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +zb_void_t zb_zcl_temp_measurement_init_server(void); +zb_void_t zb_zcl_temp_measurement_init_client(void); +#define ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT_SERVER_ROLE_INIT zb_zcl_temp_measurement_init_server +#define ZB_ZCL_CLUSTER_ID_TEMP_MEASUREMENT_CLIENT_ROLE_INIT zb_zcl_temp_measurement_init_client + + +#endif /* ! defined ZB_ZCL_TEMP_MEASUREMENT_H */ diff --git a/zboss/include/zcl/zb_zcl_thermostat.h b/zboss/include/zcl/zb_zcl_thermostat.h new file mode 100644 index 0000000000..832ab7b152 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_thermostat.h @@ -0,0 +1,1465 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Thermostat cluster defintions +*/ + +#if ! defined ZB_ZCL_THERMOSTAT_H +#define ZB_ZCL_THERMOSTAT_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Cluster ZB_ZCL_CLUSTER_ID_THERMOSTAT */ + +/** @addtogroup ZB_ZCL_THERMOSTAT + * @{ + */ + +/* <31.07.13> Tokarev CR function prototype moved from C file into header for public access */ +/** + * Thermostat initialization function + * initialize setpoint mode, shedule table + */ +void zb_zcl_thermostat_init(void); +/* <31.07.13> Tokarev CR function prototype moved from C file into header for public access */ + +/*! @name Thermostat cluster attributes + @{ +*/ + +/*! @brief Thermostat cluster attribute identifiers + @see ZCL spec, subclause 6.3.2.2 +*/ +enum zb_zcl_thermostat_attr_e +{ + /** @brief Local Temperature attribute */ + ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_ID = 0x0000, + /** OutdoorTemperature represents the outdoor temperature in degrees Celsius, + * as measured locally or remotely (over the network). */ + ZB_ZCL_ATTR_THERMOSTAT_OUTDOOR_TEMPERATURE_ID = 0x0001, + /** Occupancy specifies whether the heated/cooled space is occupied or not, + * as measured locally or remotely (over the network). */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPANCY_ID = 0x0002, + /** The AbsMinHeatSetpointLimit attribute specifies the absolute minimum level + * that the heating setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_HEAT_SETPOINT_LIMIT_ID = 0x0003, + /** The AbsMaxHeatSetpointLimit attribute specifies the absolute maximum level + * that the heating setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_HEAT_SETPOINT_LIMIT_ID = 0x0004, + /** The AbsMinCoolSetpointLimit attribute specifies the absolute minimum level + * that the cooling setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_COOL_SETPOINT_LIMIT_ID = 0x0005, + /** The AbsMaxCoolSetpointLimit attribute specifies the absolute maximum level + * that the cooling setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_COOL_SETPOINT_LIMIT_ID = 0x0006, + /** The PICoolingDemand attribute is 8 bits in length and specifies the level + * of cooling demanded by the PI (proportional integral) control loop in use + * by the thermostat (if any), in percent. */ + ZB_ZCL_ATTR_THERMOSTAT_PI_COOLING_DEMAND_ID = 0x0007, + /** The PIHeatingDemand attribute is 8 bits in length and specifies the level + * of heating demanded by the PI loop in percent. */ + ZB_ZCL_ATTR_THERMOSTAT_PI_HEATING_DEMAND_ID = 0x0008, + /** The HVACSystemTypeConfiguration attribute specifies the HVAC system type + * controlled by the thermostat. */ + ZB_ZCL_ATTR_THERMOSTAT_HVAC_SYSTEM_TYPE_CONFIGURATION_ID = 0x0009, + /** @brief Local Temperature Calibration */ + ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_ID = 0x0010, + /** @brief Occupied Cooling Setpoint attribute */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_ID = 0x0011, + /** @brief Occupied Heating Setpoint attribute */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_ID = 0x0012, + /** @brief Unoccupied Cooling Setpoint attribute */ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_COOLING_SETPOINT_ID = 0x0013, + /** @brief Unoccupied Heating Setpoint attribute */ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_HEATING_SETPOINT_ID = 0x0014, + /** The MinHeatSetpointLimit attribute specifies the minimum level that the heating + * setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_MIN_HEAT_SETPOINT_LIMIT_ID = 0x0015, + /** The MaxHeatSetpointLimit attribute specifies the maximum level that the heating + * setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_MAX_HEAT_SETPOINT_LIMIT_ID = 0x0016, + /** The MinCoolSetpointLimit attribute specifies the minimum level that the cooling + * setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_MIN_COOL_SETPOINT_LIMIT_ID = 0x0017, + /** The MaxCoolSetpointLimit attribute specifies the maximum level that the cooling + * setpoint MAY be set to. */ + ZB_ZCL_ATTR_THERMOSTAT_MAX_COOL_SETPOINT_LIMIT_ID = 0x0018, + /** The MinSetpointDeadBand attribute specifies the minimum difference between the + * Heat Setpoint and the Cool SetPoint, in steps of 0.1C. */ + ZB_ZCL_ATTR_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_ID = 0x0019, + /** The RemoteSensing attribute is an 8-bit bitmap that specifies whether the local + * temperature, outdoor temperature and occupancy are being sensed by internal sensors + * or remote networked sensors. */ + ZB_ZCL_ATTR_THERMOSTAT_REMOTE_SENSING_ID = 0x001a, + /** @brief Control Sequence Of Operation attribute */ + ZB_ZCL_ATTR_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_ID = 0x001b, + /** @brief System Mode attribute */ + ZB_ZCL_ATTR_THERMOSTAT_SYSTEM_MODE_ID = 0x001c, + /** The AlarmMask attribute specifies whether each of the alarms is enabled. */ + ZB_ZCL_ATTR_THERMOSTAT_ALARM_MASK_ID = 0x001d, + /** @brief Thermostat Running Mode attribute */ + ZB_ZCL_ATTR_THERMOSTAT_RUNNING_MODE_ID = 0x001e, + /*! @brief Start of Week attribute */ + ZB_ZCL_ATTR_THERMOSTAT_START_OF_WEEK_ID = 0x0020, + /** NumberOfWeeklyTransitions attribute determines how many weekly schedule + * transitions the thermostat is capable of handling. */ + ZB_ZCL_ATTR_THERMOSTAT_NUMBER_OF_WEEKLY_TRANSITIONS_ID = 0x0021, + /** NumberOfDailyTransitions attribute determines how many daily schedule + * transitions the thermostat is capable of handling. */ + ZB_ZCL_ATTR_THERMOSTAT_NUMBER_OF_DAILY_TRANSITIONS_ID = 0x0022, + /** TemperatureSetpointHold specifies the temperature hold status on the thermostat. */ + ZB_ZCL_ATTR_THERMOSTAT_TEMPERATURE_SETPOINT_HOLD_ID = 0x0023, + /** TemperatureSetpointHoldDuration sets the period in minutes for which a setpoint + * hold is active. */ + ZB_ZCL_ATTR_THERMOSTAT_TEMPERATURE_SETPOINT_HOLD_DURATION_ID = 0x0024, + /** The ThermostatProgrammingOperationMode attribute determines the operational state + * of the thermostats programming. */ + ZB_ZCL_ATTR_THERMOSTAT_THERMOSTAT_PROGRAMMING_OPERATION_MODE_ID = 0x0025, + /** ThermostatRunningState represents the current relay state of the heat, cool, + * and fan relays. */ + ZB_ZCL_ATTR_THERMOSTAT_THERMOSTAT_RUNNING_STATE_ID = 0x0029, + /** The SetpointChangeSource attribute specifies the source of the current active + * OccupiedCoolingSetpoint or OccupiedHeatingSetpoint (i.e., who or what determined + * the current setpoint). */ + ZB_ZCL_ATTR_THERMOSTAT_SETPOINT_CHANGE_SOURCE_ID = 0x0030, + /** The SetpointChangeAmount attribute specifies the delta between the current active + * OccupiedCoolingSetpoint or OccupiedHeatingSetpoint and the previous active + * setpoint. */ + ZB_ZCL_ATTR_THERMOSTAT_SETPOINT_CHANGE_AMOUNT_ID = 0x0031, + /** The SetpointChangeSourceTimestamp attribute specifies the time in UTC at which + * the SetpointChangeSourceAmount attribute change was recorded. */ + ZB_ZCL_ATTR_THERMOSTAT_SETPOINT_CHANGE_SOURCE_TIMESTAMP_ID = 0x0032, + /** Specifies the degrees Celsius, in 0.1 degree increments, the Thermostat server + * will allow the LocalTemperature attribute to float above the OccupiedCooling + * setpoint (i.e., OccupiedCooling + OccupiedSetback) or below the OccupiedHeating + * setpoint (i.e., occupiedHeating, OccupiedSetback) before initiating a state change + * to bring the temperature back to the users desired setpoint. */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_SETBACK_ID = 0x0034, + /** Specifies the minimum degrees Celsius, in 0.1 degree increments, + * the Thermostat server will allow the OccupiedSetback attribute + * to be configured by a user. */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_SETBACK_MIN_ID = 0x0035, + /** Specifies the maximum degrees Celsius, in 0.1 degree increments, + * the Thermostat server will allow the OccupiedSetback attribute + * to be configured by a user. */ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_SETBACK_MAX_ID = 0x0036, + /** Specifies the degrees Celsius, in 0.1 degree increments, the Thermostat server + * will allow the LocalTemperature attribute to float above the UnoccupiedCooling + * setpoint (i.e., UnoccupiedCooling + UnoccupiedSetback) or below the + * UnoccupiedHeating setpoint (i.e., UnoccupiedHeating - UnoccupiedSetback) + * before initiating a state change to bring the temperature back + * to the users desired setpoint. */ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_SETBACK_ID = 0x0037, + /** Specifies the minimum degrees Celsius, in 0.1 degree increments, the Thermostat + * server will allow the UnoccupiedSetback attribute to be configured by a user. */ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_SETBACK_MIN_ID = 0x0038, + /** Specifies the maximum degrees Celsius, in 0.1 degree increments, the Thermostat + * server will allow the UnoccupiedSetback attribute to be configured by a user. */ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_SETBACK_MAX_ID = 0x0039, + /** Specifies the delta, in 0.1 degrees Celsius, between LocalTemperature and + * the OccupiedHeatingSetpoint or UnoccupiedHeatingSetpoint attributes at which + * the Thermostat server will operate in emergency heat mode. */ + ZB_ZCL_ATTR_THERMOSTAT_EMERGENCY_HEAT_DELTA_ID = 0x003a, + /** Indicates the type of Mini Split ACType of Mini Split AC is defined depending + * on how Cooling and Heating condition is achieved by Mini Split AC. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_TYPE_ID = 0x0040, + /** Indicates capacity of Mini Split AC in terms of the format defined by + * the ACCapacityFormat attribute. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_CAPACITY_ID = 0x0041, + /** Indicates type of refrigerant used within the Mini Split AC. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_REFRIGERANT_TYPE_ID = 0x0042, + /** This indicates type of Compressor used within the Mini Split AC. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_COMPRESSOR_TYPE_ID = 0x0043, + /** This indicates the type of errors encountered within the Mini Split AC. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_ERROR_CODE_ID = 0x0044, + /** @brief AC Louver position attribute */ + ZB_ZCL_ATTR_THERMOSTAT_AC_LOUVER_POSITION_ID = 0x0045, + /** ACCoilTemperature represents the temperature in degrees Celsius, as measured + * locally or remotely (over the network). */ + ZB_ZCL_ATTR_THERMOSTAT_AC_COIL_TEMPERATURE_ID = 0x0046, + /** This is the format for the ACCapacity attribute. */ + ZB_ZCL_ATTR_THERMOSTAT_AC_CAPACITY_FORMAT_ID = 0x0047, +}; + +/*! @brief Values for Control Sequence Of Operation attribute, + @see ZCL spec, subclause 6.3.2.2.2.12 */ +enum zb_zcl_thermostat_control_sequence_of_operation_e +{ + /*! Cooling Only value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_COOLING_ONLY = 0x00, + /*! Cooling With Reheat value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_COOLING_WITH_REHEAT = 0x01, + /*! Heating Only value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_HEATING_ONLY = 0x02, + /*! Heating With Reheat value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_HEATING_WITH_REHEAT = 0x03, + /*! Cooling and Heating 4-pipes value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_COOLING_AND_HEATING_4_PIPES = 0x04, + /*! Cooling and Heating 4-pipes with Reheat value */ + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_COOLING_AND_HEATING_4_PIPES_WITH_REHEAT = 0x05, + + ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_RESERVED = 0x06 +}; + +/*! @brief Values for System Mode attribute, + @see ZCL spec, subclause 6.3.2.2.2.13 */ +enum zb_zcl_thermostat_system_mode_e +{ + /*! Off value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_OFF = 0x00, + /*! Auto value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_AUTO = 0x01, + /*! Cool value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_COOL = 0x03, + /*! Heat value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_HEAT = 0x04, + /*! Emergency Heating value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_EMERGENCY_HEATING = 0x05, + /*! Precooling value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_PRECOOLING = 0x06, + /*! Fan Only value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_FAN_ONLY = 0x07, + /*! Dry value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_DRY = 0x08, + /*! Sleep value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_SLEEP = 0x09, + /* 07/02/2015 CR [AV] */ + /*! Unknown system mode value */ + ZB_ZCL_THERMOSTAT_SYSTEM_MODE_RESERVED = 0x0a +}; + + +/*! @brief Values for AC Louver position attribute */ +enum zb_zcl_thermostat_ac_louver_position_e +{ + ZB_ZCL_THERMOSTAT_LOUVER_FULLY_CLOSED = 0x01, + ZB_ZCL_THERMOSTAT_LOUVER_FULLY_OPENED = 0x02, + ZB_ZCL_THERMOSTAT_LOUVER_QUARTER_OPEN = 0x03, + ZB_ZCL_THERMOSTAT_LOUVER_HALF_OPEN = 0x04, + ZB_ZCL_THERMOSTAT_LOUVER_THREE_QUARTERS_OPEN = 0x05, +}; + +/*! @brief Values for Start of Week attribute, + @see ZCL spec, subclause 6.3.2.2.3.1 */ +enum zb_zcl_thermostat_start_of_week_e +{ + /*! Sunday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_SUNDAY = 0x00, + /*! Monday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_MONDAY = 0x01, + /*! Tuesday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_TUESDAY = 0x02, + /*! Wednesday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_WEDNESDAY = 0x03, + /*! Thursday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_THURSDAY = 0x04, + /*! Friday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_FRIDAY = 0x05, + /*! Saturday value */ + ZB_ZCL_THERMOSTAT_START_OF_WEEK_SATURDAY = 0x06, +}; + +/*! @brief Thermostat Alarm Code for Alarming + @see ZCL spec 6.3.2.2.2.14, Table 6-18 +*/ +enum zb_zcl_thermostat_alarm_code_e +{ + /** @brief MainsVoltageAlarmCode - MainsVoltageMinThreshold reached for Mains Voltage**/ + ZB_ZCL_THERMOSTAT_ALARM_CODE_INITIALIZATION_FAILURE = 0x00, + /** @brief MainsVoltageAlarmCode - MainsVoltageMaxThreshold reached for Mains Voltage**/ + ZB_ZCL_THERMOSTAT_ALARM_CODE_HARDWARE_FAILURE = 0x01, + /** @brief BatteryAlarmCode - BatteryVoltageMinThreshold or + * BatteryPercentageMinThreshold reached for Battery Source 1 */ + ZB_ZCL_THERMOSTAT_ALARM_CODE_SELFCALIBRATION_FAILURE = 0x02, +}; +/* Default value for Start Of Week attribute */ +#define ZB_ZCL_THERMOSTAT_START_OF_WEEK_DEFAULT_VALUE ZB_ZCL_THERMOSTAT_START_OF_WEEK_SUNDAY + +/** @brief Min value for Local Temperature attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_MIN_VALUE 0x954d + +/** @brief Max value for Local Temperature attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_MAX_VALUE 0x7fff + +/** @brief Invalid value for Local Temperature attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_INVALID 0x8000 + +/** @brief Min value for Local Temperature Calibration attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_MIN_VALUE 0xe7 + +/** @brief Max value for Local Temperature Calibration attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_MAX_VALUE 0x19 + +/** @brief Default value for Occupied Cooling Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_DEFAULT_VALUE 0x0a28 + +/** @brief Min value for Occupied Cooling Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_MIN_VALUE 0x954d + +/** @brief Max value for Occupied Cooling Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_MAX_VALUE 0x7fff + +/** @brief Default value for Occupied Heating Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_DEFAULT_VALUE 0x07d0 + +/** @brief Min value for Occupied Heating Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_MIN_VALUE 0x954d + +/** @brief Max value for Occupied Heating Setpoint attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_MAX_VALUE 0x7fff + +/** @brief Min value for Min Setpoint Dead Band attribute */ +#define ZB_ZCL_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_MIN_VALUE 0x0a + +/** @brief Max value for Min Setpoint Dead Band attribute */ +#define ZB_ZCL_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_MAX_VALUE 0x19 + +#define ZB_ZCL_THERMOSTAT_REMOTE_SENSING_LOCAL_TEMPERATURE_SENSED_REMOTELY_BIT (1<<0) + +#define ZB_ZCL_THERMOSTAT_REMOTE_SENSING_OUTDOOR_TEMPERATURE_SENSED_REMOTELY_BIT (1<<1) + +#define ZB_ZCL_THERMOSTAT_REMOTE_SENSING_OCCUPANCY_SENSED_REMOTELY_BIT (1<<2) + +#define ZB_ZCL_THERMOSTAT_REMOTE_SENSING_RESERVED_BITS \ + (~(ZB_ZCL_THERMOSTAT_REMOTE_SENSING_LOCAL_TEMPERATURE_SENSED_REMOTELY_BIT \ + | ZB_ZCL_THERMOSTAT_REMOTE_SENSING_OUTDOOR_TEMPERATURE_SENSED_REMOTELY_BIT \ + | ZB_ZCL_THERMOSTAT_REMOTE_SENSING_OCCUPANCY_SENSED_REMOTELY_BIT)) + +/** @brief Default value for Control Sequence Of Operation attribute */ +#define ZB_ZCL_THERMOSTAT_CONTROL_SEQ_OF_OPERATION_DEFAULT_VALUE 0x04 + +/** @brief Default value for System Mode attribute */ +#define ZB_ZCL_THERMOSTAT_CONTROL_SYSTEM_MODE_DEFAULT_VALUE 0x01 + +/** @brief Default value for Occupancy attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPANCY_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for AbsMinHeatSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_ABS_MIN_HEAT_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x02BC) + +/** @brief Default value for AbsMaxHeatSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_ABS_MAX_HEAT_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0BB8) + +/** @brief Default value for AbsMinCoolSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_ABS_MIN_COOL_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0640) + +/** @brief Default value for AbsMaxCoolSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_ABS_MAX_COOL_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0C80) + +/** @brief Default value for HVACSystemTypeConfiguration attribute */ +#define ZB_ZCL_THERMOSTAT_HVAC_SYSTEM_TYPE_CONFIGURATION_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for LocalTemperatureCalibration attribute */ +#define ZB_ZCL_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_DEFAULT_VALUE ((zb_int8_t)0x00) + +/** @brief Default value for UnoccupiedCoolingSetpoint attribute */ +#define ZB_ZCL_THERMOSTAT_UNOCCUPIED_COOLING_SETPOINT_DEFAULT_VALUE ((zb_int16_t)0x0A28) + +/** @brief Default value for UnoccupiedHeatingSetpoint attribute */ +#define ZB_ZCL_THERMOSTAT_UNOCCUPIED_HEATING_SETPOINT_DEFAULT_VALUE ((zb_int16_t)0x07D0) + +/** @brief Default value for MinHeatSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_MIN_HEAT_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x02BC) + +/** @brief Default value for MaxHeatSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_MAX_HEAT_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0BB8) + +/** @brief Default value for MinCoolSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_MIN_COOL_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0640) + +/** @brief Default value for MaxCoolSetpointLimit attribute */ +#define ZB_ZCL_THERMOSTAT_MAX_COOL_SETPOINT_LIMIT_DEFAULT_VALUE ((zb_int16_t)0x0C80) + +/** @brief Default value for MinSetpointDeadBand attribute */ +#define ZB_ZCL_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_DEFAULT_VALUE ((zb_int8_t)0x19) + +/** @brief Default value for RemoteSensing attribute */ +#define ZB_ZCL_THERMOSTAT_REMOTE_SENSING_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for ControlSequenceOfOperation attribute */ +#define ZB_ZCL_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_DEFAULT_VALUE ((zb_uint8_t)0x04) + +/** @brief Default value for SystemMode attribute */ +#define ZB_ZCL_THERMOSTAT_SYSTEM_MODE_DEFAULT_VALUE ((zb_uint8_t)0x01) + +/** @brief Default value for AlarmMask attribute */ +#define ZB_ZCL_THERMOSTAT_ALARM_MASK_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for RunningMode attribute */ +#define ZB_ZCL_THERMOSTAT_RUNNING_MODE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for TemperatureSetpointHold attribute */ +#define ZB_ZCL_THERMOSTAT_TEMPERATURE_SETPOINT_HOLD_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for TemperatureSetpointHoldDuration attribute */ +#define ZB_ZCL_THERMOSTAT_TEMPERATURE_SETPOINT_HOLD_DURATION_DEFAULT_VALUE ((zb_uint16_t)0xFFFF) + +/** @brief Default value for ThermostatProgrammingOperationMode attribute */ +#define ZB_ZCL_THERMOSTAT_THERMOSTAT_PROGRAMMING_OPERATION_MODE_DEFAULT_VALUE ((zb_uint8_t)0) + +/** @brief Default value for SetpointChangeSource attribute */ +#define ZB_ZCL_THERMOSTAT_SETPOINT_CHANGE_SOURCE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for SetpointChangeAmount attribute */ +#define ZB_ZCL_THERMOSTAT_SETPOINT_CHANGE_AMOUNT_DEFAULT_VALUE ((zb_int16_t)0x8000) + +/** @brief Default value for SetpointChangeSourceTimestamp attribute */ +#define ZB_ZCL_THERMOSTAT_SETPOINT_CHANGE_SOURCE_TIMESTAMP_DEFAULT_VALUE ((zb_time_t)0x00000000) + +/** @brief Default value for OccupiedSetback attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_SETBACK_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for OccupiedSetbackMin attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_SETBACK_MIN_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for OccupiedSetbackMax attribute */ +#define ZB_ZCL_THERMOSTAT_OCCUPIED_SETBACK_MAX_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for UnoccupiedSetback attribute */ +#define ZB_ZCL_THERMOSTAT_UNOCCUPIED_SETBACK_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for UnoccupiedSetbackMin attribute */ +#define ZB_ZCL_THERMOSTAT_UNOCCUPIED_SETBACK_MIN_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for UnoccupiedSetbackMax attribute */ +#define ZB_ZCL_THERMOSTAT_UNOCCUPIED_SETBACK_MAX_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for EmergencyHeatDelta attribute */ +#define ZB_ZCL_THERMOSTAT_EMERGENCY_HEAT_DELTA_DEFAULT_VALUE ((zb_uint8_t)0xFF) + +/** @brief Default value for ACType attribute */ +#define ZB_ZCL_THERMOSTAT_AC_TYPE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for ACCapacity attribute */ +#define ZB_ZCL_THERMOSTAT_AC_CAPACITY_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for ACRefrigerantType attribute */ +#define ZB_ZCL_THERMOSTAT_AC_REFRIGERANT_TYPE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for ACCompressorType attribute */ +#define ZB_ZCL_THERMOSTAT_AC_COMPRESSOR_TYPE_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for ACErrorCode attribute */ +#define ZB_ZCL_THERMOSTAT_AC_ERROR_CODE_DEFAULT_VALUE ((zb_uint32_t)0x00000000) + +/** @brief Default value for ACLouverPosition attribute */ +#define ZB_ZCL_THERMOSTAT_AC_LOUVER_POSITION_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Default value for ACCapacityFormat attribute */ +#define ZB_ZCL_THERMOSTAT_AC_CAPACITY_FORMAT_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Declare attribute list for Thermostat cluster + @param attr_list - attribute list name + @param local_temperature - pointer to variable to store Local Temperature attribute value + @param local_temperature_calibration - pointer to variable to store Local Temperature Calibration attribute value + @param occupied_cooling_setpoint - pointer to variable to store Occupied Cooling Setpoint attribute value + @param occupied_heating_setpoint - pointer to variable to store Occupied Heating Setpoint attribute value + @param control_seq_of_operation - pointer to variable to store Control Sequence Of Operation attribute value + @param system_mode - pointer to variable to store System Mode attribute value + @param start_of_week - pointer to variable to store Start of Week attribute value +*/ +#define ZB_ZCL_DECLARE_THERMOSTAT_ATTRIB_LIST(attr_list, \ + local_temperature, local_temperature_calibration, occupied_cooling_setpoint, \ + occupied_heating_setpoint, control_seq_of_operation, system_mode, start_of_week) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_ID, (local_temperature)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_ID, (local_temperature_calibration)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_ID, (occupied_cooling_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_ID, (occupied_heating_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_ID, (control_seq_of_operation)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_SYSTEM_MODE_ID, (system_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_START_OF_WEEK_ID, (start_of_week)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @brief Declare attribute list for Thermostat cluster + @param attr_list - attribute list name + @param local_temperature - pointer to variable to store Local Temperature attribute value + @param abs_min_heat_setpoint_limit - pointer to variable to store Abs Min Heat Setpoint Limit attribute value + @param abs_max_heat_setpoint_limit - pointer to variable to store Abs Max Heat Setpoint Limit attribute value + @param abs_min_cool_setpoint_limit - pointer to variable to store Abs Min Cool Setpoint Limit attribute value + @param abs_max_cool_setpoint_limit - pointer to variable to store Abs Max Cool Setpoint Limit attribute value + @param PI_cooling_demand - pointer to variable to store PI Cooling Demand attribute value + @param PI_heating_demand - pointer to variable to store PI Heating Demand attribute value + @param HVAC_system_type_configuration - pointer to variable to store HVAC system type configuration attribute value + @param local_temperature_calibration - pointer to variable to store Local Temperature Calibration attribute value + @param occupied_cooling_setpoint - pointer to variable to store Occupied Cooling Setpoint attribute value + @param occupied_heating_setpoint - pointer to variable to store Occupied Heating Setpoint attribute value + @param unoccupied_cooling_setpoint - pointer to variable to store Unoccupied Cooling Setpoint attribute value + @param unoccupied_heating_setpoint - pointer to variable to store Unoccupied Heating Setpoint attribute value + @param min_heat_setpoint_limit - pointer to variable to store Min Heat Setpoint Limit attribute value + @param max_heat_setpoint_limit - pointer to variable to store Max Heat Setpoint Limit attribute value + @param min_cool_setpoint_limit - pointer to variable to store Min Cool Setpoint Limit attribute value + @param max_cool_setpoint_limit - pointer to variable to store Max Cool Setpoint Limit attribute value + @param min_setpoint_dead_band - pointer to variable to store Min Setpoint Dead Band attribute value + @param remote_sensing - pointer to variable to store remote Sensing attribute value + @param control_seq_of_operation - pointer to variable to store Control Sequence Of Operation attribute value + @param system_mode - pointer to variable to store System Mode attribute value + @param start_of_week - pointer to variable to store Start of Week attribute value +*/ +#define ZB_ZCL_DECLARE_THERMOSTAT_ATTRIB_LIST_EXT(attr_list, \ + local_temperature, abs_min_heat_setpoint_limit, abs_max_heat_setpoint_limit, abs_min_cool_setpoint_limit, \ + abs_max_cool_setpoint_limit, PI_cooling_demand, PI_heating_demand, HVAC_system_type_configuration, \ + local_temperature_calibration, occupied_cooling_setpoint, occupied_heating_setpoint, unoccupied_cooling_setpoint, \ + unoccupied_heating_setpoint, min_heat_setpoint_limit, max_heat_setpoint_limit, min_cool_setpoint_limit, \ + max_cool_setpoint_limit, min_setpoint_dead_band, remote_sensing, control_seq_of_operation, system_mode, start_of_week) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_ID, (local_temperature)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_HEAT_SETPOINT_LIMIT_ID, (abs_min_heat_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_HEAT_SETPOINT_LIMIT_ID, (abs_max_heat_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_COOL_SETPOINT_LIMIT_ID, (abs_min_cool_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_COOL_SETPOINT_LIMIT_ID, (abs_max_cool_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_PI_COOLING_DEMAND_ID, (PI_cooling_demand)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_PI_HEATING_DEMAND_ID, (PI_heating_demand)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_HVAC_SYSTEM_TYPE_CONFIGURATION_ID, (HVAC_system_type_configuration)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_ID, (local_temperature_calibration)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_ID, (occupied_cooling_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_ID, (occupied_heating_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_COOLING_SETPOINT_ID, (unoccupied_cooling_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_HEATING_SETPOINT_ID, (unoccupied_heating_setpoint)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_MIN_HEAT_SETPOINT_LIMIT_ID, (min_heat_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_MAX_HEAT_SETPOINT_LIMIT_ID, (max_heat_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_MIN_COOL_SETPOINT_LIMIT_ID, (min_cool_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_MAX_COOL_SETPOINT_LIMIT_ID, (max_cool_setpoint_limit)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_ID, (min_setpoint_dead_band)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_REMOTE_SENSING_ID, (remote_sensing)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_ID, (control_seq_of_operation)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_SYSTEM_MODE_ID, (system_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_START_OF_WEEK_ID, (start_of_week)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @brief Bits of ThermostatProgrammingOperationMode */ +enum zb_zcl_thermostat_programming_operation_mode_bit_e +{ + /*! Schedule programming bit */ + ZB_ZCL_THERMOSTAT_SCHEDULE_PROGRAMMING_MODE_BIT = 0x01, + /*! Auto/recovery bit */ + ZB_ZCL_THERMOSTAT_AUTO_RECOVERY_PROGRAMMING_MODE_BIT = 0x02, + /*! Economy/energy star bit */ + ZB_ZCL_THERMOSTAT_ECONOMY_ENERGY_START_PROGRAMMING_MODE_BIT = 0x04, +}; + +/*! @} */ /* Thermostat cluster attributes */ + +/*! @name Thermostat cluster commands + @{ +*/ + +/*! @brief Thermostat cluster command identifiers + @see ZCL spec, subclause 6.3.2.3 +*/ +enum zb_zcl_thermostat_cmd_e +{ + /** Setpoint Raise/Lower command */ + ZB_ZCL_CMD_THERMOSTAT_SETPOINT_RAISE_LOWER = 0x00, + /** Set Weekly Schedule command */ + ZB_ZCL_CMD_THERMOSTAT_SET_WEEKLY_SCHEDULE = 0x01, + /** Get Weekly Schedule command */ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE = 0x02, + /** Clear Weekly Schedule command */ + ZB_ZCL_CMD_THERMOSTAT_CLEAR_WEEKLY_SCHEDULE = 0x03, + /** Get Relay Status Log command */ + ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG = 0x04 +}; + +/*! @brief Thermostat cluster command identifiers + @see ZCL spec, subclause 6.3.2.4 +*/ +enum zb_zcl_thermostat_cmd_resp_ha_e +{ + /** Get Weekly Schedule response command */ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE_RESP = 0x00, + /** Get Relay Status Log response command */ + ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG_RESP = 0x01 +}; + +/** @cond internals_doc */ +/* Thermostat cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE_RESP, \ + ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG_RESP + +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_THERMOSTAT_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_THERMOSTAT_SETPOINT_RAISE_LOWER, \ + ZB_ZCL_CMD_THERMOSTAT_SET_WEEKLY_SCHEDULE, \ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE, \ + ZB_ZCL_CMD_THERMOSTAT_CLEAR_WEEKLY_SCHEDULE, \ + ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG + +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_THERMOSTAT_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/*! @} */ /* Thermostat cluster commands */ + +/*! + @cond internals_doc + @internal @name Thermostat cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_HEAT_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_HEAT_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_HEAT_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_HEAT_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_COOL_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MIN_COOL_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_COOL_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_ABS_MAX_COOL_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_PI_COOLING_DEMAND_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_PI_COOLING_DEMAND_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_PI_HEATING_DEMAND_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_PI_HEATING_DEMAND_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_HVAC_SYSTEM_TYPE_CONFIGURATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_HVAC_SYSTEM_TYPE_CONFIGURATION_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_LOCAL_TEMPERATURE_CALIBRATION_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_COOLING_SETPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_OCCUPIED_HEATING_SETPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_COOLING_SETPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_COOLING_SETPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_HEATING_SETPOINT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_UNOCCUPIED_HEATING_SETPOINT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_MIN_HEAT_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_MIN_HEAT_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_MAX_HEAT_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_MAX_HEAT_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_MIN_COOL_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_MIN_COOL_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_MAX_COOL_SETPOINT_LIMIT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_MAX_COOL_SETPOINT_LIMIT_ID, \ + ZB_ZCL_ATTR_TYPE_S16, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_MIN_SETPOINT_DEAD_BAND_ID, \ + ZB_ZCL_ATTR_TYPE_S8, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_REMOTE_SENSING_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_REMOTE_SENSING_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_CONTROL_SEQUENCE_OF_OPERATION_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_SYSTEM_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_SYSTEM_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE | ZB_ZCL_ATTR_ACCESS_SCENE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_START_OF_WEEK_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_START_OF_WEEK_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Thermostat cluster */ +#define ZB_ZCL_THERMOSTAT_REPORT_ATTR_COUNT 1 + +/***************************** commands *****************************/ + +/* Setpoint is defined in 0.01C, while amount is defined in 0.1C */ +#define ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_AMOUNT_MUL 10 + +/** @internal Structure for Setpoint Raise/Lower command + */ +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_setpoint_raise_lower_req_s +{ + zb_uint8_t mode; + zb_int8_t amount; +} ZB_PACKED_STRUCT zb_zcl_thermostat_setpoint_raise_lower_req_t; + +/*! @brief Values for Mode field, + @see ZCL spec, subclause 6.3.2.3.1.2 */ +enum zb_zcl_thermostat_setpoint_raise_lower_mode_e +{ + /*! Heat value */ + ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_MODE_HEAT = 0x00, + /*! Cool value */ + ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_MODE_COOL = 0x01, + /*! Both (Heat and Cool) value */ + ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_MODE_BOTH = 0x02, + + ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_MODE_RESERVED = 0x03 +}; + +#define ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_thermostat_setpoint_raise_lower_req_t) + +/*! @brief Send Setpoint Raise/Lower command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param mode - Mode value + @param amount - Amount value +*/ +#define ZB_ZCL_THERMOSTAT_SEND_SETPOINT_RAISE_LOWER_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, mode, amount) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_THERMOSTAT_SETPOINT_RAISE_LOWER); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (mode)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (amount)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_THERMOSTAT, cb);\ +} + +/*! + @brief Parses Get Setpoint Raise/Lower command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param setpoint_raise_lower_req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_THERMOSTAT_GET_SETPOINT_RAISE_LOWER_REQ(data_buf, req, status) \ +{ \ + zb_zcl_thermostat_setpoint_raise_lower_req_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_THERMOSTAT_SETPOINT_RAISE_LOWER_REQ_PAYLOAD_LEN ? \ + (zb_zcl_thermostat_setpoint_raise_lower_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_thermostat_setpoint_raise_lower_req_t)); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/* Add/Get Weekly Schedule record for Set/Get Weekly Schedule commands */ + +/** @internal Structure for Weekly Schedule record + */ +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_weekly_schedule_point_pair_s +{ + zb_uint16_t transition_time; + zb_uint16_t heat_set_point; + zb_uint16_t cool_set_point; +} ZB_PACKED_STRUCT zb_zcl_thermostat_weekly_schedule_point_pair_t; + +#define ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_POINT_PAIR_FULL_SIZE \ + sizeof(zb_zcl_thermostat_weekly_schedule_point_pair_t) + +#define ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_POINT_PAIR_ONE_SIZE \ + sizeof(zb_zcl_thermostat_weekly_schedule_point_pair_t) - sizeof(zb_uint16_t) + +#define ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MAX_NUM_OF_TRANSITIONS 10 + +/*! @brief Values for Mode for Sequence field, + @see ZCL spec, subclause 10.1.3.3.1.4 */ +enum zb_zcl_thermostat_weekly_schedule_mode_for_seq_e +{ + /*! Heat value */ + ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_HEAT = 0x01, + /*! Cool value */ + ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_COOL = 0x02, + /*! Both (Heat and Cool) value */ + ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_BOTH = 0x03, + + ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_RESERVED = 0x04 +}; + +/** @brief Add attribute value to command payload + @param cmd_ptr - pointer to a command data memory + @param mode_for_seq - Mode For Sequence value (from header) + @param transition_time - Transition Time value + @param heat_set_point - Heat Set Point value + @param cool_set_point - Cool Set Point value +*/ +#define ZB_ZCL_THERMOSTAT_ADD_VALUE_WEEKLY_SCHEDULE(cmd_ptr, \ + mode_for_seq, transition_time, heat_set_point, cool_set_point) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (transition_time)); \ + if (mode_for_seq & ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_HEAT) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (heat_set_point)); \ + } \ + if (mode_for_seq & ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_COOL) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (cool_set_point)); \ + } \ +} + +/** @brief Parses Set Weekly Schedule request and returns next Set point pair record or NULL if there + * is no more data. + + If request contains invalid data, NULL is returned. + @param data_buf - pointer to zb_buf_t buffer containing write attribute request data + @param mode_for_seq - Mode For Sequence value (from Set Weekly Schedule header) + @param pair_req - out pointer to Set Point Pair record + */ +#define ZB_ZCL_THERMOSTAT_GET_NEXT_WEEKLY_SCHEDULE_POINT_PAIR_REQ(data_buf, mode_for_seq, pair_req, status) \ +{ \ + zb_zcl_thermostat_weekly_schedule_point_pair_t *pair_req_ptr; \ + zb_uint8_t req_size; \ + \ + if (mode_for_seq == ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_BOTH) \ + { \ + req_size = ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_POINT_PAIR_FULL_SIZE; \ + } \ + else \ + { \ + req_size = ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_POINT_PAIR_ONE_SIZE; \ + } \ + \ + pair_req_ptr = (zb_buf_len(data_buf) >= req_size) ? \ + (zb_zcl_thermostat_weekly_schedule_point_pair_t*)zb_buf_begin(data_buf) : NULL; \ + if (pair_req_ptr) \ + { \ + ZB_MEMCPY(&(pair_req), pair_req_ptr, req_size); \ + \ + ZB_ZCL_HTOLE16_INPLACE(&(pair_req.transition_time)); \ + ZB_ZCL_HTOLE16_INPLACE(&(pair_req.heat_set_point)); \ + if (mode_for_seq == ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_COOL) \ + { \ + (pair_req).cool_set_point = (pair_req).heat_set_point; \ + } \ + \ + (void)zb_buf_cut_left((data_buf), req_size); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/* Set Weekly Schedule command */ + +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_set_weekly_schedule_req_s +{ + zb_uint8_t num_of_transitions; + zb_uint8_t day_of_week; + zb_uint8_t mode_for_seq; +} ZB_PACKED_STRUCT zb_zcl_thermostat_set_weekly_schedule_req_t; + +#define ZB_ZCL_THERMOSTAT_SET_WEEKLY_SCHEDULE_REQ_SIZE \ + sizeof(zb_zcl_thermostat_set_weekly_schedule_req_t) + +/* 2018/08/10 CR:MAJOR (rev. 39327): According to the spec, one Set Weekly Schedule pkt may contain up to 10 df + * transitions, but we support only one. */ + +/** @brief Initialize Set Weekly Schedule command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param def_resp - enable/disable default response + @param num_of_transition - Number Of Transition value + @param day_of_week - Day Of Week value + @param mode_for_seq - Mode For Sequence value + @param transition - Transition Time value + @param heat_set - Heat Set value + @param cool_set - Cool Set value +*/ +#define ZB_ZCL_THERMOSTAT_INIT_SET_WEEKLY_SCHEDULE_REQ(buffer, \ + cmd_ptr, def_resp, num_of_transition, day_of_week, mode_for_seq, \ + transition, heat_set, cool_set) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(cmd_ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(cmd_ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_THERMOSTAT_SET_WEEKLY_SCHEDULE); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (num_of_transition)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (day_of_week)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (mode_for_seq)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (transition)); \ + if (ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_HEAT == (mode_for_seq)) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (heat_set)); \ + } \ + else \ + if (ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_COOL == (mode_for_seq)) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (cool_set)); \ + } \ + else \ + if (ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MODE_FOR_SEQ_BOTH == (mode_for_seq)) \ + { \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (heat_set)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(cmd_ptr, (cool_set)); \ + } \ +} + + +/** @brief Send Set Weekly Schedule command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_THERMOSTAT_SEND_SET_WEEKLY_SCHEDULE_REQ( \ + buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id, \ + ZB_ZCL_CLUSTER_ID_THERMOSTAT, cb); \ +} + +/** @brief Parses Set Weekly Schedule request header + + If request contains invalid data, status is ZB_FALSE. + @param data_buf - pointer to zb_buf_t buffer containing write attribute request data + @param req - record of type @ref zb_zcl_thermostat_set_weekly_schedule_req_t + @param status - result of parsing + */ +#define ZB_ZCL_THERMOSTAT_GET_SET_WEEKLY_SCHEDULE_REQ(data_buf, req, status) \ +{ \ + zb_zcl_thermostat_set_weekly_schedule_req_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_THERMOSTAT_SET_WEEKLY_SCHEDULE_REQ_SIZE ? \ + (zb_zcl_thermostat_set_weekly_schedule_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_thermostat_set_weekly_schedule_req_t)); \ + ZB_ASSERT(req.num_of_transitions <= ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MAX_NUM_OF_TRANSITIONS);\ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + \ + (void)zb_buf_cut_left((data_buf), sizeof(zb_zcl_thermostat_set_weekly_schedule_req_t)); \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/* Get Weekly Schedule command */ + +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_get_weekly_schedule_req_s +{ + zb_uint8_t days_to_return; + zb_uint8_t mode_to_return; +} ZB_PACKED_STRUCT zb_zcl_thermostat_get_weekly_schedule_req_t; + +#define ZB_ZCL_THERMOSTAT_GET_WEEKLY_SCHEDULE_REQ_PAYLOAD_LEN \ + sizeof(zb_zcl_thermostat_get_weekly_schedule_req_t) + +/*! @brief Send Get Weekly Schedule command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param days_to_return - Days To Return value + @param mode_to_return - Mode To Return value +*/ +#define ZB_ZCL_THERMOSTAT_SEND_GET_WEEKLY_SCHEDULE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + days_to_return, mode_to_return) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (days_to_return)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (mode_to_return)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((buffer), (addr), (dst_addr_mode), \ + (dst_ep), (ep), (prfl_id), ZB_ZCL_CLUSTER_ID_THERMOSTAT, (cb)); \ +} + +/*! + @brief Parses Get Weekly Schedule command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - record of type @ref zb_zcl_thermostat_set_weekly_schedule_req_t + @param status - success or not read parameters - ZB_ZCL_PARSE_STATUS_SUCCESS or + ZB_ZCL_PARSE_STATUS_FAILURE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_THERMOSTAT_GET_GET_WEEKLY_SCHEDULE_REQ(data_buf, req, status) \ +{ \ + zb_zcl_thermostat_get_weekly_schedule_req_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_THERMOSTAT_GET_WEEKLY_SCHEDULE_REQ_PAYLOAD_LEN ? \ + (zb_zcl_thermostat_get_weekly_schedule_req_t*)zb_buf_begin(data_buf) : NULL;\ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_thermostat_get_weekly_schedule_req_t)); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/* Get Weekly Schedule response command */ + +/** Structure for Get Weekly Schedule resp command + */ +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_get_weekly_schedule_resp_s +{ + zb_uint8_t num_of_transitions; + zb_uint8_t day_of_week; + zb_uint8_t mode_for_seq; +} ZB_PACKED_STRUCT zb_zcl_thermostat_get_weekly_schedule_resp_t; + +/** @brief Initialize Get Weekly Schedule resp command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param seq - sequency + @param num_of_transitions - Number Of Transition value + @param day_of_week - Day Of Week value + @param mode_for_seq - Mode For Sequence value +*/ +#define ZB_ZCL_THERMOSTAT_INIT_GET_WEEKLY_SCHEDULE_RESP(buffer, cmd_ptr, seq, \ + num_of_transitions, day_of_week, mode_for_seq) \ +{ \ + cmd_ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(cmd_ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(cmd_ptr, (seq), \ + ZB_ZCL_CMD_THERMOSTAT_GET_WEEKLY_SCHEDULE_RESP); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (num_of_transitions)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (day_of_week)); \ + ZB_ZCL_PACKET_PUT_DATA8(cmd_ptr, (mode_for_seq)); \ +} + +/** @brief Send Get Weekly Schedule resp command + @param buffer - buffer to store command data + @param cmd_ptr - pointer to a command data memory + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param profile_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_THERMOSTAT_SEND_GET_WEEKLY_SCHEDULE_RESP( \ + buffer, cmd_ptr, addr, dst_addr_mode, dst_ep, ep, profile_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, cmd_ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, profile_id,\ + ZB_ZCL_CLUSTER_ID_THERMOSTAT, cb); \ +} + +/** @brief Parses Get Weekly Schedule response header + + If request contains invlid data, status is ZB_FALSE. + @param data_buf - pointer to zb_buf_t buffer containing write attribute request data + @param resp - record of type @ref zb_zcl_thermostat_get_weekly_schedule_resp_t + @param status - result of parsing + */ +#define ZB_ZCL_THERMOSTAT_GET_GET_WEEKLY_SCHEDULE_RESP(data_buf, resp, status) \ +{ \ + zb_zcl_thermostat_get_weekly_schedule_resp_t *resp_ptr = \ + zb_buf_len(data_buf) >= sizeof(zb_zcl_thermostat_get_weekly_schedule_resp_t) ? \ + (zb_zcl_thermostat_get_weekly_schedule_resp_t*)zb_buf_begin(data_buf) : NULL; \ + if (resp_ptr) \ + { \ + ZB_MEMCPY(&(resp), resp_ptr, sizeof(zb_zcl_thermostat_get_weekly_schedule_resp_t)); \ + ZB_ASSERT(resp.num_of_transitions <= \ + ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_MAX_NUM_OF_TRANSITIONS); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + \ + (void)zb_buf_cut_left((data_buf), sizeof(zb_zcl_thermostat_get_weekly_schedule_resp_t)); \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/* Clear Weekly Schedule command */ +/*! @brief Clear Weekly Schedule command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_THERMOSTAT_SEND_CLEAR_WEEKLY_SCHEDULE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_THERMOSTAT_CLEAR_WEEKLY_SCHEDULE); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((buffer), (addr), (dst_addr_mode), (dst_ep), \ + (ep), (prfl_id), ZB_ZCL_CLUSTER_ID_THERMOSTAT, (cb)); \ +} + +/* Get Relay Status Log command */ +/*! @brief Send Get Relay Status Log req command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_THERMOSTAT_SEND_GET_RELAY_STATUS_LOG_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT((buffer), (addr), (dst_addr_mode), (dst_ep), \ + (ep), (prfl_id), ZB_ZCL_CLUSTER_ID_THERMOSTAT, (cb)); \ +} + +/* Get Relay Status Log response */ + +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_get_relay_status_log_resp_s +{ + zb_uint16_t time_of_day; + zb_uint8_t relay_status; + zb_int16_t local_temperature; + zb_uint8_t humidity_in_percentage; + zb_int16_t set_point; + zb_uint16_t unread_entries; +} ZB_PACKED_STRUCT zb_zcl_thermostat_get_relay_status_log_resp_t; + +#define ZB_ZCL_THERMOSTAT_GET_RELAY_STATUS_LOG_RESP_SIZE \ + sizeof(zb_zcl_thermostat_get_relay_status_log_resp_t) + +/*! @brief Send Get Relay Status Log resp command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param seq - sequency + @param cb - callback for getting command send status + @param time_of_day - Time Of Day value + @param relay_status - Relay Status value + @param local_temperature - Local Temperature value + @param humidity_in_percentage - Humidity In Percentage value + @param set_point - Set Point value + @param unread_entries - Unread Entries value +*/ +#define ZB_ZCL_THERMOSTAT_SEND_GET_RELAY_STATUS_LOG_RESP( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, seq, cb, time_of_day, relay_status, \ + local_temperature, humidity_in_percentage, set_point, unread_entries) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RES_FRAME_CONTROL(ptr); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(ptr, seq, ZB_ZCL_CMD_THERMOSTAT_GET_RELAY_STATUS_LOG_RESP); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (time_of_day)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (relay_status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (local_temperature)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (humidity_in_percentage)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (set_point)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(ptr, (unread_entries)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_THERMOSTAT, cb); \ +} + +/*! + @brief Parses Get Relay Status Log command and fills data request + structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param resp - variable to save command request + @param status - success or not read parameters - ZB_ZCL_PARSE_STATUS_SUCCESS or + ZB_ZCL_PARSE_STATUS_FAILURE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_THERMOSTAT_GET_GET_RELAY_STATUS_LOG_RESP(data_buf, resp, status) \ +{ \ + zb_zcl_thermostat_get_relay_status_log_resp_t *resp_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_THERMOSTAT_GET_RELAY_STATUS_LOG_RESP_SIZE ? \ + (zb_zcl_thermostat_get_relay_status_log_resp_t*)zb_buf_begin(data_buf) : NULL; \ + if (resp_ptr) \ + { \ + ZB_MEMCPY(&(resp), resp_ptr, sizeof(zb_zcl_thermostat_get_relay_status_log_resp_t));\ + ZB_ZCL_HTOLE16_INPLACE(&(resp)->time_of_day); \ + /* FIXME: Can we use it with signed 16-bit int? */ \ + ZB_ZCL_HTOLE16_INPLACE(&(resp)->local_temperature); \ + ZB_ZCL_HTOLE16_INPLACE(&(resp)->set_point); \ + ZB_ZCL_HTOLE16_INPLACE(&(resp)->unread_entries); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/*! @} + * @endcond */ /* Thermostat cluster internals */ + +/*! @cond internals_doc + @name Thermostat cluster command internals + Internal structures and defines for execute cluster command handlers. + @{ +*/ + +/** @brief Size of table with Weekly Schedule records */ +#define ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_TABLE_SIZE 20 + +/** @brief Flag days field "record is free" */ +#define ZB_ZCL_THERMOSTAT_WEEKLY_FREE_RECORD 0 + +/** @brief Bit set "All days" */ +#define ZB_ZCL_THERMOSTAT_WEEKLY_ALL 0x7f + +/** @brief Bit "Weekly vacation" */ +#define ZB_ZCL_THERMOSTAT_WEEKLY_VACATION (1<<7) + +/** @brief Parameter - Thermostat will be schedule + * without any specific record*/ +#define ZB_ZCL_THERMOSTAT_PROCESS_NONE 0xff + +/** @brief Second per week */ +#define ZB_SECOND_PER_WEEK (60*60*24*7) + +/** @brief Second per day */ +#define ZB_SECOND_PER_DAY (60*60*24) + +/** @brief Second per minutes */ +#define ZB_SECOND_PER_MINUTE 60 + +/** @brief Days per week */ +#define ZB_DAYS_PER_WEEK 7 + +/** @brief Time delta for using setpoint: skip setpoint if it expired + * more then this value */ +#define ZB_ZCL_THERMOSTAT_SETPOINT_TIME_DELTA (10 * 60) /* 10 minutes */ + +/** @brief Subtract time in seconds round week */ +#define ZB_WEEK_TIME_SUBTRACT(a, b) ((a) > (b)) ? ((a) - (b)) : ((a) + ZB_SECOND_PER_WEEK - (b)) + +#ifdef ZB_TIMER_32 + // 1 day (24h) +/** @brief Maximum period of Thermostat process loop */ + #define ZB_ZCL_THERMOSTAT_TIMER_MAX (24*60*60) +#else + // 5 min +/** @brief Maximum period of Thermostat process loop */ + #define ZB_ZCL_THERMOSTAT_TIMER_MAX (5*60) +#endif + + +/** @brief Struct with one Weekly Schedule attribute */ +typedef struct zb_zcl_thermostat_weekly_schedule_record_s +{ + zb_uint8_t days; /*< days, ZB_ZCL_THERMOSTAT_WEEKLY_FREE_RECORD (0) - free record */ + zb_uint32_t start_time; /*< seconds after midnight */ + zb_uint8_t mode; /*< Mode for Sequence */ + zb_uint16_t heat_setpoint; /*< Heat Set Point */ + zb_uint16_t cool_setpoint; /*< Cool Set Point */ +} +zb_zcl_thermostat_weekly_schedule_record_t; + +/*! @} + @endcond */ /* Thermostat cluster internals */ + +/*! @} */ /* ZCL HA Thermostat cluster definitions */ + +/** @cond internals_doc */ +/** @brief Struct with Context Thermostat cluster */ +typedef struct zb_zcl_thermostat_context_s +{ + zb_zcl_thermostat_weekly_schedule_record_t schedule_table[ZB_ZCL_THERMOSTAT_WEEKLY_SCHEDULE_TABLE_SIZE]; + zb_uint8_t setpoint_mode; +} +zb_zcl_thermostat_context_t; + +/** @brief Declare run Thermostat command for User Application +*/ +typedef ZB_PACKED_PRE struct zb_zcl_thermostat_value_param_s +{ + zb_uint8_t mode; /*!< Mode for Sequence */ + zb_uint16_t heat_setpoint; /*!< Heat Set Point */ + zb_uint16_t cool_setpoint; /*!< Cool Set Point */ +} zb_zcl_thermostat_value_param_t; +/*! @} + * @endcond */ /* internals_doc */ +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_thermostat_init(void); +zb_uint8_t zb_zcl_thermostat_get_current_day_of_week(zb_uint8_t start_of_week); + +void zb_zcl_thermostat_init_server(void); +void zb_zcl_thermostat_init_client(void); +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_SERVER_ROLE_INIT zb_zcl_thermostat_init_server +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_CLIENT_ROLE_INIT zb_zcl_thermostat_init_client + +#endif /* ! defined ZB_ZCL_THERMOSTAT_H */ diff --git a/zboss/include/zcl/zb_zcl_thermostat_ui_config.h b/zboss/include/zcl/zb_zcl_thermostat_ui_config.h new file mode 100644 index 0000000000..44881c835d --- /dev/null +++ b/zboss/include/zcl/zb_zcl_thermostat_ui_config.h @@ -0,0 +1,173 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Thermostat UI Configuration cluster defintions +*/ + +#if ! defined ZB_ZCL_THERMOSTAT_UI_CONFIG_H +#define ZB_ZCL_THERMOSTAT_UI_CONFIG_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Cluster ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG */ + +/*! @addtogroup ZB_ZCL_THERMOSTAT_UI_CONFIG + @{ + @name Thermostat UI Configuration cluster attributes + @{ +*/ + +/*! @brief Thermostat UI Configuration cluster attribute identifiers + @see ZCL spec, subclause 6.6.2.2 +*/ +enum zb_zcl_thermostat_ui_config_attr_e +{ + /** @brief Temperature Display Mode attribute */ + ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_ID = 0x0000, + /** @brief Keypad Lockout attribute */ + ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_ID = 0x0001, + /** The ScheduleProgrammingVisibility attribute is used to hide the weekly + * schedule programming functionality or menu on a thermostat from a user + * to prevent local user programming of the weekly schedule. */ + ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_SCHEDULE_PROGRAMMING_VISIBILITY_ID = 0x0002, +}; + +/*! @brief Values for Temperature Display Mode attribute, + @see ZCL spec, subclause 6.6.2.2.1 */ +enum zb_zcl_thermostat_ui_config_temperature_display_mode_e +{ + /*! Temperature in C value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_IN_C = 0x00, + /*! Temperature in F value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_IN_F = 0x01, + + ZB_ZCL_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_RESERVED = 0x02 +}; + +/*! @brief Values for Keypad Lockout attribute, + @see ZCL spec, subclause 6.6.2.2.2 */ +enum zb_zcl_thermostat_ui_config_keypad_lockout_e +{ + /*! No Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_NO_LOCKOUT = 0x00, + /*! Level 1 Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_LEVEL_1 = 0x01, + /*! Level 2 Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_LEVEL_2 = 0x02, + /*! Level 3 Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_LEVEL_3 = 0x03, + /*! Level 4 Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_LEVEL_4 = 0x04, + /*! Level 5 Lockout value */ + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_LEVEL_5 = 0x05, + + ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_RESERVED = 0x06 +}; + +/** @brief Default value for Temperature Display Mode attribute */ +#define ZB_ZCL_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_DEFAULT_VALUE 0x00 + +/** @brief Default value for Keypad Lockout attribute */ +#define ZB_ZCL_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_DEFAULT_VALUE 0x00 + +/** @brief Default value for ScheduleProgrammingVisibility attribute */ +#define ZB_ZCL_THERMOSTAT_UI_CONFIG_SCHEDULE_PROGRAMMING_VISIBILITY_DEFAULT_VALUE ((zb_uint8_t)0x00) + +/** @brief Declare attribute list for Thermostat UI Configuration cluster + @param attr_list - attribute list name + @param temperature_display_mode - pointer to variable to store Temperature Display Mode attribute value + @param keypad_lockout - pointer to variable to store Keypad Lockout attribute value +*/ +#define ZB_ZCL_DECLARE_THERMOSTAT_UI_CONFIG_ATTRIB_LIST(attr_list, temperature_display_mode, keypad_lockout) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_ID, (temperature_display_mode)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_ID, (keypad_lockout)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/*! @} */ /* Thermostat UI Configuration cluster attributes */ + +/*! @name Thermostat UI Configuration cluster commands + @{ +*/ + +/*! @} */ /* Thermostat UI Configuration cluster commands */ + +/*! @cond internals_doc + @internal @name Thermostat UI Configuration cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_TEMPERATURE_DISPLAY_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_THERMOSTAT_UI_CONFIG_KEYPAD_LOCKOUT_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Thermostat UI Configuration cluster */ +#define ZB_ZCL_THERMOSTAT_UI_CONFIG_REPORT_ATTR_COUNT 0 + +/*! @} + @endcond */ /* Thermostat UI Configuration cluster internals */ + +/*! @} */ /* ZCL HA Thermostat UI Configuration cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_thermostat_ui_config_init_server(void); +void zb_zcl_thermostat_ui_config_init_client(void); +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG_SERVER_ROLE_INIT zb_zcl_thermostat_ui_config_init_server +#define ZB_ZCL_CLUSTER_ID_THERMOSTAT_UI_CONFIG_CLIENT_ROLE_INIT zb_zcl_thermostat_ui_config_init_client + +#endif /* ! defined ZB_ZCL_THERMOSTAT_UI_CONFIG_H */ diff --git a/zboss/include/zcl/zb_zcl_time.h b/zboss/include/zcl/zb_zcl_time.h new file mode 100644 index 0000000000..c6445c2584 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_time.h @@ -0,0 +1,435 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Time cluster defintions +*/ + +#if ! defined ZB_ZCL_TIME_H +#define ZB_ZCL_TIME_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_TIME ZCL Time cluster + * @{ + * @details + */ + +/* Cluster ZB_ZCL_CLUSTER_ID_TIME */ + +/** + * @brief Set real time clock callback + * @param[in] time - UTC time at which real time clock will be set + * @return ZB_TRUE if real time clock was set to new value and ZB_FALSE otherwise + * + */ +typedef zb_bool_t (*zb_zcl_time_set_real_time_clock_t)(zb_uint32_t time); + +/** @cond internals_doc */ + +/** + * @brief Set user's callback that will be initialize real time clock on device by + * specified value. + * @param[in] cb - Callback function + * @see zb_zcl_time_set_real_time_clock_t + * + */ +void zb_zcl_set_real_time_clock_callback(zb_zcl_time_set_real_time_clock_t cb); + +/* typedef struct */ + +/** This enum defines possible authoritative levels of time server */ +enum time_server_authoritative_level_e +{ + ZB_ZCL_TIME_SERVER_NOT_CHOSEN = 0, + ZB_ZCL_TIME_HAS_SYNCHRONIZED_BIT, + ZB_ZCL_TIME_HAS_MASTER_BIT, + ZB_ZCL_TIME_HAS_MASTER_AND_SUPERSEDING_BITS, + ZB_ZCL_TIME_COORDINATOR_WITH_MASTER_AND_SUPERSEDING_BITS +}; + +/** Time synchronization payload */ +typedef struct zb_zcl_time_sync_payload_s +{ + /** Network time received from the most authoritative Time server */ + zb_uint32_t time; + /** Source addres of the most authoritative Time server */ + zb_uint16_t addr; + /** Source endpoint of the most authoritative Time server */ + zb_uint8_t endpoint; + /** Authoritative level of Time source server. + * @see @ref time_server_authoritative_level_e + */ + zb_uint8_t level; +} zb_zcl_time_sync_payload_t; + +/** @endcond */ /* internals_doc */ + +/** + * @brief Set user's callback that will be initialize real time clock on device by + * specified value. + * "If the Master bit of the @ref ZB_ZCL_ATTR_TIME_TIME_STATUS_ID "TimeStatus" attribute has a value of 0, + * writing to @ref ZB_ZCL_ATTR_TIME_TIME_ID "Time" attribute SHALL set the real time clock to the written value, + * otherwise it cannot be written." + * @see ZCL spec, subclause 3.12.2.2.1 + * + */ +#define ZB_ZCL_TIME_SET_REAL_TIME_CLOCK_CB(func_ptr) (zb_zcl_set_real_time_clock_callback((func_ptr))) + +/** @defgroup ZB_ZCL_TIME_ATTRS Time cluster attributes + @{ +*/ + +/*! @brief Time cluster attribute identifiers + @see ZCL spec, subclause 3.12.2.2 +*/ +enum zb_zcl_time_attr_e +{ + /*! @brief Time attribute */ + ZB_ZCL_ATTR_TIME_TIME_ID = 0x0000, + /*! @brief Time Status attribute */ + ZB_ZCL_ATTR_TIME_TIME_STATUS_ID = 0x0001, + /*! @brief Time Zone attribute */ + ZB_ZCL_ATTR_TIME_TIME_ZONE_ID = 0x0002, + /*! @brief Dst Start attribute */ + ZB_ZCL_ATTR_TIME_DST_START_ID = 0x0003, + /*! @brief Dst End attribute */ + ZB_ZCL_ATTR_TIME_DST_END_ID = 0x0004, + /*! @brief Dst Shift attribute */ + ZB_ZCL_ATTR_TIME_DST_SHIFT_ID = 0x0005, + /*! @brief Standard Time attribute */ + ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID = 0x0006, + /*! @brief Local Time attribute */ + ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID = 0x0007, + /*! @brief Last Set Time attribute */ + ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID = 0x0008, + /*! @brief Valid Until Time attribute */ + ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID = 0x0009 +}; + +/*! @brief Permissible values for Time Status attribute, + @see ZCL spec, subclause 3.12.2.2.2 */ +enum zb_zcl_time_time_status_e +{ + /*! Master value */ + ZB_ZCL_TIME_MASTER = 0, + /*! Synchronized value */ + ZB_ZCL_TIME_SYNCHRONIZED = 1, + /*! Master Zone Dst value */ + ZB_ZCL_TIME_MASTER_ZONE_DST = 2, + /*! Superseding value */ + ZB_ZCL_TIME_SUPERSEDING = 3 +}; + + +/** Check if @e Master bit of @ref zb_zcl_time_attr_e::ZB_ZCL_ATTR_TIME_TIME_STATUS_ID "TimeStatus" attribute is set. + * @param val - 8-bit that contains value of @e TimeStatus attribute + * @return zb_uint8_t value greater then 0 if @e Master bit is set, and return 0 otherwise. + * @see @ref zb_zcl_time_time_status_e +*/ +#define ZB_ZCL_TIME_TIME_STATUS_MASTER_BIT_IS_SET(val) ((val) & (1 << ZB_ZCL_TIME_MASTER)) +/** Check if @e Synchronized bit of @ref zb_zcl_time_attr_e::ZB_ZCL_ATTR_TIME_TIME_STATUS_ID "TimeStatus" attribute is set. + * @param val - 8-bit that contains value of @e TimeStatus attribute + * @return zb_uint8_t value greater then 0 if @e Synchronized bit is set, and return 0 otherwise. + * @see @ref zb_zcl_time_time_status_e +*/ +#define ZB_ZCL_TIME_TIME_STATUS_SYNCHRONIZED_BIT_IS_SET(val) ((val) & (1 << ZB_ZCL_TIME_SYNCHRONIZED)) +/** Check if MasterZoneDST bit of @ref zb_zcl_time_attr_e::ZB_ZCL_ATTR_TIME_TIME_STATUS_ID "TimeStatus" attribute is set. + * @param val - 8-bit that contains value of @e TimeStatus attribute + * @return zb_uint8_t value greater then 0 if @e MasterZoneDST bit is set, and return 0 otherwise. + * @see @ref zb_zcl_time_time_status_e +*/ +#define ZB_ZCL_TIME_TIME_STATUS_MASTER_ZONE_DST_BIT_IS_SET(val) ((val) & (1 << ZB_ZCL_TIME_MASTER_ZONE_DST)) +/** Check if Superseding bit of @ref zb_zcl_time_attr_e::ZB_ZCL_ATTR_TIME_TIME_STATUS_ID "TimeStatus" attribute is set. + * @param val - 8-bit that contains value of @e TimeStatus attribute + * @return zb_uint8_t value greater then 0 if @e Superseding bit is set, and return 0 otherwise. + * @see @ref zb_zcl_time_time_status_e +*/ +#define ZB_ZCL_TIME_TIME_STATUS_SUPERSEDING_BIT_IS_SET(val) ((val) & (1 << ZB_ZCL_TIME_SUPERSEDING)) + + +/** @brief Invalid value of Time attribute */ +#define ZB_ZCL_TIME_TIME_INVALID_VALUE ((zb_time_t)0xFFFFFFFF) + +/** @brief Default value for Time attribute */ +#define ZB_ZCL_TIME_TIME_DEFAULT_VALUE ZB_ZCL_TIME_TIME_INVALID_VALUE + +/** @brief Minimum value for Time attribute */ +#define ZB_ZCL_TIME_TIME_MIN_VALUE ((zb_time_t)0x0) + +/** @brief Maximum value for Time attribute */ +#define ZB_ZCL_TIME_TIME_MAX_VALUE ((zb_time_t)0xFFFFFFFE) + +/** @brief Default value for Time Status attribute */ +#define ZB_ZCL_TIME_TIME_STATUS_DEFAULT_VALUE 0x00 + +/** @brief Default value for Time Zone attribute */ +#define ZB_ZCL_TIME_TIME_ZONE_DEFAULT_VALUE 0x00000000 + +/** @brief Default value for DstStart attribute */ +#define ZB_ZCL_TIME_DST_START_DEFAULT_VALUE ((zb_uint32_t)0xFFFFFFFF) + +/** @brief Default value for DstEnd attribute */ +#define ZB_ZCL_TIME_DST_END_DEFAULT_VALUE ((zb_uint32_t)0xFFFFFFFF) + +/** @brief Default value for Dst Shift attribute */ +#define ZB_ZCL_TIME_DST_SHIFT_DEFAULT_VALUE 0x00000000 + +/** @brief Default value for StandardTime attribute */ +#define ZB_ZCL_TIME_STANDARD_TIME_DEFAULT_VALUE ((zb_uint32_t)0xFFFFFFFF) + +/** @brief Default value for LocalTime attribute */ +#define ZB_ZCL_TIME_LOCAL_TIME_DEFAULT_VALUE ((zb_uint32_t)0xFFFFFFFF) + +/** @brief Default value for Last Set Time attribute */ +#define ZB_ZCL_TIME_LAST_SET_TIME_DEFAULT_VALUE 0xffffffff + +/** @brief Default value for Valid Until Time attribute */ +#define ZB_ZCL_TIME_VALID_UNTIL_TIME_DEFAULT_VALUE 0xffffffff + +/** @brief Declare attribute list for Time cluster + @param attr_list - attribute list name + @param time - pointer to variable to store Time attribute value + @param time_status - pointer to variable to store Time Status attribute value + @param time_zone - pointer to variable to store Time Zone attribute value + @param dst_start - pointer to variable to store Dst Start attribute value + @param dst_end - pointer to variable to store Dst End attribute value + @param dst_shift - pointer to variable to store Dst Shift attribute value + @param standard_time - pointer to variable to store Standard Time attribute value + @param local_time - pointer to variable to store Local Time attribute value + @param last_set_time - pointer to variable to store Last Set Time attribute value + @param valid_until_time - pointer to variable to store Valid Until Time attribute value +*/ +#define ZB_ZCL_DECLARE_TIME_ATTRIB_LIST(attr_list, time, time_status, time_zone, \ + dst_start, dst_end, dst_shift, standard_time, local_time, last_set_time, valid_until_time) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_TIME_ID, (time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, (time_status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, (time_zone)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_DST_START_ID, (dst_start)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_DST_END_ID, (dst_end)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_DST_SHIFT_ID, (dst_shift)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID, (standard_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID, (local_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID, (last_set_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID, (valid_until_time)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* ZB_ZCL_TIME_ATTRS */ + +/** @defgroup ZB_ZCL_TIME_COMMANDS Time cluster commands + * @{ + */ + +/** @} */ /* ZB_ZCL_TIME_COMMANDS */ + + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_TIME_STATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_TIME_STATUS_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_TIME_ZONE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_TIME_ZONE_ID, \ + ZB_ZCL_ATTR_TYPE_S32, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_DST_START_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_DST_START_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_DST_END_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_DST_END_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_DST_SHIFT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_DST_SHIFT_ID, \ + ZB_ZCL_ATTR_TYPE_S32, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U32, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_UTC_TIME, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/*! @internal Number of attributes mandatory for reporting in Time cluster */ +#define ZB_ZCL_TIME_REPORT_ATTR_COUNT 0 + +/** @endcond */ /* Time cluster internals */ + + +/** @struct zb_zcl_time_attrs_s + * @brief Time cluster attributes + */ +typedef struct zb_zcl_time_attrs_s +{ + + /** @copydoc ZB_ZCL_ATTR_TIME_TIME_ID + * @see ZB_ZCL_ATTR_TIME_TIME_ID + */ + zb_uint32_t time; + + /** @copydoc ZB_ZCL_ATTR_TIME_TIME_STATUS_ID + * @see ZB_ZCL_ATTR_TIME_TIME_STATUS_ID + */ + zb_uint8_t time_status; + + /** @copydoc ZB_ZCL_ATTR_TIME_TIME_ZONE_ID + * @see ZB_ZCL_ATTR_TIME_TIME_ZONE_ID + */ + zb_int32_t time_zone; + + /** @copydoc ZB_ZCL_ATTR_TIME_DST_START_ID + * @see ZB_ZCL_ATTR_TIME_DST_START_ID + */ + zb_uint32_t dst_start; + + /** @copydoc ZB_ZCL_ATTR_TIME_DST_END_ID + * @see ZB_ZCL_ATTR_TIME_DST_END_ID + */ + zb_uint32_t dst_end; + + /** @copydoc ZB_ZCL_ATTR_TIME_DST_SHIFT_ID + * @see ZB_ZCL_ATTR_TIME_DST_SHIFT_ID + */ + zb_uint32_t dst_shift; + + /** @copydoc ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID + * @see ZB_ZCL_ATTR_TIME_STANDARD_TIME_ID + */ + zb_uint32_t standard_time; + + /** @copydoc ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID + * @see ZB_ZCL_ATTR_TIME_LOCAL_TIME_ID + */ + zb_uint32_t local_time; + + /** @copydoc ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID + * @see ZB_ZCL_ATTR_TIME_LAST_SET_TIME_ID + */ + zb_uint32_t last_set_time; + + /** @copydoc ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID + * @see ZB_ZCL_ATTR_TIME_VALID_UNTIL_TIME_ID + */ + zb_uint32_t valid_until_time; +} zb_zcl_time_attrs_t; + + +/** @brief Declare attribute list for Time cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - variable of @ref zb_zcl_time_attrs_s type (containing Time cluster attributes) + */ +#define ZB_ZCL_DECLARE_TIME_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_TIME_ATTRIB_LIST(attr_list, \ + &attrs.time, &attrs.time_status, &attrs.time_zone, \ + &attrs.dst_start, &attrs.dst_end, &attrs.dst_shift, \ + &attrs.standard_time, &attrs.local_time, \ + &attrs.last_set_time, &attrs.valid_until_time ) + +/** @} */ /** ZB_ZCL_TIME */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_time_update_current_time(zb_uint8_t endpoint); + +void zb_zcl_time_init_server(void); +void zb_zcl_time_init_client(void); +#define ZB_ZCL_CLUSTER_ID_TIME_SERVER_ROLE_INIT zb_zcl_time_init_server +#define ZB_ZCL_CLUSTER_ID_TIME_CLIENT_ROLE_INIT zb_zcl_time_init_client + +#endif /* defined ZB_ZCL_TIME_H */ diff --git a/zboss/include/zcl/zb_zcl_tunneling.h b/zboss/include/zcl/zb_zcl_tunneling.h new file mode 100644 index 0000000000..1b333a375d --- /dev/null +++ b/zboss/include/zcl/zb_zcl_tunneling.h @@ -0,0 +1,1010 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: ZBOSS specific Tunneling cluster, purpose: general data tunneling. +*/ +#ifndef ZB_ZCL_TUNNELING_H +#define ZB_ZCL_TUNNELING_H 1 + +#define ZB_ZCL_TUNNELING_MAX_INCOMING_TRANSFER_SIZE (ZB_ASDU_MAX_FRAG_LEN - 3 /* ZCL cmd */ - 2 /* Tunnel_ID */) +#define ZB_ZCL_TUNNELING_SRV_TABLE_SIZE 10 + +#include "zcl/zb_zcl_common.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + + +/** @addtogroup ZB_ZCL_TUNNELING + * @{ + * @details + * The tunneling cluster provides an interface for tunneling protocols. It is + * comprised of commands and attributes required to transport any existing + * metering communication protocol within the payload of standard Zigbee + * frames (including the handling of issues such as addressing, fragmentation + * and flow control). Examples for such protocols are DLMS/COSEM, IEC61107, + * ANSI C12, M-Bus, ClimateTalk etc.\n + * This cluster transmits custom data between peers\n + * Model: One (client) to More (servers)\n + */ + + +/** @defgroup ZB_ZCL_TUNNELING_ATTRS Tunneling cluster attributes + * @{ + */ + +/** @brief Tunneling cluster attribute identifiers + * @see SE spec, subclause D.6.2.2 + */ +enum zb_zcl_tunneling_attr_e +{ + /*! @brief CloseTunnelTimeout defines the minimum number of seconds that the + * server waits on an inactive tunnel before closing it on its own and freeing + * its resources (without waiting for the CloseTunnel command from the client). + * Inactive means here that the timer is re-started with each new reception of + * a command.0x0000 is an invalid value. + * @see ZB_ZCL_TUNNELING_CLOSE_TUNNEL_TIMEOUT_MIN_VALUE + * @see ZB_ZCL_TUNNELING_CLOSE_TUNNEL_TIMEOUT_DEFAULT_VALUE + */ + ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID = 0 +}; + + +/** @brief Min value for the @e CloseTunnelTimeout attribute + * @see ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID */ +#define ZB_ZCL_TUNNELING_CLOSE_TUNNEL_TIMEOUT_MIN_VALUE 0x0001 + +/** @brief Default value for the @e CloseTunnelTimeout attribute + * @see ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID */ +#define ZB_ZCL_TUNNELING_CLOSE_TUNNEL_TIMEOUT_DEFAULT_VALUE 0xFFFF + + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +/** @endcond */ /* internals_doc */ + +/** @def ZB_ZCL_DECLARE_TUNNELING_ATTRIB_LIST(attr_list, close_tunnel_timeout) + * @brief Declare attribute list for Tunnelling cluster + * @param[in] attr_list - attribute list name + * @param[in] close_tunnel_timeout - pointer to variable to store On/Tunnelling attribute value + */ +#define ZB_ZCL_DECLARE_TUNNELING_ATTRIB_LIST(attr_list, close_tunnel_timeout) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID, (close_tunnel_timeout)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** + * @brief Tunneling cluster attributes + */ +typedef struct zb_zcl_tunneling_attrs_s +{ + /** @copydoc ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID + * @see ZB_ZCL_ATTR_TUNNELING_CLOSE_TUNNEL_TIMEOUT_ID + */ + zb_uint16_t close_tunnel_timeout; +} zb_zcl_tunneling_attrs_t; + + +/** @brief Declare attribute list for Tunneling cluster cluster + * @param[in] attr_list - attribute list variable name + * @param[in] attrs - pointer to @ref zb_zcl_tunneling_attrs_s structure + */ +#define ZB_ZCL_DECLARE_TUNNELING_ATTR_LIST(attr_list, attrs) \ + ZB_ZCL_DECLARE_TUNNELING_ATTRIB_LIST(attr_list, &attrs.close_tunnel_timeout ) + +/** @cond internals_doc */ + +#define ZB_ZCL_TUNNELING_TUNNEL_ID_INVALID_VALUE 0xFFFF + +#define ZB_ZCL_TUNNELING_MANUFACTURER_CODE_NOT_USED 0xFFFF + +/** @endcond */ /* internals_doc */ + +/** @} */ /* ZB_ZCL_TUNNELING_ATTRS */ + + +/** @defgroup ZB_ZCL_TUNNELING_COMMANDS Tunneling cluster commands + * @{ + */ + +/** @brief Tunnel cluster commands received + * @see SE spec, subclause D.6.2.4 + */ +enum zb_zcl_tunneling_cli_cmd_e +{ + + ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL = 0x00, /**< @brief @e RequestTunnel is the client command used to setup a tunnel + * association with the server. The request payload specifies the protocol + * identifier for the requested tunnel, a manufacturer code in case of proprietary + * protocols and the use of flow control for streaming protocols. + * @see zb_zcl_tunneling_request_tunnel_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL = 0x01, /**< @brief Client command used to close the tunnel with the server. The parameter + * in the payload specifies the tunnel identifier of the tunnel that has to be + * closed. The server leaves the tunnel open and the assigned resources allocated + * until the client sends the @e CloseTunnel command or the @e CloseTunnelTimeout + * fires. + * @see zb_zcl_tunneling_close_tunnel_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA = 0x02, /**< @brief Command that indicates (if received) that the client has sent data + * to the server. The data itself is contained within the payload. + * @see zb_zcl_tunneling_transfer_data_payload_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR = 0x03, /**< @brief This command is generated by the receiver of a @e TransferData command + * if the tunnel status indicates that something is wrong. + * @details There are three cases in which @e TransferDataError is sent:\n + *
    + *
  • The @e TransferData received contains a TunnelID that does not match to any + * of the active tunnels of the receiving device. This could happen if a + * (sleeping) device sends a @e TransferData command to a tunnel that has been + * closed by the server after the @e CloseTunnelTimeout. + *
  • + *
  • The @e TransferData received contains a proper TunnelID of an active + * tunnel, but the device sending the data does not match to it. + *
  • + *
  • The @e TransferData received contains more data + * @e MaximumIncomingTransferSize of the receiving device. + *
  • + *
+ * @see zb_zcl_tunneling_transfer_data_error_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_ACK_TRANSFER_DATA = 0x04, /**< Command sent in response to each TransferData command + * in case – and only in case – flow control has been + * requested by the client in the TunnelRequest command and + * is supported by both tunnel endpoints. The response + * payload indicates the number of octets that may still be + * received by the receiver. + * @see zb_zcl_tunneling_ack_transfer_data_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_READY_DATA = 0x05, /**< The ReadyData command is generated – after a receiver + * had to stop the dataflow using the AckTransferData(0) + * command – to indicate that the device is now ready to + * continue receiving data. The parameter NumberOfOctetsLeft + * gives a hint on how much space is left for the next + * data transfer. The ReadyData command is only issued if + * flow control is enabled. + * @see zb_zcl_tunneling_ready_data_s + */ + + ZB_ZCL_TUNNELING_CLI_CMD_GET_SUPPORTED_TUNNEL_PROTOCOLS = 0x06, /**< Get Supported Tunnel Protocols is the client command + * used to determine the tunnel protocols supported on another device. + * @see zb_zcl_tunneling_get_supported_tunnel_protocols_s + */ +}; + + +/** @brief Tunnel cluster commands generated + * @see SE spec, subclause D.6.2.5 + */ +enum zb_zcl_tunneling_srv_cmd_e +{ + ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE = 0x00, /**< @brief @e RequestTunnelResponse is sent by the server in response to a @e RequestTunnel + * command previously received from the client. The response contains the + * status of the @e RequestTunnel command and a tunnel identifier corresponding + * to the tunnel that has been set-up in the server in case of success. + * @see zb_zcl_tunneling_request_tunnel_response_s + */ + + ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA = 0x01, /**< @brief Command that transfers data from server to the client. The data + * itself has to be placed within the payload. + * @see zb_zcl_tunneling_transfer_data_payload_s + */ + + ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA_ERROR = 0x02, /**< @copydoc ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR */ + + ZB_ZCL_TUNNELING_SRV_CMD_ACK_TRANSFER_DATA = 0x03, /**< @copydoc ZB_ZCL_TUNNELING_CLI_CMD_ACK_TRANSFER_DATA */ + + ZB_ZCL_TUNNELING_SRV_CMD_READY_DATA = 0x04, /**< @copydoc ZB_ZCL_TUNNELING_CLI_CMD_READY_DATA */ + + ZB_ZCL_TUNNELING_SRV_CMD_SUPPORTED_TUNNEL_PROTOCOLS_RESPONSE = 0x05, /**< Supported Tunnel Protocols Response is sent + * in response to a Get Supported Tunnel Protocols + * command previously received. The response contains + * a list of tunnel protocols supported by the device; + * the payload of the response should be capable of + * holding up to 16 protocols. + * @see zb_zcl_tunneling_supported_tunnel_protocols_response_s + */ + + ZB_ZCL_TUNNELING_SRV_CMD_TUNNEL_CLOSURE_NOTIFICATION = 0x06, /**< TunnelClosureNotification is sent by the server + * to indicate that a tunnel has been closed due to + * expiration of a CloseTunnelTimeout. + * @see zb_zcl_tunneling_tunnel_closure_notification_s + */ +}; + +/** @cond internals_doc */ +/* TUNNELING cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_TUNNELING_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE, \ + ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA, \ + ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA_ERROR + +#define ZB_ZCL_CLUSTER_ID_TUNNELING_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_TUNNELING_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_TUNNELING_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL, \ + ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA, \ + ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR, \ + ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL + +#define ZB_ZCL_CLUSTER_ID_TUNNELING_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_TUNNELING_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** @brief @e TunnelStatus parameter values. + * @see SE spec, Table D-127 + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE "RequestTunnelResponse" + * @see zb_zcl_tunneling_request_tunnel_response_s::tunnel_status + */ +enum zb_zcl_tunneling_tunnel_status_e +{ + + ZB_ZCL_TUNNELING_STATUS_SUCCESS = 0, /**< The tunnel has been opened and may now be used to transfer data in + * both directions. + */ + + ZB_ZCL_TUNNELING_STATUS_BUSY = 1, /**< The server is busy and cannot create a new tunnel at the moment. + * The client may try again after a recommended timeout of 3 minutes. + */ + + ZB_ZCL_TUNNELING_STATUS_NO_MORE_IDS = 2, /**< The server has no more resources to setup requested tunnel. Clients + * should close any open tunnels before retrying. + */ + + ZB_ZCL_TUNNELING_STATUS_PROTOCOL_NOT_SUPPORTED = 3, /**< The server does not support the protocol that has been requested + * in the ProtocolID parameter of the RequestTunnel command. + */ + + ZB_ZCL_TUNNELING_STATUS_FLOW_CONTROL_NOT_SUPPORTED = 4, /**< Flow control has been requested by the client in the RequestTunnel + * command but cannot be provided by the server (missing resources or no + * support). + */ +}; + + +/** @brief @e TransferDataStatus parameter values. + * @see SE spec, Table D-125 + * @see zb_zcl_tunneling_transfer_data_error_t::transfer_data_status + */ +enum zb_zcl_tunneling_transfer_data_status_e +{ + + /** @brief The @e TransferData command contains a @e TunnelID of a non-existent + * tunnel. + */ + ZB_ZCL_TUNNELING_TRANSFER_DATA_STATUS_NO_SUCH_TUNNEL = 0x00, + + /** @brief The @e TransferData command contains a @e TunnelID that does not match the + * device sending the data. + */ + ZB_ZCL_TUNNELING_TRANSFER_DATA_STATUS_WRONG_DEVICE = 0x01, + + /** @brief The @e TransferData command contains more data than indicated by the + * @e MaximumIncomingTransferSize of the receiving device + */ + ZB_ZCL_TUNNELING_TRANSFER_DATA_STATUS_DATA_OVERFLOW = 0x02, + + /* Custom Internal Error status */ + ZB_ZCL_TUNNELING_TRANSFER_DATA_INTERNAL_ERROR = 0xFE, + + /* Custom OK status (does not sent in pkt) */ + ZB_ZCL_TUNNELING_TRANSFER_DATA_STATUS_OK = 0xFF, +}; + +/** @brief Tunneling @e ProtocolID Enumerations + * @see SE spec, subclause D.6.2.4.1.2, Table D-124 + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" + * @see zb_zcl_tunneling_request_tunnel_s::protocol_id + */ +typedef enum zb_zcl_tunneling_protocol_id_e +{ + ZB_ZCL_TUNNELING_PROTOCOL_DLMS_COSEM = 0, /**< DLMS/COSEM (IEC 62056) */ + ZB_ZCL_TUNNELING_PROTOCOL_IEC_61107 = 1, /**< IEC 61107 */ + ZB_ZCL_TUNNELING_PROTOCOL_ANSI_C12 = 2, /**< ANSI C12 */ + ZB_ZCL_TUNNELING_PROTOCOL_M_BUS = 3, /**< M-BUS */ + ZB_ZCL_TUNNELING_PROTOCOL_SML = 4, /**< SML */ + ZB_ZCL_TUNNELING_PROTOCOL_CLIMATE_TALK = 5, /**< ClimateTalk */ + ZB_ZCL_TUNNELING_PROTOCOL_GB_HRGP = 6, /**< GB-HRGP */ + ZB_ZCL_TUNNELING_PROTOCOL_IPv4 = 7, /**< IP v4 */ + ZB_ZCL_TUNNELING_PROTOCOL_IPv6 = 8, /**< IP v6 */ + /* 9 to 199 reserved for future growth */ + ZB_ZCL_TUNNELING_PROTOCOL_MANUFACTURER_DEFINED = 200, /**< 200 to 254 manufacturer-defined protocols */ + ZB_ZCL_TUNNELING_PROTOCOL_RESERVED = 255 /**< reserver value */ +} zb_zcl_tunneling_protocol_id_t; + +/************* Tunnel cluster command structures **************/ + +/** @brief @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command payload + * @see SE spec, subclause D.6.2.4.1.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_request_tunnel_s +{ + + /** @brief An enumeration representing the identifier of the metering + * communication protocol for which the tunnel is requested. + * @see zb_zcl_tunneling_protocol_id_e + */ + zb_uint8_t protocol_id; /* (M) */ + + /** @brief A code that is allocated by the Zigbee Alliance, relating the + * manufacturer to a device and – for the tunneling - a manufacturer specific + * protocol. The parameter is ignored when the @e ProtocolID value is less than 200. + * This allows for 55 manufacturer-defined protocols for each manufacturer to + * be defined. A value of 0xFFFF indicates that the Manufacturer Code is not used. + */ + zb_uint16_t manufacturer_code; /* (M) */ + + /** @brief A boolean type parameter that indicates whether flow control support + * is requested from the tunnel (ZB_TRUE) or not (ZB_FALSE). The default value is + * FALSE (no flow control). + */ + zb_bool_t flow_control_support; /* (M) */ + + /** @brief A value that defines the size, in octets, of the maximum data packet + * that can be transferred to the client in the payload of a single + * @e TransferData command. + */ + zb_uint16_t max_incoming_transfer_size; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_tunneling_request_tunnel_t; + + +void zb_zcl_tunneling_set_max_incoming_to_cli_transfer_size(zb_uint16_t transfer_size); + + +/** @def ZB_ZCL_TUNNELING_SEND_REQUEST_TUNNEL + * @brief Send @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command + * @param _param - Reference to buffer. + * @param _addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _ep - Current endpoint. + * @param _prfl_id - profile identifier + * @param _def_resp - enable/disable default zcl response + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _protocol_id - @ref zb_zcl_tunneling_request_tunnel_t::protocol_id value + * @param _manufacturer_code - @ref zb_zcl_tunneling_request_tunnel_t::manufacturer_code value + * @param _flow_control_support - @ref zb_zcl_tunneling_request_tunnel_t::flow_control_support value + * @param _max_incoming_transfer_size - @ref zb_zcl_tunneling_request_tunnel_t::max_incoming_transfer_size value + * @par Usage + * @n Example of sending @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command + */ +#define ZB_ZCL_TUNNELING_SEND_REQUEST_TUNNEL( \ + _param, _addr, _dst_addr_mode, _dst_ep, _ep, _prfl_id, _def_resp, _cb, \ + _protocol_id, _manufacturer_code, _flow_control_support, \ + _max_incoming_transfer_size) \ +{ \ + zb_zcl_tunneling_set_max_incoming_to_cli_transfer_size( \ + _max_incoming_transfer_size); \ + { \ + zb_bufid_t _buffer = _param; \ + zb_uint8_t* __ptr = zb_zcl_start_command_header(_buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL(ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, (_def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL, NULL); \ + ZB_ZCL_PACKET_PUT_DATA8(__ptr, (_protocol_id)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_manufacturer_code)); \ + ZB_ZCL_PACKET_PUT_DATA8(__ptr, (_flow_control_support)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_max_incoming_transfer_size)); \ + ZB_ZCL_FINISH_PACKET(_buffer, __ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + _buffer, (_addr), (_dst_addr_mode), (_dst_ep), (_ep), (_prfl_id), \ + ZB_ZCL_CLUSTER_ID_TUNNELING, (_cb)); \ + } \ +} + + +/** @brief Macro for parsing payload of @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command + * @param _data_ptr - pointer to @ref zb_zcl_tunneling_request_tunnel_t structure + * @param _buffer - pointer to buffer where @e RequestTunnel command's payload is stored. + * @param _status - status of payload parsing + */ +#define ZB_ZCL_TUNNELING_GET_REQUEST_TUNNEL(_data_ptr, _buffer, _status) \ +{ \ + zb_zcl_tunneling_request_tunnel_t *src_ptr = \ + (zb_zcl_tunneling_request_tunnel_t*)zb_buf_begin((_buffer)); \ + \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_tunneling_request_tunnel_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + (_data_ptr)->protocol_id = src_ptr->protocol_id; \ + ZB_HTOLE16(&(_data_ptr)->manufacturer_code, &(src_ptr->manufacturer_code)); \ + (_data_ptr)->flow_control_support = src_ptr->flow_control_support; \ + ZB_HTOLE16(&(_data_ptr)->max_incoming_transfer_size, \ + &(src_ptr->max_incoming_transfer_size)); \ + } \ +} + + +/** + * @brief @ref ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL "CloseTunnel" command payload + * @see SE spec, subclause D.6.2.4.2.2. + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_close_tunnel_s +{ + /** @brief The identifier of the tunnel that shall be closed. It is the same number + * that has been previously returned in the response to a @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command. + * Valid numbers range between 0..65535 and must correspond to a tunnel that is + * still active and maintained by the server. + */ + zb_uint16_t tunnel_id; +} +ZB_PACKED_STRUCT +zb_zcl_tunneling_close_tunnel_t; + + +/** @brief @ref ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL "CloseTunnel" command + * @param _param - Reference to buffer. + * @param _addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _ep - Current endpoint. + * @param _prfl_id - profiler identifier + * @param _def_resp - enable/disable default zcl response + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _tunnel_id - @ref zb_zcl_tunneling_close_tunnel_t::tunnel_id value + * @par Usage + * @n Example of sending @ref ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL "CloseTunnel" command + */ +#define ZB_ZCL_TUNNELING_SEND_CLOSE_TUNNEL( \ + _param, _addr, _dst_addr_mode, _dst_ep, _ep, _prfl_id, _def_resp, _cb, \ + _tunnel_id) \ +{ \ + zb_bufid_t _buffer = _param; \ + zb_uint8_t* __ptr = zb_zcl_start_command_header(_buffer, \ + ZB_ZCL_CONSTRUCT_FRAME_CONTROL(ZB_ZCL_FRAME_TYPE_CLUSTER_SPECIFIC, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, (_def_resp)), \ + 0, /* No manuf_code */ \ + ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL, NULL); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_tunnel_id)); \ + ZB_ZCL_FINISH_PACKET(_buffer, __ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + _buffer, (_addr), (_dst_addr_mode), (_dst_ep), (_ep), (_prfl_id), \ + ZB_ZCL_CLUSTER_ID_TUNNELING, (_cb)); \ +} + + +/** @brief Macro for parsing payload of @ref ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL "CloseTunnel" command + * @param _data_ptr - pointer to @ref zb_zcl_tunneling_close_tunnel_t structure + * @param _buffer - pointer to buffer where @e CloseTunnel command's payload is stored. + * @param _status - status of payload parsing + */ +#define ZB_ZCL_TUNNELING_GET_CLOSE_TUNNEL(_data_ptr, _buffer, _status) \ +{ \ + zb_zcl_tunneling_close_tunnel_t *src_ptr = \ + (zb_zcl_tunneling_close_tunnel_t*)zb_buf_begin((_buffer)); \ + \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_tunneling_close_tunnel_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&(_data_ptr)->tunnel_id, &(src_ptr->tunnel_id)); \ + } \ +} + + +/** + * @brief @e TransferData commands header data. + * @see SE spec, subclause D.6.2.4.3.2 + * @see @ref zb_zcl_tunneling_transfer_data_payload_t::hdr + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA "TransferData" client command + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA "TransferData" server command + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_transfer_data_hdr_s +{ + /** @brief number between 0..65535 that uniquely identifies the tunnel that has + * been allocated in the server triggered through the RequestTunnel command. + * This ID must be used to send data through the tunnel or passed with any + * commands concerning that specific tunnel. + */ + zb_uint16_t tunnel_id; +} +ZB_PACKED_STRUCT +zb_zcl_tunneling_transfer_data_hdr_t; + + +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_srv_rec_s +{ + zb_uint16_t dst_addr; + zb_uint8_t dst_ep; + zb_uint8_t src_ep; + /** */ + zb_zcl_tunneling_request_tunnel_t tunnel_options; + zb_uint16_t close_tunnel_timeout; + zb_uint16_t max_incoming_to_srv_transfer_size; +} +ZB_PACKED_STRUCT zb_zcl_tunneling_srv_rec_t; + + +typedef ZB_PACKED_PRE struct zb_zcl_tunnel_request_params_out_s +{ + zb_uint8_t tunnel_status; + zb_uint16_t max_incoming_to_srv_transfer_size; +} ZB_PACKED_STRUCT zb_zcl_tunnel_request_params_out_t; + + +/** @brief @e TransferData payload. + * This structure presents custom implementation of Transfer Data command payload defined in SE spec. + * @see SE spec, subclause D.6.2.4.3.2 and D.6.2.5.2 + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA "TransferData" client command + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA "TransferData" server command + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_transfer_data_payload_s +{ + + /** @ref zb_zcl_tunneling_transfer_data_hdr_t + */ + zb_zcl_tunneling_transfer_data_hdr_t hdr; + + /** Size of @ref tun_data */ + zb_uint8_t data_size; + + /** @brief Octet containing the data to be transferred through the tunnel in + * the format of the communication protocol for which the tunnel has been + * requested and opened. The payload contains the assembled data exactly as it + * was sent by the client. Theoretically, its length is solely limited through + * the fragmentation algorithm and the RX/TX transfer buffer sizes within the + * communication partners. The content of the payload is up to the application + * sending the data. It is neither guaranteed, that it contains a complete PDU + * nor is any other assumption on its internal format made. This is left up to + * the implementer of the specific protocol tunnel behavior. + */ + zb_uint8_t *tun_data; +} +ZB_PACKED_STRUCT +zb_zcl_tunneling_transfer_data_payload_t; + +/** @cond internals_doc */ +zb_ret_t zb_zcl_tunneling_client_send_transfer_data(zb_uint8_t param, zb_uint8_t ep, zb_uint16_t prfl_id, + zb_uint8_t def_resp, zb_callback_t cb, zb_uint16_t tunnel_id, + zb_uint16_t data_size, zb_uint8_t *image_data); +zb_ret_t zb_zcl_tunneling_server_send_transfer_data(zb_uint8_t param, zb_uint8_t ep, zb_uint16_t prfl_id, + zb_uint8_t def_resp, zb_callback_t cb, zb_uint16_t tunnel_id, + zb_uint16_t data_size, zb_uint8_t *image_data); + +/** @endcond */ /* internal_doc */ + +/*! Send @e TransferData command from Tunneling server to client + * @param _param - Reference to buffer. + * @param _ep - Current endpoint. + * @param _prfl_id - profiler identifier + * @param _def_resp - enable/disable default zcl response + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _tunnel_id - @ref zb_zcl_tunneling_transfer_data_hdr_t::tunnel_id value + * @param _data_size - @ref zb_zcl_tunneling_transfer_data_payload_t::data_size value + * @param _image_data - tun_data from @ref zb_zcl_tunneling_transfer_data_payload_t::tun_data value + * @par Usage + * @n Example of sending @e TransferData command + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA "TransferData" server command + */ +#define ZB_ZCL_TUNNELING_SERVER_SEND_TRANSFER_DATA( \ + _param, _ep, _prfl_id, _def_resp, _cb, \ + _tunnel_id, _data_size, _image_data) \ + zb_zcl_tunneling_server_send_transfer_data(_param, _ep, _prfl_id, _def_resp, _cb, \ + _tunnel_id, _data_size, _image_data) + +/*! Send @e TransferData command from Tunneling client to server + * @param _param - Reference to buffer. + * @param _ep - Current endpoint. + * @param _prfl_id - profiler identifier + * @param _def_resp - enable/disable default zcl response + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _tunnel_id - @ref zb_zcl_tunneling_transfer_data_hdr_t::tunnel_id value + * @param _data_size - @ref zb_zcl_tunneling_transfer_data_payload_t::data_size value + * @param _image_data - tun_data from @ref zb_zcl_tunneling_transfer_data_payload_t::tun_data value + * @par Usage + * @n Example of sending @e TransferData command + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA "TransferData" client command + */ +#define ZB_ZCL_TUNNELING_CLIENT_SEND_TRANSFER_DATA( \ + _param, _ep, _prfl_id, _def_resp, _cb, \ + _tunnel_id, _data_size, _image_data) \ + zb_zcl_tunneling_client_send_transfer_data(_param, _ep, _prfl_id, _def_resp, _cb, \ + _tunnel_id, _data_size, _image_data) + +/** @brief Macro for parsing payload of @e TransferData command + * @param _data_ptr - pointer to @ref zb_zcl_tunneling_transfer_data_payload_t structure + * @param _buffer - pointer to buffer where @e TransferData command's payload is stored. + * @param _status - status of payload parsing + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA "TransferData" client command + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA "TransferData" server command + */ +#define ZB_ZCL_TUNNELING_GET_TRANSFER_DATA(_data_ptr, _buffer, _status) \ +{ \ + zb_uint8_t *src_ptr = (zb_uint8_t*)zb_buf_begin((_buffer)); \ + \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_tunneling_transfer_data_hdr_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&(_data_ptr)->hdr.tunnel_id, src_ptr); \ + (_data_ptr)->data_size = zb_buf_len((_buffer)) - \ + sizeof(zb_zcl_tunneling_transfer_data_hdr_t); \ + (_data_ptr)->tun_data = (zb_uint8_t*)(src_ptr + \ + sizeof(zb_zcl_tunneling_transfer_data_hdr_t)); \ + } \ +} + + +/** @brief @e TransferDataError command payload + * @see SE spec, subclause D.6.2.4.4.2 + * @see Client @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR "TransferDataError" command + * @see Server @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA_ERROR "TransferDataError" command + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_transfer_data_error_s +{ + + /** @brief A number between 0..65535 that uniquely identifies the tunnel that + * has been allocated in the server triggered through the RequestTunnel command. + * This ID must be used for the data transfer through the tunnel or passed with + * any commands concerning that specific tunnel. + */ + zb_uint16_t tunnel_id; + + /** @brief The @e TransferDataStatus parameter indicates the error that occurred + * within the receiver after the last @e TransferData command. + * @see zb_zcl_tunneling_transfer_data_status_e + */ + zb_uint8_t transfer_data_status; +} +ZB_PACKED_STRUCT zb_zcl_tunneling_transfer_data_error_t; + + +/*! @brief Send client @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR "TransferDataError" command and + * server @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA_ERROR "TransferDataError" command + * @param _buffer - pointer to buffer. + * @param _addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _ep - Current endpoint. + * @param _prfl_id - profiler identifier + * @param _def_resp - enable/disable default zcl response + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _seq_num - ZCL transaction sequence number + * @param _tunnel_id - @ref zb_zcl_tunneling_transfer_data_error_t::tunnel_id value + * @param _transfer_data_status - @ref zb_zcl_tunneling_transfer_data_error_t::transfer_data_status value + * @param _command_id - Tunneling cluster's command identifier. + * @param _direction - command direction. + */ +#define ZB_ZCL_TUNNELING_SEND_TRANSFER_DATA_ERROR( \ + _buffer, _addr, _dst_addr_mode, _dst_ep, _ep, _prfl_id, _def_resp, _cb, _seq_num, \ + _tunnel_id, _transfer_data_status, _command_id, _direction) \ +{ \ + zb_uint8_t* __ptr = ZB_ZCL_START_PACKET((_buffer)); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(__ptr, \ + _direction, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(__ptr, _seq_num, _command_id); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_tunnel_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(__ptr, (_transfer_data_status)); \ + ZB_ZCL_FINISH_PACKET((_buffer), __ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + (_buffer), (_addr), (_dst_addr_mode), (_dst_ep), (_ep), (_prfl_id), \ + ZB_ZCL_CLUSTER_ID_TUNNELING, (_cb)); \ +} + + +/** @brief Macro for parsing payload of @e TransferDataError command + * @param _data_ptr - pointer to @ref zb_zcl_tunneling_transfer_data_error_t structure + * @param _buffer - pointer to buffer where @e TransferDataError command's payload is stored. + * @param _status - status of payload parsing + * @see @ref ZB_ZCL_TUNNELING_CLI_CMD_TRANSFER_DATA_ERROR "TransferDataError" client command + * @see @ref ZB_ZCL_TUNNELING_SRV_CMD_TRANSFER_DATA_ERROR "TransferDataError" server command + */ +#define ZB_ZCL_TUNNELING_GET_TRANSFER_DATA_ERROR(_data_ptr, _buffer, _status) \ +{ \ + zb_zcl_tunneling_transfer_data_error_t *src_ptr = \ + (zb_zcl_tunneling_transfer_data_error_t*)zb_buf_begin((_buffer)); \ + \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_tunneling_transfer_data_error_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&(_data_ptr)->tunnel_id, &(src_ptr->tunnel_id)); \ + (_data_ptr)->transfer_data_status = src_ptr->transfer_data_status; \ + } \ +} + + +/** @brief @ref ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE "RequestTunnelResponse" command payload + * @see SE spec, subclause D.6.2.5.1.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_request_tunnel_response_s +{ + + /** @brief A number between 0..65535 that uniquely identifies the tunnel that + * has been allocated in the server triggered through the @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" + * command. + * This ID must now be used to send data through this tunnel (@e TunnelID, + * @e TransferData) and is also required to close the tunnel again (@ref ZB_ZCL_TUNNELING_CLI_CMD_CLOSE_TUNNEL "CloseTunnel"). + * If the command has failed, the @e TunnelStatus contains the reason of the error + * and the @e TunnelID is set to 0xFFFF. + */ + zb_uint16_t tunnel_id; + + /** @brief The @e TunnelStatus parameter indicates the server’s internal status + * after the execution of a @ref ZB_ZCL_TUNNELING_CLI_CMD_REQUEST_TUNNEL "RequestTunnel" command. + * @see @ref zb_zcl_tunneling_tunnel_status_e + */ + zb_uint8_t tunnel_status; + + /** @brief A value that defines the size, in octets, of the maximum data packet + * that can be transferred to the server in the payload of a single @e TransferData command. + */ + zb_uint16_t max_incoming_transfer_size; +} +ZB_PACKED_STRUCT zb_zcl_tunneling_request_tunnel_response_t; + + +/** @brief Macro for sending @ref ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE "RequestTunnelResponse" command + * @param _param - Reference to buffer. + * @param _addr - Address of the device to send command to. + * @param _dst_addr_mode - Address mode for _dst_addr. + * @param _dst_ep - Destination endpoint. + * @param _ep - Current endpoint. + * @param _prfl_id - profiler identifier + * @param _def_resp - enable/disable default zcl response + * @param _seq_num - ZCL transaction sequence number + * @param _cb - Callback which should be called when the ZCL stack receives + * APS ack. + * @param _tunnel_id - @ref zb_zcl_tunneling_request_tunnel_response_t::tunnel_id value + * @param _tunnel_status - @ref zb_zcl_tunneling_request_tunnel_response_t::tunnel_status value + * @param _max_incoming_transfer_size - @ref zb_zcl_tunneling_request_tunnel_response_t::max_incoming_transfer_size value + * + */ +#define ZB_ZCL_TUNNELING_SEND_REQUEST_TUNNEL_RESPONSE( \ + _param, _addr, _dst_addr_mode, _dst_ep, _ep, _prfl_id, _def_resp, _seq_num, _cb, \ + _tunnel_id, _tunnel_status, _max_incoming_transfer_size) \ +{ \ + zb_bufid_t _buffer = _param; \ + zb_uint8_t* __ptr = ZB_ZCL_START_PACKET(_buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(__ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, \ + ZB_ZCL_NOT_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER(__ptr, _seq_num, ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_tunnel_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(__ptr, (_tunnel_status)); \ + ZB_ZCL_PACKET_PUT_DATA16_VAL(__ptr, (_max_incoming_transfer_size)); \ + ZB_ZCL_FINISH_PACKET(_buffer, __ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + _buffer, (_addr), (_dst_addr_mode), (_dst_ep), (_ep), (_prfl_id), \ + ZB_ZCL_CLUSTER_ID_TUNNELING, (_cb)); \ +} + + +/** @brief Macro for parsing payload of @ref ZB_ZCL_TUNNELING_SRV_CMD_REQUEST_TUNNEL_RESPONSE "RequestTunnelResponse" command + * @param _data_ptr - pointer to @ref zb_zcl_tunneling_request_tunnel_response_t structure + * @param _buffer - pointer to buffer where @e RequestTunnelResponse command's payload is stored. + * @param _status - status of payload parsing + */ +#define ZB_ZCL_TUNNELING_GET_REQUEST_TUNNEL_RESPONSE(_data_ptr, _buffer, _status) \ +{ \ + zb_zcl_tunneling_request_tunnel_response_t *src_ptr = \ + (zb_zcl_tunneling_request_tunnel_response_t*)zb_buf_begin((_buffer)); \ + \ + if (zb_buf_len((_buffer)) < sizeof(zb_zcl_tunneling_request_tunnel_response_t)) \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ + else \ + { \ + (_status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + ZB_HTOLE16(&(_data_ptr)->tunnel_id, &(src_ptr->tunnel_id)); \ + (_data_ptr)->tunnel_status = src_ptr->tunnel_status; \ + ZB_HTOLE16(&(_data_ptr)->max_incoming_transfer_size, \ + &(src_ptr->max_incoming_transfer_size)); \ + } \ +} + + +/** @e AckTransferData command payload. + * @see SE spec, subclause D.6.2.4.5.2. + * @see Client @ref ZB_ZCL_TUNNELING_CLI_CMD_ACK_TRANSFER_DATA "AckTransferData" comamnd + * @see Server @ref ZB_ZCL_TUNNELING_SRV_CMD_ACK_TRANSFER_DATA "AckTransferData" comamnd + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_ack_transfer_data_s +{ + + /** A number between 0..65535 that uniquely identifies the tunnel that has been allocated + * in the server triggered through the @e RequestTunnel command. + */ + zb_uint16_t tunnel_id; /* (M) */ + + /** Indicates the number of bytes that may still be received by the initiator of this command. + */ + zb_uint16_t number_of_bytes_left; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_tunneling_ack_transfer_data_t; + + +/** @e ReadyData command payload + * @see SE spec, subclause D.6.2.4.6.2 + * @see Client @ref ZB_ZCL_TUNNELING_CLI_CMD_READY_DATA "ReadyData" command + * @see Server @ref ZB_ZCL_TUNNELING_CLI_CMD_READY_DATA "ReadyData" command + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_ready_data_s +{ + + /** A number between 0..65535 that uniquely identifies the tunnel that has + * been allocated in the server triggered through the @e RequestTunnel command. + */ + zb_uint16_t tunnel_id; /* (M) */ + + /** Indicates the number of octets that may be received by the initiator of this + * command (receiver). It is most likely the remaining size of the buffer holding + * the data that is sent over @e TransferData. + */ + zb_uint16_t number_of_octets_left; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_tunneling_ready_data_t; + + +/** @ref ZB_ZCL_TUNNELING_CLI_CMD_GET_SUPPORTED_TUNNEL_PROTOCOLS "GetSupportedTunnelProtocols" command payload + * @see SE spec, subclause D.6.2.4.7.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_get_supported_tunnel_protocols_s +{ + /** Where there are more protocols supported than can be returned in a single + * Supported @e TunnelProtocolsResponse command, this field allows an offset + * to be specified on subsequent @e GetSupportedTunnelProtocols commands + */ + zb_uint8_t protocol_offset; /* (O) */ +} ZB_PACKED_STRUCT zb_zcl_tunneling_get_supported_tunnel_protocols_t; + + +/** Supported Tunnel Protocols Response Command Protocol Fields + * @see SE spec, Figure D-112 + * @see zb_zcl_tunneling_supported_tunnel_protocols_response_t::protocols + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_protocol_field_s +{ + + /** A code that is allocated by the Zigbee Alliance, relating the manufacturer + * to a device and - for tunneling - a manufacturer specific protocol. + */ + zb_uint16_t manufacturer_code; + + /** An enumeration representing the identifier of the metering communication protocol + * for the supported tunnel. + * @see SE spec, Table D-124 + * @see zb_zcl_tunneling_protocol_id_t + */ + zb_uint8_t protocol_id; +} ZB_PACKED_STRUCT zb_zcl_tunneling_protocol_field_t; + + +/** @ref ZB_ZCL_TUNNELING_SRV_CMD_SUPPORTED_TUNNEL_PROTOCOLS_RESPONSE "SupportedTunnelProtocolResponse" + * command payload. + * @see SE spec, subclause D.6.2.5.6.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_supported_tunnel_protocols_response_s +{ + /** The Protocol List Complete field is a Boolean; a value of 0(ZB_FALSE) indicates that + * there are more supported protocols available (if more than 16 protocols are supported). + * A value of 1(ZB_TRUE) indicates that the list of supported protocols is complete. + */ + zb_uint8_t protocol_list_complete; + + /** The number of Protocol fields contained in the response. + */ + zb_uint8_t protocol_count; + + /** The payload of the response should be capable of holding up to 16 protocols. + * @see zb_zcl_tunneling_protocol_field_s + */ + zb_zcl_tunneling_protocol_field_t protocol_list[16]; +} ZB_PACKED_STRUCT zb_zcl_tunneling_supported_tunnel_protocols_response_t; + + +/** @ref ZB_ZCL_TUNNELING_SRV_CMD_TUNNEL_CLOSURE_NOTIFICATION "TunnelClosureNotification" + * command payload + * @see SE spec, subclause D.6.2.5.7.2 + */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_tunnel_closure_notification_s +{ + /** The identifier of the tunnel that has been closed. It is the same number + * that has been previously returned in the response to a @e RequestTunnel command. + */ + zb_uint16_t tunnel_id; /* (M) */ +} ZB_PACKED_STRUCT zb_zcl_tunneling_tunnel_closure_notification_t; + + +/*********************** Tunnel API **************************/ + +/** @cond internal_doc */ +typedef ZB_PACKED_PRE struct zb_zcl_tunneling_cli_s +{ + zb_uint16_t tunnel_id; + zb_uint16_t dst_addr; + zb_uint8_t dst_ep; + zb_uint16_t max_incoming_to_cli_transfer_size; + zb_uint16_t max_outgoing_to_srv_transfer_size; +} +ZB_PACKED_STRUCT +zb_zcl_tunneling_cli_t; + +extern zb_zcl_tunneling_cli_t tunneling_cli; + +/** @endcond */ /* internal_doc */ + +/*! @} */ /* ZB_ZCL_TUNNELING_COMMANDS */ + +/** @} */ /* addtogroup */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +/**************************** Tunnel internal **********************************/ + +zb_void_t zb_zcl_tunneling_init_server(void); +zb_void_t zb_zcl_tunneling_init_client(void); +#define ZB_ZCL_CLUSTER_ID_TUNNELING_SERVER_ROLE_INIT zb_zcl_tunneling_init_server +#define ZB_ZCL_CLUSTER_ID_TUNNELING_CLIENT_ROLE_INIT zb_zcl_tunneling_init_client + +#endif /* ZB_ZCL_TUNNELING_H */ diff --git a/zboss/include/zcl/zb_zcl_window_covering.h b/zboss/include/zcl/zb_zcl_window_covering.h new file mode 100644 index 0000000000..b3c42c9cc5 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_window_covering.h @@ -0,0 +1,708 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: Window Covering cluster defintions +*/ + +#ifndef ZB_ZCL_WINDOW_COVERING_H +#define ZB_ZCL_WINDOW_COVERING_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/** @addtogroup ZB_ZCL_WINDOW_COVERING + * @{ + * @details + * All commands in the cluster have request form only, and could be responded with Default + * Response command, if not disabled explicitly. + * + */ + +/** @name Window Covering cluster attributes + @{ +*/ + +/** @brief Window Covering cluster information attribute set identifiers + @see ZCL spec, subclause 9.4.2.1.1 - 9.4.2.1.4 +*/ +enum zb_zcl_window_covering_info_attr_e +{ + /** @brief Window Covering Type attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_WINDOW_COVERING_TYPE_ID = 0x0000, + /** @brief PhysicalClosedLimit Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_PHYSICAL_CLOSED_LIMIT_LIFT_ID = 0x0001, + /** @brief PhysicalClosedLimit Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_PHY_CLOSED_LIMIT_TILT_ID = 0x0002, + /** @brief CurrentPosition Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_ID = 0x0003, + /** @brief CurrentPosition Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_ID = 0x0004, + /** @brief Number of Actuations Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_NUMBER_OF_ACTUATIONS_LIFT_ID = 0x0005, + /** @brief Number of Actuations Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_NUMBER_OF_ACTUATIONS_TILT_ID = 0x0006, + /** @brief Config/Status attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_ID = 0x0007, + /** @brief Current Position Lift Percentage attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID = 0x0008, + /** @brief Current Position Tilt Percentage attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID = 0x0009 +}; + +/** @brief Permissible values for Type attribute + * @see ZCL spec, subclause 9.4.2.1.2 + */ +enum zb_zcl_window_covering_window_covering_type_e +{ + /** Rollershade value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_ROLLERSHADE = 0x00, + /** Rollershade - 2 Motor value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_ROLLERSHADE_2_MOTOR = 0x01, + /** Rollershade - Exterior value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_ROLLERSHADE_EXTERIOR = 0x02, + /** Rollershade - Exterior - 2 Motor value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_ROLLERSHADE_EXTERIOR_2_MOTOR = 0x03, + /** Drapery value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_DRAPERY = 0x04, + /** Awning value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_AWNING = 0x05, + /** Shutter value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_SHUTTER = 0x06, + /** Tilt Blind - Tilt Only value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_TILT_BLIND_TILT_ONLY = 0x07, + /** Tilt Blind - Lift and Tilt value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_TILT_BLIND_LIFT_AND_TILT = 0x08, + /** Projector screen value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_PROJECTOR_SCREEN = 0x09 +}; + +/** @brief Permissible values for Config/Status attribute + @see ZCL spec, subclause 9.4.2.1.2.7*/ +enum zb_zcl_window_covering_config_status_e +{ + /** Operational value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_OPERATIONAL = 0x01, + /** Online value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_ONLINE = 0x02, + /** Open/Up Commands have been reversed value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_REVERSE_COMMANDS = 0x04, + /** Lift control is Closed Loop value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_LIFT_CONTROL_IS_CLOSED_LOOP = 0x08, + /** Tilt control is Closed Loop value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_TILT_CONTROL_IS_CLOSED_LOOP = 0x10, + /** Lift Encoder Controlled value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_LIFT_ENCODER_CONTROLLED = 0x20, + /** Tilt Encoder Controlled value */ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_TILT_ENCODER_CONTROLLED = 0x40 +}; + +/** @brief Window covering cluster settings attribute set identifiers + @see ZCL spec, subclause 9.4.2.1.5 +*/ +enum zb_zcl_window_covering_settings_attr_e +{ + /** @brief InstalledOpenLimit - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_ID = 0x0010, + /** @brief InstalledClosedLimit - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_ID = 0x0011, + /** @brief InstalledOpenLimit - Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_ID = 0x0012, + /** @brief InstalledClosedLimit - Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_ID = 0x0013, + /** @brief Velocity - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_VELOCITY_ID = 0x0014, + /** @brief Acceleration Time - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_ACCELERATION_TIME_ID = 0x0015, + /** @brief Deceleration Time - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_DECELERATION_TIME_ID = 0x0016, + /** @brief Mode attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_MODE_ID = 0x0017, + /** @brief Intermediate Setpoints - Lift attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INTERMEDIATE_SETPOINTS_LIFT_ID = 0x0018, + /** @brief Intermediate Setpoints - Tilt attribute */ + ZB_ZCL_ATTR_WINDOW_COVERING_INTERMEDIATE_SETPOINTS_TILT_ID = 0x0019 +}; + +/** @brief Permissible values for Mode attribute + @see ZCL spec, subclause 9.4.2.1.5.7.1*/ +enum zb_zcl_window_covering_mode_e +{ + /** Reversed motor direction value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_REVERSED_MOTOR_DIRECTION = 0x01, + /** Run in calibration mode value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_RUN_IN_CALIBRATION_MODE = 0x02, + /** Motor is running in maintenance mode value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_MOTOR_IS_RUNNING_IN_MAINTENANCE_MODE = 0x04, + /** LEDs will display feedback value */ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_LEDS_WILL_DISPLAY_FEEDBACK = 0x08 +}; + +/** @brief Default value for PhysicalClosedLimitLift attribute */ +#define ZB_ZCL_WINDOW_COVERING_PHYSICAL_CLOSED_LIMIT_LIFT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for PhyClosedLimitTilt attribute */ +#define ZB_ZCL_WINDOW_COVERING_PHY_CLOSED_LIMIT_TILT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for CurrentPositionLift attribute */ +#define ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_LIFT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for CurrentPositionTilt attribute */ +#define ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_TILT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for NumberOfActuationsLift attribute */ +#define ZB_ZCL_WINDOW_COVERING_NUMBER_OF_ACTUATIONS_LIFT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for NumberOfActuationsTilt attribute */ +#define ZB_ZCL_WINDOW_COVERING_NUMBER_OF_ACTUATIONS_TILT_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Window covering type attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_WINDOW_COVERING_TYPE_DEFAULT_VALUE 0x00 + + +/** @brief Config/status attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_CONFIG_STATUS_DEFAULT_VALUE \ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_OPERATIONAL \ + | ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_ONLINE + +/** @brief Current position lift percentage attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_DEFAULT_VALUE 0x00 + +/** @brief Current position tilt percentage attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_DEFAULT_VALUE 0x00 + +/** @brief Installed open limit lift attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_DEFAULT_VALUE 0x0000 + +/** @brief Installed closed limit lift attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_DEFAULT_VALUE 0xffff + +/** @brief Installed open limit tilt attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_DEFAULT_VALUE 0x0000 + +/** @brief Installed closed limit tilt attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_DEFAULT_VALUE 0xffff + +/** @brief Default value for Velocity attribute */ +#define ZB_ZCL_WINDOW_COVERING_VELOCITY_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for AccelerationTime attribute */ +#define ZB_ZCL_WINDOW_COVERING_ACCELERATION_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + +/** @brief Default value for DecelerationTime attribute */ +#define ZB_ZCL_WINDOW_COVERING_DECELERATION_TIME_DEFAULT_VALUE ((zb_uint16_t)0x0000) + + +/** @brief Mode attribute default value */ +#define ZB_ZCL_WINDOW_COVERING_MODE_DEFAULT_VALUE \ + ZB_ZCL_ATTR_WINDOW_COVERING_TYPE_MOTOR_IS_RUNNING_IN_MAINTENANCE_MODE + +/** @brief Default value for IntermediateSetpointsLift attribute */ +#define ZB_ZCL_WINDOW_COVERING_INTERMEDIATE_SETPOINTS_LIFT_DEFAULT_VALUE {0x31, 0x2C, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x00} + +/** @brief Default value for IntermediateSetpointsTilt attribute */ +#define ZB_ZCL_WINDOW_COVERING_INTERMEDIATE_SETPOINTS_TILT_DEFAULT_VALUE {0x31, 0x2C, 0x30, 0x78, 0x30, 0x30, 0x30, 0x30, 0x00} + +/** @brief Declare attribute list for Window Covering cluster + @param attr_list - attribute list name + @param window_covering_type - pointer to variable to store Window Covering Type attribute value + @param config_status - pointer to variable to store Config/Status attribute value + @param current_position_lift_percentage - pointer to variable to store + Current Position Lift Percentage attribute value + @param current_position_tilt_percentage - pointer to variable to store + Current Position Tilt Percentage attribute value + @param installed_open_limit_lift - pointer to variable to store Installed Open Limit Lift + attribute value + @param installed_closed_limit_lift - pointer to variable to store Installed Closed Limit Lift + attribute value + @param installed_open_limit_tilt - pointer to variable to store Installed Open Limit Tilt + attribute value + @param installed_closed_limit_tilt - pointer to variable to store Installed Closed Limit Tilt + attribute value + @param mode - pointer to variable to store Mode attribute value +*/ +#define ZB_ZCL_DECLARE_WINDOW_COVERING_CLUSTER_ATTRIB_LIST(attr_list, window_covering_type, \ + config_status, current_position_lift_percentage, current_position_tilt_percentage, \ + installed_open_limit_lift, installed_closed_limit_lift, installed_open_limit_tilt, \ + installed_closed_limit_tilt, mode) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_WINDOW_COVERING_TYPE_ID, \ + (window_covering_type)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_ID, \ + (config_status)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID, \ + (current_position_lift_percentage)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID, \ + (current_position_tilt_percentage)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_ID, \ + (installed_open_limit_lift)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_ID, \ + (installed_closed_limit_lift)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_ID, \ + (installed_open_limit_tilt)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_ID, \ + (installed_closed_limit_tilt)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WINDOW_COVERING_MODE_ID, (mode)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + +/** @} */ /* Window Covering cluster attributes */ + +/** + * @name Attribute value manipulation API + * @{ + */ + +/** @internal Set bits from conf_var variable to type_value */ +#define ZB_ZCL_SET_BIT(conf_var, type_value) \ +{ \ + (conf_var) = (conf_var) | (type_value); \ +} + +/** @internal Get type_value bits from conf_var variable */ +#define ZB_ZCL_GET_BIT(conf_var, type_value) ((conf_var) & (type_value)) + +/** @internal Clear type_value bits in conf_var variable */ +#define ZB_ZCL_CLR_BIT(conf_var, type_value) \ +{ \ + (conf_var) = (conf_var) & ~(type_value); \ +} + +/** + * @brief Sets bits of Config/Status parameter. + * @param type_value - bit to set. + * @param conf_var - config variable. + * @hideinitializer + */ +#define ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_SET(conf_var, type_value) \ + ZB_ZCL_SET_BIT(conf_var, type_value) + +/** @brief Gets bit value of Config/Status parameter + @param type_value - bit value to check + @param conf_var - config variable + * @hideinitializer +*/ +#define ZB_ZCL_ATTR_WINDOW_COVERING_GET_CONFIG_STATUS_BIT_VAL(conf_var, type_value) \ + ZB_ZCL_GET_BIT(conf_var, type_value) + +/** @brief Clear bit of Config/Status parameter + @param type_value - bit to clear + @param conf_var - config variable + * @hideinitializer +*/ +#define ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_CLEAR(conf_var, type_value) \ + ZB_ZCL_CLR_BIT(conf_var, type_value) + +/** @brief Sets bits of Mode parameter + @param type_value - type which need to set + @param mode_var - mode variable + * @hideinitializer +*/ +#define ZB_ZCL_ATTR_WINDOW_COVERING_MODE_SET(mode_var, type_value) \ + ZB_ZCL_SET_BIT(mode_var, type_value) + +/** @brief Gets bits of Mode parameter + @param type_value - type which need to set + @param mode_var - mode variable + * @hideinitializer +*/ +#define ZB_ZCL_ATTR_WINDOW_COVERING_MODE_GET(mode_var, type_value) \ + ZB_ZCL_GET_BIT(mode_var, type_value) + +/** @brief Clear bytes of Mode parameter + @param type_value - type which need to set + @param mode_var - mode variable +*/ +#define ZB_ZCL_ATTR_WINDOW_COVERING_MODE_CLEAR(mode_var, type_value) \ + ZB_ZCL_CLR_BIT(mode_var, type_value) + +/** @cond internals_doc */ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_WINDOW_COVERING_TYPE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_WINDOW_COVERING_TYPE_ID, \ + ZB_ZCL_ATTR_TYPE_8BIT_ENUM, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_CONFIG_STATUS_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_LIFT_PERCENTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_CURRENT_POSITION_TILT_PERCENTAGE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY | ZB_ZCL_ATTR_ACCESS_SCENE | ZB_ZCL_ATTR_ACCESS_REPORTING, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_LIFT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_ID( \ + data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_LIFT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_OPEN_LIMIT_TILT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_ID( \ + data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_INSTALLED_CLOSED_LIMIT_TILT_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WINDOW_COVERING_MODE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WINDOW_COVERING_MODE_ID, \ + ZB_ZCL_ATTR_TYPE_8BITMAP, \ + ZB_ZCL_ATTR_ACCESS_READ_WRITE, \ + (zb_voidp_t) data_ptr \ +} + +/** @internal Number of attributes mandatory for reporting in window covering cluster */ +#define ZB_ZCL_WINDOW_COVERING_REPORT_ATTR_COUNT 2 + +/** @endcond */ /* internals_doc */ + +/** @} */ /* Attribute value manipulation API */ + +/** @name Window Covering cluster commands + @{ +*/ + +/** @brief Window Covering cluster command identifiers + @see ZCL spec, subclause 9.4.2.2 +*/ +enum zb_zcl_window_covering_cmd_e +{ + /** Up/Open command */ + ZB_ZCL_CMD_WINDOW_COVERING_UP_OPEN = 0x00, + /** Down/Close command */ + ZB_ZCL_CMD_WINDOW_COVERING_DOWN_CLOSE = 0x01, + /** Stop command */ + ZB_ZCL_CMD_WINDOW_COVERING_STOP = 0x02, + /** Go to Lift Value command */ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_LIFT_VALUE = 0x04, + /** Go to Lift Percentage command */ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_LIFT_PERCENTAGE = 0x05, + /** Go to Tilt Value command */ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_TILT_VALUE = 0x07, + /** Go to Tilt Percentage command */ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE = 0x08 +}; + +/** @cond internals_doc */ +/* Window covering cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_WINDOW_COVERING_UP_OPEN, \ + ZB_ZCL_CMD_WINDOW_COVERING_DOWN_CLOSE, \ + ZB_ZCL_CMD_WINDOW_COVERING_STOP, \ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_LIFT_PERCENTAGE, \ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE + +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_CLIENT_ROLE_GENERATED_CMD_LIST +/*! @} + * @endcond */ /* internals_doc */ + +/** Mandatory commands defines */ + +/** @brief Structured representsation of GO_TO_LIFT_VALUE command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_go_to_lift_value_req_s +{ + /** Lift Value */ + zb_uint16_t lift_value; +} ZB_PACKED_STRUCT zb_zcl_go_to_lift_value_req_t; + +/** @brief Structured representsation of GO_TO_LIFT_PERCENTAGE command payload + @see ZCL spec, subclause 9.4.2.2.5.2.1*/ +typedef ZB_PACKED_PRE struct zb_zcl_go_to_lift_percentage_req_s +{ + /** Percentage Lift Value */ + zb_uint8_t percentage_lift_value; +} ZB_PACKED_STRUCT zb_zcl_go_to_lift_percentage_req_t; + +/** @brief Structured representsation of GO_TO_TILT_VALUE command payload */ +typedef ZB_PACKED_PRE struct zb_zcl_go_to_tilt_value_req_s +{ + /** Tilt Value */ + zb_uint16_t tilt_value; +} ZB_PACKED_STRUCT zb_zcl_go_to_tilt_value_req_t; + +/** @brief Structured representsation of GO_TO_TILT_PERCENTAGE command payload + @see ZCL spec, subclause 9.4.2.2.5.5.1*/ +typedef ZB_PACKED_PRE struct zb_zcl_go_to_tilt_percentage_req_s +{ + /** Percentage Tilt Value */ + zb_uint8_t percentage_tilt_value; +} ZB_PACKED_STRUCT zb_zcl_go_to_tilt_percentage_req_t; + +/** @brief Send Up/Open command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WINDOW_COVERING_SEND_UP_OPEN_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_WINDOW_COVERING_UP_OPEN); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, \ + prfl_id, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, cb); \ +} + +/** @brief Send Down/Close command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WINDOW_COVERING_SEND_DOWN_CLOSE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_WINDOW_COVERING_DOWN_CLOSE); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, \ + prfl_id, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, cb); \ +} + +/** @brief Send Stop command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WINDOW_COVERING_SEND_STOP_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_WINDOW_COVERING_STOP); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, \ + prfl_id, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, cb); \ +} + +/** @brief Send Go to Lift Percentage command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param percentage_lift_value - Percentage Lift value +*/ +#define ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_LIFT_PERCENTAGE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, percentage_lift_value) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_LIFT_PERCENTAGE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, percentage_lift_value); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, \ + prfl_id, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, cb); \ +} + +/** @brief Parses Get Go to Lift Percentage command and fills data request + structure. If request contains invalid data, status parameter is ZB_FALSE + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param lift_percentage_req - pointer to a variable to save command request to + @param status - return ZB_ZCL_PARSE_STATUS_SUCCESS if request contains valid data, + else ZB_ZCL_PARSE_STATUS_FAILURE + @note data_buf buffer should contain command request payload without ZCL header. + */ +#define ZB_ZCL_WINDOW_COVERING_GET_GO_TO_LIFT_PERCENTAGE_REQ( \ + data_buf, lift_percentage_req, status) \ +{ \ + zb_zcl_go_to_lift_percentage_req_t *lift_percentage_req_ptr; \ + (lift_percentage_req_ptr) = zb_buf_len(data_buf) == \ + sizeof(zb_zcl_go_to_lift_percentage_req_t) ? \ + (zb_zcl_go_to_lift_percentage_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (lift_percentage_req_ptr) \ + { \ + (lift_percentage_req)->percentage_lift_value = \ + lift_percentage_req_ptr->percentage_lift_value; \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Send Go to Tilt Percentage command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param percentage_tilt_value - Percentage Tilt value +*/ +#define ZB_ZCL_WINDOW_COVERING_SEND_GO_TO_TILT_PERCENTAGE_REQ( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, percentage_tilt_value) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET_REQ(buffer) \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL(ptr, def_resp) \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_REQ(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_CMD_WINDOW_COVERING_GO_TO_TILT_PERCENTAGE); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, percentage_tilt_value); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT(buffer, addr, dst_addr_mode, dst_ep, ep, \ + prfl_id, ZB_ZCL_CLUSTER_ID_WINDOW_COVERING, cb); \ +} + +/** @brief Parses Get Go to Tilt Percentage command and fills to data request + structure. If request contains invalid data, -1 is returned as Percentage Tilt Value + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param tilt_percentage_req - variable to save command request + @param status - return ZB_ZCL_PARSE_STATUS_SUCCESS if request contains valid data, + else ZB_ZCL_PARSE_STATUS_FAILURE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WINDOW_COVERING_GET_GO_TO_TILT_PERCENTAGE_REQ( \ + data_buf, tilt_percentage_req, status) \ +{ \ + zb_zcl_go_to_tilt_percentage_req_t *tilt_percentage_req_ptr; \ + (tilt_percentage_req_ptr) = zb_buf_len(data_buf) == \ + sizeof(zb_zcl_go_to_tilt_percentage_req_t) ? \ + (zb_zcl_go_to_tilt_percentage_req_t*)zb_buf_begin(data_buf) : NULL; \ + if (tilt_percentage_req_ptr) \ + { \ + (tilt_percentage_req)->percentage_tilt_value = \ + tilt_percentage_req_ptr->percentage_tilt_value; \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @} */ /* Window Covering cluster commands */ + +/** @} */ /* ZCL Window Covering cluster definitions */ + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +void zb_zcl_window_covering_init_server(void); +void zb_zcl_window_covering_init_client(void); +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_SERVER_ROLE_INIT zb_zcl_window_covering_init_server +#define ZB_ZCL_CLUSTER_ID_WINDOW_COVERING_CLIENT_ROLE_INIT zb_zcl_window_covering_init_client + +#endif /* ZB_ZCL_WINDOW_COVERING_H */ diff --git a/zboss/include/zcl/zb_zcl_wwah.h b/zboss/include/zcl/zb_zcl_wwah.h new file mode 100644 index 0000000000..9ba3832fd7 --- /dev/null +++ b/zboss/include/zcl/zb_zcl_wwah.h @@ -0,0 +1,2621 @@ +/* + * ZBOSS Zigbee 3.0 + * + * Copyright (c) 2012-2020 DSR Corporation, Denver CO, USA. + * http://www.dsr-zboss.com + * http://www.dsr-corporation.com + * All rights reserved. + * + * + * Use in source and binary forms, redistribution in binary form only, with + * or without modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 2. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 3. This software, with or without modification, must only be used with a Nordic + * Semiconductor ASA integrated circuit. + * + * 4. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +/* PURPOSE: WWAH cluster definitions +*/ + +#if ! defined ZB_ZCL_WWAH_H +#define ZB_ZCL_WWAH_H + +#include "zcl/zb_zcl_common.h" +#include "zcl/zb_zcl_commands.h" + +/** @cond DOXYGEN_ZCL_SECTION */ + +/* Cluster ZB_ZCL_CLUSTER_ID_WWAH */ + +/** @addtogroup ZB_ZCL_WWAH + * @{ + * @details + * This cluster provides an opportunity to use various features + * of the Work With All Hubs cluster. + * + * The WWAH cluster shall exist on only 1 endpoint of the Zigbee node, + * it should be identified using cluster ID 0xfc57 and manufacturer ID 0x1217. + * + * All configurations/command settings in this cluster shall be persisted across power cycles + * and rejoins. Only a device factory reset can reset this cluster and put it back to default + * settings. + * + * For more information see Zigbee WWAH Cluster definiton (dnocument number in Zigbee Alliance + * 17-01067-022). + * + */ + + +/*! @defgroup ZB_ZCL_WWAH_ATTR WWAH cluster attributes + @{ +*/ + +/* Amazon Lab 126 manufacturer code */ +#define WWAH_MANUFACTURER_CODE 0x1217 + +/*! @brief WWAH cluster attribute identifiers + @see WWAH spec, subclause 6.3.2.2 +*/ +enum zb_zcl_wwah_attr_e +{ + /** If set to TRUE, the device SHALL disallow downgrades of it's firmware. */ + ZB_ZCL_ATTR_WWAH_DISABLE_OTA_DOWNGRADES_ID = 0x0002, + /** If set to FALSE, the node SHALL ignore MGMT Leave Without Rejoin commands. */ + ZB_ZCL_ATTR_WWAH_MGMT_LEAVE_WITHOUT_REJOIN_ENABLED_ID = 0x0003, + /** This attribute is a fixed value containing the number of Network Level Retries + * the device performs when sending a unicast command, not including APS retries. */ + ZB_ZCL_ATTR_WWAH_NWK_RETRY_COUNT_ID = 0x0004, + /** This attribute is a fixed value containing the number of MAC Level Retries the + * device performs when sending a unicast command, not including APS retries. */ + ZB_ZCL_ATTR_WWAH_MAC_RETRY_COUNT_ID = 0x0005, + /** This attribute is set to TRUE if the router's check-in algorithm has been enabled + * through the 'Enable Periodic Router Check-Ins' command detailed below. */ + ZB_ZCL_ATTR_WWAH_ROUTER_CHECK_IN_ENABLED_ID = 0x0006, + /** This attribute is set to FALSE if support for Touchlink Interpan messages has been + * disabled on the device. */ + ZB_ZCL_ATTR_WWAH_TOUCHLINK_INTERPAN_ENABLED_ID = 0x0007, + /** If set to TRUE, the device SHALL enable the WWAH Parent Classification + * Advertisements feature. */ + ZB_ZCL_ATTR_WWAH_WWAH_PARENT_CLASSIFICATION_ENABLED_ID = 0x0008, + /** This attribute is TRUE if the WWAH Application Event Retry Algorithm is enabled. */ + ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_ENABLED_ID = 0x0009, + /** This attribute is the queue size for re-delivery attempts in the WWAH Application + * Event Retry Algorithm. */ + ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_ID = 0x000A, + /** This attribute is set to TRUE if the WWAH Rejoin Algorithm is enabled. */ + ZB_ZCL_ATTR_WWAH_WWAH_REJOIN_ENABLED_ID = 0x000B, + /** This attribute is the time in seconds the device waits before retrying a data poll + * when a MAC level data poll fails for any reason. */ + ZB_ZCL_ATTR_WWAH_MAC_POLL_FAILURE_WAIT_TIME_ID = 0x000C, + /** This attribute indicates whether the device is able to be configured using ZDO + * commands that are not encrypted using the Trust Center Link Key. */ + ZB_ZCL_ATTR_WWAH_CONFIGURATION_MODE_ENABLED_ID = 0x000D, + /** This attribute contains the ID of the current debug report stored on the node. */ + ZB_ZCL_ATTR_WWAH_CURRENT_DEBUG_REPORT_ID_ID = 0x000E, + /** If this attribute is set to TRUE, the node SHALL only process network + * key rotation commands which are sent via unicast and are encrypted by + * the Trust Center Link Key. */ + ZB_ZCL_ATTR_WWAH_TC_SECURITY_ON_NWK_KEY_ROTATION_ENABLED_ID = 0x000F, + /** If this attribute is set to TRUE, the endpoint device SHALL enable + * the WWAH Bad Parent Recovery feature. */ + ZB_ZCL_ATTR_WWAH_WWAH_BAD_PARENT_RECOVERY_ENABLED_ID = 0x0010, + /** This attribute contains the channel number of the only channel the device + * SHALL accept in a ZDO Mgmt Network Update command. */ + ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_ID = 0x0011, + /** This attribute contains the only short PAN ID the device SHALL accept in + * a NLME Network Update command. */ + ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_PANID_ID = 0x0012, + /** This attribute contains the maximum time in seconds the device may be unavailable + * after completing its OTA download (while restarting, etc). */ + ZB_ZCL_ATTR_WWAH_OTA_MAX_OFFLINE_DURATION_ID = 0x0013, +}; + +/** @brief Minimum value for Cluster Revision attribute */ +#define ZB_ZCL_WWAH_CLUSTER_REVISION_MIN_VALUE 0x0001 + +/** @brief Default value for MGMTLeaveWithoutRejoinEnabled attribute */ +#define ZB_ZCL_WWAH_MGMT_LEAVE_WITHOUT_REJOIN_ENABLED_DEFAULT_VALUE ZB_TRUE + +/** @brief Minimum value for NWKRetryCount attribute */ +#define ZB_ZCL_WWAH_NWK_RETRY_COUNT_MIN_VALUE 0x03 + +/** @brief Maximum value for NWKRetryCount attribute */ +#define ZB_ZCL_WWAH_NWK_RETRY_COUNT_MAX_VALUE 0xFF + +/** @brief Minimum value for MACRetryCount attribute */ +#define ZB_ZCL_WWAH_MAC_RETRY_COUNT_MIN_VALUE 0x03 + +/** @brief Maximum value for MACRetryCount attribute */ +#define ZB_ZCL_WWAH_MAC_RETRY_COUNT_MAX_VALUE 0xFF + +/** @brief Default value for RouterCheckInEnabled attribute */ +#define ZB_ZCL_WWAH_ROUTER_CHECK_IN_ENABLED_DEFAULT_VALUE ZB_FALSE + +/** @brief Default value for WWAHParentClassificationEnabled attribute */ +#define ZB_ZCL_WWAH_WWAH_PARENT_CLASSIFICATION_ENABLED_DEFAULT_VALUE ZB_FALSE + +/** @brief Default value for WWAHAppEventRetryEnabled attribute */ +#define ZB_ZCL_WWAH_WWAH_APP_EVENT_RETRY_ENABLED_DEFAULT_VALUE ZB_TRUE + +/** @brief Minimum value for WWAHAppEventRetryQueueSize attribute */ +#define ZB_ZCL_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_MIN_VALUE 10 + +/** @brief Maximum value for WWAHAppEventRetryQueueSize attribute */ +#define ZB_ZCL_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_MAX_VALUE 0xFF + +/** @brief Default value for WWAHAppEventRetryQueueSize attribute */ +#define ZB_ZCL_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_DEFAULT_VALUE 10 + +/** @brief Default value for WWAHRejoinEnabled attribute */ +#define ZB_ZCL_WWAH_WWAH_REJOIN_ENABLED_DEFAULT_VALUE ZB_FALSE + +/** @brief Minimum value for MACPollFailureWaitTime attribute */ +#define ZB_ZCL_WWAH_MAC_POLL_FAILURE_WAIT_TIME_MIN_VALUE 0x00 + +/** @brief Maximum value for MACPollFailureWaitTime attribute */ +#define ZB_ZCL_WWAH_MAC_POLL_FAILURE_WAIT_TIME_MAX_VALUE 0xFF + +/** @brief Default value for MACPollFailureWaitTime attribute */ +#define ZB_ZCL_WWAH_MAC_POLL_FAILURE_WAIT_TIME_DEFAULT_VALUE 3 + +/** @brief Default value for ConfigurationModeEnabled attribute */ +#define ZB_ZCL_WWAH_CONFIGURATION_MODE_ENABLED_DEFAULT_VALUE ZB_TRUE + +/** @brief Minimum value for CurrentDebugReportID attribute */ +#define ZB_ZCL_WWAH_CURRENT_DEBUG_REPORT_ID_MIN_VALUE 0x00 + +/** @brief Maximum value for CurrentDebugReportID attribute */ +#define ZB_ZCL_WWAH_CURRENT_DEBUG_REPORT_ID_MAX_VALUE 0xFF + +/** @brief Default value for TCSecurityOnNwkKeyRotationEnabled attribute */ +#define ZB_ZCL_WWAH_TC_SECURITY_ON_NWK_KEY_ROTATION_ENABLED_DEFAULT_VALUE ZB_FALSE + +/** @brief Default value for WWAHBadParentRecoveryEnabled attribute */ +#define ZB_ZCL_WWAH_WWAH_BAD_PARENT_RECOVERY_ENABLED_DEFAULT_VALUE ZB_FALSE + +/** @brief Minimum value for PendingNetworkUpdateChannel attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_MIN_VALUE 0x00 + +/** @brief Maximum value for PendingNetworkUpdateChannel attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_MAX_VALUE 0xFF + +/** @brief Default value for PendingNetworkUpdateChannel attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_DEFAULT_VALUE 0xFF + +/** @brief Minimum value for PendingNetworkUpdatePANID attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_PANID_MIN_VALUE 0x0000 + +/** @brief Maximum value for PendingNetworkUpdatePANID attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_PANID_MAX_VALUE 0xFFFF + +/** @brief Default value for PendingNetworkUpdatePANID attribute */ +#define ZB_ZCL_WWAH_PENDING_NETWORK_UPDATE_PANID_DEFAULT_VALUE 0xFFFF + +/** @brief Minimum value for OTAMaxOfflineDuration attribute */ +#define ZB_ZCL_WWAH_OTA_MAX_OFFLINE_DURATION_MIN_VALUE 0x0000 + +/** @brief Maximum value for OTAMaxOfflineDuration attribute */ +#define ZB_ZCL_WWAH_OTA_MAX_OFFLINE_DURATION_MAX_VALUE 0xFFFF + +/** @brief Additional MAC Poll retry count */ +#define ZB_ZCL_WWAH_MAC_POLL_RETRY_COUNT 2 + +/*! @} */ /* WWAH cluster attributes */ + +/*! @defgroup ZB_ZCL_WWAH_COMMANDS WWAH cluster commands + @{ +*/ + +/*! @brief WWAH cluster command identifiers + @see WWAH spec +*/ +enum zb_zcl_wwah_cmd_e +{ + /** Enable APS Link Key Authorization command */ + ZB_ZCL_CMD_WWAH_ENABLE_APS_LINK_KEY_AUTHORIZATION_ID = 0x00, + /** Disable APS Link Key Authorization command */ + ZB_ZCL_CMD_WWAH_DISABLE_APS_LINK_KEY_AUTHORIZATION_ID = 0x01, + /** APS Link Key Authorization Query command */ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_ID = 0x02, + /** Request New APS Link Key command */ + ZB_ZCL_CMD_WWAH_REQUEST_NEW_APS_LINK_KEY_ID = 0x03, + /** Enable WWAH App Event Retry Algorithm command */ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID = 0x04, + /** Disable WWAH App Event Retry Algorithm command */ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID = 0x05, + /** Request Time command */ + ZB_ZCL_CMD_WWAH_REQUEST_TIME_ID = 0x06, + /** Enable WWAH Rejoin Algorithm command */ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_ID = 0x07, + /** Disable WWAH Rejoin Algorithm command */ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_REJOIN_ALGORITHM_ID = 0x08, + /** Set IAS Zone Enrollment Method command */ + ZB_ZCL_CMD_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_ID = 0x09, + /** Clear Binding Table command */ + ZB_ZCL_CMD_WWAH_CLEAR_BINDING_TABLE_ID = 0x0A, + /** Enable Periodic Router Check Ins command */ + ZB_ZCL_CMD_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_ID = 0x0B, + /** Disable Periodic Router Check Ins command */ + ZB_ZCL_CMD_WWAH_DISABLE_PERIODIC_ROUTER_CHECK_INS_ID = 0x0C, + /** Set MAC Poll CCA Wait Time command */ + ZB_ZCL_CMD_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_ID = 0x0D, + /** Set Pending Network Update command */ + ZB_ZCL_CMD_WWAH_SET_PENDING_NETWORK_UPDATE_ID = 0x0E, + /** Require APS ACKs on Unicasts command */ + ZB_ZCL_CMD_WWAH_REQUIRE_APS_ACKS_ON_UNICASTS_ID = 0x0F, + /** Remove APS ACKs on Unicasts Requirement command */ + ZB_ZCL_CMD_WWAH_REMOVE_APS_ACKS_ON_UNICASTS_REQUIREMENT_ID = 0x10, + /** APS ACK Requirement Query command */ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_ID = 0x11, + /** Debug Report Query command */ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_ID = 0x12, + /** Survey Beacons command */ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_ID = 0x13, + /** Disable OTA Downgrades command */ + ZB_ZCL_CMD_WWAH_DISABLE_OTA_DOWNGRADES_ID = 0x14, + /** Disable MGMT Leave Without Rejoin command */ + ZB_ZCL_CMD_WWAH_DISABLE_MGMT_LEAVE_WITHOUT_REJOIN_ID = 0x15, + /** Disable Touchlink Interpan Message Support command */ + ZB_ZCL_CMD_WWAH_DISABLE_TOUCHLINK_INTERPAN_MESSAGE_SUPPORT_ID = 0x16, + /** Enable WWAH Parent Classification command */ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_PARENT_CLASSIFICATION_ID = 0x17, + /** Disable WWAH Parent Classification command */ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_PARENT_CLASSIFICATION_ID = 0x18, + /** Enable TC Security On Nwk Key Rotation command */ + ZB_ZCL_CMD_WWAH_ENABLE_TC_SECURITY_ON_NWK_KEY_ROTATION_ID = 0x19, + /** Enable WWAH Bad Parent Recovery command */ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_BAD_PARENT_RECOVERY_ID = 0x1A, + /** Disable WWAH Bad Parent Recovery command */ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_BAD_PARENT_RECOVERY_ID = 0x1B, + /** Enable Configuration Mode command */ + ZB_ZCL_CMD_WWAH_ENABLE_CONFIGURATION_MODE_ID = 0x1C, + /** Disable Configuration Mode command */ + ZB_ZCL_CMD_WWAH_DISABLE_CONFIGURATION_MODE_ID = 0x1D, + /** Use Trust Center for Cluster command */ + ZB_ZCL_CMD_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_ID = 0x1E, + /** Trust Center for Cluster Server Query command */ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_ID = 0x1F, +}; + +enum zb_zcl_wwah_cmd_resp_e +{ + /** APS Link Key Authorization Query Response command */ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_ID = 0x00, + /** Powering Off Notification command */ + ZB_ZCL_CMD_WWAH_POWERING_OFF_NOTIFICATION_ID = 0x01, + /** Powering On Notification command */ + ZB_ZCL_CMD_WWAH_POWERING_ON_NOTIFICATION_ID = 0x02, + /** Short Address Change command */ + ZB_ZCL_CMD_WWAH_SHORT_ADDRESS_CHANGE_ID = 0x03, + /** APS ACK Requirement Query Response command */ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_RESPONSE_ID = 0x04, + /** Power Descriptor Change command */ + ZB_ZCL_CMD_WWAH_POWER_DESCRIPTOR_CHANGE_ID = 0x05, + /** New Debug Report Notification command */ + ZB_ZCL_CMD_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_ID = 0x06, + /** Debug Report Query Response command */ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_RESPONSE_ID = 0x07, + /** Trust Center for Cluster Server Query Response command */ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_ID = 0x08, + /** Survey Beacons Response command */ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_RESPONSE_ID = 0x09, +}; + + +/* WWAH control cluster commands list : only for information - do not modify */ +#define ZB_ZCL_CLUSTER_ID_WWAH_SERVER_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_ID, \ + ZB_ZCL_CMD_WWAH_POWERING_OFF_NOTIFICATION_ID, \ + ZB_ZCL_CMD_WWAH_POWERING_ON_NOTIFICATION_ID, \ + ZB_ZCL_CMD_WWAH_SHORT_ADDRESS_CHANGE_ID, \ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_RESPONSE_ID, \ + ZB_ZCL_CMD_WWAH_POWER_DESCRIPTOR_CHANGE_ID, \ + ZB_ZCL_CMD_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_ID, \ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_RESPONSE_ID, \ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_ID, \ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_RESPONSE_ID + +#define ZB_ZCL_CLUSTER_ID_WWAH_CLIENT_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_WWAH_SERVER_ROLE_GENERATED_CMD_LIST + +#define ZB_ZCL_CLUSTER_ID_WWAH_CLIENT_ROLE_GENERATED_CMD_LIST \ + ZB_ZCL_CMD_WWAH_ENABLE_APS_LINK_KEY_AUTHORIZATION_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_APS_LINK_KEY_AUTHORIZATION_ID, \ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_ID, \ + ZB_ZCL_CMD_WWAH_REQUEST_NEW_APS_LINK_KEY_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID, \ + ZB_ZCL_CMD_WWAH_REQUEST_TIME_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_REJOIN_ALGORITHM_ID, \ + ZB_ZCL_CMD_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_ID, \ + ZB_ZCL_CMD_WWAH_CLEAR_BINDING_TABLE_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_PERIODIC_ROUTER_CHECK_INS_ID, \ + ZB_ZCL_CMD_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_ID, \ + ZB_ZCL_CMD_WWAH_SET_PENDING_NETWORK_UPDATE_ID, \ + ZB_ZCL_CMD_WWAH_REQUIRE_APS_ACKS_ON_UNICASTS_ID, \ + ZB_ZCL_CMD_WWAH_REMOVE_APS_ACKS_ON_UNICASTS_REQUIREMENT_ID, \ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_ID, \ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_ID, \ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_OTA_DOWNGRADES_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_MGMT_LEAVE_WITHOUT_REJOIN_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_TOUCHLINK_INTERPAN_MESSAGE_SUPPORT_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_PARENT_CLASSIFICATION_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_PARENT_CLASSIFICATION_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_TC_SECURITY_ON_NWK_KEY_ROTATION_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_BAD_PARENT_RECOVERY_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_BAD_PARENT_RECOVERY_ID, \ + ZB_ZCL_CMD_WWAH_ENABLE_CONFIGURATION_MODE_ID, \ + ZB_ZCL_CMD_WWAH_DISABLE_CONFIGURATION_MODE_ID, \ + ZB_ZCL_CMD_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_ID, \ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_ID + +#define ZB_ZCL_CLUSTER_ID_WWAH_SERVER_ROLE_RECEIVED_CMD_LIST ZB_ZCL_CLUSTER_ID_WWAH_CLIENT_ROLE_GENERATED_CMD_LIST + + +/** @brief Size of APS ACK Exempt Table */ +#define ZB_ZCL_WWAH_APS_ACK_EXEMPT_TABLE_SIZE 10 +ZB_ASSERT_VALUE_ALIGNED_TO_4(ZB_ZCL_WWAH_APS_ACK_EXEMPT_TABLE_SIZE * sizeof(zb_uint16_t)) + +/** @brief Size of APS Link Key Authorization Table */ +#define ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_TABLE_SIZE 10 +ZB_ASSERT_VALUE_ALIGNED_TO_4(ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_TABLE_SIZE * sizeof(zb_uint16_t)) + +/** @brief Size of Use Trust Center for Cluster Table */ +#define ZB_ZCL_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_TABLE_SIZE 4 +ZB_ASSERT_VALUE_ALIGNED_TO_4(ZB_ZCL_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_TABLE_SIZE * sizeof(zb_uint16_t)) + +/** @brief WWAH Cluster arrays "record is free" flag */ +#define ZB_ZCL_WWAH_CLUSTER_ID_FREE_RECORD 0xFFFF + +/** @brief Debug Report ID field reserved value + * The value 0x00 is reserved to indicate that there are no debug reports and SHALL not be used + * as IDs of a debug report.*/ +#define ZB_ZCL_WWAH_RESERVED_DEBUG_REPORT_ID 0x00 + +#define ZB_ZCL_WWAH_DEBUG_REPORT_FREE_RECORD (zb_zcl_wwah_debug_report_t){ZB_ZCL_WWAH_RESERVED_DEBUG_REPORT_ID, 0, NULL} + +/** @brief Context WWAH cluster */ + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_debug_report_s +{ + zb_uint8_t report_id; /**< Report ID. 0x00 means lack of report */ + zb_uint32_t report_size; /**< Report size */ + zb_char_t *report; /**< Pointer to report data*/ +} +ZB_PACKED_STRUCT zb_zcl_wwah_debug_report_t; + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_classification_mask_s +{ + zb_bitfield_t tc_connectivity :1; /**< TC Connectivity value */ + zb_bitfield_t long_uptime :1; /**< Long Uptime value */ + zb_bitfield_t reserved :6; /**< Reserved */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_classification_mask_t; + +#define ZB_ZCL_WWAH_PERIODIC_CHECKINS_CLUSTER_MATCH_DESC_TIME (ZB_TIME_ONE_SECOND * 20) +#define ZB_ZCL_WWAH_PERIODIC_CHECKINS_MAX_FAILURE_CNT 3 + +#define ZB_ZCL_WWAH_PERIODIC_CHECKINS_READ_KEEPALIVE 0 +#define ZB_ZCL_WWAH_PERIODIC_CHECKINS_READ_CLUSTER_REVISION 1 +#define ZB_ZCL_WWAH_PERIODIC_CHECKINS_NOT_SUPPORTED 2 + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_periodic_checkins_data_s +{ + zb_uint8_t poll_method; + zb_uint8_t tsn; + zb_uint8_t endpoint; + zb_uint8_t failure_cnt; + zb_uint32_t countdown; + zb_uint16_t keepalive_base; /* Base timeout in seconds*/ + zb_uint16_t keepalive_jitter; +} ZB_PACKED_STRUCT zb_zcl_wwah_periodic_checkins_data_t; + +typedef enum zb_zcl_wwah_bad_parent_recovery_signal_e +{ + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_RSSI_WITH_PARENT_BAD = 0, + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_RSSI_WITH_PARENT_OK, + + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_APS_ACK_FAILED, + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_APS_ACK_OK, + + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_POLL_CONTROL_CHECK_IN_FAILED, + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_POLL_CONTROL_CHECK_IN_OK, + + ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_RESERVED +} zb_zcl_wwah_bad_parent_recovery_signal_t; + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_bad_parent_recovery_data_s +{ + zb_bitfield_t started:1; + zb_bitfield_t poll_control_checkin_failed_cnt:2; + zb_bitfield_t reserved:5; +} ZB_PACKED_STRUCT zb_zcl_wwah_bad_parent_recovery_data_t; + +typedef enum zb_zcl_wwah_behavior_e +{ + ZB_ZCL_WWAH_BEHAVIOR_OFF = 0, + ZB_ZCL_WWAH_BEHAVIOR_CLIENT, + ZB_ZCL_WWAH_BEHAVIOR_SERVER, + + ZB_ZCL_WWAH_BEHAVIOR_RESERVED +} zb_zcl_wwah_behavior_t; + +/*! @} */ /* WWAH cluster commands */ + +/*! + @cond internals_doc + @internal @name WWAH cluster internals + Internal structures for attribute representation in cluster definitions. + @{ +*/ + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_DISABLE_OTA_DOWNGRADES_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_DISABLE_OTA_DOWNGRADES_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_MGMT_LEAVE_WITHOUT_REJOIN_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_MGMT_LEAVE_WITHOUT_REJOIN_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_NWK_RETRY_COUNT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_NWK_RETRY_COUNT_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_MAC_RETRY_COUNT_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_MAC_RETRY_COUNT_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_ROUTER_CHECK_IN_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_ROUTER_CHECK_IN_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_TOUCHLINK_INTERPAN_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_TOUCHLINK_INTERPAN_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_WWAH_PARENT_CLASSIFICATION_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_WWAH_PARENT_CLASSIFICATION_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_WWAH_REJOIN_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_WWAH_REJOIN_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_MAC_POLL_FAILURE_WAIT_TIME_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_MAC_POLL_FAILURE_WAIT_TIME_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_CONFIGURATION_MODE_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_CONFIGURATION_MODE_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_CURRENT_DEBUG_REPORT_ID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_CURRENT_DEBUG_REPORT_ID_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_TC_SECURITY_ON_NWK_KEY_ROTATION_ENABLED_ID(data_ptr)\ +{ \ + ZB_ZCL_ATTR_WWAH_TC_SECURITY_ON_NWK_KEY_ROTATION_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_WWAH_BAD_PARENT_RECOVERY_ENABLED_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_WWAH_BAD_PARENT_RECOVERY_ENABLED_ID, \ + ZB_ZCL_ATTR_TYPE_BOOL, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_ID, \ + ZB_ZCL_ATTR_TYPE_U8, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_PANID_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_PANID_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +#define ZB_SET_ATTR_DESCR_WITH_ZB_ZCL_ATTR_WWAH_OTA_MAX_OFFLINE_DURATION_ID(data_ptr) \ +{ \ + ZB_ZCL_ATTR_WWAH_OTA_MAX_OFFLINE_DURATION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) data_ptr \ +} + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_cluster_list_s +{ + zb_uint8_t number_of_clusters; /**< Number of Clusters */ + zb_uint16_t *cluster_id; /**< Cluster ID */ +} +ZB_PACKED_STRUCT zb_zcl_wwah_cluster_list_t; + +/*! + @brief Parses various commands with cluster list variable length payload and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ + +#define ZB_ZCL_WWAH_GET_CLUSTER_LIST_CMD(data_buf, req, status) \ +{ \ + zb_zcl_wwah_cluster_list_t *src_ptr = (zb_zcl_wwah_cluster_list_t*)zb_buf_begin((data_buf)); \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (zb_buf_len((data_buf)) >= sizeof(zb_uint8_t)) \ + { \ + (req)->number_of_clusters = src_ptr->number_of_clusters; \ + if (src_ptr->number_of_clusters) \ + { \ + if (zb_buf_len((data_buf)) >= sizeof(zb_uint8_t) + \ + src_ptr->number_of_clusters * sizeof(zb_uint16_t)) \ + { \ + (req)->cluster_id = (zb_uint16_t*)(&(src_ptr->cluster_id)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +#define ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_PAYLOAD_LEN (sizeof(zb_uint16_t)) + +/*! + @brief Parses APS Link Key Authorization Query command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_APS_LINK_KEY_AUTHORIZATION_QUERY(data_buf, req, status) \ +{ \ + zb_uint16_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_PAYLOAD_LEN ? \ + (zb_uint16_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_PAYLOAD_LEN); \ + status = ((req) == ZB_ZCL_WWAH_CLUSTER_ID_FREE_RECORD) ? \ + ZB_ZCL_PARSE_STATUS_FAILURE : ZB_ZCL_PARSE_STATUS_SUCCESS; \ + \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Enable WWAH App Event Retry Algorithm command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_s +{ + zb_uint8_t first_backoff_time_in_seconds; /**< First Backoff Time In Seconds */ + zb_uint8_t backoff_sequence_common_ratio; /**< Backoff Sequence Common Ratio */ + zb_uint32_t max_backoff_time_in_seconds; /**< Max Backoff Time In Seconds */ + zb_uint8_t max_re_delivery_attempts; /**< Max Re-Delivery Attempts */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_t; + +#define ZB_ZCL_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_PAYLOAD_LEN (sizeof(zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_t)) +/*! + @brief Parses Enable WWAH App Event Retry Algorithm command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM(data_buf, req, status) \ +{ \ + zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_PAYLOAD_LEN ? \ + (zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_PAYLOAD_LEN); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Enable WWAH Rejoin Algorithm command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_enable_wwah_rejoin_algorithm_s +{ + zb_uint16_t fast_rejoin_timeout_in_seconds; /**< Fast Rejoin Timeout In Seconds */ + zb_uint16_t duration_between_each_rejoin_in_seconds; /**< Duration Between Each Rejoin In Seconds */ + zb_uint16_t fast_rejoin_first_backoff_in_seconds; /**< Fast Rejoin First Backoff In Seconds */ + zb_uint16_t rejoin_max_backoff_time_in_seconds; /**< Max Backoff Time In Seconds */ + zb_uint16_t max_backoff_iterations; /**< Max Backoff Iterations */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_enable_wwah_rejoin_algorithm_t; + +#define ZB_ZCL_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_PAYLOAD_LEN (sizeof(zb_zcl_wwah_enable_wwah_rejoin_algorithm_t)) + +/*! + @brief Parses Enable WWAH Rejoin Algorithm command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_ENABLE_WWAH_REJOIN_ALGORITHM(data_buf, req, status) \ +{ \ + zb_zcl_wwah_enable_wwah_rejoin_algorithm_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_PAYLOAD_LEN ? \ + (zb_zcl_wwah_enable_wwah_rejoin_algorithm_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_PAYLOAD_LEN); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +#define ZB_ZCL_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_PAYLOAD_LEN (sizeof(zb_uint8_t)) +/*! + @brief Parses Set IAS Zone Enrollment Method command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_SET_IAS_ZONE_ENROLLMENT_METHOD(data_buf, req, status) \ +{ \ + zb_uint8_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_PAYLOAD_LEN ? \ + (zb_uint8_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_PAYLOAD_LEN); \ + switch(*(zb_uint8_t*)req_ptr) \ + { \ + case ZB_ZCL_WWAH_ENROLLMENT_MODE_TRIP_TO_PAIR: \ + case ZB_ZCL_WWAH_ENROLLMENT_MODE_AUTO_ENROLL_RESPONSE: \ + case ZB_ZCL_WWAH_ENROLLMENT_MODE_AUTO_ENROLL_REQUEST: \ + { \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + break; \ + } \ + default: \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + break; \ + } \ + } \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +#define ZB_ZCL_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_PAYLOAD_LEN (sizeof(zb_uint16_t)) + +/*! + @brief Parses Enable Periodic Router Check-Ins command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_ENABLE_PERIODIC_ROUTER_CHECK_INS(data_buf, req, status) \ +{ \ + zb_uint16_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_PAYLOAD_LEN ? \ + (zb_uint16_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +#define ZB_ZCL_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_PAYLOAD_LEN (sizeof(zb_uint8_t)) + +/*! + @brief Parses Set MAC Poll CCA Wait Time command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_SET_MAC_POLL_CCA_WAIT_TIME(data_buf, req, status) \ +{ \ + zb_uint8_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_PAYLOAD_LEN ? \ + (zb_uint8_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Set Pending Network Update command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_set_pending_network_update_s +{ + zb_uint8_t channel; /**< Channel */ + zb_uint16_t pan_id; /**< PAN ID */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_set_pending_network_update_t; + +#define ZB_ZCL_WWAH_SET_PENDING_NETWORK_UPDATE_PAYLOAD_LEN (sizeof(zb_zcl_wwah_set_pending_network_update_t)) +/*! + @brief Parses Set Pending Network Update command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_SET_PENDING_NETWORK_UPDATE(data_buf, req, status) \ +{ \ + zb_zcl_wwah_set_pending_network_update_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_SET_PENDING_NETWORK_UPDATE_PAYLOAD_LEN ? \ + (zb_zcl_wwah_set_pending_network_update_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_SET_PENDING_NETWORK_UPDATE_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +#define ZB_ZCL_WWAH_DEBUG_REPORT_QUERY_PAYLOAD_LEN (sizeof(zb_uint8_t)) +/*! + @brief Parses Debug Report Query command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_DEBUG_REPORT_QUERY(data_buf, req, status) \ +{ \ + zb_uint8_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_DEBUG_REPORT_QUERY_PAYLOAD_LEN ? \ + (zb_uint8_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_DEBUG_REPORT_QUERY_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +#define ZB_ZCL_WWAH_SURVEY_BEACONS_PAYLOAD_LEN (sizeof(zb_uint8_t)) +/*! + @brief Parses Survey Beacons command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_SURVEY_BEACONS(data_buf, req, status) \ +{ \ + zb_uint8_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_SURVEY_BEACONS_PAYLOAD_LEN ? \ + (zb_uint8_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_SURVEY_BEACONS_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief APS Link Key Authorization Query Response command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_aps_link_key_authorization_query_response_s +{ + zb_uint16_t cluster_id; /**< Cluster ID */ + zb_uint8_t aps_link_key_authorization_status; /**< APS Link Key Authorization Status */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_aps_link_key_authorization_query_response_t; + +#define ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_PAYLOAD_LEN (sizeof(zb_zcl_wwah_aps_link_key_authorization_query_response_t)) +/*! + @brief Parses APS Link Key Authorization Query Response command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE(data_buf, req, status) \ +{ \ + zb_zcl_wwah_aps_link_key_authorization_query_response_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_PAYLOAD_LEN ? \ + (zb_zcl_wwah_aps_link_key_authorization_query_response_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Short Address Change command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_short_address_change_s +{ + zb_ieee_addr_t device_eui64; /**< DeviceEUI64 */ + zb_uint16_t device_short; /**< DeviceShort */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_short_address_change_t; + +#define ZB_ZCL_WWAH_SHORT_ADDRESS_CHANGE_PAYLOAD_LEN (sizeof(zb_zcl_wwah_short_address_change_t)) +/*! + @brief Parses Short Address Change command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_SHORT_ADDRESS_CHANGE(data_buf, req, status) \ +{ \ + zb_zcl_wwah_short_address_change_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_SHORT_ADDRESS_CHANGE_PAYLOAD_LEN ? \ + (zb_zcl_wwah_short_address_change_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_SHORT_ADDRESS_CHANGE_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Power Descriptor Change command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_power_descriptor_change_s +{ + zb_uint32_t current_power_mode; /**< Current power mode */ + zb_uint32_t available_power_sources; /**< Available power sources */ + zb_uint32_t current_power_source; /**< Current power source */ + zb_uint32_t current_power_source_level; /**< Current power source level */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_power_descriptor_change_t; + + +/*! + @brief Parses Power Descriptor Change command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_POWER_DESCRIPTOR_CHANGE(data_buf, req, status) \ +{ \ + zb_zcl_wwah_power_descriptor_change_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_POWER_DESCRIPTOR_CHANGE_PAYLOAD_LEN ? \ + (zb_zcl_wwah_power_descriptor_change_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, sizeof(zb_zcl_wwah_power_descriptor_change_t)); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Powering On/Off Notification command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_powering_on_off_notification_s +{ + zb_uint8_t power_notification_reason; /**< PowerNotificationReason */ + zb_uint16_t manufacturer_id; /**< Manufacturer ID */ + zb_uint8_t manufacturer_power_notification_reason_length; /**< Manufacturer Power Notification Reason Length */ + zb_uint8_t *manufacturer_power_notification_reason; /**< Manufacturer Power Notification Reason */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_powering_on_off_notification_t; + +#define ZB_ZCL_WWAH_POWERING_ON_OFF_NOTIFICATION_PAYLOAD_LEN (sizeof(zb_uint8_t) + sizeof(zb_uint16_t)+ sizeof(zb_uint8_t)) +/*! + @brief Parses Powering On/Off Notification command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_POWERING_ON_OFF_NOTIFICATION(data_buf, req, status) \ +{ \ + zb_zcl_wwah_powering_on_off_notification_t *src_ptr = \ + (zb_zcl_wwah_powering_on_off_notification_t*)zb_buf_begin((data_buf)); \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (zb_buf_len((data_buf)) >= ZB_ZCL_WWAH_POWERING_ON_OFF_NOTIFICATION_PAYLOAD_LEN) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_POWERING_ON_OFF_NOTIFICATION_PAYLOAD_LEN); \ + if (src_ptr->manufacturer_power_notification_reason_length) \ + { \ + if (zb_buf_len((data_buf)) >= ZB_ZCL_WWAH_POWERING_ON_OFF_NOTIFICATION_PAYLOAD_LEN + \ + src_ptr->manufacturer_power_notification_reason_length * sizeof(zb_uint8_t)) \ + { \ + (req)->manufacturer_power_notification_reason = \ + (zb_uint8_t*)(&(src_ptr->manufacturer_power_notification_reason)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ + else \ + { \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + } \ +} + +/** @brief New Debug Report Notification command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_new_debug_report_notification_s +{ + zb_uint8_t debug_report_id; /**< Debug Report ID */ + zb_uint32_t size_of_report; /**< Size of Report */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_new_debug_report_notification_t; + +#define ZB_ZCL_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_PAYLOAD_LEN (sizeof(zb_zcl_wwah_new_debug_report_notification_t)) +/*! + @brief Parses New Debug Report Notification command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_NEW_DEBUG_REPORT_NOTIFICATION(data_buf, req, status) \ +{ \ + zb_zcl_wwah_new_debug_report_notification_t *req_ptr = \ + zb_buf_len(data_buf) >= ZB_ZCL_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_PAYLOAD_LEN ? \ + (zb_zcl_wwah_new_debug_report_notification_t*)zb_buf_begin(data_buf) : NULL; \ + if (req_ptr) \ + { \ + ZB_MEMCPY(&(req), req_ptr, ZB_ZCL_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_PAYLOAD_LEN); \ + status = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ + else \ + { \ + status = ZB_ZCL_PARSE_STATUS_FAILURE; \ + } \ +} + +/** @brief Debug Report Query Response command structure */ +typedef ZB_PACKED_PRE struct zb_zcl_wwah_debug_report_query_response_s +{ + zb_uint8_t debug_report_id; /**< Debug Report ID */ + zb_uint8_t *report_data; /**< Report data */ +} +ZB_PACKED_STRUCT +zb_zcl_wwah_debug_report_query_response_t; + +/*! + @brief Parses Debug Report Query Response command and fills data request structure. + @param data_buf - pointer to zb_buf_t buffer containing command request data + @param req - variable to save command request + @param status - success or not read parameters - ZB_TRUE or ZB_FALSE + @note data_buf buffer should contain command request payload without ZCL header. +*/ +#define ZB_ZCL_WWAH_GET_DEBUG_REPORT_QUERY_RESPONSE(data_buf, req, status) \ +{ \ + zb_zcl_wwah_debug_report_query_response_t *src_ptr = \ + (zb_zcl_wwah_debug_report_query_response_t*)zb_buf_begin((data_buf)); \ + (status) = ZB_ZCL_PARSE_STATUS_FAILURE; \ + if (zb_buf_len((data_buf)) > sizeof(zb_uint8_t)) \ + { \ + (req)->debug_report_id = src_ptr->debug_report_id; \ + (req)->report_data = (zb_uint8_t*)(&(src_ptr->report_data)); \ + (status) = ZB_ZCL_PARSE_STATUS_SUCCESS; \ + } \ +} + +/*! @brief Structure saved all WWAH attributes */ +typedef struct zb_zcl_wwah_attr_s +{ + zb_uint16_t cluster_revision; + zb_bool_t disable_ota_downgrades; + zb_bool_t mgmt_leave_without_rejoin_enabled; + zb_uint8_t nwk_retry_count; + zb_uint8_t mac_retry_count; + zb_bool_t router_check_in_enabled; + zb_bool_t touchlink_interpan_enabled; + zb_bool_t wwah_parent_classification_enabled; + zb_bool_t wwah_app_event_retry_enabled; + zb_uint8_t wwah_app_event_retry_queue_size; + zb_bool_t wwah_rejoin_enabled; + zb_uint8_t mac_poll_failure_wait_time; + zb_bool_t configuration_mode_enabled; + zb_uint8_t current_debug_report_id; + zb_bool_t tc_security_on_nwk_key_rotation_enabled; + zb_bool_t wwah_bad_parent_recovery_enabled; + zb_uint8_t pending_network_update_channel; + zb_uint16_t pending_network_update_panid; + zb_uint16_t ota_max_offline_duration; +} zb_zcl_wwah_attr_t; + +extern zb_zcl_wwah_attr_t wwah_attr; + +/** @internal @brief Declare attribute list for WWAH cluster + @param attr_list - attribute list name +*/ + +#define ZB_ZCL_DECLARE_WWAH_ATTRIB_LIST(attr_list) \ + zb_zcl_attr_t attr_list [] = { \ + { \ + ZB_ZCL_ATTR_GLOBAL_CLUSTER_REVISION_ID, \ + ZB_ZCL_ATTR_TYPE_U16, \ + ZB_ZCL_ATTR_ACCESS_READ_ONLY, \ + (zb_voidp_t) &(wwah_attr.cluster_revision) \ + }, \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_DISABLE_OTA_DOWNGRADES_ID, &(wwah_attr.disable_ota_downgrades)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_MGMT_LEAVE_WITHOUT_REJOIN_ENABLED_ID, &(wwah_attr.mgmt_leave_without_rejoin_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_NWK_RETRY_COUNT_ID, &(wwah_attr.nwk_retry_count)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_MAC_RETRY_COUNT_ID, &(wwah_attr.mac_retry_count)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_ROUTER_CHECK_IN_ENABLED_ID, &(wwah_attr.router_check_in_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_TOUCHLINK_INTERPAN_ENABLED_ID, &(wwah_attr.touchlink_interpan_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_WWAH_PARENT_CLASSIFICATION_ENABLED_ID, &(wwah_attr.wwah_parent_classification_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_ENABLED_ID, &(wwah_attr.wwah_app_event_retry_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_WWAH_APP_EVENT_RETRY_QUEUE_SIZE_ID, &(wwah_attr.wwah_app_event_retry_queue_size)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_WWAH_REJOIN_ENABLED_ID, &(wwah_attr.wwah_rejoin_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_MAC_POLL_FAILURE_WAIT_TIME_ID, &(wwah_attr.mac_poll_failure_wait_time)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_CONFIGURATION_MODE_ENABLED_ID, &(wwah_attr.configuration_mode_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_CURRENT_DEBUG_REPORT_ID_ID, &(wwah_attr.current_debug_report_id)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_TC_SECURITY_ON_NWK_KEY_ROTATION_ENABLED_ID, &(wwah_attr.tc_security_on_nwk_key_rotation_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_WWAH_BAD_PARENT_RECOVERY_ENABLED_ID, &(wwah_attr.wwah_bad_parent_recovery_enabled)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_CHANNEL_ID, &(wwah_attr.pending_network_update_channel)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_PENDING_NETWORK_UPDATE_PANID_ID, &(wwah_attr.pending_network_update_panid)) \ + ZB_ZCL_SET_ATTR_DESC(ZB_ZCL_ATTR_WWAH_OTA_MAX_OFFLINE_DURATION_ID, &(wwah_attr.ota_max_offline_duration)) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST + + /* Declare Cluster Revision Attribute */ +#define ZB_ZCL_DECLARE_WWAH_CLIENT_ATTRIB_LIST(attr_list) \ + ZB_ZCL_START_DECLARE_ATTRIB_LIST(attr_list) \ + ZB_ZCL_FINISH_DECLARE_ATTRIB_LIST \ + +/*! @internal Number of attributes mandatory for reporting in WWAH cluster */ +#define ZB_ZCL_WWAH_REPORT_ATTR_COUNT 0 + +/***************************** commands *****************************/ + +/** @internal Structure for beaconSurvey data type + */ + +/** + * @brief Determine a parent choose priority (WWAH-Requirements C-20) + * + * End Devices examine all beacons in the Good Link Quality group + * (if received beacon with an RSSI above @see minRssiForReceivingPackets + * +30 dbm) and choose the parent with highest parent priority, as shown below. + * If no suitable parents exist in the Good Link Quality group, then the End + * Device shall examine all beacons in the Marginal Link Quality group. + */ +typedef enum zb_zcl_wwah_parent_priority_e +{ + /*! Invalid value for parent priority */ + ZB_ZCL_WWAH_PARENT_PRIORITY_INVALID = 0, + + /*! 0b00 - no TC connectivity and Short Uptime or no WWAH parent */ + ZB_ZCL_WWAH_PARENT_PRIORITY_VERY_LOW = 1, + + /*! 0b01 - no TC connectivity and Long Uptime */ + ZB_ZCL_WWAH_PARENT_PRIORITY_LOW = 2, + + /*! 0b10 - TC connectivity and Short Uptime */ + ZB_ZCL_WWAH_PARENT_PRIORITY_HIGH = 3, + + /*! 0b11 - TC connectivity and Long Uptime */ + ZB_ZCL_WWAH_PARENT_PRIORITY_VERY_HIGH = 4 +} +zb_zcl_wwah_parent_priority_t; + +typedef ZB_PACKED_PRE struct zb_zcl_wwah_beacon_survey_s +{ + /*! The DeviceShort field contains the 16 bit short address of the beaconing device. */ + zb_uint16_t device_short; + /*! This is the RSSI of the beacon, expressed in dBm. */ + zb_int8_t rssi; + /*! This is the parent classification mask. */ + zb_uint8_t classification_mask; +} ZB_PACKED_STRUCT zb_zcl_wwah_beacon_survey_t; + +/*! @brief The PowerNotificationReason field is an enum containing all possible reasons for the power notification. + */ +enum zb_zcl_wwah_power_notification_reason_e +{ + /*! Unknown value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_UNKNOWN = 0x00, + /*! Battery value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_BATTERY = 0x01, + /*! Brownout value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_BROWNOUT = 0x02, + /*! Watchdog value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_WATCHDOG = 0x03, + /*! Reset Pin value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_RESET_PIN = 0x04, + /*! Memory/HW Fault value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_MEMORY_OR_HW_FAULT = 0x05, + /*! Software Exception value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_SOFTWARE_EXCEPTION = 0x06, + /*! OTA / Bootload Success value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_OTA_OR_BOOTLOAD_SUCCESS = 0x07, + /*! Software Reset value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_SOFTWARE_RESET = 0x08, + /*! Power Button value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_POWER_BUTTON = 0x09, + /*! Temperature value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_TEMPERATURE = 0x0A, + /*! Bootload Failure value */ + ZB_ZCL_WWAH_POWER_NOTIFICATION_REASON_BOOTLOAD_FAILURE = 0x0B, +}; + +/*! @brief The Enrollment Mode field is an enum containing the possible enrollment methods for an IAS Zone server. + */ + + +enum zb_zcl_wwah_enrollment_mode_e +{ + /*! Trip-to-pair value */ + ZB_ZCL_WWAH_ENROLLMENT_MODE_TRIP_TO_PAIR = 0x00, + /*! Auto-Enroll-Response value */ + ZB_ZCL_WWAH_ENROLLMENT_MODE_AUTO_ENROLL_RESPONSE = 0x01, + /*! Auto-Enroll-Request value */ + ZB_ZCL_WWAH_ENROLLMENT_MODE_AUTO_ENROLL_REQUEST = 0x02 +}; + +/*! @} + @endcond */ /* WWAH cluster internals */ + +/*! @} */ /* ZCL WWAH cluster definitions */ + +/*! @brief Add cluster_id to Enable APS Link Key Authorization command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_APS_LINK_KEY_AUTHORIZATION_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief Start Enable APS Link Key Authorization command + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param number_of_clusters_to_exempt - Number of Clusters To Exempt value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_ENABLE_APS_LINK_KEY_AUTHORIZATION_ADD +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_APS_LINK_KEY_AUTHORIZATION_START( \ + buffer, def_resp, number_of_clusters_to_exempt, ptr) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_APS_LINK_KEY_AUTHORIZATION_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters_to_exempt)); \ +} + +/*! @brief End form Enable APS Link Key Authorization command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_APS_LINK_KEY_AUTHORIZATION_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Start Disable APS Link Key Authorization command + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param number_of_clusters_to_exempt - Number of Clusters To Exempt value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_DISABLE_APS_LINK_KEY_AUTHORIZATION_ADD +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_APS_LINK_KEY_AUTHORIZATION_START( \ + buffer, def_resp, number_of_clusters_to_exempt, ptr) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_APS_LINK_KEY_AUTHORIZATION_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters_to_exempt)); \ +} + +/*! @brief Add cluster_id to Disable APS Link Key Authorization command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_APS_LINK_KEY_AUTHORIZATION_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief End form Disable APS Link Key Authorization command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_APS_LINK_KEY_AUTHORIZATION_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send APS Link Key Authorization Query command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param cluster_id - Cluster ID value*/ +#define ZB_ZCL_WWAH_SEND_APS_LINK_KEY_AUTHORIZATION_QUERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, cluster_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_ID); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Request New APS Link Key command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_REQUEST_NEW_APS_LINK_KEY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_REQUEST_NEW_APS_LINK_KEY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable WWAH App Event Retry Algorithm command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param first_backoff_time_in_seconds - First Backoff Time In Seconds value + @param backoff_sequence_common_ratio - Backoff Sequence Common Ratio value + @param max_backoff_time_in_seconds - Max Backoff Time In Seconds value + @param max_re_delivery_attempts - Max Re_Delivery Attempts value*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + first_backoff_time_in_seconds, backoff_sequence_common_ratio, \ + max_backoff_time_in_seconds, max_re_delivery_attempts) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (first_backoff_time_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (backoff_sequence_common_ratio)); \ + ZB_ZCL_PACKET_PUT_DATA32(ptr, (max_backoff_time_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (max_re_delivery_attempts)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable WWAH App Event Retry Algorithm command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_WWAH_APP_EVENT_RETRY_ALGORITHM( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_APP_EVENT_RETRY_ALGORITHM_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Request Time command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_REQUEST_TIME( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_REQUEST_TIME_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable WWAH Rejoin Algorithm command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param fast_rejoin_timeout_in_seconds - Fast Rejoin Timeout In Seconds value + @param duration_between_each_rejoin_in_seconds - Duration Between Each Rejoin In Seconds value + @param fast_rejoin_first_backoff_in_seconds - Fast Rejoin First Backoff In Seconds value + @param max_backoff_time_in_seconds - Max Backoff Time In Seconds value + @param max_backoff_iterations - max backoff iterations*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_WWAH_REJOIN_ALGORITHM( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, \ + fast_rejoin_timeout_in_seconds, duration_between_each_rejoin_in_seconds, \ + fast_rejoin_first_backoff_in_seconds, max_backoff_time_in_seconds, \ + max_backoff_iterations) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_REJOIN_ALGORITHM_ID); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (fast_rejoin_timeout_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (duration_between_each_rejoin_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (fast_rejoin_first_backoff_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (max_backoff_time_in_seconds)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (max_backoff_iterations)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable WWAH Rejoin Algorithm command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_WWAH_REJOIN_ALGORITHM( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_REJOIN_ALGORITHM_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Set IAS Zone Enrollment Method command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param enrollment_mode - Enrollment Mode value*/ +#define ZB_ZCL_WWAH_SEND_SET_IAS_ZONE_ENROLLMENT_METHOD( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, enrollment_mode) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SET_IAS_ZONE_ENROLLMENT_METHOD_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (enrollment_mode)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Clear Binding Table command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_CLEAR_BINDING_TABLE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_CLEAR_BINDING_TABLE_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable Periodic Router Check Ins command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param check_in_interval - Check_In Interval value*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_PERIODIC_ROUTER_CHECK_INS( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, check_in_interval) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_PERIODIC_ROUTER_CHECK_INS_ID); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (check_in_interval)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable Periodic Router Check Ins command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_PERIODIC_ROUTER_CHECK_INS( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_PERIODIC_ROUTER_CHECK_INS_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Set MAC Poll CCA Wait Time command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param wait_time - Wait Time value*/ +#define ZB_ZCL_WWAH_SEND_SET_MAC_POLL_CCA_WAIT_TIME( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, wait_time) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SET_MAC_POLL_CCA_WAIT_TIME_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (wait_time)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Set Pending Network Update command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param channel - Channel value + @param pan_id - PAN ID value*/ +#define ZB_ZCL_WWAH_SEND_SET_PENDING_NETWORK_UPDATE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, channel, pan_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SET_PENDING_NETWORK_UPDATE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (channel)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (pan_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Add cluster_id to Require APS ACKs on Unicasts command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_REQUIRE_APS_ACKS_ON_UNICASTS_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief Start Require APS ACKs on Unicasts command + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param number_of_clusters_to_exempt - Number of Clusters to Exempt value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_REQUIRE_APS_ACKS_ON_UNICASTS_ADD +*/ +#define ZB_ZCL_WWAH_SEND_REQUIRE_APS_ACKS_ON_UNICASTS_START( \ + buffer, def_resp, number_of_clusters_to_exempt, ptr) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_REQUIRE_APS_ACKS_ON_UNICASTS_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters_to_exempt)); \ +} + +/*! @brief End form Require APS ACKs on Unicasts command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_REQUIRE_APS_ACKS_ON_UNICASTS_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Remove APS ACKs on Unicasts Requirement command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_REMOVE_APS_ACKS_ON_UNICASTS_REQUIREMENT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_REMOVE_APS_ACKS_ON_UNICASTS_REQUIREMENT_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send APS ACK Requirement Query command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_APS_ACK_REQUIREMENT_QUERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Debug Report Query command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param debug_report_id - Debug Report ID value*/ +#define ZB_ZCL_WWAH_SEND_DEBUG_REPORT_QUERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, debug_report_id) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (debug_report_id)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Survey Beacons command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status + @param standard_beacons - Standard Beacons value*/ +#define ZB_ZCL_WWAH_SEND_SURVEY_BEACONS( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb, standard_beacons) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (standard_beacons)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable OTA Downgrades command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_OTA_DOWNGRADES( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_OTA_DOWNGRADES_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable MGMT Leave Without Rejoin command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_MGMT_LEAVE_WITHOUT_REJOIN( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_MGMT_LEAVE_WITHOUT_REJOIN_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable Touchlink Interpan Message Support command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_TOUCHLINK_INTERPAN_MESSAGE_SUPPORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_TOUCHLINK_INTERPAN_MESSAGE_SUPPORT_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable WWAH Parent Classification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_WWAH_PARENT_CLASSIFICATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_PARENT_CLASSIFICATION_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} +/*! @brief Send Disable WWAH Parent Classification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_WWAH_PARENT_CLASSIFICATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_PARENT_CLASSIFICATION_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable TC Security On Ntwk Key Rotation command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_TC_SECURITY_ON_NWK_KEY_ROTATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_TC_SECURITY_ON_NWK_KEY_ROTATION_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} +/*! @brief Send Enable WWAH Bad Parent Recovery command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_WWAH_BAD_PARENT_RECOVERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_WWAH_BAD_PARENT_RECOVERY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable WWAH Bad Parent Recovery command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_WWAH_BAD_PARENT_RECOVERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_WWAH_BAD_PARENT_RECOVERY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Enable Configuration Mode command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_ENABLE_CONFIGURATION_MODE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_ENABLE_CONFIGURATION_MODE_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Disable Configuration Mode command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_DISABLE_CONFIGURATION_MODE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DISABLE_CONFIGURATION_MODE_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Add cluster_id to Use Trust Center for Cluster command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_USE_TRUST_CENTER_FOR_CLUSTER_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief Start Use Trust Center for Cluster command + @param buffer - to put packet to + @param def_resp - enable/disable default response + @param number_of_clusters - Number of Clusters value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_USE_TRUST_CENTER_FOR_CLUSTER_ADD +*/ +#define ZB_ZCL_WWAH_SEND_USE_TRUST_CENTER_FOR_CLUSTER_START( \ + buffer, def_resp, number_of_clusters, ptr) \ +{ \ + ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters)); \ +} + +/*! @brief End form Use Trust Center for Cluster command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_USE_TRUST_CENTER_FOR_CLUSTER_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Trust Center for Cluster Server Query command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param def_resp - enable/disable default response + @param cb - callback for getting command send status +*/ +#define ZB_ZCL_WWAH_SEND_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, def_resp, cb) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_REQ_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_SRV, ZB_ZCL_MANUFACTURER_SPECIFIC, def_resp); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_ID); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send APS Link Key Authorization Query Response command + @param buffer - to put packet to + @param seq - sequence + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param cluster_id - Cluster ID value + @param aps_link_key_authorization_status - APS Link Key Authorization Status value*/ +#define ZB_ZCL_WWAH_SEND_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE( \ + buffer, seq, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, cluster_id, \ + aps_link_key_authorization_status) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, (seq), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_APS_LINK_KEY_AUTHORIZATION_QUERY_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (aps_link_key_authorization_status)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Powering Off Notification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param power_notification_reason - PowerNotificationReason value + @param manufacturer_id - Manufacturer ID value + @param manufacturer_power_notification_reason_length - Manufacturer Power Notification Reason Length value + @param manufacturer_power_notification_reason - Manufacturer Power Notification Reason value*/ +#define ZB_ZCL_WWAH_SEND_POWERING_OFF_NOTIFICATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, \ + power_notification_reason, manufacturer_id, \ + manufacturer_power_notification_reason_length, \ + manufacturer_power_notification_reason) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_POWERING_OFF_NOTIFICATION_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (power_notification_reason)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (manufacturer_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (manufacturer_power_notification_reason_length)); \ + ZB_ZCL_PACKET_PUT_DATA_N(ptr, (manufacturer_power_notification_reason), \ + (manufacturer_power_notification_reason_length)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Powering On Notification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param power_notification_reason - PowerNotificationReason value + @param manufacturer_id - Manufacturer ID value + @param manufacturer_power_notification_reason_length - Manufacturer Power Notification Reason Length value + @param manufacturer_power_notification_reason - Manufacturer Power Notification Reason value*/ +#define ZB_ZCL_WWAH_SEND_POWERING_ON_NOTIFICATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, \ + power_notification_reason, manufacturer_id, \ + manufacturer_power_notification_reason_length, \ + manufacturer_power_notification_reason) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_POWERING_ON_NOTIFICATION_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (power_notification_reason)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (manufacturer_id)); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (manufacturer_power_notification_reason_length)); \ + ZB_ZCL_PACKET_PUT_DATA_N(ptr, (manufacturer_power_notification_reason), \ + (manufacturer_power_notification_reason_length)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Short Address Change command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param device_eui64 - DeviceEUI64 value + @param device_short - DeviceShort value*/ +#define ZB_ZCL_WWAH_SEND_SHORT_ADDRESS_CHANGE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, device_eui64, device_short) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SHORT_ADDRESS_CHANGE_ID); \ + ZB_ZCL_PACKET_PUT_DATA64(ptr, (device_eui64)); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (device_short)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Add cluster_id to APS ACK Requirement Query Response command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_APS_ACK_REQUIREMENT_QUERY_RESPONSE_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief Start APS ACK Requirement Query Response command + @param buffer - to put packet to + @param seq - sequence + @param number_of_clusters_to_exempt - Number of Clusters to Exempt value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_APS_ACK_REQUIREMENT_QUERY_RESPONSE_ADD +*/ +#define ZB_ZCL_WWAH_SEND_APS_ACK_REQUIREMENT_QUERY_RESPONSE_START( \ + buffer, seq, number_of_clusters_to_exempt, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, (seq), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_APS_ACK_REQUIREMENT_QUERY_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters_to_exempt)); \ +} + +/*! @brief End form APS ACK Requirement Query Response command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_WWAH_SEND_APS_ACK_REQUIREMENT_QUERY_RESPONSE_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, NULL); \ +} + +/*! @brief Send Power Descriptor Change command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param node_power_desc - Node Power Decriptor value */ +#define ZB_ZCL_WWAH_SEND_POWER_DESCRIPTOR_CHANGE( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, node_power_desc) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_POWER_DESCRIPTOR_CHANGE_ID); \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (node_power_desc)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send New Debug Report Notification command + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param debug_report_id - Debug Report ID value + @param size_of_report - Size of Report value*/ +#define ZB_ZCL_WWAH_SEND_NEW_DEBUG_REPORT_NOTIFICATION( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, debug_report_id, \ + size_of_report) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, ZB_ZCL_GET_SEQ_NUM(), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_NEW_DEBUG_REPORT_NOTIFICATION_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (debug_report_id)); \ + ZB_ZCL_PACKET_PUT_DATA32(ptr, (size_of_report)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Send Debug Report Query Response command + @param buffer - to put packet to + @param seq - sequence + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier + @param cb - callback for getting command send status + @param debug_report_id - Debug Report ID value + @param report_data - Report data value + @param size_of_report - Report data size */ + +#define ZB_ZCL_WWAH_SEND_DEBUG_REPORT_QUERY_RESPONSE( \ + buffer, seq, addr, dst_addr_mode, dst_ep, ep, prfl_id, cb, debug_report_id, report_data, \ + size_of_report) \ +{ \ + zb_uint8_t* ptr = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, (seq), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_DEBUG_REPORT_QUERY_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (debug_report_id)); \ + ZB_ZCL_PACKET_PUT_DATA_N(ptr, (report_data), (size_of_report)); \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, cb); \ +} + +/*! @brief Add cluster_id to Trust Center for Cluster Server Query Response command + @param ptr - [in/out] (zb_uint8_t*) current position + @param cluster_id - Cluster ID value +*/ +#define ZB_ZCL_WWAH_SEND_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_ADD(ptr, cluster_id) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA16(ptr, (cluster_id)); \ +} + +/*! @brief Start Trust Center for Cluster Server Query Response command + @param buffer - to put packet to + @param seq - sequence + @param number_of_clusters - Number of Clusters value + @param ptr - [out] (zb_uint8_t*) current position for ZB_ZCL_WWAH_SEND_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_ADD +*/ +#define ZB_ZCL_WWAH_SEND_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_START( \ + buffer, seq, number_of_clusters, ptr) \ +{ \ + (ptr) = ZB_ZCL_START_PACKET(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, (seq), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_ID); \ + ZB_ZCL_PACKET_PUT_DATA8(ptr, (number_of_clusters)); \ +} + +/*! @brief End form Trust Center for Cluster Server Query Response command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_WWAH_SEND_TRUST_CENTER_FOR_CLUSTER_SERVER_QUERY_RESPONSE_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, NULL); \ +} + +/*! @brief Start Survey Beacons Response command + @param buffer - to put packet to + @param seq - sequence +*/ +#define ZB_ZCL_WWAH_SEND_SURVEY_BEACONS_RESPONSE_START( \ + buffer, seq) \ +{ \ + zb_uint8_t *ptr = zb_buf_begin(buffer); \ + ZB_ZCL_CONSTRUCT_SPECIFIC_COMMAND_RESP_FRAME_CONTROL_A(ptr, \ + ZB_ZCL_FRAME_DIRECTION_TO_CLI, ZB_ZCL_MANUFACTURER_SPECIFIC); \ + ZB_ZCL_CONSTRUCT_COMMAND_HEADER_EXT(ptr, (seq), \ + ZB_ZCL_MANUFACTURER_SPECIFIC, WWAH_MANUFACTURER_CODE, \ + ZB_ZCL_CMD_WWAH_SURVEY_BEACONS_RESPONSE_ID); \ +} + +/*! @brief Add beacons number and beacon survey info to Survey Beacons Response command + @param ptr - [in/out] (zb_uint8_t*) current position + @param src - source pointer to the first Beacon value + @param num - number of beacons +*/ +#define ZB_ZCL_WWAH_SEND_SURVEY_BEACONS_RESPONSE_ADD_ALL(ptr, src, num) \ +{ \ + ZB_ZCL_PACKET_PUT_DATA8((ptr), (num)); \ + ZB_MEMMOVE((ptr), (src), ((num) * sizeof(zb_zcl_wwah_beacon_survey_t))); \ + (ptr) += ((num) * sizeof(zb_zcl_wwah_beacon_survey_t)); \ +} + +/*! @brief End form Survey Beacons Response command + @param ptr - (zb_uint8_t*) current position + @param buffer - to put packet to + @param addr - address to send packet to + @param dst_addr_mode - addressing mode + @param dst_ep - destination endpoint + @param ep - sending endpoint + @param prfl_id - profile identifier +*/ +#define ZB_ZCL_WWAH_SEND_SURVEY_BEACONS_RESPONSE_END( \ + ptr, buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id) \ +{ \ + ZB_ZCL_FINISH_PACKET(buffer, ptr) \ + ZB_ZCL_SEND_COMMAND_SHORT( \ + buffer, addr, dst_addr_mode, dst_ep, ep, prfl_id, ZB_ZCL_CLUSTER_ID_WWAH, NULL); \ +} +zb_bool_t zb_is_wwah_server(void); +zb_bool_t zb_zcl_wwah_check_new_channel(zb_uint32_t new_channel_mask); +zb_bool_t zb_zcl_wwah_check_new_panid(zb_uint16_t new_panid); +zb_uint8_t zb_zcl_wwah_mac_poll_cca_retry_count(void); +zb_time_t zb_zcl_wwah_mac_poll_failure_wait_time(void); +zb_bool_t zb_zcl_wwah_check_if_forced_to_use_tc(zb_uint16_t cluster_id); +zb_bool_t zb_zcl_wwah_check_nwk_key_commands_broadcast_allowed(void); +zb_bool_t zb_zcl_wwah_check_zdo_command(zb_apsde_data_indication_t *di); +zb_bool_t zb_zcl_wwah_check_if_aps_ack_needed(zb_uint16_t cluster_id); +zb_bool_t zb_zcl_wwah_check_if_aps_link_key_authorization_needed(zb_uint16_t cluster_id); +zb_bool_t zb_zcl_wwah_check_cluster_permission(zb_uint16_t nwk_addr, zb_uint16_t cluster_id); +zb_bool_t zb_zcl_wwah_check_if_leave_without_rejoin_allowed(void); +zb_bool_t zb_zcl_wwah_check_if_wwah_rejoin_enabled(void); +void zb_zcl_wwah_schedule_send_power_descriptor_change(void); +zb_bool_t zb_zcl_wwah_check_zdo_command(zb_apsde_data_indication_t *di); +zb_bool_t zb_zcl_wwah_check_if_interpan_supported(void); +zb_bool_t zb_zcl_wwah_check_if_downgrade_disabled(void); +zb_bool_t zb_zcl_wwah_periodic_checkin_read_attr_handle(zb_uint8_t param); +zb_bool_t zb_zcl_wwah_periodic_checkin_block_zcl_cmd(zb_zcl_parsed_hdr_t *cmd_info); +void zb_zcl_wwah_periodic_checkin_tc_poll(zb_uint8_t param); +void zb_zcl_wwah_periodic_checkin_match_desc_req(zb_uint8_t param); +void zb_zcl_wwah_periodic_checkin_match_desc_req_delayed(zb_uint8_t param); +void zb_zcl_wwah_stop_periodic_checkin(void); +void zb_zcl_wwah_start_periodic_checkin(void); +zb_bool_t zb_zcl_wwah_check_src_addr_for_cluster(zb_uint16_t short_addr, zb_uint16_t cluster_id); + +zb_void_t zb_zcl_wwah_set_wwah_behavior(zb_uint8_t behavior); +void zb_zcl_wwah_stop_bad_parent_recovery(void); +void zb_zcl_wwah_start_bad_parent_recovery(void); + +#ifdef ZB_JOIN_CLIENT +zb_ret_t zb_zcl_wwah_get_rejoin_tmo(zb_uint16_t attempt, zb_time_t *tmo); +#endif + +/** @endcond */ /* DOXYGEN_ZCL_SECTION */ + +#define ZB_ZCL_WWAH_REPORT_ATTR_COUNT 0 + +#if (defined ZB_ZCL_SUPPORT_CLUSTER_WWAH && (defined ZB_ZCL_ENABLE_WWAH_SERVER || defined ZB_ZCL_ENABLE_WWAH_CLIENT)) +typedef ZB_PACKED_PRE struct zb_zcl_wwah_context_s +{ + zb_uint8_t wwah_behavior; +#ifdef ZB_ZCL_ENABLE_WWAH_SERVER + zb_uint8_t wwah_hub_endpoint; + zb_uint16_t wwah_hub_address; + zb_uint16_t time_server_addr; + zb_uint8_t time_server_endpoint; + + zb_uint8_t aps_ack_exempt_table_cnt; + /* This is a list of clusters that should be exempt from requiring APS ACKs on unicasts. */ + zb_uint16_t aps_ack_exempt_table[ZB_ZCL_WWAH_APS_ACK_EXEMPT_TABLE_SIZE]; + + /* ZB_TRUE - enforces that all cluster commands for the cluster have APS level security + * except for those in the exemption list*/ + /* ZB_FALSE - enforces that all cluster commands for the cluster doesn't have APS level security + * except for those in the exemption list. This is default value*/ + zb_bool_t aps_link_key_enabled_by_default; + + zb_uint8_t aps_link_key_authorization_table_cnt; + /* This is a exemption list of clusters for requiring APS level security */ + zb_uint16_t aps_link_key_authorization_table[ZB_ZCL_WWAH_APS_LINK_KEY_AUTHORIZATION_TABLE_SIZE]; + + zb_uint8_t use_trust_center_for_cluster_table_cnt; + /* This is a list of clusters that should be forced to use the Trust Center. */ + zb_uint16_t use_trust_center_for_cluster_table[ZB_ZCL_WWAH_USE_TRUST_CENTER_FOR_CLUSTER_TABLE_SIZE]; + /* ======= Survey Beacon related context ======= */ + /** + * @brief Reference to a buffer with Survey Beacons Response command + * + * Also it's used as status flag: ref == 0 when Survey Beacons procedure + * is not started. + */ + zb_uint8_t survey_beacons_resp_ref; + + /* FIXME: Remove? We use ZB_NIB().nwk_hub_connectivity and + * ZB_NIB().ZB_NIB().nwk_hub_connectivity instead. */ + zb_zcl_wwah_classification_mask_t classification_mask; + zb_zcl_wwah_periodic_checkins_data_t periodic_checkins; + + zb_zcl_wwah_enable_wwah_rejoin_algorithm_t rejoin_alg; + zb_zcl_wwah_bad_parent_recovery_data_t bad_parent_recovery; +#endif +#if !(defined ZB_ZCL_ENABLE_WWAH_SERVER || defined ZB_ZCL_ENABLE_WWAH_CLIENT) + zb_uint8_t make_iso_compiler_happy; +#endif +} zb_zcl_wwah_context_t; +#endif + +#define ZB_ZCL_WWAH_REJOIN_SLEEPY_ED_TIMEOUT (ZB_TIME_ONE_SECOND * 60 * 15) +#define ZB_ZCL_WWAH_REJOIN_NON_SLEEPY_ED_ROUTER_TIMEOUT (ZB_TIME_ONE_SECOND * 60 * 60 * 24) +/* For dubug purpose: #define ZB_ZCL_WWAH_REJOIN_NON_SLEEPY_ED_ROUTER_TIMEOUT (ZB_TIME_ONE_SECOND * 60)*/ + +#define ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_TIMEOUT (ZB_TIME_ONE_SECOND * 60 * 60 * 24) +/* For dubug purpose: #define ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_TIMEOUT (ZB_TIME_ONE_SECOND * 30)*/ +#define ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_POLL_CONTROL_CHECK_IN_FAILED_CNT 3 +/* FIXME: Is it defined somewhere in WWAH spec? */ +#define ZB_ZCL_WWAH_BAD_PARENT_RECOVERY_RSSI_IS_GOOD(rssi) (rssi >= -100) +void zb_zcl_wwah_bad_parent_recovery_signal(zb_zcl_wwah_bad_parent_recovery_signal_t sig); + +zb_ret_t zb_zcl_wwah_request_new_aps_link_key_handler(zb_uint8_t param); +zb_ret_t zb_zcl_wwah_enable_wwah_app_event_retry_algorithm_handler(zb_uint8_t param); +zb_ret_t zb_zcl_wwah_disable_wwah_app_event_retry_algorithm_handler(zb_uint8_t param); +zb_ret_t zb_zcl_wwah_request_time_handler(zb_uint8_t param); +zb_ret_t zb_zcl_wwah_enable_wwah_rejoin_algorithm_handler(zb_uint8_t param); +zb_ret_t zb_zcl_wwah_disable_wwah_rejoin_algorithm_handler(zb_uint8_t param); + +void zb_zcl_wwah_init_server(void); +void zb_zcl_wwah_init_server_attr(void); +void zb_zcl_wwah_init_client(void); +zb_ret_t zb_zcl_wwah_update_time(zb_uint8_t param); +#define ZB_ZCL_CLUSTER_ID_WWAH_SERVER_ROLE_INIT zb_zcl_wwah_init_server +#define ZB_ZCL_CLUSTER_ID_WWAH_CLIENT_ROLE_INIT zb_zcl_wwah_init_client + +#endif /* ! defined ZB_ZCL_WWAH_H */ diff --git a/zboss/lib/cortex-m4/hard-float/libzboss.a b/zboss/lib/cortex-m4/hard-float/libzboss.a new file mode 100644 index 0000000000..a4646d60b9 Binary files /dev/null and b/zboss/lib/cortex-m4/hard-float/libzboss.a differ diff --git a/zboss/lib/cortex-m4/hard-float/libzboss.ed.a b/zboss/lib/cortex-m4/hard-float/libzboss.ed.a new file mode 100644 index 0000000000..dd99ff47e5 Binary files /dev/null and b/zboss/lib/cortex-m4/hard-float/libzboss.ed.a differ diff --git a/zboss/src/zb_error/zb_error_to_string.c b/zboss/src/zb_error/zb_error_to_string.c new file mode 100644 index 0000000000..c8d864a878 --- /dev/null +++ b/zboss/src/zb_error/zb_error_to_string.c @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +/** + * @addtogroup zb_error + * + * @brief Module for converting ZBOSS error code into a printable string. + * @{ + */ +#ifdef CONFIG_ZIGBEE_ERROR_TO_STRING_ENABLED +#include "zb_error_to_string.h" + +/** Counts number of elements inside the array + */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +#endif + +/** + * @brief Macro for adding an entity to the description array. + * + * Macro that helps to create a single entity in the description array. + */ +#define ZB_ERROR_STRING(mnemonic) {.code = -mnemonic, .name = #mnemonic} + +/** + * @brief Array entity element that describes an error. + */ +typedef struct +{ + zb_ret_t code; /**< Error code. */ + char const * name; /**< Descriptive name (the same as the internal error mnemonic). */ +} zb_strerror_desc_t; + +/** + * @brief Unknown error code. + * + * The constant string used by @ref zb_strerror_get when the error description was not found. + */ +static char const m_unknown_str[] = "Unknown error code"; + +/** + * @brief Array with error codes. + * + * Array that describes error codes. + * + * @note It is required for this array to have error codes placed in ascending order. + * This condition is checked in automatic unit test before the release. + */ +static zb_strerror_desc_t const zb_strerror_array[] = +{ + ZB_ERROR_STRING(RET_OK), + ZB_ERROR_STRING(RET_ERROR), + ZB_ERROR_STRING(RET_BLOCKED), + ZB_ERROR_STRING(RET_EXIT), + ZB_ERROR_STRING(RET_BUSY), + ZB_ERROR_STRING(RET_EOF), + ZB_ERROR_STRING(RET_OUT_OF_RANGE), + ZB_ERROR_STRING(RET_EMPTY), + ZB_ERROR_STRING(RET_CANCELLED), + + ZB_ERROR_STRING(RET_INVALID_PARAMETER_1), + ZB_ERROR_STRING(RET_INVALID_PARAMETER_2), + ZB_ERROR_STRING(RET_INVALID_PARAMETER_3), + ZB_ERROR_STRING(RET_INVALID_PARAMETER_4), + ZB_ERROR_STRING(RET_INVALID_PARAMETER_6), + ZB_ERROR_STRING(RET_PENDING), + ZB_ERROR_STRING(RET_NO_MEMORY), + ZB_ERROR_STRING(RET_INVALID_PARAMETER), + ZB_ERROR_STRING(RET_OPERATION_FAILED), + ZB_ERROR_STRING(RET_BUFFER_TOO_SMALL), + ZB_ERROR_STRING(RET_END_OF_LIST), + ZB_ERROR_STRING(RET_ALREADY_EXISTS), + ZB_ERROR_STRING(RET_NOT_FOUND), + ZB_ERROR_STRING(RET_OVERFLOW), + ZB_ERROR_STRING(RET_TIMEOUT), + ZB_ERROR_STRING(RET_NOT_IMPLEMENTED), + ZB_ERROR_STRING(RET_NO_RESOURCES), + ZB_ERROR_STRING(RET_UNINITIALIZED), + ZB_ERROR_STRING(RET_INVALID_STATE), + ZB_ERROR_STRING(RET_CONNECTION_FAILED), + ZB_ERROR_STRING(RET_CONNECTION_LOST), + ZB_ERROR_STRING(RET_UNAUTHORIZED), + ZB_ERROR_STRING(RET_CONFLICT), + ZB_ERROR_STRING(RET_INVALID_FORMAT), + ZB_ERROR_STRING(RET_NO_MATCH), + ZB_ERROR_STRING(RET_PROTOCOL_ERROR), + ZB_ERROR_STRING(RET_VERSION), + ZB_ERROR_STRING(RET_FILE_NOT_FOUND), + ZB_ERROR_STRING(RET_CONVERSION_ERROR), + ZB_ERROR_STRING(RET_FILE_CORRUPTED), + ZB_ERROR_STRING(RET_PAGE_NOT_FOUND), + ZB_ERROR_STRING(RET_ILLEGAL_REQUEST), + ZB_ERROR_STRING(RET_INVALID_GROUP), + ZB_ERROR_STRING(RET_TABLE_FULL), + ZB_ERROR_STRING(RET_IGNORE), + ZB_ERROR_STRING(RET_AGAIN), + ZB_ERROR_STRING(RET_DEVICE_NOT_FOUND), + ZB_ERROR_STRING(RET_OBSOLETE) +}; + +char const * zb_error_to_string_get(zb_ret_t code) +{ + char const * p_ret = zb_error_to_string_find(code); + return (p_ret == NULL) ? m_unknown_str : p_ret; +} + +char const * zb_error_to_string_find(zb_ret_t code) +{ + zb_strerror_desc_t const * p_start; + zb_strerror_desc_t const * p_end; + p_start = zb_strerror_array; + p_end = zb_strerror_array + ARRAY_SIZE(zb_strerror_array); + + while (p_start < p_end) { + zb_strerror_desc_t const * p_mid = p_start + ((p_end - p_start) / 2); + zb_ret_t mid_c = p_mid->code; + if (mid_c > code) { + p_end = p_mid; + } else if (mid_c < code) { + p_start = p_mid + 1; + } else { + return p_mid->name; + } + } + return NULL; +} + +#endif /* CONFIG_ZIGBEE_ERROR_TO_STRING_ENABLED */ + +/** @} */ diff --git a/zboss/src/zb_error/zb_error_to_string.h b/zboss/src/zb_error/zb_error_to_string.h new file mode 100644 index 0000000000..59bce018b3 --- /dev/null +++ b/zboss/src/zb_error/zb_error_to_string.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic + */ + +/** + * @addtogroup zb_error + * + * @brief Module for converting ZBOSS error code into a printable string. + * @{ + */ +#ifndef ZB_ERRPR_TO_STRING_H__ +#define ZB_ERRPR_TO_STRING_H__ + +#include "zboss_api.h" +#include "zb_errors.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Function for getting a printable error string. + * + * @param code Error code to convert. + * + * @note This function cannot fail. + * For the function that may fail with error translation, + * see @ref zb_error_to_string_find. + * + * @return Pointer to the printable string. + * If the string is not found, + * it returns a simple string that says that the error is unknown. + */ +char const * zb_error_to_string_get(zb_ret_t code); + +/** + * @brief Function for finding a printable error string. + * + * This function gets the error string in the same way as @ref zb_error_to_string_get, + * but if the string is not found, it returns NULL. + * + * @param code Error code to convert. + * @return Pointer to the printable string. + * If the string is not found, NULL is returned. + */ +char const * zb_error_to_string_find(zb_ret_t code); + +/** @} */ + +#ifdef __cplusplus +} +#endif + +#endif /* ZB_STRERROR_H__ */