diff --git a/Makefile b/Makefile index 3dec36ee2fae36..8d3f35ee2cf0ab 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,5 @@ SUB_DIRS=src .PHONY: all clean test all test clean: + git submodule update --init $(foreach dir,$(SUB_DIRS), $(MAKE) $@ -C $(dir)) diff --git a/src/Makefile b/src/Makefile index 779c80ef5ff576..d822552004f3ab 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,6 +1,6 @@ TOPTARGETS := all clean run_tests -SUBDIRS = lwip system +SUBDIRS = lwip system lib/core lib/support $(TOPTARGETS): $(SUBDIRS) $(SUBDIRS): diff --git a/src/lib/core/CHIPConfig.h b/src/lib/core/CHIPConfig.h new file mode 100644 index 00000000000000..cc585ac287fba9 --- /dev/null +++ b/src/lib/core/CHIPConfig.h @@ -0,0 +1,2331 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines default compile-time configuration constants + * for chip. + * + * Package integrators that wish to override these values should + * either use preprocessor definitions or create a project- + * specific chipProjectConfig.h header and then assert + * HAVE_CHIPPROJECTCONFIG_H via the package configuration tool + * via --with-chip-project-includes=DIR where DIR is the + * directory that contains the header. + * + * NOTE WELL: On some platforms, this header is included by C-language programs. + * + */ + +#ifndef CHIP_CONFIG_H_ +#define CHIP_CONFIG_H_ + +#include + +/* COMING SOON: making the INET Layer optional entails making this inclusion optional. */ +//#include "InetConfig.h" +/* +#if INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL <= 0 +#error "chip SDK requires INET_TCP_IDLE_CHECK_INTERVAL > 0" +#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT && INET_TCP_IDLE_CHECK_INTERVAL <= 0 +*/ +/* Include a project-specific configuration file, if defined. + * + * An application or module that incorporates chip can define a project configuration + * file to override standard chip configuration with application-specific values. + * The chipProjectConfig.h file is typically located outside the Openchip source tree, + * alongside the source code for the application. + */ +#ifdef CHIP_PROJECT_CONFIG_INCLUDE +#include CHIP_PROJECT_CONFIG_INCLUDE +#endif + +/* Include a platform-specific configuration file, if defined. + * + * A platform configuration file contains overrides to standard chip configuration + * that are specific to the platform or OS on which chip is running. It is typically + * provided as apart of an adaptation layer that adapts Openchip to the target + * environment. This adaptation layer may be included in the Openchip source tree + * itself or implemented externally. + */ +#ifdef CHIP_PLATFORM_CONFIG_INCLUDE +#include CHIP_PLATFORM_CONFIG_INCLUDE +#endif + +// clang-format off + +/** + * @def CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES + * + * @brief + * This boolean configuration option is (1) if the obsolescent interfaces + * of the chip layer are still available for transitional purposes. + * + */ +#ifndef CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES +#define CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES 0 +#endif // CHIP_CONFIG_PROVIDE_OBSOLESCENT_INTERFACES + +// Profile-specific Configuration Headers +/* +#include "CHIPBDXConfig.h" + +#include "CHIPDMConfig.h" + +#include "CHIPTimeConfig.h" + +#include "CHIPTunnelConfig.h" + +#include "CHIPEventLoggingConfig.h" + +#include "CHIPWRMPConfig.h" +*/ +/** + * @def CHIP_CONFIG_ERROR_TYPE + * + * @brief + * This defines the data type used to represent errors for chip. + * + */ +#ifndef CHIP_CONFIG_ERROR_TYPE +#include + +#define CHIP_CONFIG_ERROR_TYPE int32_t +#endif // CHIP_CONFIG_ERROR_TYPE + +/** + * @def CHIP_CONFIG_NO_ERROR + * + * @brief + * This defines the chip error code for no error or success. + * + */ +#ifndef CHIP_CONFIG_NO_ERROR +#define CHIP_CONFIG_NO_ERROR 0 +#endif // CHIP_CONFIG_NO_ERROR + +/** + * @def CHIP_CONFIG_ERROR_MIN + * + * @brief + * This defines the base or minimum chip error number range. + * + */ +#ifndef CHIP_CONFIG_ERROR_MIN +#define CHIP_CONFIG_ERROR_MIN 4000 +#endif // CHIP_CONFIG_ERROR_MIN + +/** + * @def CHIP_CONFIG_ERROR_MAX + * + * @brief + * This defines the top or maximum chip error number range. + * + */ +#ifndef CHIP_CONFIG_ERROR_MAX +#define CHIP_CONFIG_ERROR_MAX 4999 +#endif // CHIP_CONFIG_ERROR_MAX + +/** + * @def _CHIP_CONFIG_ERROR + * + * @brief + * This defines a mapping function for chip errors that allows + * mapping such errors into a platform- or system-specific manner. + * + */ +#ifndef _CHIP_CONFIG_ERROR +#define _CHIP_CONFIG_ERROR(e) (CHIP_ERROR_MIN + (e)) +#endif // _CHIP_CONFIG_ERROR + +/** + * @def CHIP_CONFIG_USE_OPENSSL_ECC + * + * @brief + * Use the OpenSSL implementation of the elliptic curve primitives + * for chip communication. + * + * Note that this option is mutually exclusive with + * #CHIP_CONFIG_USE_MICRO_ECC. + */ +#ifndef CHIP_CONFIG_USE_OPENSSL_ECC +#define CHIP_CONFIG_USE_OPENSSL_ECC 1 +#endif // CHIP_CONFIG_USE_OPENSSL_ECC + +/** + * @def CHIP_CONFIG_USE_MICRO_ECC + * + * @brief + * Use the Micro ECC implementation of the elliptic curve primitives + * for chip communication. + * + * Note that this option is mutually exclusive with + * #CHIP_CONFIG_USE_OPENSSL_ECC. + * + */ +#ifndef CHIP_CONFIG_USE_MICRO_ECC +#define CHIP_CONFIG_USE_MICRO_ECC 0 +#endif // CHIP_CONFIG_USE_MICRO_ECC + +#if CHIP_CONFIG_USE_MICRO_ECC && CHIP_CONFIG_USE_OPENSSL_ECC +#error "Please assert one of either CHIP_CONFIG_USE_MICRO_ECC or CHIP_CONFIG_USE_OPENSSL_ECC, but not both." +#endif // CHIP_CONFIG_USE_MICRO_ECC && CHIP_CONFIG_USE_OPENSSL_ECC + +/** + * @name chip Elliptic Curve Security Configuration + * + * @brief + * The following definitions enable one or more of four potential + * elliptic curves: + * + * * #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 + * * #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 + * * #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 + * * #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 + * + * @{ + */ + +/** + * @def CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 + * + * @brief + * Enable (1) or disable (0) support for the Standards for + * Efficient Cryptography Group (SECG) secp160r1 elliptic curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 +#define CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 0 +#endif // CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 + +/** + * @def CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 + * + * @brief + * Enable (1) or disable (0) support for the Standards for + * Efficient Cryptography Group (SECG) secp192r1 elliptic curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 +#define CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 1 +#endif // CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 + +/** + * @def CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 + * + * @brief + * Enable (1) or disable (0) support for the Standards for + * Efficient Cryptography Group (SECG) secp224r1 / National + * Institute of Standards (NIST) P-224 elliptic curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 +#define CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 1 +#endif // CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 + +/** + * @def CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 + * + * @brief + * Enable (1) or disable (0) support for the Standards for + * Efficient Cryptography Group (SECG) secp256r1 / American + * National Standards Institute (ANSI) prime256v1 / National + * Institute of Standards (NIST) P-256 elliptic curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 +#define CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 1 +#endif // CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 + +/** + * @} + */ + +/** + * @name chip Password Authenticated Session Establishment (PASE) Configuration + * + * @brief + * The following definitions define the configurations supported + * for chip's Password Authenticated Session Establishment (PASE) + * protocol. + * + * This protocol is used primarily for establishing a secure + * session for provisioning. chip supports the following PASE + * configurations: + * + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG1 + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG2 + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG3 + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG4 + * * #CHIP_CONFIG_SUPPORT_PASE_CONFIG5 + * + * which are summarized in the table below: + * + * | Configuration | J-PAKE Style | Curve | Test Only | Notes | + * | :------------: | :-------------- | :-------: | :---------: | :----------------------------------- | + * | 0 | - | - | Y | Test-only | + * | 1 | Finite Field | - | N | Original chip default configuration | + * | 2 | Elliptic Curve | secp160r1 | N | | + * | 3 | Elliptic Curve | secp192r1 | N | | + * | 4 | Elliptic Curve | secp224r1 | N | Future chip default configuration | + * | 5 | Elliptic Curve | secp256r1 | N | | + * + * @{ + * + */ + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY + * + * @brief + * This chip PASE configuration does not use the J-PAKE algorithm + * and sends deterministic messages over the communications + * channel. The size and structure of the messages are similar to + * #CHIP_CONFIG_SUPPORT_PASE_CONFIG5. + * + * @note The results of this configuration are insecure because the + * computational overhead of the cryptography has largely been + * disabled since the focus of this configuration is testing + * the overall PASE protocol exchange, independently of the + * cryptography. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY 0 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG1 + * + * @brief + * This chip PASE configuration uses Finite Field J-PAKE and is + * the original, default chip PASE configuration. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG1 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG1 1 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG1 + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG2 + * + * @brief + * This chip PASE configuration uses Elliptic Curve J-PAKE with a + * SECG secp160r1 curve. + * + * @note When this PASE configuration is enabled, the corresponding + * elliptic curve (i.e. #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1) + * should also be enabled. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG2 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG2 0 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG2 + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG3 + * + * @brief + * This chip PASE configuration uses Elliptic Curve J-PAKE with a + * SECG secp192r1 curve. + * + * @note When this PASE configuration is enabled, the corresponding + * elliptic curve (i.e. #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1) + * should also be enabled. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG3 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG3 0 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG3 + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG4 + * + * @brief + * This chip PASE configuration uses Elliptic Curve J-PAKE with a + * SECG secp224r1 curve and will be the new, default chip PASE + * configuration. + * + * @note When this PASE configuration is enabled, the corresponding + * elliptic curve (i.e. #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1) + * should also be enabled. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG4 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG4 1 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG4 + +/** + * @def CHIP_CONFIG_SUPPORT_PASE_CONFIG5 + * + * @brief + * This chip PASE configuration uses Elliptic Curve J-PAKE with a + * SECG secp256r1 curve. + * + * @note When this PASE configuration is enabled, the corresponding + * elliptic curve (i.e. #CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1) + * should also be enabled. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASE_CONFIG5 +#define CHIP_CONFIG_SUPPORT_PASE_CONFIG5 0 +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG5 + +/** + * @} + */ + +#if CHIP_CONFIG_SUPPORT_PASE_CONFIG2 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 +#error "Please assert CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 when CHIP_CONFIG_SUPPORT_PASE_CONFIG2 is asserted" +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG2 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP160R1 + +#if CHIP_CONFIG_SUPPORT_PASE_CONFIG3 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 +#error "Please assert CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 when CHIP_CONFIG_SUPPORT_PASE_CONFIG3 is asserted" +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG3 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 + +#if CHIP_CONFIG_SUPPORT_PASE_CONFIG4 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 +#error "Please assert CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 when CHIP_CONFIG_SUPPORT_PASE_CONFIG4 is asserted" +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG4 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 + +#if CHIP_CONFIG_SUPPORT_PASE_CONFIG5 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 +#error "Please assert CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 when CHIP_CONFIG_SUPPORT_PASE_CONFIG5 is asserted" +#endif // CHIP_CONFIG_SUPPORT_PASE_CONFIG5 && !CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 + +/** + * @def CHIP_CONFIG_PASE_MESSAGE_PAYLOAD_ALIGNMENT + * + * @brief + * Align payload on 4-byte boundary for PASE messages. + * Currently, payload alignment is required only when micro-ecc + * library is used and it is compiled with ARM assembly. + * If implementation guarantees that payload is always 4-byte + * aligned this option should stay deasserted to save code size. + * + */ +#ifndef CHIP_CONFIG_PASE_MESSAGE_PAYLOAD_ALIGNMENT +#if CHIP_CONFIG_USE_MICRO_ECC +#define CHIP_CONFIG_PASE_MESSAGE_PAYLOAD_ALIGNMENT 1 +#else +#define CHIP_CONFIG_PASE_MESSAGE_PAYLOAD_ALIGNMENT 0 +#endif // CHIP_CONFIG_USE_MICRO_ECC +#endif // CHIP_CONFIG_PASE_MESSAGE_PAYLOAD_ALIGNMENT + +/** + * @def CHIP_CONFIG_PASE_RATE_LIMITER_TIMEOUT + * + * @brief + * The amount of time (in milliseconds) in which the Security Manager + * is allowed to have maximum #CHIP_CONFIG_PASE_RATE_LIMITER_MAX_ATTEMPTS + * counted PASE attempts. + * + */ +#ifndef CHIP_CONFIG_PASE_RATE_LIMITER_TIMEOUT +#define CHIP_CONFIG_PASE_RATE_LIMITER_TIMEOUT 15000 +#endif // CHIP_CONFIG_PASE_RATE_LIMITER_TIMEOUT + +/** + * @def CHIP_CONFIG_PASE_RATE_LIMITER_MAX_ATTEMPTS + * + * @brief + * The maximum number of PASE attempts after which the + * next PASE session establishment attempt will be allowed + * only after #CHIP_CONFIG_PASE_RATE_LIMITER_TIMEOUT expires. + * * For PASE negotiations with key confirmation option enabled: + * only attempts that failed with key confirmation error are counted. + * Successful PASE negotiations do not reset the rate limiter. + * * For PASE negotiations with key confirmation option disabled: + * every PASE negotiation, successful or otherwise, is added + * to the rate limiter. + * + */ +#ifndef CHIP_CONFIG_PASE_RATE_LIMITER_MAX_ATTEMPTS +#define CHIP_CONFIG_PASE_RATE_LIMITER_MAX_ATTEMPTS 3 +#endif // CHIP_CONFIG_PASE_RATE_LIMITER_MAX_ATTEMPTS + +/** + * @name chip Security Manager Memory Management Configuration + * + * @brief + * The following definitions enable one of three potential chip + * Security Manager memory-management options: + * + * * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM + * * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE + * * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC + * + * Note that these options are mutually exclusive and only one + * of these options should be set. + * + * @{ + */ + +/** + * @def CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM + * + * @brief + * Enable (1) or disable (0) support for platform-specific + * implementation of chip Security Manager memory-management + * functions. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE and + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC. + * + */ +#ifndef CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM +#define CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM 0 +#endif // CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM + +/** + * @def CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE + * + * @brief + * Enable (1) or disable (0) support for a chip-provided + * implementation of chip Security Manager memory-management + * functions based on temporary network buffer allocation / + * release. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM and + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC. + * + */ +#ifndef CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE +#define CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE 0 +#endif // CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE + +/** + * @def CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC + * + * @brief + * Enable (1) or disable (0) support for a chip-provided + * implementation of chip Security Manager memory-management + * functions based on the C Standard Library malloc / free + * functions. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM and + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE. + * + */ +#ifndef CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC +#define CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC 1 +#endif // CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC + +/** + * @} + */ + +#if ((CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM + CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE + CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC) != 1) +#error "Please assert exactly one of CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM, CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE, or CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC." +#endif // ((CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_PLATFORM + CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE + CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_MALLOC) != 1) + +/** + * @def CHIP_CONFIG_SIMPLE_ALLOCATOR_USE_SMALL_BUFFERS + * + * @brief + * Enable (1) or disable (0) simple memory allocator support + * for small size network buffers. When enabled, this configuration + * requires 4 network buffers with minimum available payload size of + * 600 bytes. + * + * @note This configuration is only relevant when + * #CHIP_CONFIG_SECURITY_MGR_MEMORY_MGMT_SIMPLE is set and + * ignored otherwise. + * + */ +#ifndef CHIP_CONFIG_SIMPLE_ALLOCATOR_USE_SMALL_BUFFERS +#define CHIP_CONFIG_SIMPLE_ALLOCATOR_USE_SMALL_BUFFERS 0 +#endif // CHIP_CONFIG_SIMPLE_ALLOCATOR_USE_SMALL_BUFFERS + +/** + * @name chip Security Manager Time-Consuming Crypto Alerts. + * + * @brief + * The following definitions enable one of two potential chip + * Security Manager time-consuming crypto alerts implementations: + * + * * #CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY + * * #CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM + * + * Note that these options are mutually exclusive and only one + * of these options should be set. + * + * @{ + */ + +/** + * @def CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY + * + * @brief + * Enable (1) or disable (0) support for chip-provided dummy + * implementation of chip security manager time-consuming + * crypto alerts functions. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM. + * + */ +#ifndef CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY +#define CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY 1 +#endif // CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY + +/** + * @def CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM + * + * @brief + * Enable (1) or disable (0) support for a platform-specific + * implementation of chip security manager time-consuming + * crypto alerts functions. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY. + * + */ +#ifndef CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM +#define CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM 0 +#endif // CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM + +/** + * @} + */ + +#if ((CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY + CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM) != 1) +#error "Please assert exactly one of CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY or CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM." +#endif // ((CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_DUMMY + CHIP_CONFIG_SECURITY_MGR_TIME_ALERTS_PLATFORM) != 1) + +/** + * @name chip Random Number Generator (RNG) Implementation Configuration + * + * @brief + * The following definitions enable one of three potential chip + * RNG implementation options: + * + * * #CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + * * #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + * * #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL + * + * Note that these options are mutually exclusive and only one of + * these options should be set. + * + * @{ + */ + +/** + * @def CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + * + * @brief + * Enable (1) or disable (0) support for platform-specific + * implementation of the chip Random Number Generator. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG and + * #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL. + * + */ +#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM +#define CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM 0 +#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + +/** + * @def CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + * + * @brief + * Enable (1) or disable (0) support for a chip-provided + * implementation of the chip Random Number Generator. + * This implementation is based on AES-CTR DRBG as + * specified in the NIST SP800-90A document. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM and + * #CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL. + * + */ +#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG +#define CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG 0 +#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + +/** + * @def CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL + * + * @brief + * Enable (1) or disable (0) support for a standard OpenSSL + * implementation of the chip Random Number Generator. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM and + * #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG. + * + */ +#ifndef CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL +#define CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL 1 +#endif // CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL + +/** + * @} + */ + +#if ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1) +#error "Please assert exactly one of CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM, CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG, or CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL." +#endif // ((CHIP_CONFIG_RNG_IMPLEMENTATION_PLATFORM + CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + CHIP_CONFIG_RNG_IMPLEMENTATION_OPENSSL) != 1) + + +/** + * @def CHIP_CONFIG_DEV_RANDOM_DRBG_SEED + * + * @brief + * Enable (1) or disable (0) a function for seeding the DRBG with + * entropy from the /dev/(u)random device. + * + * @note When enabled along with #CHIP_CONFIG_RNG_IMPLEMENTATION_NESTDRBG + * this function becomes the default seeding function for the DRBG if + * another isn't specified at initialization time. + * + */ +#ifndef CHIP_CONFIG_DEV_RANDOM_DRBG_SEED +#define CHIP_CONFIG_DEV_RANDOM_DRBG_SEED 0 +#endif // CHIP_CONFIG_DEV_RANDOM_DRBG_SEED + +/** + * @def CHIP_CONFIG_DEV_RANDOM_DEVICE_NAME + * + * @brief + * The device name used by the dev random entropy function. + * + * @note Only meaningful when #CHIP_CONFIG_DEV_RANDOM_DRBG_SEED is enabled. + * + */ +#ifndef CHIP_CONFIG_DEV_RANDOM_DEVICE_NAME +#define CHIP_CONFIG_DEV_RANDOM_DEVICE_NAME "/dev/urandom" +#endif // CHIP_CONFIG_DEV_RANDOM_DEVICE_NAME + + + +/** + * @name chip AES Block Cipher Algorithm Implementation Configuration. + * + * @brief + * The following definitions enable one of the potential chip + * AES implementation options: + * + * * #CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM + * * #CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL + * + * Note that these options are mutually exclusive and only one of + * these options should be set. + * + * @{ + */ + +/** + * @def CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM + * + * @brief + * Enable (1) or disable (0) support for platform-specific + * implementation of the chip AES functions. + * + * @note This configuration is mutual exclusive with + * #CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL and + * #CHIP_CONFIG_AES_IMPLEMENTATION_AESNI + * + */ +#ifndef CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM +#define CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM 0 +#endif // CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM + +/** + * @def CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL + * + * @brief + * Enable (1) or disable (0) support for the OpenSSL + * implementation of the chip AES functions. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_AES_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL +#define CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL 1 +#endif // CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL + +/** + * @def CHIP_CONFIG_AES_IMPLEMENTATION_AESNI + * + * @brief + * Enable (1) or disable (0) support for an implementation + * of the chip AES functions using Intel AES-NI intrinsics. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_AES_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_AES_IMPLEMENTATION_AESNI +#define CHIP_CONFIG_AES_IMPLEMENTATION_AESNI 0 +#endif // CHIP_CONFIG_AES_IMPLEMENTATION_AESNI + +/** + * @def CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS + * + * @brief + * Enable (1) or disable (0) support the mbed TLS + * implementation of the chip AES functions. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_AES_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS +#define CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS 0 +#endif // CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS + +/** + * @} + */ + +#if ((CHIP_CONFIG_AES_IMPLEMENTATION_PLATFORM + \ + CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL + \ + CHIP_CONFIG_AES_IMPLEMENTATION_AESNI + \ + CHIP_CONFIG_AES_IMPLEMENTATION_MBEDTLS) != 1) +#error "Please assert exactly one CHIP_CONFIG_AES_IMPLEMENTATION_... option." +#endif + +/** + * @def CHIP_CONFIG_AES_USE_EXPANDED_KEY + * + * @brief + * Defines whether AES key is used in its expanded (1) or native (0) form. + * + * @note OpenSSL AES implementation uses its own AES key declaration + * and this configuration option is ignored when + * #CHIP_CONFIG_AES_IMPLEMENTATION_OPENSSL is set. + * + */ +#ifndef CHIP_CONFIG_AES_USE_EXPANDED_KEY +#define CHIP_CONFIG_AES_USE_EXPANDED_KEY 0 +#endif // CHIP_CONFIG_AES_USE_EXPANDED_KEY + + +/** + * @name chip SHA1 and SHA256 Hash Algorithms Implementation Configuration. + * + * @brief + * The following definitions enable one of three potential chip + * hash implementation options: + * + * * #CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM + * * #CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT + * * #CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL + * * #CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS + * + * Note that these options are mutually exclusive and only one of + * these options should be set. + * + * @{ + */ + +/** + * @def CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM + * + * @brief + * Enable (1) or disable (0) support for platform-specific + * implementation of the chip SHA1 and SHA256 hashes. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_HASH_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM +#define CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM 0 +#endif // CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM + +/** + * @def CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT + * + * @brief + * Enable (1) or disable (0) support for a chip-provided + * implementation of the chip SHA1 and SHA256 hash functions. + * This implementation is using sha1 and sha256 engines from + * mincrypt library of Android core. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_HASH_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT 0 +#endif // CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT + +/** + * @def CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL + * + * @brief + * Enable (1) or disable (0) support for the OpenSSL + * implementation of the chip SHA1 and SHA256 hash functions. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_HASH_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL +#define CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL 1 +#endif // CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL + +/** + * @def CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS + * + * @brief + * Enable (1) or disable (0) support for the mbedTLS + * implementation of the chip SHA1 and SHA256 hash functions. + * + * @note This configuration is mutual exclusive with other + * CHIP_CONFIG_HASH_IMPLEMENTATION options. + * + */ +#ifndef CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS +#define CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS 0 +#endif // CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS + +/** + * @} + */ + +#if ((CHIP_CONFIG_HASH_IMPLEMENTATION_PLATFORM + \ + CHIP_CONFIG_HASH_IMPLEMENTATION_MINCRYPT + \ + CHIP_CONFIG_HASH_IMPLEMENTATION_OPENSSL + \ + CHIP_CONFIG_HASH_IMPLEMENTATION_MBEDTLS) != 1) +#error "Please assert exactly one CHIP_CONFIG_HASH_IMPLEMENTATION_... option." +#endif + + +/** + * @name chip key export protocol configuration. + * + * @brief + * The following definitions define the configurations supported + * for chip's key export protocol. + * + * This protocol is used to export secret key material from chip device. + * chip supports the following protocol configurations: + * + * * #CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG1 + * * #CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG2 + * + * which are summarized in the table below: + * + * | Configuration | Curve | Notes | + * | :------------: | :-------: | :---------------------- | + * | 1 | secp224r1 | Default configuration | + * | 2 | secp256r1 | | + * + * @{ + * + */ + +/** + * @def CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG1 + * + * @brief + * This chip key export protocol configuration uses secp224r1 + * Elliptic Curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG1 +#define CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG1 1 +#endif // CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG1 + +/** + * @def CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG2 + * + * @brief + * This chip key export protocol configuration uses secp256r1 + * Elliptic Curve. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG2 +#define CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG2 1 +#endif // CHIP_CONFIG_SUPPORT_KEY_EXPORT_CONFIG2 + +/** + * @} + */ + + +/** + * @def CHIP_CONFIG_ALLOW_NON_STANDARD_ELLIPTIC_CURVES + * + * @brief + * Allow the use of elliptic curves beyond the standard ones + * supported by chip. + * + */ +#ifndef CHIP_CONFIG_ALLOW_NON_STANDARD_ELLIPTIC_CURVES +#define CHIP_CONFIG_ALLOW_NON_STANDARD_ELLIPTIC_CURVES 0 +#endif // CHIP_CONFIG_ALLOW_NON_STANDARD_ELLIPTIC_CURVES + +/** + * @def CHIP_CONFIG_MAX_EC_BITS + * + * @brief + * The maximum size elliptic curve supported, in bits. + * + */ +#ifndef CHIP_CONFIG_MAX_EC_BITS +#define CHIP_CONFIG_MAX_EC_BITS 256 +#endif // CHIP_CONFIG_MAX_EC_BITS + +/** + * @def CHIP_CONFIG_MAX_RSA_BITS + * + * @brief + * The maximum size RSA modulus supported, in bits. + * + */ +#ifndef CHIP_CONFIG_MAX_RSA_BITS +#define CHIP_CONFIG_MAX_RSA_BITS 4096 +#endif // CHIP_CONFIG_MAX_RSA_BITS + +/** + * @def CHIP_CONFIG_MAX_PEER_NODES + * + * @brief + * Maximum number of peer nodes that the local node can communicate + * with. + * + */ +#ifndef CHIP_CONFIG_MAX_PEER_NODES +#define CHIP_CONFIG_MAX_PEER_NODES 128 +#endif // CHIP_CONFIG_MAX_PEER_NODES + +/** + * @def CHIP_CONFIG_MAX_CONNECTIONS + * + * @brief + * Maximum number of simultaneously active connections. + * + */ +#ifndef CHIP_CONFIG_MAX_CONNECTIONS +#define CHIP_CONFIG_MAX_CONNECTIONS INET_CONFIG_NUM_TCP_ENDPOINTS +#endif // CHIP_CONFIG_MAX_CONNECTIONS + +/** + * @def CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS + * + * @brief + * Maximum number of simultaneously active inbound TCP connections. + * + * Regardless of what #CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS + * is set to, the total number of inbound connections cannot exceed + * #CHIP_CONFIG_MAX_CONNECTIONS, which is the overall limit for + * inbound and outbound connections. + */ +#ifndef CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS +#define CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS (CHIP_CONFIG_MAX_CONNECTIONS * 4 / 5) +#endif // CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS + +/** + * @def CHIP_CONFIG_MAX_INCOMING_TCP_CON_FROM_SINGLE_IP + * + * @brief + * Maximum number of simultaneously active inbound TCP connections + * from the single IP address. + * + * Regardless of what #CHIP_CONFIG_MAX_INCOMING_TCP_CON_FROM_SINGLE_IP + * is set to, the total number of inbound connections from a single IP + * address cannot exceed #CHIP_CONFIG_MAX_CONNECTIONS or + * #CHIP_CONFIG_MAX_INCOMING_TCP_CONNECTIONS. + */ +#ifndef CHIP_CONFIG_MAX_INCOMING_TCP_CON_FROM_SINGLE_IP +#define CHIP_CONFIG_MAX_INCOMING_TCP_CON_FROM_SINGLE_IP 2 +#endif // CHIP_CONFIG_MAX_INCOMING_TCP_CON_FROM_SINGLE_IP + +/** + * @def CHIP_CONFIG_MAX_TUNNELS + * + * @brief + * Maximum number of simultaneously active connection tunnels. + * + */ +#ifndef CHIP_CONFIG_MAX_TUNNELS +#define CHIP_CONFIG_MAX_TUNNELS 1 +#endif // CHIP_CONFIG_MAX_TUNNELS + +/** + * @def CHIP_CONFIG_MAX_SESSION_KEYS + * + * @brief + * Maximum number of simultaneously active session keys. + * + */ +#ifndef CHIP_CONFIG_MAX_SESSION_KEYS +#define CHIP_CONFIG_MAX_SESSION_KEYS CHIP_CONFIG_MAX_CONNECTIONS +#endif // CHIP_CONFIG_MAX_SESSION_KEYS + +/** + * @def CHIP_CONFIG_MAX_APPLICATION_EPOCH_KEYS + * + * @brief + * Maximum number of simultaneously supported application epoch keys. + * This define should be set to the maximum number of epoch keys + * that can be simultaneously provisioned on chip node by chip + * service. The maximum supported value is 8, however, in most cases + * only two such keys will exist on device at any given point in time. + * + */ +#ifndef CHIP_CONFIG_MAX_APPLICATION_EPOCH_KEYS +#define CHIP_CONFIG_MAX_APPLICATION_EPOCH_KEYS 4 +#endif // CHIP_CONFIG_MAX_APPLICATION_EPOCH_KEYS + +/** + * @def CHIP_CONFIG_MAX_APPLICATION_GROUPS + * + * @brief + * Maximum number of simultaneously supported application groups. + * This define should be set to the number of chip application + * groups, in which associated chip node has membership. + * + */ +#ifndef CHIP_CONFIG_MAX_APPLICATION_GROUPS +#define CHIP_CONFIG_MAX_APPLICATION_GROUPS 8 +#endif // CHIP_CONFIG_MAX_APPLICATION_GROUPS + +/** + * @def CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC + * + * @brief + * Enable (1) or disable (0) support for the application group keys + * used for chip message encryption. + * + */ +#ifndef CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC +#define CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC 1 +#endif // CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC + +/** + * @def CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS + * + * @brief + * Maximum number of simultaneously cached chip message encryption + * application keys. + * Caching these keys speeds up message encoding/decoding processes + * and eliminates the need to retrieve constituent key material from + * the platform memory every time we derive these keys. + * This define can be set equal to the number of application groups + * (#CHIP_CONFIG_MAX_APPLICATION_GROUPS) supported by the chip node + * such that exactly one key can be cached for each application group. + * It might be a good idea to allocate few more entries in the key + * cache for the corner cases, where application group is having + * simultaneous conversations using an 'old' and a 'new' epoch key. + * + * @note This configuration is only relevant when + * #CHIP_CONFIG_USE_APP_GROUP_KEYS_FOR_MSG_ENC is set and + * ignored otherwise. + * + */ +#ifndef CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS +#define CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS (CHIP_CONFIG_MAX_APPLICATION_GROUPS + 1) +#endif // CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS + +#if !(CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS > 0 && CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS < 256) +#error "Please set CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS to a value greater than zero and smaller than 256." +#endif // !(CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS > 0 && CHIP_CONFIG_MAX_CACHED_MSG_ENC_APP_KEYS < 256) + +/** + * @name chip Encrypted Passcode Configuration + * + * @brief + * The following definitions enable (1) or disable (0) supported for + * chip encrypted passcode configurations. Each configuration + * uniquely specifies how chip passcode was encrypted, authenticated, + * and structured. chip supports the following passcode + * configurations: + * + * * #CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY + * * #CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG2 + * + * which are summarized in the table below: + * + * | Configuration | Encryption | Authentication | Fingerprint | Notes | + * | :-----------: | :--------: | :------------: | :---------: | :-------------------- | + * | 1 | - | SHA1 Hash | SHA1 Hash | Test-only | + * | 2 | AES128-ECB | SHA1 HMAC | SHA1 HMAC | Default configuration | + * + * @{ + * + */ + +/** + * @def CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY + * + * @brief + * This chip passcode configuration does not encrypt the passcode + * and doesn't use secret keys to authenticate and uniquely identify + * (fingerprint) the passcode. + * + * @note For this configuration the computational overhead of the + * cryptography has largely been disabled since the focus + * of this configuration is testing the overall passcode + * encryption/decryption protocol, independently of the + * cryptography. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY +#define CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY 0 +#endif // CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY + +/** + * @def CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG2 + * + * @brief + * This chip passcode configuration uses AES128 algorithm in ECB + * mode to encrypt passcodes. It also uses SHA1 Hash-based Message + * Authentication Code (HMAC) to authenticate and uniquely identify + * (fingerprint) the passcode. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG2 +#define CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG2 1 +#endif // CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG2 + +/** + * @} + */ + +/** + * @def CHIP_CONFIG_DEFAULT_SECURITY_SESSION_ESTABLISHMENT_TIMEOUT + * + * @brief + * The default amount of time, in milliseconds, after which an in-progess + * session establishment will fail due to a timeout. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_SECURITY_SESSION_ESTABLISHMENT_TIMEOUT +#define CHIP_CONFIG_DEFAULT_SECURITY_SESSION_ESTABLISHMENT_TIMEOUT 30000 +#endif // CHIP_CONFIG_DEFAULT_SECURITY_SESSION_ESTABLISHMENT_TIMEOUT + +/** + * @def CHIP_CONFIG_DEFAULT_SECURITY_SESSION_IDLE_TIMEOUT + * + * @brief + * The default minimum amount of time, in milliseconds, that an unreserved and idle + * security session will be allowed to exist before being destroyed. In practice, + * unreserved idle sessions can exist for up to twice this value. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_SECURITY_SESSION_IDLE_TIMEOUT +#define CHIP_CONFIG_DEFAULT_SECURITY_SESSION_IDLE_TIMEOUT 15000 +#endif // CHIP_CONFIG_DEFAULT_SECURITY_SESSION_IDLE_TIMEOUT + +/** + * @def CHIP_CONFIG_NUM_MESSAGE_BUFS + * + * @brief + * Total number of message buffers. Only used for the BSD sockets + * configuration. + * + */ +#ifndef CHIP_CONFIG_NUM_MESSAGE_BUFS +#define CHIP_CONFIG_NUM_MESSAGE_BUFS 16 +#endif // CHIP_CONFIG_NUM_MESSAGE_BUFS + +/** + * @def CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + * + * @brief + * Maximum number of simultaneously active unsolicited message + * handlers. + * + */ +#ifndef CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS +#define CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS 32 +#endif // CHIP_CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS + +/** + * @def CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + * + * @brief + * Maximum number of simultaneously active exchange contexts. + * + */ +#ifndef CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS +#define CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS 16 +#endif // CHIP_CONFIG_MAX_EXCHANGE_CONTEXTS + +/** + * @def CHIP_CONFIG_MAX_BINDINGS + * + * @brief + * Maximum number of simultaneously active bindings per chipExchangeManager + * The new single source TimeSync client takes one binding. + * Every WDM one-way subscription takes one binding. Mutual subscription counts as two one-way subscriptions. + * A reserved slot is needed to take an incoming subscription request. + * For a device with 2 mutual subscriptions, and one single source time sync client, it needs 2 x 2 + 1 = 5 bindings at least. + * At least six is needed if it still wants to take new WDM subscriptions under this load. + */ +#ifndef CHIP_CONFIG_MAX_BINDINGS +#define CHIP_CONFIG_MAX_BINDINGS 6 +#endif // CHIP_CONFIG_MAX_BINDINGS + +/** + * @def CHIP_CONFIG_CONNECT_IP_ADDRS + * + * @brief + * Maximum number of IP addresses tried when connecting to a + * hostname. + * + */ +#ifndef CHIP_CONFIG_CONNECT_IP_ADDRS +#define CHIP_CONFIG_CONNECT_IP_ADDRS 4 +#endif // CHIP_CONFIG_CONNECT_IP_ADDRS + +/** + * @def CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE + * + * @brief + * The default MTU size for an IPv6 datagram carrying UDP. This is useful + * for senders who want to send UDP chip messages that fit within a single + * IPv6 datagram. + * + * 1280 is the guaranteed minimum IPv6 MTU. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE +#define CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE 1280 +#endif // CHIP_CONFIG_DEFAULT_UDP_MTU_SIZE + +/** + * @def CHIP_HEADER_RESERVE_SIZE + * + * @brief + * The number of bytes to reserve in a network packet buffer to contain the + * chip message and exchange headers. + * + * This number was calculated as follows: + * + * chip Message Header: + * + * 2 -- Frame Length + * 2 -- Message Header + * 4 -- Message Id + * 8 -- Source Node Id + * 8 -- Destination Node Id + * 2 -- Key Id + * + * chip Exchange Header: + * + * 1 -- Application Version + * 1 -- Message Type + * 2 -- Exchange Id + * 4 -- Profile Id + * 4 -- Acknowleged Message Id + * + * @note A number of these fields are optional or not presently used. + * So most headers will be considerably smaller than this. + * + */ +#ifndef CHIP_HEADER_RESERVE_SIZE +#define CHIP_HEADER_RESERVE_SIZE 38 +#endif // CHIP_HEADER_RESERVE_SIZE + +/** + * @def CHIP_TRAILER_RESERVE_SIZE + * + * @brief + * TODO + * + */ +#ifndef CHIP_TRAILER_RESERVE_SIZE +#define CHIP_TRAILER_RESERVE_SIZE 20 +#endif // CHIP_TRAILER_RESERVE_SIZE + +/** + * @def CHIP_PORT + * + * @brief + * chip TCP/UDP port for secured chip traffic. + * + */ +#ifndef CHIP_PORT +#define CHIP_PORT 11095 +#endif // CHIP_PORT + +/** + * @def CHIP_UNSECURED_PORT + * + * @brief + * chip TCP/UDP port for unsecured chip traffic. + * + */ +#ifndef CHIP_UNSECURED_PORT +#define CHIP_UNSECURED_PORT 11096 +#endif // CHIP_UNSECURED_PORT + +/** + * @def CHIP_CONFIG_ENABLE_EPHEMERAL_UDP_PORT + * + * @brief + * Enable use of an ephemeral UDP source port for locally initiated chip exchanges. + */ +#ifndef CHIP_CONFIG_ENABLE_EPHEMERAL_UDP_PORT +#define CHIP_CONFIG_ENABLE_EPHEMERAL_UDP_PORT 0 +#endif // CHIP_CONFIG_ENABLE_EPHEMERAL_UDP_PORT + +/** + * @def CHIP_CONFIG_SECURITY_TEST_MODE + * + * @brief + * Enable various features that make it easier to debug secure chip communication. + * + * @note + * WARNING: This option makes it possible to circumvent basic chip security functionality, + * including message encryption. Because of this it SHOULD NEVER BE ENABLED IN PRODUCTION BUILDS. + */ +#ifndef CHIP_CONFIG_SECURITY_TEST_MODE +#define CHIP_CONFIG_SECURITY_TEST_MODE 0 +#endif // CHIP_CONFIG_SECURITY_TEST_MODE + +/** + * @def CHIP_CONFIG_ENABLE_DNS_RESOLVER + * + * @brief + * Enable support for resolving hostnames with a DNS resolver. + */ +#ifndef CHIP_CONFIG_ENABLE_DNS_RESOLVER +#define CHIP_CONFIG_ENABLE_DNS_RESOLVER (INET_CONFIG_ENABLE_DNS_RESOLVER) +#endif // CHIP_CONFIG_ENABLE_DNS_RESOLVER + +/** + * @def CHIP_CONFIG_RESOLVE_IPADDR_LITERAL + * + * @brief + * Enable support for resolving hostnames as literal IP addresses without a DNS resolver. + * + * For historical reasons, the default is \c TRUE where \c CHIP_SYSTEM_CONFIG_USE_SOCKETS=1, + * and \c FALSE otherwise. The exception in the LwIP-only case was originally made to facilitate + * integration and change management with existing development lines. The default may + * change in the future to \c TRUE in all cases. + */ +#ifndef CHIP_CONFIG_RESOLVE_IPADDR_LITERAL +#define CHIP_CONFIG_RESOLVE_IPADDR_LITERAL (CHIP_SYSTEM_CONFIG_USE_SOCKETS) +#endif // CHIP_CONFIG_RESOLVE_IPADDR_LITERAL + +/** + * @def CHIP_CONFIG_ENABLE_TARGETED_LISTEN + * + * @brief + * Enable support for listening on particular addresses/interfaces. + * + * This allows testing multiple instances of the chip stack + * running on a single host. + * + */ +#ifndef CHIP_CONFIG_ENABLE_TARGETED_LISTEN +#define CHIP_CONFIG_ENABLE_TARGETED_LISTEN (!CHIP_SYSTEM_CONFIG_USE_LWIP) +#endif // CHIP_CONFIG_ENABLE_TARGETED_LISTEN + +/** + * @def CHIP_CONFIG_ENABLE_UNSECURED_TCP_LISTEN + * + * @brief + * Enable support for receiving TCP connections over an unsecured + * network layer (for example, from a device that is provisionally joined + * to a 6LowPAN network but does not possess the 802.15.4 network + * keys). + * + */ +#ifndef CHIP_CONFIG_ENABLE_UNSECURED_TCP_LISTEN +#define CHIP_CONFIG_ENABLE_UNSECURED_TCP_LISTEN 0 +#endif // CHIP_CONFIG_ENABLE_UNSECURED_TCP_LISTEN + +/** + * @def CHIP_CONFIG_DEBUG_CERT_VALIDATION + * + * @brief + * Enable support for debugging output from certificate validation. + * + */ +#ifndef CHIP_CONFIG_DEBUG_CERT_VALIDATION +#define CHIP_CONFIG_DEBUG_CERT_VALIDATION 1 +#endif // CHIP_CONFIG_DEBUG_CERT_VALIDATION + +/** + * @def CHIP_CONFIG_OPERATIONAL_DEVICE_CERT_CURVE_ID + * + * @brief + * EC curve to be used to generate chip operational device certificate. + * + */ +#ifndef CHIP_CONFIG_OPERATIONAL_DEVICE_CERT_CURVE_ID +#define CHIP_CONFIG_OPERATIONAL_DEVICE_CERT_CURVE_ID (chip::Profiles::Security::kchipCurveId_prime256v1) +#endif // CHIP_CONFIG_OPERATIONAL_DEVICE_CERT_CURVE_ID + +/** + * @def CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_BEFORE + * + * @brief + * This is a packed valid date to be encoded in the chip + * operational device certificate. Any date before + * that date the certificate is considered invalid. + * The following functions can be used to calculate packed + * date/time: PackCertTime() and PackedCertTimeToDate(). + * chip packed certificate dates are limited to representing + * dates that are on or after 2000/01/01. + * Mathematical expression to calculate packed date is: + * (((year - 2000) * 12 + (mon - 1)) * 31 + (day - 1)) + * Currently encoded value corresponds to 2019/01/01. + * + */ +#ifndef CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_BEFORE +#define CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_BEFORE 0x1B9C +#endif // CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_BEFORE + +/** + * @def CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_AFTER + * + * @brief + * This is the valid date to be encoded in the chip + * operational device certificate. Any date after + * that date the certificate is considered invalid. + * The following functions can be used to calculate packed + * date/time: PackCertTime() and PackedCertTimeToDate(). + * chip packed certificate dates are limited to representing + * dates that are on or after 2000/01/01. + * Mathematical expression to calculate packed date is: + * (((year - 2000) * 12 + (mon - 1)) * 31 + (day - 1)) + * Currently encoded value corresponds to 2069/01/01. + * + */ +#ifndef CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_AFTER +#define CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_AFTER 0x6444 +#endif // CHIP_CONFIG_OP_DEVICE_CERT_VALID_DATE_NOT_AFTER + +/** + * @def CHIP_CONFIG_ENABLE_PASE_INITIATOR + * + * @brief + * Enable support for initiating PASE sessions. + * + */ +#ifndef CHIP_CONFIG_ENABLE_PASE_INITIATOR +#define CHIP_CONFIG_ENABLE_PASE_INITIATOR 1 +#endif // CHIP_CONFIG_ENABLE_PASE_INITIATOR + +/** + * @def CHIP_CONFIG_ENABLE_PASE_RESPONDER + * + * @brief + * Enable support for responding to PASE sessions initiated by + * other nodes. + * + */ +#ifndef CHIP_CONFIG_ENABLE_PASE_RESPONDER +#define CHIP_CONFIG_ENABLE_PASE_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_PASE_RESPONDER + +/** + * @def CHIP_CONFIG_ENABLE_CASE_INITIATOR + * + * @brief + * Enable support for initiating CASE sessions. + * + */ +#ifndef CHIP_CONFIG_ENABLE_CASE_INITIATOR +#define CHIP_CONFIG_ENABLE_CASE_INITIATOR 1 +#endif // CHIP_CONFIG_ENABLE_CASE_INITIATOR + +/** + * @def CHIP_CONFIG_ENABLE_CASE_RESPONDER + * + * @brief + * Enable support for responding to CASE sessions initiated by other nodes. + * + */ +#ifndef CHIP_CONFIG_ENABLE_CASE_RESPONDER +#define CHIP_CONFIG_ENABLE_CASE_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_CASE_RESPONDER + +/** + * @def CHIP_CONFIG_SUPPORT_CASE_CONFIG1 + * + * @brief + * Enable use of CASE protocol configuration 1. + * + * @note CASE config 1 uses SHA-1 for message signatures, which is deprecated. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_CASE_CONFIG1 +#define CHIP_CONFIG_SUPPORT_CASE_CONFIG1 1 +#endif // CHIP_CONFIG_SUPPORT_CASE_CONFIG1 + +/** + * @def CHIP_CONFIG_DEFAULT_CASE_CURVE_ID + * + * @brief + * Default ECDH curve to be used when initiating a CASE session, if not overridden by the application. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_CASE_CURVE_ID +#if CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 +#define CHIP_CONFIG_DEFAULT_CASE_CURVE_ID (chip::Profiles::Security::kchipCurveId_secp224r1) +#elif CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 +#define CHIP_CONFIG_DEFAULT_CASE_CURVE_ID (chip::Profiles::Security::kchipCurveId_prime256v1) +#elif CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP192R1 +#define CHIP_CONFIG_DEFAULT_CASE_CURVE_ID (chip::Profiles::Security::kchipCurveId_prime192v1) +#else +#define CHIP_CONFIG_DEFAULT_CASE_CURVE_ID (chip::Profiles::Security::kchipCurveId_secp160r1) +#endif +#endif // CHIP_CONFIG_DEFAULT_CASE_CURVE_ID + +/** + * @def CHIP_CONFIG_DEFAULT_CASE_ALLOWED_CURVES + * + * @brief + * Default set of ECDH curves allowed to be used in a CASE session (initiating or responding), if not overridden by the application. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_CASE_ALLOWED_CURVES +#if CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP224R1 || CHIP_CONFIG_SUPPORT_ELLIPTIC_CURVE_SECP256R1 +#define CHIP_CONFIG_DEFAULT_CASE_ALLOWED_CURVES (chip::Profiles::Security::kchipCurveSet_secp224r1|chip::Profiles::Security::kchipCurveSet_prime256v1) +#else +#define CHIP_CONFIG_DEFAULT_CASE_ALLOWED_CURVES (chip::Profiles::Security::kchipCurveSet_All) +#endif +#endif // CHIP_CONFIG_DEFAULT_CASE_ALLOWED_CURVES + +/** + * @def CHIP_CONFIG_LEGACY_CASE_AUTH_DELEGATE + * + * @brief + * Enable use of the legacy chipCASEAuthDelegate interface. + */ +#ifndef CHIP_CONFIG_LEGACY_CASE_AUTH_DELEGATE +#define CHIP_CONFIG_LEGACY_CASE_AUTH_DELEGATE 1 +#endif + +/** + * @def CHIP_CONFIG_MAX_SHARED_SESSIONS_END_NODES + * + * @brief + * The maximum number of end nodes simultaneously supported + * for all active shared sessions. + * + */ +#ifndef CHIP_CONFIG_MAX_SHARED_SESSIONS_END_NODES +#define CHIP_CONFIG_MAX_SHARED_SESSIONS_END_NODES 10 +#endif // CHIP_CONFIG_MAX_SHARED_SESSIONS_END_NODES + +/** + * @def CHIP_CONFIG_MAX_END_NODES_PER_SHARED_SESSION + * + * @brief + * The maximum number of end nodes simultaneously supported + * per active shared session. + * + */ +#ifndef CHIP_CONFIG_MAX_END_NODES_PER_SHARED_SESSION +#define CHIP_CONFIG_MAX_END_NODES_PER_SHARED_SESSION 10 +#endif // CHIP_CONFIG_MAX_END_NODES_PER_SHARED_SESSION + +/** + * @def CHIP_CONFIG_ENABLE_TAKE_INITIATOR + * + * @brief + * Enable support for initiating TAKE sessions. + * + */ +#ifndef CHIP_CONFIG_ENABLE_TAKE_INITIATOR +#define CHIP_CONFIG_ENABLE_TAKE_INITIATOR 0 +#endif // CHIP_CONFIG_ENABLE_TAKE_INITIATOR + +/** + * @def CHIP_CONFIG_ENABLE_TAKE_RESPONDER + * + * @brief + * Enable support for responding to TAKE sessions initiated by other nodes. + * + */ +#ifndef CHIP_CONFIG_ENABLE_TAKE_RESPONDER +#define CHIP_CONFIG_ENABLE_TAKE_RESPONDER 0 +#endif // CHIP_CONFIG_ENABLE_TAKE_RESPONDER + +/** + * @def CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR + * + * @brief + * Enable support for initiating key export request. + * + */ +#ifndef CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR 1 +#endif // CHIP_CONFIG_ENABLE_KEY_EXPORT_INITIATOR + +/** + * @def CHIP_CONFIG_ENABLE_KEY_EXPORT_RESPONDER + * + * @brief + * Enable support for responding to key export request initiated by other nodes. + * + */ +#ifndef CHIP_CONFIG_ENABLE_KEY_EXPORT_RESPONDER +#define CHIP_CONFIG_ENABLE_KEY_EXPORT_RESPONDER 1 +#endif // CHIP_CONFIG_ENABLE_KEY_EXPORT_RESPONDER + +/** + * @def CHIP_CONFIG_LEGACY_KEY_EXPORT_DELEGATE + * + * @brief + * Enable use of the legacy chipKeyExportDelegate interface. + */ +#ifndef CHIP_CONFIG_LEGACY_KEY_EXPORT_DELEGATE +#define CHIP_CONFIG_LEGACY_KEY_EXPORT_DELEGATE 1 +#endif + +/** + * @def CHIP_CONFIG_REQUIRE_AUTH + * + * @brief + * Enable (1) or disable (0) support for client requests via an + * authenticated session. + * + * This broadly controls whether or not a number of chip servers + * require client requests to be sent via an authenticated session + * and provides a default configuration value to these related + * definitions: + * + * * #CHIP_CONFIG_REQUIRE_AUTH_DEVICE_CONTROL + * * #CHIP_CONFIG_REQUIRE_AUTH_FABRIC_PROV + * * #CHIP_CONFIG_REQUIRE_AUTH_NETWORK_PROV + * * #CHIP_CONFIG_REQUIRE_AUTH_SERVICE_PROV + * + * @note These configurations shall be deasserted for development + * and testing purposes only. No chip-enabled device shall + * be certified without these asserted. + * + */ +#ifndef CHIP_CONFIG_REQUIRE_AUTH +#define CHIP_CONFIG_REQUIRE_AUTH 1 +#endif // CHIP_CONFIG_REQUIRE_AUTH + +/** + * @def CHIP_CONFIG_REQUIRE_AUTH_DEVICE_CONTROL + * + * @brief + * Enable (1) or disable (0) support for client requests to the + * chip Device Control server via an authenticated session. See + * also #CHIP_CONFIG_REQUIRE_AUTH. + * + * @note This configuration shall be deasserted for development + * and testing purposes only. No chip-enabled device shall + * be certified without this asserted. + * + */ +#ifndef CHIP_CONFIG_REQUIRE_AUTH_DEVICE_CONTROL +#define CHIP_CONFIG_REQUIRE_AUTH_DEVICE_CONTROL CHIP_CONFIG_REQUIRE_AUTH +#endif // CHIP_CONFIG_REQUIRE_AUTH_DEVICE_CONTROL + +/** + * @def CHIP_CONFIG_REQUIRE_AUTH_FABRIC_PROV + * + * @brief + * Enable (1) or disable (0) support for client requests to the + * chip Fabric Provisioning server via an authenticated + * session. See also #CHIP_CONFIG_REQUIRE_AUTH. + * + * @note This configuration shall be deasserted for development + * and testing purposes only. No chip-enabled device shall + * be certified without this asserted. + * + */ +#ifndef CHIP_CONFIG_REQUIRE_AUTH_FABRIC_PROV +#define CHIP_CONFIG_REQUIRE_AUTH_FABRIC_PROV CHIP_CONFIG_REQUIRE_AUTH +#endif // CHIP_CONFIG_REQUIRE_AUTH_FABRIC_PROV + +/** + * @def CHIP_CONFIG_REQUIRE_AUTH_NETWORK_PROV + * + * @brief + * Enable (1) or disable (0) support for client requests to the + * chip Network Provisioning server via an authenticated + * session. See also #CHIP_CONFIG_REQUIRE_AUTH. + * + * @note This configuration shall be deasserted for development + * and testing purposes only. No chip-enabled device shall + * be certified without this asserted. + * + */ +#ifndef CHIP_CONFIG_REQUIRE_AUTH_NETWORK_PROV +#define CHIP_CONFIG_REQUIRE_AUTH_NETWORK_PROV CHIP_CONFIG_REQUIRE_AUTH +#endif // CHIP_CONFIG_REQUIRE_AUTH_NETWORK_PROV + +/** + * @def CHIP_CONFIG_REQUIRE_AUTH_SERVICE_PROV + * + * @brief + * Enable (1) or disable (0) support for client requests to the + * chip Service Provisioning server via an authenticated + * session. See also #CHIP_CONFIG_REQUIRE_AUTH. + * + * @note This configuration shall be deasserted for development + * and testing purposes only. No chip-enabled device shall + * be certified without this asserted. + * + */ +#ifndef CHIP_CONFIG_REQUIRE_AUTH_SERVICE_PROV +#define CHIP_CONFIG_REQUIRE_AUTH_SERVICE_PROV CHIP_CONFIG_REQUIRE_AUTH +#endif // CHIP_CONFIG_REQUIRE_AUTH_SERVICE_PROV + +/** + * @def CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT + * + * @brief + * Enable (1) or disable (0) support for the handling of chip + * Provisioning Bundles. + * + * chip Provisioning Bundles are a chip TLV payload containing + * the chip certificate, corresponding private key, and pairing + * code / entry key that a chip device would have otherwise + * received at its time of manufacture. + * + * Enable this if your family of device needs to support in-field + * provisioning (IFP). IFP for chip devices is neither generally + * supported nor recommended. + * + */ +#ifndef CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT +#define CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT 1 +#endif // CHIP_CONFIG_ENABLE_PROVISIONING_BUNDLE_SUPPORT + +/** + * @def CHIP_ERROR_LOGGING + * + * @brief + * If asserted (1), enable logging of all messages in the + * chip::Logging::LogCategory::kLogCategory_Error category. + * + */ +#ifndef CHIP_ERROR_LOGGING +#define CHIP_ERROR_LOGGING 1 +#endif // CHIP_ERROR_LOGGING + +/** + * @def CHIP_PROGRESS_LOGGING + * + * @brief + * If asserted (1), enable logging of all messages in the + * chip::Logging::LogCategory::kLogCategory_Progress category. + * + */ +#ifndef CHIP_PROGRESS_LOGGING +#define CHIP_PROGRESS_LOGGING 1 +#endif // CHIP_PROGRESS_LOGGING + +/** + * @def CHIP_DETAIL_LOGGING + * + * @brief + * If asserted (1), enable logging of all messages in the + * chip::Logging::kLogCategory_Detail category. + * + */ +#ifndef CHIP_DETAIL_LOGGING +#define CHIP_DETAIL_LOGGING 1 +#endif // CHIP_DETAIL_LOGGING + +/** + * @def CHIP_RETAIN_LOGGING + * + * @brief + * If asserted (1), enable logging of all messages in the + * chip::Logging::LogCategory::kLogCategory_Retain category. + * If not defined by the application, by default CHIP_RETAIN_LOGGING is + * remapped to CHIP_PROGRESS_LOGGING + * + */ + + +/** + * @def CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING + * + * @brief + * If asserted (1), enable logging of errors at function exit via the + * chipLogFunctError() macro. + */ +#ifndef CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING +#define CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING 0 +#endif // CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING + + +/** + * @def CHIP_CONFIG_ENABLE_CONDITION_LOGGING + * + * @brief + * If asserted (1), enable logging of failed conditions via the + * chipLogIfFalse() macro. + */ +#ifndef CHIP_CONFIG_ENABLE_CONDITION_LOGGING +#define CHIP_CONFIG_ENABLE_CONDITION_LOGGING 0 +#endif // CHIP_CONFIG_ENABLE_CONDITION_LOGGING + + +/** + * @def CHIP_CONFIG_ENABLE_SERVICE_DIRECTORY + * + * @brief + * If set to (1), use of the ServiceDirectory implementation + * is enabled. Default value is (1) or enabled. + * + * @note + * Enabling this profile allows applications using chip to + * request a connection to a particular chip service using + * a predefined service endpoint. It is relevant for + * applications that run on devices that interact with the + * Service over a direct TCP/IPv4 connection rather than those + * that use the chip Tunnel through a gateway device. For + * devices of the latter category, the Service Directory + * profile can be disabled via this compilation switch. + * + */ +#ifndef CHIP_CONFIG_ENABLE_SERVICE_DIRECTORY +#define CHIP_CONFIG_ENABLE_SERVICE_DIRECTORY 1 +#endif // CHIP_CONFIG_ENABLE_SERVICE_DIRECTORY + +/** + * @def CHIP_CONFIG_SERVICE_DIR_CONNECT_TIMEOUT_MSECS + * + * @brief + * This is the default timeout for the connect call to the + * directory server to wait for success or being notified + * of an error. + * + */ +#ifndef CHIP_CONFIG_SERVICE_DIR_CONNECT_TIMEOUT_MSECS +#define CHIP_CONFIG_SERVICE_DIR_CONNECT_TIMEOUT_MSECS (10000) +#endif // CHIP_CONFIG_SERVICE_DIR_CONNECT_TIMEOUT_MSECS + +/** + * @def CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT + * + * @brief + * The maximum amount of time, in milliseconds, that an idle inbound + * chip connection will be allowed to exist before being closed. + * + * This is a default value that can be overridden at runtime by the + * application. + * + * A value of 0 disables automatic closing of idle connections. + * + */ +#ifndef CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT +#define CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT 15000 +#endif // CHIP_CONFIG_DEFAULT_INCOMING_CONNECTION_IDLE_TIMEOUT + +/** + * @def CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT + * + * @brief + * The amount of time (in milliseconds) which a peer is given + * to respond to a message counter synchronization request. + * Depending on when the request is sent, peers may + * actually have up to twice this time. + * + */ +#ifndef CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT +#define CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT 2000 +#endif // CHIP_CONFIG_MSG_COUNTER_SYNC_RESP_TIMEOUT + +/** + * @def CHIP_CONFIG_TEST + * + * @brief + * If asserted (1), enable APIs that help implement + * unit and integration tests. + * + */ +#ifndef CHIP_CONFIG_TEST +#define CHIP_CONFIG_TEST 0 +#endif // CHIP_CONFIG_TEST + +/** + * @def CHIP_CONFIG_SHORT_ERROR_STR + * + * @brief + * If asserted (1), produce shorter error strings that only carry a + * minimum of information. + * + */ +#ifndef CHIP_CONFIG_SHORT_ERROR_STR +#define CHIP_CONFIG_SHORT_ERROR_STR 0 +#endif // CHIP_CONFIG_SHORT_ERROR_STR + +/** + * @def CHIP_CONFIG_ERROR_STR_SIZE + * + * @brief + * This defines the size of the buffer to store a formatted error string. + * If the formatting of an error string exceeds this size it will be truncated. + * + * The default size varies based on the CHIP_CONFIG_SHORT_ERROR_STR option. + * + * When CHIP_CONFIG_SHORT_ERROR_STR is 0, a large default buffer size is used + * to accommodate descriptive text summarizing the cause of the error. E.g.: + * + * "chip Error 4047 (0x00000FCF): Invalid Argument" + * + * When CHIP_CONFIG_SHORT_ERROR_STR is 1, the buffer size is set to accommodate + * a minimal error string consisting of a 10 character subsystem name followed + * by an 8 character error number, plus boilerplate. E.g.: + * + * "Error chip:0x00000FCF" + * + */ +#ifndef CHIP_CONFIG_ERROR_STR_SIZE +#if CHIP_CONFIG_SHORT_ERROR_STR +#define CHIP_CONFIG_ERROR_STR_SIZE (5 + 1 + 10 + 3 + 8 + 1) +#else // CHIP_CONFIG_SHORT_ERROR_STR +#define CHIP_CONFIG_ERROR_STR_SIZE 256 +#endif // CHIP_CONFIG_SHORT_ERROR_STR +#endif // CHIP_CONFIG_ERROR_STR_SIZE + +/** + * @def CHIP_CONFIG_CUSTOM_ERROR_FORMATTER + * + * @brief + * If asserted (1), suppress definition of the standard error formatting function + * (#FormatError()) allowing an application-specific implementation to be used. + * + */ +#ifndef CHIP_CONFIG_CUSTOM_ERROR_FORMATTER +#define CHIP_CONFIG_CUSTOM_ERROR_FORMATTER 0 +#endif // CHIP_CONFIG_CUSTOM_ERROR_FORMATTER + +/** + * @def CHIP_CONFIG_SHORT_FORM_ERROR_VALUE_FORMAT + * + * @brief + * The printf-style format string used to format error values. + * + * On some platforms, the structure of error values makes them more convenient to + * read in either hex or decimal format. This option can be used to override + * the default hex format. + * + * Note that this option only affects short-form error strings (i.e. when + * CHIP_CONFIG_SHORT_ERROR_STR == 1). Long form error strings always show both hex + * and decimal values + */ +#ifndef CHIP_CONFIG_SHORT_FORM_ERROR_VALUE_FORMAT +#define CHIP_CONFIG_SHORT_FORM_ERROR_VALUE_FORMAT "0x%08" PRIX32 +#endif // CHIP_CONFIG_SHORT_FORM_ERROR_VALUE_FORMAT + +/** + * @def CHIP_CONFIG_BLE_PKT_RESERVED_SIZE + * + * @brief + * The number of bytes that chip should reserve at the front of + * every outgoing BLE packet for the sake of the underlying BLE + * stack. + * + */ +#ifndef CHIP_CONFIG_BLE_PKT_RESERVED_SIZE +#define CHIP_CONFIG_BLE_PKT_RESERVED_SIZE 0 +#endif // CHIP_CONFIG_BLE_PKT_RESERVED_SIZE + +/** + * @def CHIP_CONFIG_ENABLE_SECURITY_DEBUG_FUNCS + * + * @brief + * Enable (1) or disable (0) support for utility functions for + * decoding and outputing information related to chip security. + * + */ +#ifndef CHIP_CONFIG_ENABLE_SECURITY_DEBUG_FUNCS +#define CHIP_CONFIG_ENABLE_SECURITY_DEBUG_FUNCS 1 +#endif // CHIP_CONFIG_ENABLE_SECURITY_DEBUG_FUNCS + +/** + * @def CHIP_CONFIG_IsPlatformErrorNonCritical(CODE) + * + * This macro checks if a platform generated error is critical and + * needs to be reported to the application/caller. The criticality + * of an error (in the context of that platform) is determined by how + * it impacts the logic flow, i.e., whether or not the current flow + * can continue despite the error or it needs to be reported back + * resulting in a potential stoppage. + * + * @note + * This is a default set of platform errors which are configured as + * non-critical from the context of that platform. Any new error that + * the platforms deem as non-critical could be added by overriding + * this default macro definition after careful thought towards its + * implication in the logic flow in that platform. + * + * @param[in] CODE The #CHIP_ERROR being checked for criticality. + * + * @return true if the error is non-critical; false otherwise. + * + */ +#ifndef CHIP_CONFIG_IsPlatformErrorNonCritical +#if CHIP_SYSTEM_CONFIG_USE_LWIP +#define _CHIP_CONFIG_IsPlatformLwIPErrorNonCritical(CODE) \ + ((CODE) == chip::System::MapErrorLwIP(ERR_RTE) || \ + (CODE) == chip::System::MapErrorLwIP(ERR_MEM)) +#else // !CHIP_SYSTEM_CONFIG_USE_LWIP +#define _CHIP_CONFIG_IsPlatformLwIPErrorNonCritical(CODE) 0 +#endif // !CHIP_SYSTEM_CONFIG_USE_LWIP + +#if CHIP_SYSTEM_CONFIG_USE_SOCKETS +#define _CHIP_CONFIG_IsPlatformPOSIXErrorNonCritical(CODE) \ + ((CODE) == chip::System::MapErrorPOSIX(EHOSTUNREACH) || \ + (CODE) == chip::System::MapErrorPOSIX(ENETUNREACH) || \ + (CODE) == chip::System::MapErrorPOSIX(EADDRNOTAVAIL) || \ + (CODE) == chip::System::MapErrorPOSIX(EPIPE)) +#else // !CHIP_SYSTEM_CONFIG_USE_SOCKETS +#define _CHIP_CONFIG_IsPlatformPOSIXErrorNonCritical(CODE) 0 +#endif // !CHIP_SYSTEM_CONFIG_USE_SOCKETS + +#define CHIP_CONFIG_IsPlatformErrorNonCritical(CODE) \ + (_CHIP_CONFIG_IsPlatformPOSIXErrorNonCritical(CODE) || \ + _CHIP_CONFIG_IsPlatformLwIPErrorNonCritical(CODE)) +#endif // CHIP_CONFIG_IsPlatformErrorNonCritical + +/** + * @def CHIP_CONFIG_WILL_OVERRIDE_PLATFORM_MATH_FUNCS + * + * @brief + * Enable (1) or disable (0) replacing math functions + * which may not be available in the standard/intrinsic library, + * and hence require special support from the platform. + * + */ +#ifndef CHIP_CONFIG_WILL_OVERRIDE_PLATFORM_MATH_FUNCS +#define CHIP_CONFIG_WILL_OVERRIDE_PLATFORM_MATH_FUNCS 0 +#endif // CHIP_CONFIG_WILL_OVERRIDE_PLATFORM_MATH_FUNCS + +/** + * @def CHIP_CONFIG_SERIALIZATION_USE_MALLOC + * + * @brief If turned on, then schema event serialization and + * deserialization will use the stdlib implementations of malloc, + * free, and realloc by default (if no other implementations have + * been provided). We will fail at compile time if the stdlib + * implementations are not present. + */ +#ifndef CHIP_CONFIG_SERIALIZATION_USE_MALLOC +#define CHIP_CONFIG_SERIALIZATION_USE_MALLOC 0 +#endif + +/** + * @def CHIP_CONFIG_SERIALIZATION_DEBUG_LOGGING + * + * @brief Enable debug logging for the serialization/deserialization APIs. + */ +#ifndef CHIP_CONFIG_SERIALIZATION_DEBUG_LOGGING +#define CHIP_CONFIG_SERIALIZATION_DEBUG_LOGGING 0 +#endif + +/** + * @def CHIP_CONFIG_SERIALIZATION_ENABLE_DESERIALIZATION + * + * @brief Enable deserialization as well as serialization APIs. We + * make deserialization configurable because it requires some extra + * memory that a highly resource-constrained platform could preserve + * if it doesn't consume WDM events or otherwise has no need to + * deserialize. + */ +#ifndef CHIP_CONFIG_SERIALIZATION_ENABLE_DESERIALIZATION +#define CHIP_CONFIG_SERIALIZATION_ENABLE_DESERIALIZATION 1 +#endif + +/** + * @def CHIP_CONFIG_SERIALIZATION_LOG_FLOATS + * + * @brief Enable debug logging of floats and doubles for the + * serialization/deserialization APIs. Not all platforms + * support these types, and may not compile if there are + * any references to them. Only matters if + * CHIP_CONFIG_SERIALIZATION_DEBUG_LOGGING is enabled. + */ +#ifndef CHIP_CONFIG_SERIALIZATION_LOG_FLOATS +#define CHIP_CONFIG_SERIALIZATION_LOG_FLOATS 1 +#endif + +/** + * @def CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE + * + * @brief + * The data type used to represent the key of a persistedly-stored + * key/value pair. + */ +#ifndef CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE +#define CHIP_CONFIG_PERSISTED_STORAGE_KEY_TYPE const char * +#endif + +/** + * @def CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID + * + * @brief + * The group key message counter persisted storage Id. + * + */ +#ifndef CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID "EncMsgCntr" +#endif // CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_ID + +/** + * @def CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_EPOCH + * + * @brief + * The group key message counter persisted storage epoch. + * + */ +#ifndef CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_EPOCH +#define CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_EPOCH 0x1000 +#endif // CHIP_CONFIG_PERSISTED_STORAGE_ENC_MSG_CNTR_EPOCH + +/** + * @def CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH + * + * @brief The maximum length of the key in a key/value pair + * stored in the platform's persistent storage. + */ +#ifndef CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_KEY_LENGTH 16 +#endif + +/** + * @def CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH + * + * @brief The maximum length of the value in a key/value pair + * stored in the platform's persistent storage. + */ +#ifndef CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH +#define CHIP_CONFIG_PERSISTED_STORAGE_MAX_VALUE_LENGTH 256 +#endif + +/** + * @def CHIP_CONFIG_PERSISTED_COUNTER_DEBUG_LOGGING + * + * @brief Enable debug logging for the PersistedCounter API. + */ +#ifndef CHIP_CONFIG_PERSISTED_COUNTER_DEBUG_LOGGING +#define CHIP_CONFIG_PERSISTED_COUNTER_DEBUG_LOGGING 0 +#endif + +/** + * @def CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS + * + * @brief Enable verbose debug logging for the EventLogging API. + * This setting is incompatible with platforms that route console + * logs into event logging, as it would result in circular logic. + */ +#ifndef CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS +#define CHIP_CONFIG_EVENT_LOGGING_VERBOSE_DEBUG_LOGS 1 +#endif + +/** + * @def CHIP_CONFIG_ENABLE_ARG_PARSER + * + * @brief Enable support functions for parsing command-line arguments + */ +#ifndef CHIP_CONFIG_ENABLE_ARG_PARSER +#define CHIP_CONFIG_ENABLE_ARG_PARSER 0 +#endif + +/** + * @def CHIP_CONFIG_ENABLE_ARG_PARSER_SANTIY_CHECK + * + * @brief Enable santiy checking of command-line argument definitions. + */ +#ifndef CHIP_CONFIG_ENABLE_ARG_PARSER_SANTIY_CHECK +#define CHIP_CONFIG_ENABLE_ARG_PARSER_SANTIY_CHECK 1 +#endif + +/** + * @def CHIP_CONFIG_SERVICE_PROV_RESPONSE_TIMEOUT + * + * @brief + * The amount of time (in milliseconds) which the service is given + * to respond to a pair device to account request. + */ +#ifndef CHIP_CONFIG_SERVICE_PROV_RESPONSE_TIMEOUT +#define CHIP_CONFIG_SERVICE_PROV_RESPONSE_TIMEOUT 60000 +#endif + +/** + * @def CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE + * + * @brief + * Enable (1) or disable (0) support for the depricated + * version of AddNetwork() message in the Network Provisioning + * profile. + * This option should be enabled to support pairing with Nest + * legacy devices that don't have latest SW. + * + */ +#ifndef CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE +#define CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE 1 +#endif // CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE + +/** + * @def CHIP_CONFIG_ALWAYS_USE_LEGACY_ADD_NETWORK_MESSAGE + * + * @brief + * Enable (1) or disable (0) the exclusive use of the depricated + * version of AddNetwork() message in the Network Provisioning + * profile. + * This option should be enabled when exclusively pairing with Nest + * legacy devices that don't have latest SW. + * This option requires that + * CHIP_CONFIG_SUPPORT_LEGACY_ADD_NETWORK_MESSAGE is enabled. + * + */ +#ifndef CHIP_CONFIG_ALWAYS_USE_LEGACY_ADD_NETWORK_MESSAGE +#define CHIP_CONFIG_ALWAYS_USE_LEGACY_ADD_NETWORK_MESSAGE 0 +#endif // CHIP_CONFIG_ALWAYS_USE_LEGACY_ADD_NETWORK_MESSAGE + +/** + * @def CHIP_CONFIG_ENABLE_IFJ_SERVICE_FABRIC_JOIN + * + * @brief Enable the Service Provisioning profile message + * for notification of successful in-field joining of the + * chip fabric. + */ +#ifndef CHIP_CONFIG_ENABLE_IFJ_SERVICE_FABRIC_JOIN +#define CHIP_CONFIG_ENABLE_IFJ_SERVICE_FABRIC_JOIN 0 +#endif // CHIP_CONFIG_ENABLE_IFJ_SERVICE_FABRIC_JOIN + +/** + * @def CHIP_NON_PRODUCTION_MARKER + * + * @brief Defines the name of a mark symbol whose presence signals that the chip code + * includes development/testing features that should never be used in production contexts. + */ +#ifndef CHIP_NON_PRODUCTION_MARKER +#if (CHIP_CONFIG_SECURITY_TEST_MODE || \ + CHIP_CONFIG_SUPPORT_PASE_CONFIG0_TEST_ONLY || \ + CHIP_CONFIG_SUPPORT_PASSCODE_CONFIG1_TEST_ONLY || \ + (!CHIP_CONFIG_REQUIRE_AUTH) || \ + CHIP_FUZZING_ENABLED) +#define CHIP_NON_PRODUCTION_MARKER WARNING__DO_NOT_SHIP__CONTAINS_NON_PRODUCTION_CHIP_CODE +#endif +#endif + +#ifdef CHIP_NON_PRODUCTION_MARKER +extern const char CHIP_NON_PRODUCTION_MARKER[]; +#endif + +// clang-format on + +#endif /* CHIP_CONFIG_H_ */ diff --git a/src/lib/core/CHIPCore.h b/src/lib/core/CHIPCore.h new file mode 100644 index 00000000000000..9e5cd4c90e5783 --- /dev/null +++ b/src/lib/core/CHIPCore.h @@ -0,0 +1,61 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file is the master "umbrella" include file for the core + * chip library. + * + */ + +#ifndef CHIPCORE_H_ +#define CHIPCORE_H_ + +#include +/* +#include + +#if CONFIG_NETWORK_LAYER_BLE +#include +#endif // CONFIG_NETWORK_LAYER_BLE + +#include +*/ +#define CHIP_CORE_IDENTITY "chip-core" +#define CHIP_CORE_PREFIX CHIP_CORE_IDENTITY ": " + +namespace chip { +/* +#if CONFIG_NETWORK_LAYER_BLE +using namespace ::Ble; +#endif // CONFIG_NETWORK_LAYER_BLE + +using namespace ::Inet; +*/ +} + +#include +/* +#include "core/CHIPKeyIds.h" +#include "core/CHIPFabricState.h" +#include "core/CHIPMessageLayer.h" +#include "core/CHIPBinding.h" +#include "core/CHIPExchangeMgr.h" +#include "core/CHIPSecurityMgr.h" +#include "core/CHIPGlobals.h" +*/ +#endif /* CHIPCORE_H_ */ diff --git a/src/lib/core/CHIPError.cpp b/src/lib/core/CHIPError.cpp new file mode 100644 index 00000000000000..7e9dba528648df --- /dev/null +++ b/src/lib/core/CHIPError.cpp @@ -0,0 +1,240 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file contains functions for working with CHIP errors. + */ + +#include + +#include +#include + +namespace chip { + +/** + * Given a CHIP error, returns a human-readable NULL-terminated C string + * describing the error. + * + * @param[in] buf Buffer into which the error string will be placed. + * @param[in] bufSize Size of the supplied buffer in bytes. + * @param[in] err The error to be described. + * + * @return true If a description string was written into the supplied buffer. + * @return false If the supplied error was not a CHIP error. + * + */ +bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err) +{ + const char * desc = NULL; + + if (err < CHIP_ERROR_MIN || err > CHIP_ERROR_MAX) + { + return false; + } + +#if !CHIP_CONFIG_SHORT_ERROR_STR + switch (err) + { + case CHIP_ERROR_TOO_MANY_CONNECTIONS : desc = "Too many connections"; break; + case CHIP_ERROR_SENDING_BLOCKED : desc = "Sending blocked"; break; + case CHIP_ERROR_CONNECTION_ABORTED : desc = "Connection aborted"; break; + case CHIP_ERROR_INCORRECT_STATE : desc = "Incorrect state"; break; + case CHIP_ERROR_MESSAGE_TOO_LONG : desc = "Message too long"; break; + case CHIP_ERROR_UNSUPPORTED_EXCHANGE_VERSION : desc = "Unsupported exchange version"; break; + case CHIP_ERROR_TOO_MANY_UNSOLICITED_MESSAGE_HANDLERS : desc = "Too many unsolicited message handlers"; break; + case CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER : desc = "No unsolicited message handler"; break; + case CHIP_ERROR_NO_CONNECTION_HANDLER : desc = "No connection handler"; break; + case CHIP_ERROR_TOO_MANY_PEER_NODES : desc = "Too many peer nodes"; break; + case CHIP_ERROR_NO_MEMORY : desc = "No memory"; break; + case CHIP_ERROR_NO_MESSAGE_HANDLER : desc = "No message handler"; break; + case CHIP_ERROR_MESSAGE_INCOMPLETE : desc = "Message incomplete"; break; + case CHIP_ERROR_DATA_NOT_ALIGNED : desc = "Data not aligned"; break; + case CHIP_ERROR_UNKNOWN_KEY_TYPE : desc = "Unknown key type"; break; + case CHIP_ERROR_KEY_NOT_FOUND : desc = "Key not found"; break; + case CHIP_ERROR_WRONG_ENCRYPTION_TYPE : desc = "Wrong encryption type"; break; + case CHIP_ERROR_TOO_MANY_KEYS : desc = "Too many keys"; break; + case CHIP_ERROR_INTEGRITY_CHECK_FAILED : desc = "Integrity check failed"; break; + case CHIP_ERROR_INVALID_SIGNATURE : desc = "Invalid signature"; break; + case CHIP_ERROR_UNSUPPORTED_MESSAGE_VERSION : desc = "Unsupported message version"; break; + case CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE : desc = "Unsupported encryption type"; break; + case CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE : desc = "Unsupported signature type"; break; + case CHIP_ERROR_INVALID_MESSAGE_LENGTH : desc = "Invalid message length"; break; + case CHIP_ERROR_BUFFER_TOO_SMALL : desc = "Buffer too small"; break; + case CHIP_ERROR_DUPLICATE_KEY_ID : desc = "Duplicate key id"; break; + case CHIP_ERROR_WRONG_KEY_TYPE : desc = "Wrong key type"; break; + case CHIP_ERROR_WELL_UNINITIALIZED : desc = "Well uninitialized"; break; + case CHIP_ERROR_WELL_EMPTY : desc = "Well empty"; break; + case CHIP_ERROR_INVALID_STRING_LENGTH : desc = "Invalid string length"; break; + case CHIP_ERROR_INVALID_LIST_LENGTH : desc = "invalid list length"; break; + case CHIP_ERROR_INVALID_INTEGRITY_TYPE : desc = "Invalid integrity type"; break; + case CHIP_END_OF_TLV : desc = "End of TLV"; break; + case CHIP_ERROR_TLV_UNDERRUN : desc = "TLV underrun"; break; + case CHIP_ERROR_INVALID_TLV_ELEMENT : desc = "Invalid TLV element"; break; + case CHIP_ERROR_INVALID_TLV_TAG : desc = "Invalid TLV tag"; break; + case CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG : desc = "Unknown implicit TLV tag"; break; + case CHIP_ERROR_WRONG_TLV_TYPE : desc = "Wrong TLV type"; break; + case CHIP_ERROR_TLV_CONTAINER_OPEN : desc = "TLV container open"; break; + case CHIP_ERROR_INVALID_TRANSFER_MODE : desc = "Invalid transfer mode"; break; + case CHIP_ERROR_INVALID_PROFILE_ID : desc = "Invalid profile id"; break; + case CHIP_ERROR_INVALID_MESSAGE_TYPE : desc = "Invalid message type"; break; + case CHIP_ERROR_UNEXPECTED_TLV_ELEMENT : desc = "Unexpected TLV element"; break; + case CHIP_ERROR_STATUS_REPORT_RECEIVED : desc = "Status Report received from peer"; break; + case CHIP_ERROR_NOT_IMPLEMENTED : desc = "Not Implemented"; break; + case CHIP_ERROR_INVALID_ADDRESS : desc = "Invalid address"; break; + case CHIP_ERROR_INVALID_ARGUMENT : desc = "Invalid argument"; break; + case CHIP_ERROR_TLV_TAG_NOT_FOUND : desc = "TLV tag not found"; break; + + case CHIP_ERROR_INVALID_PATH_LIST : desc = "Invalid TLV path list"; break; + case CHIP_ERROR_INVALID_DATA_LIST : desc = "Invalid TLV data list"; break; + case CHIP_ERROR_TRANSACTION_CANCELED : desc = "Transaction canceled"; break; + case CHIP_ERROR_LISTENER_ALREADY_STARTED : desc = "Listener already started"; break; + case CHIP_ERROR_LISTENER_ALREADY_STOPPED : desc = "Listener already stopped"; break; + case CHIP_ERROR_UNKNOWN_TOPIC : desc = "Unknown Topic"; break; + + case CHIP_ERROR_TIMEOUT : desc = "Timeout"; break; + case CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR : desc = "Invalid device descriptor"; break; + case CHIP_ERROR_UNSUPPORTED_DEVICE_DESCRIPTOR_VERSION : desc = "Unsupported device descriptor version"; break; + case CHIP_END_OF_INPUT : desc = "End of input"; break; + case CHIP_ERROR_RATE_LIMIT_EXCEEDED : desc = "Rate limit exceeded"; break; + case CHIP_ERROR_SECURITY_MANAGER_BUSY : desc = "Security manager busy"; break; + case CHIP_ERROR_INVALID_PASE_PARAMETER : desc = "Invalid PASE parameter"; break; + case CHIP_ERROR_PASE_SUPPORTS_ONLY_CONFIG1 : desc = "PASE supports only Config1"; break; + case CHIP_ERROR_NO_COMMON_PASE_CONFIGURATIONS : desc = "No supported PASE configurations in common"; break; + case CHIP_ERROR_INVALID_PASE_CONFIGURATION : desc = "Invalid PASE configuration"; break; + case CHIP_ERROR_KEY_CONFIRMATION_FAILED : desc = "Key confirmation failed"; break; + case CHIP_ERROR_INVALID_USE_OF_SESSION_KEY : desc = "Invalid use of session key"; break; + case CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY : desc = "Connection closed unexpectedly"; break; + case CHIP_ERROR_MISSING_TLV_ELEMENT : desc = "Missing TLV element"; break; + case CHIP_ERROR_RANDOM_DATA_UNAVAILABLE : desc = "Random data unavailable"; break; + case CHIP_ERROR_UNSUPPORTED_HOST_PORT_ELEMENT : desc = "Unsupported type in host/port list"; break; + case CHIP_ERROR_INVALID_HOST_SUFFIX_INDEX : desc = "Invalid suffix index in host/port list"; break; + case CHIP_ERROR_HOST_PORT_LIST_EMPTY : desc = "Host/port empty"; break; + case CHIP_ERROR_UNSUPPORTED_AUTH_MODE : desc = "Unsupported authentication mode"; break; + + case CHIP_ERROR_INVALID_SERVICE_EP : desc = "Invalid service endpoint"; break; + case CHIP_ERROR_INVALID_DIRECTORY_ENTRY_TYPE : desc = "Invalid directory entry type"; break; + case CHIP_ERROR_FORCED_RESET : desc = "Service manager forced reset"; break; + case CHIP_ERROR_NO_ENDPOINT : desc = "No endpoint was available to send the message"; break; + case CHIP_ERROR_INVALID_DESTINATION_NODE_ID : desc = "Invalid destination node id"; break; + case CHIP_ERROR_NOT_CONNECTED : desc = "Not connected"; break; + case CHIP_ERROR_NO_SW_UPDATE_AVAILABLE : desc = "No SW update available"; break; + + case CHIP_ERROR_CA_CERT_NOT_FOUND : desc = "CA certificate not found"; break; + case CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED : desc = "Certificate path length constraint exceeded"; break; + case CHIP_ERROR_CERT_PATH_TOO_LONG : desc = "Certificate path too long"; break; + case CHIP_ERROR_CERT_USAGE_NOT_ALLOWED : desc = "Requested certificate usage is not allowed"; break; + case CHIP_ERROR_CERT_EXPIRED : desc = "Certificate expired"; break; + case CHIP_ERROR_CERT_NOT_VALID_YET : desc = "Certificate not yet valid"; break; + case CHIP_ERROR_UNSUPPORTED_CERT_FORMAT : desc = "Unsupported certificate format"; break; + case CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE : desc = "Unsupported elliptic curve"; break; + case CHIP_CERT_NOT_USED : desc = "Certificate was not used in chain validation"; break; + case CHIP_ERROR_CERT_NOT_FOUND : desc = "Certificate not found"; break; + case CHIP_ERROR_INVALID_CASE_PARAMETER : desc = "Invalid CASE parameter"; break; + case CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION : desc = "Unsupported CASE configuration"; break; + case CHIP_ERROR_CERT_LOAD_FAIL : desc = "Unable to load certificate"; break; + case CHIP_ERROR_CERT_NOT_TRUSTED : desc = "Certificate not trusted"; break; + case CHIP_ERROR_INVALID_ACCESS_TOKEN : desc = "Invalid access token"; break; + case CHIP_ERROR_WRONG_CERT_SUBJECT : desc = "Wrong certificate subject"; break; + case CHIP_ERROR_WRONG_NODE_ID : desc = "Wrong node ID"; break; + case CHIP_ERROR_CONN_ACCEPTED_ON_WRONG_PORT : desc = "Connection accepted on wrong port"; break; + case CHIP_ERROR_CALLBACK_REPLACED : desc = "Application callback replaced"; break; + case CHIP_ERROR_NO_CASE_AUTH_DELEGATE : desc = "No CASE auth delegate set"; break; + case CHIP_ERROR_DEVICE_LOCATE_TIMEOUT : desc = "Timeout attempting to locate device"; break; + case CHIP_ERROR_DEVICE_CONNECT_TIMEOUT : desc = "Timeout connecting to device"; break; + case CHIP_ERROR_DEVICE_AUTH_TIMEOUT : desc = "Timeout authenticating device"; break; + case CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED : desc = "Message not acknowledged after max retries"; break; + case CHIP_ERROR_RETRANS_TABLE_FULL : desc = "Retransmit Table is already full"; break; + case CHIP_ERROR_INVALID_ACK_ID : desc = "Invalid Acknowledgment Id"; break; + case CHIP_ERROR_SEND_THROTTLED : desc = "Sending to peer is throttled on this Exchange"; break; + case CHIP_ERROR_WRONG_MSG_VERSION_FOR_EXCHANGE : desc = "Message version not supported by current exchange context"; break; + case CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE : desc = "Required feature not supported by this configuration"; break; + case CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR : desc = "Unsolicited msg with originator bit clear"; break; + case CHIP_ERROR_UNSUPPORTED_TUNNEL_VERSION : desc = "Unsupported Tunnel version"; break; + case CHIP_ERROR_INVALID_FABRIC_ID : desc = "Invalid Fabric Id"; break; + case CHIP_ERROR_TUNNEL_NEXTHOP_TABLE_FULL : desc = "Local tunnel nexthop table full"; break; + case CHIP_ERROR_TUNNEL_SERVICE_QUEUE_FULL : desc = "Service queue full"; break; + case CHIP_ERROR_TUNNEL_PEER_ENTRY_NOT_FOUND : desc = "Shortcut Tunnel peer entry not found"; break; + case CHIP_ERROR_TUNNEL_FORCE_ABORT : desc = "Forced Tunnel Abort."; break; + case CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED : desc = "DRBG entropy source failed to generate entropy data"; break; + case CHIP_ERROR_NO_TAKE_AUTH_DELEGATE : desc = "No TAKE auth delegate set"; break; + case CHIP_ERROR_TAKE_RECONFIGURE_REQUIRED : desc = "TAKE requires a reconfigure"; break; + case CHIP_ERROR_TAKE_REAUTH_POSSIBLE : desc = "TAKE can do a reauthentication"; break; + case CHIP_ERROR_INVALID_TAKE_PARAMETER : desc = "TAKE received an invalid parameter"; break; + case CHIP_ERROR_UNSUPPORTED_TAKE_CONFIGURATION : desc = "TAKE Unsupported configuration"; break; + case CHIP_ERROR_TAKE_TOKEN_IDENTIFICATION_FAILED : desc = "TAKE token identification failed"; break; + case CHIP_ERROR_INVALID_TOKENPAIRINGBUNDLE : desc = "Invalid Token Pairing Bundle"; break; + case CHIP_ERROR_UNSUPPORTED_TOKENPAIRINGBUNDLE_VERSION : desc = "Unsupported Token Pairing Bundle version"; break; + case CHIP_ERROR_KEY_NOT_FOUND_FROM_PEER : desc = "Key not found error code received from peer"; break; + case CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER : desc = "Wrong encryption type error code received from peer"; break; + case CHIP_ERROR_UNKNOWN_KEY_TYPE_FROM_PEER : desc = "Unknown key type error code received from peer"; break; + case CHIP_ERROR_INVALID_USE_OF_SESSION_KEY_FROM_PEER : desc = "Invalid use of session key error code received from peer"; break; + case CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE_FROM_PEER : desc = "Unsupported encryption type error code received from peer"; break; + case CHIP_ERROR_INTERNAL_KEY_ERROR_FROM_PEER : desc = "Internal key error code received from peer"; break; + case CHIP_ERROR_INVALID_KEY_ID : desc = "Invalid key identifier"; break; + case CHIP_ERROR_INVALID_TIME : desc = "Valid time value is not available"; break; + case CHIP_ERROR_LOCKING_FAILURE : desc = "Failure to lock/unlock OS-provided lock"; break; + case CHIP_ERROR_UNSUPPORTED_PASSCODE_CONFIG : desc = "Unsupported passcode encryption configuration."; break; + case CHIP_ERROR_PASSCODE_AUTHENTICATION_FAILED : desc = "Passcode authentication failed."; break; + case CHIP_ERROR_PASSCODE_FINGERPRINT_FAILED : desc = "Passcode fingerprint failed."; break; + case CHIP_ERROR_SERIALIZATION_ELEMENT_NULL : desc = "Element requested is null."; break; + case CHIP_ERROR_WRONG_CERT_SIGNATURE_ALGORITHM : desc = "Certificate not signed with required signature algorithm"; break; + case CHIP_ERROR_WRONG_CHIP_SIGNATURE_ALGORITHM : desc = "CHIP signature not signed with required signature algorithm"; break; + case CHIP_ERROR_WDM_SCHEMA_MISMATCH : desc = "Schema mismatch in WDM."; break; + case CHIP_ERROR_INVALID_INTEGER_VALUE : desc = "Invalid integer value."; break; + case CHIP_ERROR_TOO_MANY_CASE_RECONFIGURATIONS : desc = "Too many CASE reconfigurations were received."; break; + case CHIP_ERROR_INVALID_MESSAGE_FLAG : desc = "Invalid message flag."; break; + case CHIP_ERROR_KEY_EXPORT_RECONFIGURE_REQUIRED : desc = "Key export protocol required to reconfigure."; break; + case CHIP_ERROR_NO_COMMON_KEY_EXPORT_CONFIGURATIONS : desc = "No supported key export protocol configurations in common"; break; + case CHIP_ERROR_INVALID_KEY_EXPORT_CONFIGURATION : desc = "Invalid key export protocol configuration"; break; + case CHIP_ERROR_NO_KEY_EXPORT_DELEGATE : desc = "No key export protocol delegate set"; break; + case CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_REQUEST : desc = "Unauthorized key export request"; break; + case CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_RESPONSE : desc = "Unauthorized key export response"; break; + case CHIP_ERROR_EXPORTED_KEY_AUTHENTICATION_FAILED : desc = "Exported key authentication failed"; break; + case CHIP_ERROR_TOO_MANY_SHARED_SESSION_END_NODES : desc = "Too many shared session end nodes"; break; + case CHIP_ERROR_WDM_MALFORMED_DATA_ELEMENT : desc = "Malformed WDM DataElement"; break; + case CHIP_ERROR_WRONG_CERT_TYPE : desc = "Wrong certificate type"; break; + case CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED : desc = "Default event handler not called"; break; + case CHIP_ERROR_PERSISTED_STORAGE_FAIL : desc = "Persisted storage failed"; break; + case CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND : desc = "Value not found in the persisted storage"; break; + case CHIP_ERROR_PROFILE_STRING_CONTEXT_ALREADY_REGISTERED : desc = "String context already registered"; break; + case CHIP_ERROR_PROFILE_STRING_CONTEXT_NOT_REGISTERED : desc = "String context not registered"; break; + case CHIP_ERROR_INCOMPATIBLE_SCHEMA_VERSION : desc = "Incompatible data schema version"; break; + case CHIP_ERROR_TUNNEL_ROUTING_RESTRICTED : desc = "Restricted Routing: Border Routing disabled"; break; + case CHIP_ERROR_TUNNEL_RESET_RECONNECT_ALREADY_ARMED : desc = "The Reset reconnect timer is already armed"; break; + case CHIP_ERROR_MISMATCH_UPDATE_REQUIRED_VERSION : desc = "Update Required Version mismatch"; break; + case CHIP_ERROR_WDM_MALFORMED_STATUS_ELEMENT : desc = "Status Element in WDM update is malformed"; break; + case CHIP_ERROR_WDM_SUBSCRIPTIONLESS_NOTIFY_PARTIAL : desc = "The WDM Subscriptionless Notify is partial"; break; + case CHIP_ERROR_ACCESS_DENIED : desc = "The CHIP message is not granted access"; break; + case CHIP_ERROR_UNKNOWN_RESOURCE_ID : desc = "Unknown resource ID"; break; + case CHIP_ERROR_WDM_MALFORMED_UPDATE_RESPONSE : desc = "Malformed WDM Update response"; break; + case CHIP_ERROR_WDM_VERSION_MISMATCH : desc = "The conditional update of a WDM path failed for a version mismatch"; break; + case CHIP_ERROR_WDM_POTENTIAL_DATA_LOSS : desc = "A potential data loss was detected in a WDM Trait Instance"; break; + case CHIP_ERROR_UNSUPPORTED_THREAD_NETWORK_CREATE : desc = "Legacy device doesn't support standalone Thread network creation"; break; + case CHIP_ERROR_WDM_INCONSISTENT_CONDITIONALITY : desc = "The Trait Instance is already being updated with a different conditionality"; break; + case CHIP_ERROR_WDM_LOCAL_DATA_INCONSISTENT : desc = "The local data does not match any known version of the Trait Instance"; break; + case CHIP_ERROR_WDM_PATH_STORE_FULL : desc = "A WDM TraitPath store is full"; break; + } +#endif // !CHIP_CONFIG_SHORT_ERROR_STR + + FormatError(buf, bufSize, "CHIP", err, desc); + + return true; +} + +} // namespace chip diff --git a/src/lib/core/CHIPError.h b/src/lib/core/CHIPError.h new file mode 100644 index 00000000000000..a25f2f87b98ddf --- /dev/null +++ b/src/lib/core/CHIPError.h @@ -0,0 +1,1747 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines error constants for the CHIP core + * subsystem. + * + * Error types, ranges, and mappings overrides may be made by + * defining the appropriate CHIP_CONFIG_* or _CHIP_CONFIG_* + * macros. + * + * NOTE WELL: On some platforms, this header is included by C-language programs. + * + */ + +#ifndef CHIP_ERROR_H +#define CHIP_ERROR_H + +#include +// clang-format off + +/** + * @def CHIP_NO_ERROR + * + * @brief + * This defines the CHIP error code for success or no error. + * This value may be configured via #CHIP_CONFIG_NO_ERROR." + * + */ +#define CHIP_NO_ERROR CHIP_CONFIG_NO_ERROR + +/** + * @def CHIP_ERROR_MIN + * + * @brief + * This defines the bottom or minimum CHIP error number range. + * This value may be configured via #CHIP_CONFIG_ERROR_MIN. + * + */ +#define CHIP_ERROR_MIN CHIP_CONFIG_ERROR_MIN + +/** + * @def CHIP_ERROR_MAX + * + * @brief + * This defines the top or maximum CHIP error number range. + * This value may be configured via #CHIP_CONFIG_ERROR_MAX. + * + */ +#define CHIP_ERROR_MAX CHIP_CONFIG_ERROR_MAX + +/** + * @def _CHIP_ERROR(e) + * + * @brief + * This defines a mapping function for CHIP errors that allows + * mapping such errors into a platform- or system-specific range. + * This function may be configured via #_CHIP_CONFIG_ERROR(e). + * + * @param[in] e The CHIP error to map. + * + * @return The mapped CHIP error. + * + * + */ +#define _CHIP_ERROR(e) _CHIP_CONFIG_ERROR(e) + +/** + * The basic type for all CHIP errors. + * + * @brief + * This is defined to a platform- or system-specific type. + * + */ +typedef CHIP_CONFIG_ERROR_TYPE CHIP_ERROR; + +/** + * @name Error Definitions + * + * @{ + */ + +/** + * @def CHIP_ERROR_TOO_MANY_CONNECTIONS + * + * @brief + * The attempt to allocate a connection object failed because too many + * connections exist. + * + */ +#define CHIP_ERROR_TOO_MANY_CONNECTIONS _CHIP_ERROR(0) + +/** + * @def CHIP_ERROR_SENDING_BLOCKED + * + * @brief + * A message exceeds the sent limit. + * + */ +#define CHIP_ERROR_SENDING_BLOCKED _CHIP_ERROR(1) + +/** + * @def CHIP_ERROR_CONNECTION_ABORTED + * + * @brief + * A connection has been aborted. + * + */ +#define CHIP_ERROR_CONNECTION_ABORTED _CHIP_ERROR(2) + +/** + * @def CHIP_ERROR_INCORRECT_STATE + * + * @brief + * An unexpected state was encountered. + * + */ +#define CHIP_ERROR_INCORRECT_STATE _CHIP_ERROR(3) + +/** + * @def CHIP_ERROR_MESSAGE_TOO_LONG + * + * @brief + * A message is too long. + * + */ +#define CHIP_ERROR_MESSAGE_TOO_LONG _CHIP_ERROR(4) + +/** + * @def CHIP_ERROR_UNSUPPORTED_EXCHANGE_VERSION + * + * @brief + * An exchange version is not supported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_EXCHANGE_VERSION _CHIP_ERROR(5) + +/** + * @def CHIP_ERROR_TOO_MANY_UNSOLICITED_MESSAGE_HANDLERS + * + * @brief + * The attempt to register an unsolicited message handler failed because the + * unsolicited message handler pool is full. + * + */ +#define CHIP_ERROR_TOO_MANY_UNSOLICITED_MESSAGE_HANDLERS _CHIP_ERROR(6) + +/** + * @def CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER + * + * @brief + * The attempt to unregister an unsolicited message handler failed because + * the target handler was not found in the unsolicited message handler pool. + * + */ +#define CHIP_ERROR_NO_UNSOLICITED_MESSAGE_HANDLER _CHIP_ERROR(7) + +/** + * @def CHIP_ERROR_NO_CONNECTION_HANDLER + * + * @brief + * No callback has been registered for handling a connection. + * + */ +#define CHIP_ERROR_NO_CONNECTION_HANDLER _CHIP_ERROR(8) + +/** + * @def CHIP_ERROR_TOO_MANY_PEER_NODES + * + * @brief + * The number of peer nodes exceeds the maximum limit of a local node. + * + */ +#define CHIP_ERROR_TOO_MANY_PEER_NODES _CHIP_ERROR(9) + +/** + * @def CHIP_ERROR_NO_MEMORY + * + * @brief + * The attempt to allocate a buffer or object failed due to a lack of memory. + * + */ +#define CHIP_ERROR_NO_MEMORY _CHIP_ERROR(11) + +/** + * @def CHIP_ERROR_NO_MESSAGE_HANDLER + * + * @brief + * No callback has been registered for handling a message. + * + */ +#define CHIP_ERROR_NO_MESSAGE_HANDLER _CHIP_ERROR(12) + +/** + * @def CHIP_ERROR_MESSAGE_INCOMPLETE + * + * @brief + * A message is incomplete. + * + */ +#define CHIP_ERROR_MESSAGE_INCOMPLETE _CHIP_ERROR(13) + +/** + * @def CHIP_ERROR_DATA_NOT_ALIGNED + * + * @brief + * The data is not aligned. + * + */ +#define CHIP_ERROR_DATA_NOT_ALIGNED _CHIP_ERROR(14) + +/** + * @def CHIP_ERROR_UNKNOWN_KEY_TYPE + * + * @brief + * The encryption key type is unknown. + * + */ +#define CHIP_ERROR_UNKNOWN_KEY_TYPE _CHIP_ERROR(15) + +/** + * @def CHIP_ERROR_KEY_NOT_FOUND + * + * @brief + * The encryption key is not found. + * + */ +#define CHIP_ERROR_KEY_NOT_FOUND _CHIP_ERROR(16) + +/** + * @def CHIP_ERROR_WRONG_ENCRYPTION_TYPE + * + * @brief + * The encryption type is incorrect for the specified key. + * + */ +#define CHIP_ERROR_WRONG_ENCRYPTION_TYPE _CHIP_ERROR(17) + +/** + * @def CHIP_ERROR_TOO_MANY_KEYS + * + * @brief + * The attempt to allocate a key failed because the number of active keys + * exceeds the maximum limit. + * + */ +#define CHIP_ERROR_TOO_MANY_KEYS _CHIP_ERROR(18) + +/** + * @def CHIP_ERROR_INTEGRITY_CHECK_FAILED + * + * @brief + * The integrity check in the message does not match the expected integrity + * check. + * + */ +#define CHIP_ERROR_INTEGRITY_CHECK_FAILED _CHIP_ERROR(19) + +/** + * @def CHIP_ERROR_INVALID_SIGNATURE + * + * @brief + * Invalid signature. + * + */ +#define CHIP_ERROR_INVALID_SIGNATURE _CHIP_ERROR(20) + +/** + * @def CHIP_ERROR_UNSUPPORTED_MESSAGE_VERSION + * + * @brief + * A message version is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_MESSAGE_VERSION _CHIP_ERROR(21) + +/** + * @def CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE + * + * @brief + * An encryption type is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE _CHIP_ERROR(22) + +/** + * @def CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE + * + * @brief + * A signature type is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_SIGNATURE_TYPE _CHIP_ERROR(23) + +/** + * @def CHIP_ERROR_INVALID_MESSAGE_LENGTH + * + * @brief + * A message length is invalid. + * + */ +#define CHIP_ERROR_INVALID_MESSAGE_LENGTH _CHIP_ERROR(24) + +/** + * @def CHIP_ERROR_BUFFER_TOO_SMALL + * + * @brief + * A buffer is too small. + * + */ +#define CHIP_ERROR_BUFFER_TOO_SMALL _CHIP_ERROR(25) + +/** + * @def CHIP_ERROR_DUPLICATE_KEY_ID + * + * @brief + * A key id is duplicate. + * + */ +#define CHIP_ERROR_DUPLICATE_KEY_ID _CHIP_ERROR(26) + +/** + * @def CHIP_ERROR_WRONG_KEY_TYPE + * + * @brief + * A key type does not match the expected key type. + * + */ +#define CHIP_ERROR_WRONG_KEY_TYPE _CHIP_ERROR(27) + +/** + * @def CHIP_ERROR_WELL_UNINITIALIZED + * + * @brief + * A requested object is uninitialized. + * + */ +#define CHIP_ERROR_WELL_UNINITIALIZED _CHIP_ERROR(28) + +/** + * @def CHIP_ERROR_WELL_EMPTY + * + * @brief + * A requested object is empty. + * + */ +#define CHIP_ERROR_WELL_EMPTY _CHIP_ERROR(29) + +/** + * @def CHIP_ERROR_INVALID_STRING_LENGTH + * + * @brief + * A string length is invalid. + * + */ +#define CHIP_ERROR_INVALID_STRING_LENGTH _CHIP_ERROR(30) + +/** + * @def CHIP_ERROR_INVALID_LIST_LENGTH + * + * @brief + * A list length is invalid. + * + */ +#define CHIP_ERROR_INVALID_LIST_LENGTH _CHIP_ERROR(31) + +/** + * @def CHIP_ERROR_INVALID_INTEGRITY_TYPE + * + * @brief + * An integrity type is invalid. + * + */ +#define CHIP_ERROR_INVALID_INTEGRITY_TYPE _CHIP_ERROR(32) + +/** + * @def CHIP_END_OF_TLV + * + * @brief + * The end of a TLV encoding, + * or the end of a TLV container element has been reached. + * + */ +#define CHIP_END_OF_TLV _CHIP_ERROR(33) + +/** + * @def CHIP_ERROR_TLV_UNDERRUN + * + * @brief + * The TLV encoding ended prematurely. + * + */ +#define CHIP_ERROR_TLV_UNDERRUN _CHIP_ERROR(34) + +/** + * @def CHIP_ERROR_INVALID_TLV_ELEMENT + * + * @brief + * A TLV element is invalid. + * + */ +#define CHIP_ERROR_INVALID_TLV_ELEMENT _CHIP_ERROR(35) + +/** + * @def CHIP_ERROR_INVALID_TLV_TAG + * + * @brief + * A TLV tag is invalid. + * + */ +#define CHIP_ERROR_INVALID_TLV_TAG _CHIP_ERROR(36) + +/** + * @def CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG + * + * @brief + * An implicitly encoded TLV tag was encountered, + * but an implicit profile id has not been defined. + * + */ +#define CHIP_ERROR_UNKNOWN_IMPLICIT_TLV_TAG _CHIP_ERROR(37) + +/** + * @def CHIP_ERROR_WRONG_TLV_TYPE + * + * @brief + * A TLV type is wrong. + * + */ +#define CHIP_ERROR_WRONG_TLV_TYPE _CHIP_ERROR(38) + +/** + * @def CHIP_ERROR_TLV_CONTAINER_OPEN + * + * @brief + * A TLV container is unexpectedly open. + * + */ +#define CHIP_ERROR_TLV_CONTAINER_OPEN _CHIP_ERROR(39) + +/** + * @def CHIP_ERROR_INVALID_TRANSFER_MODE + * + * @brief + * A transfer mode is invalid. + * + */ +#define CHIP_ERROR_INVALID_TRANSFER_MODE _CHIP_ERROR(40) + +/** + * @def CHIP_ERROR_INVALID_PROFILE_ID + * + * @brief + * A profile id is invalid. + * + */ +#define CHIP_ERROR_INVALID_PROFILE_ID _CHIP_ERROR(41) + +/** + * @def CHIP_ERROR_INVALID_MESSAGE_TYPE + * + * @brief + * A message type is invalid. + * + */ +#define CHIP_ERROR_INVALID_MESSAGE_TYPE _CHIP_ERROR(42) + +/** + * @def CHIP_ERROR_UNEXPECTED_TLV_ELEMENT + * + * @brief + * An unexpected TLV element was encountered. + * + */ +#define CHIP_ERROR_UNEXPECTED_TLV_ELEMENT _CHIP_ERROR(43) + +/** + * @def CHIP_ERROR_STATUS_REPORT_RECEIVED + * + * @brief + * A status report is received from a peer node. + * + */ +#define CHIP_ERROR_STATUS_REPORT_RECEIVED _CHIP_ERROR(44) + +/** + * @def CHIP_ERROR_NOT_IMPLEMENTED + * + * @brief + * A requested function or feature is not implemented. + * + */ +#define CHIP_ERROR_NOT_IMPLEMENTED _CHIP_ERROR(45) + +/** + * @def CHIP_ERROR_INVALID_ADDRESS + * + * @brief + * An address is invalid. + * + */ +#define CHIP_ERROR_INVALID_ADDRESS _CHIP_ERROR(46) + +/** + * @def CHIP_ERROR_INVALID_ARGUMENT + * + * @brief + * An argument is invalid. + * + */ +#define CHIP_ERROR_INVALID_ARGUMENT _CHIP_ERROR(47) + +/** + * @def CHIP_ERROR_INVALID_PATH_LIST + * + * @brief + * A TLV path list is invalid. + * + */ +#define CHIP_ERROR_INVALID_PATH_LIST _CHIP_ERROR(48) + +/** + * @def CHIP_ERROR_INVALID_DATA_LIST + * + * @brief + * A TLV data list is invalid. + * + */ +#define CHIP_ERROR_INVALID_DATA_LIST _CHIP_ERROR(49) + +/** + * @def CHIP_ERROR_TIMEOUT + * + * @brief + * A request timed out. + * + */ +#define CHIP_ERROR_TIMEOUT _CHIP_ERROR(50) + +/** + * @def CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR + * + * @brief + * A device descriptor is invalid. + * + */ +#define CHIP_ERROR_INVALID_DEVICE_DESCRIPTOR _CHIP_ERROR(51) + +/** + * @def CHIP_ERROR_UNSUPPORTED_DEVICE_DESCRIPTOR_VERSION + * + * @brief + * A device descriptor version is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_DEVICE_DESCRIPTOR_VERSION _CHIP_ERROR(52) + +/** + * @def CHIP_END_OF_INPUT + * + * @brief + * An input ended. + * + */ +#define CHIP_END_OF_INPUT _CHIP_ERROR(53) + +/** + * @def CHIP_ERROR_RATE_LIMIT_EXCEEDED + * + * @brief + * A rate limit is exceeded. + * + */ +#define CHIP_ERROR_RATE_LIMIT_EXCEEDED _CHIP_ERROR(54) + +/** + * @def CHIP_ERROR_SECURITY_MANAGER_BUSY + * + * @brief + * A security manager is busy. + * + */ +#define CHIP_ERROR_SECURITY_MANAGER_BUSY _CHIP_ERROR(55) + +/** + * @def CHIP_ERROR_INVALID_PASE_PARAMETER + * + * @brief + * A PASE parameter is invalid. + * + */ +#define CHIP_ERROR_INVALID_PASE_PARAMETER _CHIP_ERROR(56) + +/** + * @def CHIP_ERROR_PASE_SUPPORTS_ONLY_CONFIG1 + * + * @brief + * PASE supports only config1. + * + */ +#define CHIP_ERROR_PASE_SUPPORTS_ONLY_CONFIG1 _CHIP_ERROR(57) + +/** + * @def CHIP_ERROR_KEY_CONFIRMATION_FAILED + * + * @brief + * A key confirmation failed. + * + */ +#define CHIP_ERROR_KEY_CONFIRMATION_FAILED _CHIP_ERROR(58) + +/** + * @def CHIP_ERROR_INVALID_USE_OF_SESSION_KEY + * + * @brief + * A use of session key is invalid. + * + */ +#define CHIP_ERROR_INVALID_USE_OF_SESSION_KEY _CHIP_ERROR(59) + +/** + * @def CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY + * + * @brief + * A connection is closed unexpectedly. + * + */ +#define CHIP_ERROR_CONNECTION_CLOSED_UNEXPECTEDLY _CHIP_ERROR(60) + +/** + * @def CHIP_ERROR_MISSING_TLV_ELEMENT + * + * @brief + * A TLV element is missing. + * + */ +#define CHIP_ERROR_MISSING_TLV_ELEMENT _CHIP_ERROR(61) + +/** + * @def CHIP_ERROR_RANDOM_DATA_UNAVAILABLE + * + * @brief + * Secure random data is not available. + * + */ +#define CHIP_ERROR_RANDOM_DATA_UNAVAILABLE _CHIP_ERROR(62) + +/** + * @def CHIP_ERROR_UNSUPPORTED_HOST_PORT_ELEMENT + * + * @brief + * A type in host/port list is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_HOST_PORT_ELEMENT _CHIP_ERROR(63) + +/** + * @def CHIP_ERROR_INVALID_HOST_SUFFIX_INDEX + * + * @brief + * A suffix index in host/port list is invalid. + * + */ +#define CHIP_ERROR_INVALID_HOST_SUFFIX_INDEX _CHIP_ERROR(64) + +/** + * @def CHIP_ERROR_HOST_PORT_LIST_EMPTY + * + * @brief + * A host/port list is empty. + * + */ +#define CHIP_ERROR_HOST_PORT_LIST_EMPTY _CHIP_ERROR(65) + +/** + * @def CHIP_ERROR_UNSUPPORTED_AUTH_MODE + * + * @brief + * An authentication mode is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_AUTH_MODE _CHIP_ERROR(66) + +/** + * @def CHIP_ERROR_INVALID_SERVICE_EP + * + * @brief + * A service endpoint is invalid. + * + */ +#define CHIP_ERROR_INVALID_SERVICE_EP _CHIP_ERROR(67) + +/** + * @def CHIP_ERROR_INVALID_DIRECTORY_ENTRY_TYPE + * + * @brief + * A directory entry type is unknown. + * + */ +#define CHIP_ERROR_INVALID_DIRECTORY_ENTRY_TYPE _CHIP_ERROR(68) + +/** + * @def CHIP_ERROR_FORCED_RESET + * + * @brief + * A service manager is forced to reset. + * + */ +#define CHIP_ERROR_FORCED_RESET _CHIP_ERROR(69) + +/** + * @def CHIP_ERROR_NO_ENDPOINT + * + * @brief + * No endpoint is available. + * + */ +#define CHIP_ERROR_NO_ENDPOINT _CHIP_ERROR(70) + +/** + * @def CHIP_ERROR_INVALID_DESTINATION_NODE_ID + * + * @brief + * A destination node id is invalid. + * + */ +#define CHIP_ERROR_INVALID_DESTINATION_NODE_ID _CHIP_ERROR(71) + +/** + * @def CHIP_ERROR_NOT_CONNECTED + * + * @brief + * The operation cannot be performed because the underlying object is not + * connected. + * + */ +#define CHIP_ERROR_NOT_CONNECTED _CHIP_ERROR(72) + +/** + * @def CHIP_ERROR_NO_SW_UPDATE_AVAILABLE + * + * @brief + * No software update is available. + * + */ +#define CHIP_ERROR_NO_SW_UPDATE_AVAILABLE _CHIP_ERROR(73) + +/** + * @def CHIP_ERROR_CA_CERT_NOT_FOUND + * + * @brief + * CA certificate is not found. + * + */ +#define CHIP_ERROR_CA_CERT_NOT_FOUND _CHIP_ERROR(74) + +/** + * @def CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED + * + * @brief + * A certificate path length exceeds the constraint. + * + */ +#define CHIP_ERROR_CERT_PATH_LEN_CONSTRAINT_EXCEEDED _CHIP_ERROR(75) + +/** + * @def CHIP_ERROR_CERT_PATH_TOO_LONG + * + * @brief + * A certificate path is too long. + * + */ +#define CHIP_ERROR_CERT_PATH_TOO_LONG _CHIP_ERROR(76) + +/** + * @def CHIP_ERROR_CERT_USAGE_NOT_ALLOWED + * + * @brief + * A requested certificate usage is not allowed. + * + */ +#define CHIP_ERROR_CERT_USAGE_NOT_ALLOWED _CHIP_ERROR(77) + +/** + * @def CHIP_ERROR_CERT_EXPIRED + * + * @brief + * A certificate expired. + * + */ +#define CHIP_ERROR_CERT_EXPIRED _CHIP_ERROR(78) + +/** + * @def CHIP_ERROR_CERT_NOT_VALID_YET + * + * @brief + * A certificate is not valid yet. + * + */ +#define CHIP_ERROR_CERT_NOT_VALID_YET _CHIP_ERROR(79) + +/** + * @def CHIP_ERROR_UNSUPPORTED_CERT_FORMAT + * + * @brief + * A certificate format is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_CERT_FORMAT _CHIP_ERROR(80) + +/** + * @def CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE + * + * @brief + * An elliptic curve is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_ELLIPTIC_CURVE _CHIP_ERROR(81) + +/** + * @def CHIP_CERT_NOT_USED + * + * @brief + * A certificate was not used during the chain validation. + * + */ +#define CHIP_CERT_NOT_USED _CHIP_ERROR(82) + +/** + * @def CHIP_ERROR_CERT_NOT_FOUND + * + * @brief + * A certificate is not found. + * + */ +#define CHIP_ERROR_CERT_NOT_FOUND _CHIP_ERROR(83) + +/** + * @def CHIP_ERROR_INVALID_CASE_PARAMETER + * + * @brief + * A CASE parameter is invalid. + * + */ +#define CHIP_ERROR_INVALID_CASE_PARAMETER _CHIP_ERROR(84) + +/** + * @def CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION + * + * @brief + * A CASE configuration is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_CASE_CONFIGURATION _CHIP_ERROR(85) + +/** + * @def CHIP_ERROR_CERT_LOAD_FAIL + * + * @brief + * A certificate load failed. + * + */ +#define CHIP_ERROR_CERT_LOAD_FAIL _CHIP_ERROR(86) + +/** + * @def CHIP_ERROR_CERT_NOT_TRUSTED + * + * @brief + * A certificate is not trusted. + * + */ +#define CHIP_ERROR_CERT_NOT_TRUSTED _CHIP_ERROR(87) + +/** + * @def CHIP_ERROR_INVALID_ACCESS_TOKEN + * + * @brief + * An access token is invalid. + * + */ +#define CHIP_ERROR_INVALID_ACCESS_TOKEN _CHIP_ERROR(88) + +/** + * @def CHIP_ERROR_WRONG_CERT_SUBJECT + * + * @brief + * A certificate subject is wrong. + * + */ +#define CHIP_ERROR_WRONG_CERT_SUBJECT _CHIP_ERROR(89) + +// deprecated alias +#define CHIP_ERROR_WRONG_CERTIFICATE_SUBJECT CHIP_ERROR_WRONG_CERT_SUBJECT + +/** + * @def CHIP_ERROR_INVALID_PROVISIONING_BUNDLE + * + * @brief + * A provisioning bundle is invalid. + * + */ +#define CHIP_ERROR_INVALID_PROVISIONING_BUNDLE _CHIP_ERROR(90) + +/** + * @def CHIP_ERROR_PROVISIONING_BUNDLE_DECRYPTION_ERROR + * + * @brief + * A provision bundle encountered a decryption error. + * + */ +#define CHIP_ERROR_PROVISIONING_BUNDLE_DECRYPTION_ERROR _CHIP_ERROR(91) + +/** + * @def CHIP_ERROR_WRONG_NODE_ID + * + * @brief + * A node id is wrong. + * + */ +#define CHIP_ERROR_WRONG_NODE_ID _CHIP_ERROR(92) + +/** + * @def CHIP_ERROR_CONN_ACCEPTED_ON_WRONG_PORT + * + * @brief + * A connection is accepted on a wrong port. + * + */ +#define CHIP_ERROR_CONN_ACCEPTED_ON_WRONG_PORT _CHIP_ERROR(93) + +/** + * @def CHIP_ERROR_CALLBACK_REPLACED + * + * @brief + * An application callback has been replaced. + * + */ +#define CHIP_ERROR_CALLBACK_REPLACED _CHIP_ERROR(94) + +/** + * @def CHIP_ERROR_NO_CASE_AUTH_DELEGATE + * + * @brief + * No CASE authentication delegate is set. + * + */ +#define CHIP_ERROR_NO_CASE_AUTH_DELEGATE _CHIP_ERROR(95) + +/** + * @def CHIP_ERROR_DEVICE_LOCATE_TIMEOUT + * + * @brief + * The attempt to locate device timed out. + * + */ +#define CHIP_ERROR_DEVICE_LOCATE_TIMEOUT _CHIP_ERROR(96) + +/** + * @def CHIP_ERROR_DEVICE_CONNECT_TIMEOUT + * + * @brief + * The attempt to connect device timed out. + * + */ +#define CHIP_ERROR_DEVICE_CONNECT_TIMEOUT _CHIP_ERROR(97) + +/** + * @def CHIP_ERROR_DEVICE_AUTH_TIMEOUT + * + * @brief + * The attempt to authenticate device timed out. + * + */ +#define CHIP_ERROR_DEVICE_AUTH_TIMEOUT _CHIP_ERROR(98) + +/** + * @def CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED + * + * @brief + * A message is not acknowledged after max retries. + * + */ +#define CHIP_ERROR_MESSAGE_NOT_ACKNOWLEDGED _CHIP_ERROR(99) + +/** + * @def CHIP_ERROR_RETRANS_TABLE_FULL + * + * @brief + * A retransmission table is already full. + * + */ +#define CHIP_ERROR_RETRANS_TABLE_FULL _CHIP_ERROR(100) + +/** + * @def CHIP_ERROR_INVALID_ACK_ID + * + * @brief + * An acknowledgment id is invalid. + * + */ +#define CHIP_ERROR_INVALID_ACK_ID _CHIP_ERROR(101) + +/** + * @def CHIP_ERROR_SEND_THROTTLED + * + * @brief + * A send is throttled. + * + */ +#define CHIP_ERROR_SEND_THROTTLED _CHIP_ERROR(102) + +/** + * @def CHIP_ERROR_WRONG_MSG_VERSION_FOR_EXCHANGE + * + * @brief + * A message version is not supported by the current exchange context. + * + */ +#define CHIP_ERROR_WRONG_MSG_VERSION_FOR_EXCHANGE _CHIP_ERROR(103) + +/** + * @def CHIP_ERROR_TRANSACTION_CANCELED + * + * @brief + * A transaction is cancelled. + * + */ +#define CHIP_ERROR_TRANSACTION_CANCELED _CHIP_ERROR(104) + +/** + * @def CHIP_ERROR_LISTENER_ALREADY_STARTED + * + * @brief + * A listener has already started. + * + */ +#define CHIP_ERROR_LISTENER_ALREADY_STARTED _CHIP_ERROR(105) + +/** + * @def CHIP_ERROR_LISTENER_ALREADY_STOPPED + * + * @brief + * A listener has already stopped. + * + */ +#define CHIP_ERROR_LISTENER_ALREADY_STOPPED _CHIP_ERROR(106) + +/** + * @def CHIP_ERROR_UNKNOWN_TOPIC + * + * @brief + * A topic ID was unknown to the recipient. + * + */ +#define CHIP_ERROR_UNKNOWN_TOPIC _CHIP_ERROR(107) + +/** + * @def CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE + * + * @brief + * A CHIP feature is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE _CHIP_ERROR(108) + +/** + * @def CHIP_ERROR_PASE_RECONFIGURE_REQUIRED + * + * @brief + * PASE is required to reconfigure. + * + */ +#define CHIP_ERROR_PASE_RECONFIGURE_REQUIRED _CHIP_ERROR(109) + +/** + * @def CHIP_ERROR_INVALID_PASE_CONFIGURATION + * + * @brief + * A PASE configuration is invalid. + * + */ +#define CHIP_ERROR_INVALID_PASE_CONFIGURATION _CHIP_ERROR(110) + +/** + * @def CHIP_ERROR_NO_COMMON_PASE_CONFIGURATIONS + * + * @brief + * No PASE configuration is in common. + * + */ +#define CHIP_ERROR_NO_COMMON_PASE_CONFIGURATIONS _CHIP_ERROR(111) + +/** + * @def CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR + * + * @brief + * An unsolicited message with the originator bit clear. + * + */ +#define CHIP_ERROR_UNSOLICITED_MSG_NO_ORIGINATOR _CHIP_ERROR(112) + +/** + * @def CHIP_ERROR_INVALID_FABRIC_ID + * + * @brief + * A fabric id is invalid. + * + */ +#define CHIP_ERROR_INVALID_FABRIC_ID _CHIP_ERROR(113) + +/** + * @def CHIP_ERROR_UNSUPPORTED_TUNNEL_VERSION + * + * @brief + * A tunnel version is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_TUNNEL_VERSION _CHIP_ERROR(114) + +/** + * @def CHIP_ERROR_TUNNEL_NEXTHOP_TABLE_FULL + * + * @brief + * A tunnel nexthop table is full. + * + */ +#define CHIP_ERROR_TUNNEL_NEXTHOP_TABLE_FULL _CHIP_ERROR(115) + +/** + * @def CHIP_ERROR_TUNNEL_SERVICE_QUEUE_FULL + * + * @brief + * A tunnel service queue is full. + * + */ +#define CHIP_ERROR_TUNNEL_SERVICE_QUEUE_FULL _CHIP_ERROR(116) + +/** + * @def CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED + * + * @brief + * DRBG entropy source failed to generate entropy data. + * + */ +#define CHIP_ERROR_DRBG_ENTROPY_SOURCE_FAILED _CHIP_ERROR(117) + +/** + * @def CHIP_ERROR_TLV_TAG_NOT_FOUND + * + * @brief + * A specified TLV tag was not found. + * + */ +#define CHIP_ERROR_TLV_TAG_NOT_FOUND _CHIP_ERROR(118) + +/** + * @def CHIP_ERROR_INVALID_TOKENPAIRINGBUNDLE + * + * @brief + * A token pairing bundle is invalid. + * + */ +#define CHIP_ERROR_INVALID_TOKENPAIRINGBUNDLE _CHIP_ERROR(119) + +/** + * @def CHIP_ERROR_UNSUPPORTED_TOKENPAIRINGBUNDLE_VERSION + * + * @brief + * A token pairing bundle is invalid. + * + */ +#define CHIP_ERROR_UNSUPPORTED_TOKENPAIRINGBUNDLE_VERSION _CHIP_ERROR(120) + +/** + * @def CHIP_ERROR_NO_TAKE_AUTH_DELEGATE + * + * @brief + * No TAKE authentication delegate is set. + * + */ +#define CHIP_ERROR_NO_TAKE_AUTH_DELEGATE _CHIP_ERROR(121) + +/** + * @def CHIP_ERROR_TAKE_RECONFIGURE_REQUIRED + * + * @brief + * TAKE requires a reconfigure. + * + */ +#define CHIP_ERROR_TAKE_RECONFIGURE_REQUIRED _CHIP_ERROR(122) + +/** + * @def CHIP_ERROR_TAKE_REAUTH_POSSIBLE + * + * @brief + * TAKE can do a reauthentication. + * + */ +#define CHIP_ERROR_TAKE_REAUTH_POSSIBLE _CHIP_ERROR(123) + +/** + * @def CHIP_ERROR_INVALID_TAKE_PARAMETER + * + * @brief + * Received an invalid TAKE paramter. + * + */ +#define CHIP_ERROR_INVALID_TAKE_PARAMETER _CHIP_ERROR(124) + +/** + * @def CHIP_ERROR_UNSUPPORTED_TAKE_CONFIGURATION + * + * @brief + * This configuration is not supported by TAKE. + * + */ +#define CHIP_ERROR_UNSUPPORTED_TAKE_CONFIGURATION _CHIP_ERROR(125) + +/** + * @def CHIP_ERROR_TAKE_TOKEN_IDENTIFICATION_FAILED + * + * @brief + * The TAKE Token Identification failed. + * + */ +#define CHIP_ERROR_TAKE_TOKEN_IDENTIFICATION_FAILED _CHIP_ERROR(126) + +/** + * @def CHIP_ERROR_KEY_NOT_FOUND_FROM_PEER + * + * @brief + * The encryption key is not found error received from a peer node. + * + */ +#define CHIP_ERROR_KEY_NOT_FOUND_FROM_PEER _CHIP_ERROR(127) + +/** + * @def CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER + * + * @brief + * The wrong encryption type error received from a peer node. + * + */ +#define CHIP_ERROR_WRONG_ENCRYPTION_TYPE_FROM_PEER _CHIP_ERROR(128) + +/** + * @def CHIP_ERROR_UNKNOWN_KEY_TYPE_FROM_PEER + * + * @brief + * The unknown key type error received from a peer node. + * + */ +#define CHIP_ERROR_UNKNOWN_KEY_TYPE_FROM_PEER _CHIP_ERROR(129) + +/** + * @def CHIP_ERROR_INVALID_USE_OF_SESSION_KEY_FROM_PEER + * + * @brief + * The invalid use of session key error received from a peer node. + * + */ +#define CHIP_ERROR_INVALID_USE_OF_SESSION_KEY_FROM_PEER _CHIP_ERROR(130) + +/** + * @def CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE_FROM_PEER + * + * @brief + * An unsupported encryption type error received from a peer node. + * + */ +#define CHIP_ERROR_UNSUPPORTED_ENCRYPTION_TYPE_FROM_PEER _CHIP_ERROR(131) + +/** + * @def CHIP_ERROR_INTERNAL_KEY_ERROR_FROM_PEER + * + * @brief + * The internal key error received from a peer node. + * + */ +#define CHIP_ERROR_INTERNAL_KEY_ERROR_FROM_PEER _CHIP_ERROR(132) + +/** + * @def CHIP_ERROR_INVALID_KEY_ID + * + * @brief + * A key id is invalid. + * + */ +#define CHIP_ERROR_INVALID_KEY_ID _CHIP_ERROR(133) + +/** + * @def CHIP_ERROR_INVALID_TIME + * + * @brief + * Time has invalid value. + * + */ +#define CHIP_ERROR_INVALID_TIME _CHIP_ERROR(134) + +/** + * @def CHIP_ERROR_TUNNEL_PEER_ENTRY_NOT_FOUND + * + * @brief + * A tunnel shortcut peer entry not found in the cache. + * + */ +#define CHIP_ERROR_TUNNEL_PEER_ENTRY_NOT_FOUND _CHIP_ERROR(135) + +/** + * @def CHIP_ERROR_LOCKING_FAILURE + * + * @brief + * Failure to acquire or release an OS provided mutex. + * + */ +#define CHIP_ERROR_LOCKING_FAILURE _CHIP_ERROR(136) + +/** + * @def CHIP_ERROR_UNSUPPORTED_PASSCODE_CONFIG + * + * @brief + * A passcode encryption configuration is unsupported. + * + */ +#define CHIP_ERROR_UNSUPPORTED_PASSCODE_CONFIG _CHIP_ERROR(137) + +/** + * @def CHIP_ERROR_PASSCODE_AUTHENTICATION_FAILED + * + * @brief + * The CHIP passcode authentication failed. + * + */ +#define CHIP_ERROR_PASSCODE_AUTHENTICATION_FAILED _CHIP_ERROR(138) + +/** + * @def CHIP_ERROR_PASSCODE_FINGERPRINT_FAILED + * + * @brief + * The CHIP passcode fingerprint failed. + * + */ +#define CHIP_ERROR_PASSCODE_FINGERPRINT_FAILED _CHIP_ERROR(139) + +/** + * @def CHIP_ERROR_TUNNEL_FORCE_ABORT + * + * @brief + * The CHIP error code to be used with the API for stopping + * the tunnel to enforce it to abort its TCP connection and return + * synchronously to the caller. + * + */ +#define CHIP_ERROR_TUNNEL_FORCE_ABORT _CHIP_ERROR(140) + +/** + * @def CHIP_ERROR_SERIALIZATION_ELEMENT_NULL + * + * @brief + * The element of the struct is null. + * + */ +#define CHIP_ERROR_SERIALIZATION_ELEMENT_NULL _CHIP_ERROR(141) + +/** + * @def CHIP_ERROR_WRONG_CERT_SIGNATURE_ALGORITHM + * + * @brief + * The certificate was not signed using the required signature algorithm. + * + */ +#define CHIP_ERROR_WRONG_CERT_SIGNATURE_ALGORITHM _CHIP_ERROR(142) + +/** + * @def CHIP_ERROR_WRONG_CHIP_SIGNATURE_ALGORITHM + * + * @brief + * The CHIP signature was not signed using the required signature algorithm. + * + */ +#define CHIP_ERROR_WRONG_CHIP_SIGNATURE_ALGORITHM _CHIP_ERROR(143) + +/** + * @def CHIP_ERROR_WDM_SCHEMA_MISMATCH + * + * @brief + * A mismatch in schema was encountered. + * + */ +#define CHIP_ERROR_WDM_SCHEMA_MISMATCH _CHIP_ERROR(144) + +/** + * @def CHIP_ERROR_INVALID_INTEGER_VALUE + * + * @brief + * An integer does not have the kind of value we expect. + * + */ +#define CHIP_ERROR_INVALID_INTEGER_VALUE _CHIP_ERROR(145) + +/** + * @def CHIP_ERROR_CASE_RECONFIG_REQUIRED + * + * @brief + * CASE is required to reconfigure. + * + */ +#define CHIP_ERROR_CASE_RECONFIG_REQUIRED _CHIP_ERROR(146) + +/** + * @def CHIP_ERROR_TOO_MANY_CASE_RECONFIGURATIONS + * + * @brief + * Too many CASE reconfigurations were received. + * + */ +#define CHIP_ERROR_TOO_MANY_CASE_RECONFIGURATIONS _CHIP_ERROR(147) + +/** + * @def CHIP_ERROR_BAD_REQUEST + * + * @brief + * The request cannot be processed or fulfilled + * + */ +#define CHIP_ERROR_BAD_REQUEST _CHIP_ERROR(148) + +/** + * @def CHIP_ERROR_INVALID_MESSAGE_FLAG + * + * @brief + * One or more message flags have invalid value. + * + */ +#define CHIP_ERROR_INVALID_MESSAGE_FLAG _CHIP_ERROR(149) + +/** + * @def CHIP_ERROR_KEY_EXPORT_RECONFIGURE_REQUIRED + * + * @brief + * Key export protocol required to reconfigure. + * + */ +#define CHIP_ERROR_KEY_EXPORT_RECONFIGURE_REQUIRED _CHIP_ERROR(150) + +/** + * @def CHIP_ERROR_INVALID_KEY_EXPORT_CONFIGURATION + * + * @brief + * A key export protocol configuration is invalid. + * + */ +#define CHIP_ERROR_INVALID_KEY_EXPORT_CONFIGURATION _CHIP_ERROR(151) + +/** + * @def CHIP_ERROR_NO_COMMON_KEY_EXPORT_CONFIGURATIONS + * + * @brief + * No key export protocol configuration is in common. + * + */ +#define CHIP_ERROR_NO_COMMON_KEY_EXPORT_CONFIGURATIONS _CHIP_ERROR(152) + +/** + * @def CHIP_ERROR_NO_KEY_EXPORT_DELEGATE + * + * @brief + * No key export delegate is set. + * + */ +#define CHIP_ERROR_NO_KEY_EXPORT_DELEGATE _CHIP_ERROR(153) + +/** + * @def CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_REQUEST + * + * @brief + * Unauthorized key export request. + * + */ +#define CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_REQUEST _CHIP_ERROR(154) + +/** + * @def CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_RESPONSE + * + * @brief + * Unauthorized key export response. + * + */ +#define CHIP_ERROR_UNAUTHORIZED_KEY_EXPORT_RESPONSE _CHIP_ERROR(155) + +/** + * @def CHIP_ERROR_EXPORTED_KEY_AUTHENTICATION_FAILED + * + * @brief + * The CHIP exported encrypted key authentication failed. + * + */ +#define CHIP_ERROR_EXPORTED_KEY_AUTHENTICATION_FAILED _CHIP_ERROR(156) + +/** + * @def CHIP_ERROR_TOO_MANY_SHARED_SESSION_END_NODES + * + * @brief + * The number of shared secure sessions end nodes exceeds + * the maximum limit. + * + */ +#define CHIP_ERROR_TOO_MANY_SHARED_SESSION_END_NODES _CHIP_ERROR(157) + +/** + * @def CHIP_ERROR_WDM_MALFORMED_DATA_ELEMENT + * + * @brief + * The WDM DataElement is malformed: it either does not contain + * the required elements, or it contais both the MergeData element + * and DeletedDictionaryKeyList. + */ +#define CHIP_ERROR_WDM_MALFORMED_DATA_ELEMENT _CHIP_ERROR(158) + +/** + * @def CHIP_ERROR_WRONG_CERT_TYPE + * + * @brief + * The presented certificate was of the wrong type. + */ +#define CHIP_ERROR_WRONG_CERT_TYPE _CHIP_ERROR(159) + +/** + * @def CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED + * + * @brief + * The application's event handler failed to call the default event handler function + * when presented with an unknown event. + */ +#define CHIP_ERROR_DEFAULT_EVENT_HANDLER_NOT_CALLED _CHIP_ERROR(162) + +/** + * @def CHIP_ERROR_PERSISTED_STORAGE_FAIL + * + * @brief + * Persisted storage memory read/write failure. + * + */ +#define CHIP_ERROR_PERSISTED_STORAGE_FAIL _CHIP_ERROR(163) + +/** + * @def CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND + * + * @brief + * The specific value is not found in the persisted storage. + * + */ +#define CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND _CHIP_ERROR(164) + +/** + * @def CHIP_ERROR_PROFILE_STRING_CONTEXT_ALREADY_REGISTERED + * + * @brief + * The specified profile string support context is already registered. + * + */ +#define CHIP_ERROR_PROFILE_STRING_CONTEXT_ALREADY_REGISTERED _CHIP_ERROR(165) + +/** + * @def CHIP_ERROR_PROFILE_STRING_CONTEXT_NOT_REGISTERED + * + * @brief + * The specified profile string support context is not registered. + * + */ +#define CHIP_ERROR_PROFILE_STRING_CONTEXT_NOT_REGISTERED _CHIP_ERROR(166) + +/** + * @def CHIP_ERROR_INCOMPATIBLE_SCHEMA_VERSION + * + * @brief + * Encountered a mismatch in compatibility w.r.t to IDL schema version + */ +#define CHIP_ERROR_INCOMPATIBLE_SCHEMA_VERSION _CHIP_ERROR(167) + +/** + * @def CHIP_ERROR_TUNNEL_ROUTING_RESTRICTED + * + * @brief + * Indicates that the Tunnel can only be used by the border gateway + * for itself and, it cannot forward packets for any other device. + * + */ +#define CHIP_ERROR_TUNNEL_ROUTING_RESTRICTED _CHIP_ERROR(168) + +/** + * @def CHIP_ERROR_TUNNEL_RESET_RECONNECT_ALREADY_ARMED + * + * @brief + * The Tunnel reset reconnect timer is already armed + */ +#define CHIP_ERROR_TUNNEL_RESET_RECONNECT_ALREADY_ARMED _CHIP_ERROR(169) + +/** + * @def CHIP_ERROR_MISMATCH_UPDATE_REQUIRED_VERSION + * + * @brief + * Encountered a mismatch between wdm update required version and current version + */ +#define CHIP_ERROR_MISMATCH_UPDATE_REQUIRED_VERSION _CHIP_ERROR(170) + +/** + * @def CHIP_ERROR_WDM_MALFORMED_STATUS_ELEMENT + * + * @brief + * The WDM StatusElement is malformed: it does not contain + * either the profile id or the status code. + */ +#define CHIP_ERROR_WDM_MALFORMED_STATUS_ELEMENT _CHIP_ERROR(171) + +/** + * @def CHIP_ERROR_WDM_SUBSCRIPTIONLESS_NOTIFY_PARTIAL + * + * @brief + * The WDM Subscriptionless Notify is partial. + */ +#define CHIP_ERROR_WDM_SUBSCRIPTIONLESS_NOTIFY_PARTIAL _CHIP_ERROR(172) + +/** + * @def CHIP_ERROR_ACCESS_DENIED + * + * @brief + * The CHIP message is not granted access for further processing. + */ +#define CHIP_ERROR_ACCESS_DENIED _CHIP_ERROR(173) + +/** + * @def CHIP_ERROR_UNKNOWN_RESOURCE_ID + * + * @brief + * Unknown resource ID + * + */ +#define CHIP_ERROR_UNKNOWN_RESOURCE_ID _CHIP_ERROR(174) + +/** + * @def CHIP_ERROR_WDM_MALFORMED_UPDATE_RESPONSE + * + * @brief + * The WDM UpdateResponse payload is malformed: it does not contain + * either the StatusList or the VersionList. + */ +#define CHIP_ERROR_WDM_MALFORMED_UPDATE_RESPONSE _CHIP_ERROR(175) + +/** + * @def CHIP_ERROR_WDM_VERSION_MISMATCH + * + * @brief + * The conditional update of a trait instance path has failed + * because the local changes are based on an obsolete version of the + * data. + */ +#define CHIP_ERROR_WDM_VERSION_MISMATCH _CHIP_ERROR(176) + +/** + * @def CHIP_ERROR_WDM_POTENTIAL_DATA_LOSS + * + * @brief + * A potential data loss was detected for a Trait Instance. + */ +#define CHIP_ERROR_WDM_POTENTIAL_DATA_LOSS _CHIP_ERROR(177) + +/** + * @def CHIP_ERROR_UNSUPPORTED_THREAD_NETWORK_CREATE + * + * @brief + * Device doesn't support standalone Thread network creation. + * On some legacy devices new Thread network can only be created + * together with CHIP Fabric using CrateFabric() message. + * + */ +#define CHIP_ERROR_UNSUPPORTED_THREAD_NETWORK_CREATE _CHIP_ERROR(178) + +/** + * @def CHIP_ERROR_WDM_INCONSISTENT_CONDITIONALITY + * + * @brief + * A TraitPath was declared updated with a conditionality that + * does not match that of other TraitPaths already updated in the + * same Trait Instance. + * + */ +#define CHIP_ERROR_WDM_INCONSISTENT_CONDITIONALITY _CHIP_ERROR(179) + +/** + * @def CHIP_ERROR_WDM_LOCAL_DATA_INCONSISTENT + * + * @brief + * The local data does not match any known version of the + * Trait Instance and cannot support the operation requested. + * + */ +#define CHIP_ERROR_WDM_LOCAL_DATA_INCONSISTENT _CHIP_ERROR(180) + +/** + * @def CHIP_ERROR_WDM_PATH_STORE_FULL + * + * @brief + * WDM cannot store a TraitPath for lack of memory. + * + */ +#define CHIP_ERROR_WDM_PATH_STORE_FULL _CHIP_ERROR(181) +/** + * @def CHIP_EVENT_ID_FOUND + * + * @brief + * Event ID matching the criteria was found + */ +#define CHIP_EVENT_ID_FOUND _CHIP_ERROR(182) + +/** + * @} + */ + +// !!!!! IMPORTANT !!!!! If you add new CHIP errors, please update the translation +// of error codes to strings in CHIPError.cpp, and add them to unittest +// in test-apps/TestErrorStr.cpp + +// clang-format on + +namespace chip { + +extern bool FormatCHIPError(char * buf, uint16_t bufSize, int32_t err); + +} // namespace chip + +#endif // CHIP_ERROR_H diff --git a/src/lib/core/Makefile b/src/lib/core/Makefile new file mode 100644 index 00000000000000..82b1f618acfb8e --- /dev/null +++ b/src/lib/core/Makefile @@ -0,0 +1,26 @@ +TOP_DIR = ../../.. +Test_Dir = tests + +.PHONY: all clean run_tests + +all: libcore.a run_tests + +include $(TOP_DIR)/.yams/cpp_rules.min + +Module_Includes = \ + -I. \ + -I$(TOP_DIR)/src/include \ + -I$(TOP_DIR)/src/lib/ \ + -I$(TOP_DIR)/src/system \ + -I$(TOP_DIR)/build/config/standalone/ + +Module_Test_Includes = $(Module_Includes) + +CPP_Files = CHIPError.cpp + +libcore.a: $(CPP_Objects) + ar rvs $@ $^ + @echo "LINK => $@" + +clean: my_clean + @rm -f libcore.a *.gcda *.gcno *.gcov diff --git a/src/lib/support/CodeUtils.h b/src/lib/support/CodeUtils.h new file mode 100644 index 00000000000000..1b6989cd29931f --- /dev/null +++ b/src/lib/support/CodeUtils.h @@ -0,0 +1,409 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines and implements a number of miscellaneous + * templates for finding object minima and maxima and interface + * macros for assertion checking. + * + */ + +#ifndef CODEUTILS_H_ +#define CODEUTILS_H_ + +#include +#include +#include "support/logging/CHIPLogging.h" + +/** + * @name chip-specific nlassert.h Overrides + * + * @{ + * + */ + +/** + * @def CHIP_ASSERT_ABORT() + * + * @brief + * This implements a chip-specific override for #CHIP_ASSERT_ABORT * + * from nlassert.h. + * + */ +#if !defined(CHIP_ASSERT_ABORT) +#define CHIP_ASSERT_ABORT() \ + chipDie() +#endif + +/** + * @def CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) + * + * @brief + * This implements a chip-specific override for \c CHIP_ASSERT_LOG + * from nlassert.h. + * + * @param[in] aPrefix A pointer to a NULL-terminated C string printed + * at the beginning of the logged assertion + * message. Typically this is and should be + * \c CHIP_ASSERT_PREFIX_STRING. + * @param[in] aName A pointer to a NULL-terminated C string printed + * following @a aPrefix that indicates what + * module, program, application or subsystem + * the assertion occurred in Typically this + * is and should be + * \c CHIP_ASSERT_COMPONENT_STRING. + * @param[in] aCondition A pointer to a NULL-terminated C string indicating + * the expression that evaluated to false in + * the assertion. Typically this is a + * stringified version of the actual + * assertion expression. + * @param[in] aLabel An optional pointer to a NULL-terminated C string + * indicating, for exception-style + * assertions, the label that will be + * branched to when the assertion expression + * evaluates to false. + * @param[in] aFile A pointer to a NULL-terminated C string indicating + * the file in which the exception + * occurred. Typically this is and should be + * \_\_FILE\_\_ from the C preprocessor. + * @param[in] aLine The line number in @a aFile on which the assertion + * expression evaluated to false. Typically + * this is and should be \_\_LINE\_\_ from the C + * preprocessor. + * @param[in] aMessage An optional pointer to a NULL-terminated C string + * containing a caller-specified message + * further describing the assertion failure. + * + */ +#if !defined(CHIP_ASSERT_LOG) +#define CHIP_ASSERT_LOG(aPrefix, aName, aCondition, aLabel, aFile, aLine, aMessage) \ + do \ + { \ + chipLogError(NotSpecified, \ + CHIP_ASSERT_LOG_FORMAT_DEFAULT, \ + aPrefix, \ + (((aName) == 0) || (*(aName) == '\0')) ? "" : aName, \ + (((aName) == 0) || (*(aName) == '\0')) ? "" : ": ", \ + aCondition, \ + (((aMessage) == 0) ? "" : aMessage), \ + (((aMessage) == 0) ? "" : ", "), \ + aFile, \ + aLine); \ + } while (0) +#endif + +/** + * @} chip-specific nlassert.h Overrides + * + */ + +#include + +namespace chip { + +// Generic min() and max() functions +// +template +inline const _T & +min(const _T &a, const _T &b) +{ + if (b < a) + return b; + + return a; +} + +template +inline const _T & +max(const _T &a, const _T &b) +{ + if (a < b) + return b; + + return a; +} + +} // namespace chip + +/** + * @def IgnoreUnusedVariable(aVariable) + * + * @brief + * This casts the specified @a aVariable to void to quell any + * compiler-issued unused variable warnings or errors. + * + * @code + * void foo (int err) + * { + * IgnoreUnusedVariable(err) + * } + * @endcode + * + */ +#define IgnoreUnusedVariable(aVariable) \ + ((void)(aVariable)) + +/** + * @def SuccessOrExit(aStatus) + * + * @brief + * This checks for the specified status, which is expected to + * commonly be successful (CHIP_NO_ERROR), and branches to + * the local label 'exit' if the status is unsuccessful. + * + * Example Usage: + * + * @code + * CHIP_ERROR TryHard() + * { + * CHIP_ERROR err; + * + * err = TrySomething(); + * SuccessOrExit(err); + * + * err = TrySomethingElse(); + * SuccessOrExit(err); + * + * exit: + * return err; + * } + * @endcode + * + * @param[in] aStatus A scalar status to be evaluated against zero (0). + * + */ +#define SuccessOrExit(aStatus) \ + nlEXPECT((aStatus) == CHIP_NO_ERROR, exit) + +/** + * @def VerifyOrExit(aCondition, anAction) + * + * @brief + * This checks for the specified condition, which is expected to + * commonly be true, and both executes @a anAction and branches to + * the local label 'exit' if the condition is false. + * + * Example Usage: + * + * @code + * CHIP_ERROR MakeBuffer(const uint8_t *& buf) + * { + * CHIP_ERROR err = CHIP_NO_ERROR; + * + * buf = (uint8_t *)malloc(1024); + * VerifyOrExit(buf != NULL, err = CHIP_ERROR_NO_MEMORY); + * + * memset(buf, 0, 1024); + * + * exit: + * return err; + * } + * @endcode + * + * @param[in] aCondition A Boolean expression to be evaluated. + * @param[in] anAction An expression or block to execute when the + * assertion fails. + * + */ +#define VerifyOrExit(aCondition, anAction) \ + nlEXPECT_ACTION(aCondition, exit, anAction) + +/** + * @def ExitNow(...) + * + * @brief + * This unconditionally executes @a ... and branches to the local + * label 'exit'. + * + * @note The use of this interface implies neither success nor + * failure for the overall exit status of the enclosing function + * body. + * + * Example Usage: + * + * @code + * CHIP_ERROR ReadAll(Reader& reader) + * { + * CHIP_ERROR err; + * + * while (true) + * { + * err = reader.ReadNext(); + * if (err == CHIP_ERROR_AT_END) + * ExitNow(err = CHIP_NO_ERROR); + * SuccessOrExit(err); + * DoSomething(); + * } + * + * exit: + * return err; + * } + * @endcode + * + * @param[in] ... An optional expression or block to execute + * when the assertion fails. + * + */ +#define ExitNow(...) \ + do { \ + __VA_ARGS__; \ + goto exit; \ + } while (0) + +/** + * @brief + * This is invoked when a #VerifyOrDie or #VerifyOrDieWithMsg + * assertion expression evaluates to false. + * + * Developers may override and customize this by defining #chipDie + * before CodeUtils.h is included by the preprocessor. + * + * Example Usage: + * + * @code + * chipDie(); + * @endcode + * + */ +#ifndef chipDie +extern "C" void chipDie(void) __attribute((noreturn)); + +inline void chipDie(void) +{ + chipLogError(NotSpecified, "chipDie chipDie chipDie"); + + while (true) + { + // CHIP_ASSERT_ABORT is redefined to be chipDie, so not useful here. + abort(); + } +} +#endif // chipDie + +/** + * @def VerifyOrDie(aCondition) + * + * @brief + * This checks for the specified condition, which is expected to + * commonly be true and forces an immediate abort if the condition + * is false. + * + * Example Usage: + * + * @code + * void FreeBuffer(const uint8_t *buf) + * { + * VerifyOrDie(buf != NULL); + * free(buf); + * } + * @endcode + * + * @param[in] aCondition A Boolean expression to be evaluated. + * + * @sa #VerifyOrDieWithMsg + * @sa #chipDie + * + */ +#define VerifyOrDie(aCondition) \ + nlABORT(aCondition) + +/** + * @def VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...) + * + * @brief + * This checks for the specified condition, which is expected to + * commonly be true and both prints @a aMessage and forces an + * immediate abort if the condition is false. + * + * Example Usage: + * + * @code + * void FreeBuffer(const uint8_t *buf) + * { + * VerifyOrDieWithMsg(buf != NULL, MemoryManagement, "Invalid pointer passed to FreeBuffer"); + * free(buf); + * } + * @endcode + * + * @param[in] aCondition A Boolean expression to be evaluated. + * @param[in] aModule A chip LogModule short-hand mnemonic identifing + * the logical section of code that is a + * source the logged message. + * @param[in] aMessage A pointer to a NULL-terminated C string with + * C Standard Library-style format specifiers + * containing the log message to be formatted + * and logged. + * @param[in] ... A variadic argument list whose elements should + * correspond to the format specifiers in @a + * aMessage. + * + * @sa #VerifyOrDie + * @sa #chipDie + * + */ +#define VerifyOrDieWithMsg(aCondition, aModule, aMessage, ...) \ + nlABORT_ACTION(aCondition, chipLogDetail(aModule, aMessage, ## __VA_ARGS__)) + +/** + * @def ArraySize(aArray) + * + * @brief + * Returns the size of an array in number of elements. + * + * Example Usage: + * + * @code + * int numbers[10]; + * SortNumbers(numbers, ArraySize(numbers)); + * @endcode + * + * @return The size of an array in number of elements. + */ +#define ArraySize(a) (sizeof(a)/sizeof((a)[0])) + +#if defined(__cplusplus) && (__cplusplus >= 201103L) + +#ifndef __FINAL +#define __FINAL final +#endif + +#ifndef __OVERRIDE +#define __OVERRIDE override +#endif + +#ifndef __CONSTEXPR +#define __CONSTEXPR constexpr +#endif + +#else + +#ifndef __FINAL +#define __FINAL +#endif + +#ifndef __OVERRIDE +#define __OVERRIDE +#endif + +#ifndef __CONSTEXPR +#define __CONSTEXPR constexpr +#endif + +#endif // defined(__cplusplus) && (__cplusplus >= 201103L) + +#endif /* CODEUTILS_H_ */ diff --git a/src/lib/support/Makefile b/src/lib/support/Makefile new file mode 100644 index 00000000000000..5c65357727eaee --- /dev/null +++ b/src/lib/support/Makefile @@ -0,0 +1,28 @@ +TOP_DIR = ../../.. +Test_Dir = tests + +.PHONY: all clean run_tests + +all: libsupport.a run_tests + +include $(TOP_DIR)/.yams/cpp_rules.min + +Module_Includes = \ + -I. \ + -I$(TOP_DIR)/src/include \ + -I$(TOP_DIR)/src/lib \ + -I$(TOP_DIR)/src/lib/core \ + -I$(TOP_DIR)/src/system \ + -I$(TOP_DIR)/build/config/standalone/ \ + -I$(TOP_DIR)/third_party/nlassert/repo/include + +Module_Test_Includes = $(Module_Includes) + +CPP_Files = logging/CHIPLogging.cpp + +libsupport.a: $(CPP_Objects) + ar rvs $@ $^ + @echo "LINK => $@" + +clean: my_clean + @rm -f libsupport.a *.gcda *.gcno *.gcov diff --git a/src/lib/support/logging/CHIPLogging.cpp b/src/lib/support/logging/CHIPLogging.cpp new file mode 100644 index 00000000000000..61f6cd35b51fd9 --- /dev/null +++ b/src/lib/support/logging/CHIPLogging.cpp @@ -0,0 +1,247 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file implements macros, constants, and interfaces for a + * platform-independent logging interface for the chip SDK. + * + */ + +#include +#include +#include + +#include "support/DLLUtil.h" +#include +#include "support/CodeUtils.h" +#include "CHIPLogging.h" + +#if CHIP_LOGGING_STYLE_ANDROID && defined(__ANDROID__) +#include +#endif + +#if HAVE_SYS_TIME_H && CHIP_LOGGING_STYLE_STDIO_WITH_TIMESTAMPS +#include +#endif // HAVE_SYS_TIME_H && CHIP_LOGGING_STYLE_STDIO_WITH_TIMESTAMPS + +namespace chip { +namespace Logging { + +#if _CHIP_USE_LOGGING + +/* + * Array of strings containing the names for each of the chip log + * modules. + * + * NOTE: The names must be in the order defined in the LogModule + * enumeration. Each name must be a fixed number of characters + * long (chipLoggingModuleNameLen) padded with nulls as + * necessary. + * + */ +static const char ModuleNames[] = + "-\0\0" // None + "IN\0" // Inet + "BLE" // BLE + "ML\0" // MessageLayer + "SM\0" // SecurityManager + "EM\0" // ExchangeManager + "TLV" // TLV + "ASN" // ASN1 + "CR\0" // Crypto + "DM\0" // DeviceManager + "AL\0" // Alarm + "BDX" // BulkDataTransfer + "DMG" // DataManagement + "DC\0" // DeviceControl + "DD\0" // DeviceDescription + "ECH" // Echo + "FP\0" // FabricProvisioning + "NP\0" // NetworkProvisioning + "SD\0" // ServiceDirectory + "SP\0" // ServiceProvisioning + "SWU" // SoftwareUpdate + "TP\0" // TokenPairing + "TS\0" // TimeServices + "WT\0" // chipTunnel + "HB\0" // Heartbeat + "WSL" // chipSystemLayer + "EVL" // Event Logging + "SPT" // Support + ; + +#define ModuleNamesCount ((sizeof(ModuleNames) - 1) / chipLoggingModuleNameLen) + +#define chipPrefix "CHIP:" +#define chipPrefixSeparator ": " +#define chipMessageTrailer "\n" + +void GetModuleName(char *buf, uint8_t module) +{ + const char *moduleNamePtr = ModuleNames + ((module < ModuleNamesCount) ? module * chipLoggingModuleNameLen : 0); + memcpy(buf, moduleNamePtr, chipLoggingModuleNameLen); + buf[chipLoggingModuleNameLen] = 0; +} + +void GetMessageWithPrefix(char *buf, uint8_t bufSize, uint8_t module, const char *msg) +{ + char moduleName[chipLoggingModuleNameLen + 1]; + + GetModuleName(moduleName, module); + snprintf(buf, bufSize, chipPrefix "%s" chipPrefixSeparator "%s" chipMessageTrailer, moduleName, msg); +} + +void PrintMessagePrefix(uint8_t module) +{ + char moduleName[chipLoggingModuleNameLen + 1]; + GetModuleName(moduleName, module); + +#if CHIP_LOGGING_STYLE_STDIO_WITH_TIMESTAMPS + struct timeval tv; + struct tm* time_ptr; + char detailed_time[30]; + int64_t milliseconds; + int status; + + status = gettimeofday(&tv, NULL); + VerifyOrExit(status == 0, perror("gettimeofday")); + + time_ptr = localtime(&tv.tv_sec); + VerifyOrExit(time_ptr != NULL, status = -1; perror("localtime")); + + status = strftime(detailed_time, sizeof(detailed_time), "%F %T%z", time_ptr); + VerifyOrExit(status >= 0, perror("strftime")); + + milliseconds = tv.tv_usec / 1000; + printf("%s.%03ld " chipPrefix "%s: ", detailed_time, milliseconds, moduleName); + +exit: + if (status < 0) + { + printf("\?\?\?\?-\?\?-\?\? \?\?:\?\?:\?\?.\?\?\?+\?\?\?\?" chipPrefix "%s: ", moduleName); + } + +#else // !CHIP_LOGGING_STYLE_STDIO_WITH_TIMESTAMPS + + printf(chipPrefix "%s: ", moduleName); + +#endif // CHIP_LOGGING_STYLE_STDIO_WITH_TIMESTAMPS +} + +#if CHIP_LOG_FILTERING + +uint8_t gLogFilter = kLogCategory_Max; + +#endif // CHIP_LOG_FILTERING + +#if !CHIP_LOGGING_STYLE_EXTERNAL +/* + * Only enable an in-package implementation of the logging interface + * if external logging was not requested. Within that, the package + * supports either Android-style or C Standard I/O-style logging. + * + * In the event a "weak" variant is specified, i.e + * CHIP_LOGGING_STYLE_STDIO_WEAK, the in-package implementation will + * be provided but with "weak" linkage + */ + +/** + * Log, to the platform-specified mechanism, the specified log + * message, @a msg, for the specified module, @a module, in the + * provided category, @a category. + * + * @param[in] module A LogModule enumeration indicating the + * source of the chip package module that + * generated the log message. This must be + * translated within the function to a module + * name for inclusion in the log message. + * @param[in] category A LogCategory enumeration indicating the + * category of the log message. The category + * may be filtered in or out if + * CHIP_LOG_FILTERING was asserted. + * @param[in] msg A pointer to a NULL-terminated C string with + * C Standard Library-style format specifiers + * containing the log message to be formatted and + * logged. + * @param[in] ... A variadic argument list whose elements should + * correspond to the format specifiers in @a msg. + * + */ + +#if CHIP_LOGGING_STYLE_STDIO_WEAK +#define __CHIP_LOGGING_LINK_ATTRIBUTE __attribute__((weak)) +#else +#define __CHIP_LOGGING_LINK_ATTRIBUTE +#endif + +DLL_EXPORT __CHIP_LOGGING_LINK_ATTRIBUTE void Log(uint8_t module, uint8_t category, const char *msg, ...) +{ + va_list v; + + va_start(v, msg); + + if (IsCategoryEnabled(category)) + { + +#if CHIP_LOGGING_STYLE_ANDROID + + char moduleName[chipLoggingModuleNameLen + 1]; + GetModuleName(moduleName, module); + + int priority = (category == kLogCategory_Error) ? ANDROID_LOG_ERROR : ANDROID_LOG_DEBUG; + + __android_log_vprint(priority, moduleName, msg, v); + +#elif CHIP_LOGGING_STYLE_STDIO || CHIP_LOGGING_STYLE_STDIO_WEAK + + PrintMessagePrefix(module); + vprintf(msg, v); + printf("\n"); + +#else + +#error "Undefined platform-specific implementation for non-externnal chip logging style!" + +#endif /* CHIP_LOGGING_STYLE_ANDROID */ + + } + + va_end(v); +} +#endif /* !CHIP_LOGGING_STYLE_EXTERNAL */ + +DLL_EXPORT uint8_t GetLogFilter() +{ +#if CHIP_LOG_FILTERING + return gLogFilter; +#else + return kLogCategory_Max; +#endif +} + +DLL_EXPORT void SetLogFilter(uint8_t category) +{ +#if CHIP_LOG_FILTERING + gLogFilter = category; +#endif +} + +#endif /* _CHIP_USE_LOGGING */ + +} // namespace Logging +} // namespace chip diff --git a/src/lib/support/logging/CHIPLogging.h b/src/lib/support/logging/CHIPLogging.h new file mode 100644 index 00000000000000..e0a386f5d294e5 --- /dev/null +++ b/src/lib/support/logging/CHIPLogging.h @@ -0,0 +1,456 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * This file defines macros, constants, and interfaces for a + * platform-independent logging interface for the chip SDK. + * + * chip SDK clients may choose, at compile time, among Android, + * C Standard I/O, or external (platform- and integrator-defined) + * logging style implementations that will be invoked when any of + * the following preprocessor symbols are asserted: + * + * - #CHIP_ERROR_LOGGING + * - #CHIP_PROGRESS_LOGGING + * - #CHIP_DETAIL_LOGGING + * + */ + +#ifndef CHIPLOGGING_H_ +#define CHIPLOGGING_H_ + +#include + +#include + +/** + * @namespace chip::Logging + * + * @brief + * This namespace includes all interfaces within chip for shared + * logging support. + * + * The interfaces include macros, constants, and functions for a + * platform-independent logging interface for the chip SDK. + * + * chip SDK clients may choose, at compile time, among Android, + * C Standard I/O, or external (platform- and integrator-defined) + * logging style implementations that will be invoked when any of + * the following preprocessor symbols are asserted: + * + * - #CHIP_ERROR_LOGGING + * - #CHIP_PROGRESS_LOGGING + * - #CHIP_DETAIL_LOGGING + * + */ + +namespace chip { +namespace Logging { + +/** + * @enum LogModule + * + * @brief + * Identifies a logical section of code that is a source of log + * messages. + * + * @note If you add modules or rearrange this list you must update the + * ModuleNames tables in chipLogging.cpp. + * + */ +enum LogModule +{ + kLogModule_NotSpecified = 0, + + kLogModule_Inet, + kLogModule_Ble, + kLogModule_MessageLayer, + kLogModule_SecurityManager, + kLogModule_ExchangeManager, + kLogModule_TLV, + kLogModule_ASN1, + kLogModule_Crypto, + kLogModule_DeviceManager, + kLogModule_Alarm, + kLogModule_BDX, + kLogModule_DataManagement, + kLogModule_DeviceControl, + kLogModule_DeviceDescription, + kLogModule_Echo, + kLogModule_FabricProvisioning, + kLogModule_NetworkProvisioning, + kLogModule_ServiceDirectory, + kLogModule_ServiceProvisioning, + kLogModule_SoftwareUpdate, + kLogModule_TokenPairing, + kLogModule_TimeService, + kLogModule_chipTunnel, + kLogModule_Heartbeat, + kLogModule_chipSystemLayer, + kLogModule_EventLogging, + kLogModule_Support, + + kLogModule_Max +}; + +/** + * @enum LogCategory + * + * @brief + * Identifies a category to which an particular error message + * belongs. + * + */ +enum LogCategory +{ + /*!< + * This log category indicates, when passed to SetLogFilter(), + * that no messages should be logged. + * + */ + kLogCategory_None = 0, + + /*!< + * Indicates a category of log message that describes an unexpected + * or severe failure. + * + * This log category indicates that a logged message describes + * an unexpected or severe failure in the code. + * + * It should be used for things such as out-of-resource errors, + * internal inconsistencies, API misuse, etc. In general, errors + * that are expected to occur as part of normal operation, or + * that are largely determined by external factors (e.g. network + * errors, user/operator induced errors, etc.) should be logged + * as kLogCategory_Progress messages, not as kLogCategory_Error + * messages. + * + */ + kLogCategory_Error = 1, + + /*!< + * Indicates a category of log message that describes an event + * that marks the start or end of a major activity, or a major + * change in the state of the overall system. + * + * It should be reserved for high-level events. Such messages + * should provide the log reader with a good sense of the + * overall activity of the system at any point in time, while + * being minimally verbose. Where necessary such messages should + * include identifiers or other values that can be used to + * correlate messages involving a common actor or subject + * (e.g. connection ids, request ids, etc.) and/or to identify + * types of actions being taken or handled (e.g. message types, + * requested resource types, error numbers, etc.). + * + */ + kLogCategory_Progress = 2, + + /*!< + * Indicates a category of log message that describes detailed + * information about an event or the state of the system. + * + * Such messages can be used to provide ancillary information + * not suitable for the kLogCategory_Error and + * kLogCategory_Progress categories. + * + */ + kLogCategory_Detail = 3, + + /*!< + * Indicates a category of log message that describes information + * needed by IE and QA teams for automated testing. + * + */ + kLogCategory_Retain = 4, + + kLogCategory_Max = kLogCategory_Retain +}; + +extern void Log(uint8_t module, uint8_t category, const char *msg, ...); +extern uint8_t GetLogFilter(void); +extern void SetLogFilter(uint8_t category); + +#ifndef CHIP_ERROR_LOGGING +#define CHIP_ERROR_LOGGING 1 +#endif + +#ifndef CHIP_LOG_FILTERING +#define CHIP_LOG_FILTERING 1 +#endif + +#if CHIP_ERROR_LOGGING +/** + * @def chipLogError(MOD, MSG, ...) + * + * @brief + * Log a chip message for the specified module in the 'Error' + * category. + * + */ +#ifndef chipLogError +#define chipLogError(MOD, MSG, ...) chip::Logging::Log( chip::Logging::kLogModule_##MOD , chip::Logging::kLogCategory_Error, MSG, ## __VA_ARGS__) +#endif +#else +#define chipLogError(MOD, MSG, ...) +#endif + +#ifndef CHIP_PROGRESS_LOGGING +#define CHIP_PROGRESS_LOGGING 1 +#endif + +#if CHIP_PROGRESS_LOGGING +/** + * @def chipLogProgress(MOD, MSG, ...) + * + * @brief + * Log a chip message for the specified module in the 'Progress' + * category. + * + */ +#ifndef chipLogProgress +#define chipLogProgress(MOD, MSG, ...) chip::Logging::Log( chip::Logging::kLogModule_##MOD , chip::Logging::kLogCategory_Progress, MSG, ## __VA_ARGS__) +#endif +#else +#define chipLogProgress(MOD, MSG, ...) +#endif + + +#ifndef CHIP_DETAIL_LOGGING +#define CHIP_DETAIL_LOGGING 1 +#endif + +#if CHIP_DETAIL_LOGGING +/** + * @def chipLogDetail(MOD, MSG, ...) + * + * @brief + * Log a chip message for the specified module in the 'Detail' + * category. + * + */ +#ifndef chipLogDetail +#define chipLogDetail(MOD, MSG, ...) chip::Logging::Log( chip::Logging::kLogModule_##MOD , chip::Logging::kLogCategory_Detail, MSG, ## __VA_ARGS__) +#endif +#else +#define chipLogDetail(MOD, MSG, ...) +#endif + +#ifndef CHIP_RETAIN_LOGGING +#define CHIP_RETAIN_LOGGING CHIP_PROGRESS_LOGGING +#define chipLogRetain(MOD, MSG, ...) chipLogProgress(MOD, MSG, ## __VA_ARGS__) +#endif + +#if CHIP_RETAIN_LOGGING +/** + * @def chipLogRetain(MOD, MSG, ...) + * + * @brief + * Log a chip message for the specified module in the 'Retain' + * category. This is used for IE testing. + * If the product has not defined CHIP_RETAIN_LOGGING, it defaults to the same as chipLogProgress + * + */ +#ifndef chipLogRetain +#define chipLogRetain(MOD, MSG, ...) chip::Logging::Log( chip::Logging::kLogModule_##MOD , chip::Logging::kLogCategory_Retain, MSG, ## __VA_ARGS__) +#endif + +#else // #if CHIP_RETAIN_LOGGING +#ifdef chipLogRetain +// This is to ensure that chipLogRetain is null if +// the product has defined CHIP_RETAIN_LOGGING to 0 itself +#undef chipLogRetain +#endif +#define chipLogRetain(MOD, MSG, ...) +#endif // #if CHIP_RETAIN_LOGGING + + +#if CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING || CHIP_RETAIN_LOGGING +#define _CHIP_USE_LOGGING 1 +#else +#define _CHIP_USE_LOGGING 0 +#endif /* CHIP_ERROR_LOGGING || CHIP_PROGRESS_LOGGING || CHIP_DETAIL_LOGGING || CHIP_RETAIN_LOGGING */ + +#if _CHIP_USE_LOGGING + +#define chipLoggingchipPrefixLen 6 +#define chipLoggingModuleNameLen 3 +#define chipLoggingMessageSeparatorLen 2 +#define chipLoggingMessageTrailerLen 2 +#define chipLoggingTotalMessagePadding (chipLoggingchipPrefixLen + \ + chipLoggingModuleNameLen + \ + chipLoggingMessageSeparatorLen + \ + chipLoggingMessageTrailerLen) + +extern void GetMessageWithPrefix(char *buf, uint8_t bufSize, uint8_t module, const char *msg); +extern void GetModuleName(char *buf, uint8_t module); +void PrintMessagePrefix(uint8_t module); + +#else + +static inline void GetMessageWithPrefix(char *buf, uint8_t bufSize, uint8_t module, const char *msg) +{ + return; +} + +static inline void GetModuleName(char *buf, uint8_t module) +{ + return; +} + +#endif // _CHIP_USE_LOGGING + +#if CHIP_LOG_FILTERING + +extern uint8_t gLogFilter; + +#define IsCategoryEnabled(CAT) ((CAT) <= gLogFilter) + +#else // CHIP_LOG_FILTERING + +#define IsCategoryEnabled(CAT) (true) + +#endif // CHIP_LOG_FILTERING + + + +/** + * @def chipLogIfFalse(aCondition) + * + * @brief + * This checks for the specified condition, which is expected to + * commonly be true and emits some log, based on configuration, if + * the condition is false. + * + * @note + * Evaluation of @a aCondition is always done, but logging is only enabled when + * #CHIP_CONFIG_ENABLE_CONDITION_LOGGING is enabled. This can be turned on or + * off for each compilation unit by enabling or disabling, as desired, + * #CHIP_CONFIG_ENABLE_CONDITION_LOGGING before chipLogging.h is included by + * the preprocessor. + * + * Example Usage: + * + * @code + * #define CHIP_CONFIG_ENABLE_CONDITION_LOGGING 1 + * + * #include + * + * ... + * + * void foo(void) + * { + * CHIP_ERROR err = CHIP_NO_ERROR; + * + * ... + * + * exit: + * chipLogIfFalse(CHIP_END_OF_TLV == err); + * } + * @endcode + * + * @param[in] aCondition A Boolean expression to be evaluated. + * + * @sa CHIP_CONFIG_ENABLE_TRACE_ON_CHECK_FAILURE + * + */ + +#if CHIP_CONFIG_ENABLE_CONDITION_LOGGING && !defined(chipLogIfFalse) + +#define chipLogIfFalse(aCondition) \ +do \ +{ \ + if (!(aCondition)) \ + { \ + chipLogError(NotSpecified, "Condition Failed (%s) at %s:%d", \ + #aCondition, __FILE__, __LINE__); \ + } \ +} while (0) + +#else // CHIP_CONFIG_ENABLE_CONDITION_LOGGING + +#define chipLogIfFalse(aCondition) \ + IgnoreUnusedVariable(aCondition) + +#endif // CHIP_CONFIG_ENABLE_CONDITION_LOGGING + + +/** + * @def chipLogFunctError(aErr) + * + * @brief + * If the given error value (@a aErr) is not successful (!= CHIP_NO_ERROR), + * the method logs the file name, line number, and the error code. + * + * @note + * Evaluation of @a aErr is always done, but logging is only enabled when + * #CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING is enabled. This can be turned + * on or off for each compilation unit by enabling or disabling, as desired, + * #CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING before chipLogging.h is included + * by the preprocessor. + * + * Example Usage: + * + * @code + * #define CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING 1 + * + * #include + * + * ... + * + * void foo(void) + * { + * CHIP_ERROR err = CHIP_NO_ERROR; + * + * ... + * + * exit: + * chipLogFunctError(err); + * } + * @endcode + * + * @param[in] aErr A scalar status to be evaluated against CHIP_NO_ERROR. + * + * @sa #CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING + * + */ + +#if CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING && !defined(chipLogFunctError) + +#define chipLogFunctError(aErr) \ +do \ +{ \ + if ((aErr) != CHIP_NO_ERROR) \ + { \ + chipLogError(NotSpecified, "%s at %s:%d", ErrorStr(aErr), __FILE__, __LINE__);\ + } \ +} while (0) + +#else // CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING + +#define chipLogFunctError(aErr) \ + IgnoreUnusedVariable(aErr) + +#endif // CHIP_CONFIG_ENABLE_FUNCT_ERROR_LOGGING + + + +} // namespace Logging +} // namespace chip + +#endif /* CHIPLOGGING_H_ */