diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index b28b1a6049..40fa8f5075 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -658,23 +658,25 @@ if(CONFIG_BT_ENABLED) if(NOT (CONFIG_BT_LE_CRYPTO_STACK_MBEDTLS OR CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS)) list(APPEND include_dirs - porting/ext/tinycrypt/include + common/tinycrypt/include + common/tinycrypt/port ) - list(APPEND srcs "porting/ext/tinycrypt/src/utils.c" - "porting/ext/tinycrypt/src/sha256.c" - "porting/ext/tinycrypt/src/ecc.c" - "porting/ext/tinycrypt/src/ctr_prng.c" - "porting/ext/tinycrypt/src/ctr_mode.c" - "porting/ext/tinycrypt/src/aes_decrypt.c" - "porting/ext/tinycrypt/src/aes_encrypt.c" - "porting/ext/tinycrypt/src/ccm_mode.c" - "porting/ext/tinycrypt/src/ecc_dsa.c" - "porting/ext/tinycrypt/src/cmac_mode.c" - "porting/ext/tinycrypt/src/ecc_dh.c" - "porting/ext/tinycrypt/src/hmac_prng.c" - "porting/ext/tinycrypt/src/ecc_platform_specific.c" - "porting/ext/tinycrypt/src/hmac.c" - "porting/ext/tinycrypt/src/cbc_mode.c") + list(APPEND srcs "common/tinycrypt/src/utils.c" + "common/tinycrypt/src/sha256.c" + "common/tinycrypt/src/ecc.c" + "common/tinycrypt/src/ctr_prng.c" + "common/tinycrypt/src/ctr_mode.c" + "common/tinycrypt/src/aes_decrypt.c" + "common/tinycrypt/src/aes_encrypt.c" + "common/tinycrypt/src/ccm_mode.c" + "common/tinycrypt/src/ecc_dsa.c" + "common/tinycrypt/src/cmac_mode.c" + "common/tinycrypt/src/ecc_dh.c" + "common/tinycrypt/src/hmac_prng.c" + "common/tinycrypt/src/ecc_platform_specific.c" + "common/tinycrypt/src/hmac.c" + "common/tinycrypt/src/cbc_mode.c" + "common/tinycrypt/port/esp_tinycrypt_port.c") endif() if(CONFIG_BT_NIMBLE_ENABLED) diff --git a/components/bt/porting/ext/tinycrypt/AUTHORS b/components/bt/common/tinycrypt/AUTHORS similarity index 100% rename from components/bt/porting/ext/tinycrypt/AUTHORS rename to components/bt/common/tinycrypt/AUTHORS diff --git a/components/bt/porting/ext/tinycrypt/LICENSE b/components/bt/common/tinycrypt/LICENSE similarity index 100% rename from components/bt/porting/ext/tinycrypt/LICENSE rename to components/bt/common/tinycrypt/LICENSE diff --git a/components/bt/porting/ext/tinycrypt/README b/components/bt/common/tinycrypt/README similarity index 100% rename from components/bt/porting/ext/tinycrypt/README rename to components/bt/common/tinycrypt/README diff --git a/components/bt/porting/ext/tinycrypt/VERSION b/components/bt/common/tinycrypt/VERSION similarity index 100% rename from components/bt/porting/ext/tinycrypt/VERSION rename to components/bt/common/tinycrypt/VERSION diff --git a/components/bt/porting/ext/tinycrypt/documentation/tinycrypt.rst b/components/bt/common/tinycrypt/documentation/tinycrypt.rst similarity index 100% rename from components/bt/porting/ext/tinycrypt/documentation/tinycrypt.rst rename to components/bt/common/tinycrypt/documentation/tinycrypt.rst diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/aes.h b/components/bt/common/tinycrypt/include/tinycrypt/aes.h similarity index 97% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/aes.h rename to components/bt/common/tinycrypt/include/tinycrypt/aes.h index 885c02e089..04f6de5085 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/aes.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/aes.h @@ -1,4 +1,8 @@ -/* aes.h - TinyCrypt interface to an AES-128 implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/cbc_mode.h b/components/bt/common/tinycrypt/include/tinycrypt/cbc_mode.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/cbc_mode.h rename to components/bt/common/tinycrypt/include/tinycrypt/cbc_mode.h index 4a837fd01a..dadc59fc8e 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/cbc_mode.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/cbc_mode.h @@ -1,4 +1,8 @@ -/* cbc_mode.h - TinyCrypt interface to a CBC mode implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ccm_mode.h b/components/bt/common/tinycrypt/include/tinycrypt/ccm_mode.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ccm_mode.h rename to components/bt/common/tinycrypt/include/tinycrypt/ccm_mode.h index 69c798e2f5..af9d79ba39 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ccm_mode.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ccm_mode.h @@ -1,4 +1,8 @@ -/* ccm_mode.h - TinyCrypt interface to a CCM mode implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/cmac_mode.h b/components/bt/common/tinycrypt/include/tinycrypt/cmac_mode.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/cmac_mode.h rename to components/bt/common/tinycrypt/include/tinycrypt/cmac_mode.h index f44b0a53c1..e1cf7d5698 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/cmac_mode.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/cmac_mode.h @@ -1,4 +1,8 @@ -/* cmac_mode.h -- interface to a CMAC implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/constants.h b/components/bt/common/tinycrypt/include/tinycrypt/constants.h similarity index 94% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/constants.h rename to components/bt/common/tinycrypt/include/tinycrypt/constants.h index 965490e00c..3abe98dbbf 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/constants.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/constants.h @@ -1,4 +1,8 @@ -/* constants.h - TinyCrypt interface to constants */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_mode.h b/components/bt/common/tinycrypt/include/tinycrypt/ctr_mode.h similarity index 97% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_mode.h rename to components/bt/common/tinycrypt/include/tinycrypt/ctr_mode.h index dc221f9ee7..1b0bab4323 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_mode.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ctr_mode.h @@ -1,4 +1,8 @@ -/* ctr_mode.h - TinyCrypt interface to CTR mode */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_prng.h b/components/bt/common/tinycrypt/include/tinycrypt/ctr_prng.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_prng.h rename to components/bt/common/tinycrypt/include/tinycrypt/ctr_prng.h index 69cbe020ad..ecff008ded 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ctr_prng.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ctr_prng.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* ctr_prng.h - TinyCrypt interface to a CTR-PRNG implementation */ /* diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc.h b/components/bt/common/tinycrypt/include/tinycrypt/ecc.h similarity index 99% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc.h rename to components/bt/common/tinycrypt/include/tinycrypt/ecc.h index e8357320ab..d963ae3c08 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ecc.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* ecc.h - TinyCrypt interface to common ECC functions */ /* Copyright (c) 2014, Kenneth MacKay diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dh.h b/components/bt/common/tinycrypt/include/tinycrypt/ecc_dh.h similarity index 97% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dh.h rename to components/bt/common/tinycrypt/include/tinycrypt/ecc_dh.h index b828e195db..e28e8a6538 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dh.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ecc_dh.h @@ -1,4 +1,8 @@ -/* ecc_dh.h - TinyCrypt interface to EC-DH implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (c) 2014, Kenneth MacKay diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dsa.h b/components/bt/common/tinycrypt/include/tinycrypt/ecc_dsa.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dsa.h rename to components/bt/common/tinycrypt/include/tinycrypt/ecc_dsa.h index aca00bc95e..76181088e3 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_dsa.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ecc_dsa.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* ecc_dh.h - TinyCrypt interface to EC-DSA implementation */ /* diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_platform_specific.h b/components/bt/common/tinycrypt/include/tinycrypt/ecc_platform_specific.h similarity index 97% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_platform_specific.h rename to components/bt/common/tinycrypt/include/tinycrypt/ecc_platform_specific.h index a55adf4f6a..553c8a03de 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/ecc_platform_specific.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/ecc_platform_specific.h @@ -1,4 +1,8 @@ -/* uECC_platform_specific.h - Interface to platform specific functions*/ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* Copyright (c) 2014, Kenneth MacKay * All rights reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac.h b/components/bt/common/tinycrypt/include/tinycrypt/hmac.h similarity index 96% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac.h rename to components/bt/common/tinycrypt/include/tinycrypt/hmac.h index 3a081494a8..1f624ef827 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/hmac.h @@ -1,4 +1,8 @@ -/* hmac.h - TinyCrypt interface to an HMAC implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -124,7 +128,7 @@ int tc_hmac_update(TCHmacState_t ctx, const void *data, * key == NULL or * taglen != TC_SHA256_DIGEST_SIZE * @note ctx is erased before exiting. This should never be changed/removed. - * @note Assumes the tag bufer is at least sizeof(hmac_tag_size(state)) bytes + * @note Assumes the tag buffer is at least sizeof(hmac_tag_size(state)) bytes * state has been initialized by tc_hmac_init * @param tag IN/OUT -- buffer to receive computed HMAC tag * @param taglen IN -- size of tag in bytes diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac_prng.h b/components/bt/common/tinycrypt/include/tinycrypt/hmac_prng.h similarity index 98% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac_prng.h rename to components/bt/common/tinycrypt/include/tinycrypt/hmac_prng.h index ad12cbbf0f..98c2e70c31 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/hmac_prng.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/hmac_prng.h @@ -1,4 +1,8 @@ -/* hmac_prng.h - TinyCrypt interface to an HMAC-PRNG implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/sha256.h b/components/bt/common/tinycrypt/include/tinycrypt/sha256.h similarity index 97% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/sha256.h rename to components/bt/common/tinycrypt/include/tinycrypt/sha256.h index af5e8baf79..860665eeaf 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/sha256.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/sha256.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* sha256.h - TinyCrypt interface to a SHA-256 implementation */ /* diff --git a/components/bt/porting/ext/tinycrypt/include/tinycrypt/utils.h b/components/bt/common/tinycrypt/include/tinycrypt/utils.h similarity index 96% rename from components/bt/porting/ext/tinycrypt/include/tinycrypt/utils.h rename to components/bt/common/tinycrypt/include/tinycrypt/utils.h index bab5c3202e..18224c894e 100644 --- a/components/bt/porting/ext/tinycrypt/include/tinycrypt/utils.h +++ b/components/bt/common/tinycrypt/include/tinycrypt/utils.h @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* utils.h - TinyCrypt interface to platform-dependent run-time operations */ /* diff --git a/components/bt/common/tinycrypt/port/esp_tinycrypt_port.c b/components/bt/common/tinycrypt/port/esp_tinycrypt_port.c new file mode 100644 index 0000000000..c4424c56eb --- /dev/null +++ b/components/bt/common/tinycrypt/port/esp_tinycrypt_port.c @@ -0,0 +1,87 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include "esp_tinycrypt_port.h" + +#include "esp_crypto_lock.h" +#include "esp_private/esp_crypto_lock_internal.h" + +#if SOC_ECC_SUPPORTED +#include "hal/ecc_hal.h" +#include "hal/ecc_ll.h" +#endif /* SOC_ECC_SUPPORTED */ + + +#if SOC_ECC_SUPPORTED +static void esp_tinycrypt_acquire_ecc_hardware(void) +{ + esp_crypto_ecc_lock_acquire(); + + ECC_RCC_ATOMIC() { + ecc_ll_enable_bus_clock(true); + ecc_ll_power_up(); + ecc_ll_reset_register(); + } +} + +static void esp_tinycrypt_release_ecc_hardware(void) +{ + ECC_RCC_ATOMIC() { + ecc_ll_enable_bus_clock(false); + ecc_ll_power_down(); + } + + esp_crypto_ecc_lock_release(); +} + +int esp_tinycrypt_verify_ecc_point(const uint8_t *pk_x, const uint8_t *pk_y, uint8_t length) +{ + int result; + + esp_tinycrypt_acquire_ecc_hardware(); + + ecc_hal_write_verify_param(pk_x, pk_y, length); + ecc_hal_set_mode(ECC_MODE_VERIFY); + ecc_hal_start_calc(); + while (!ecc_hal_is_calc_finished()); + result = ecc_hal_read_verify_result(); + + esp_tinycrypt_release_ecc_hardware(); + + if (result == 1) { + return 0; + } else { + return -1; + } +} + +int esp_tinycrypt_calc_ecc_mult(const uint8_t *p_x, const uint8_t *p_y, const uint8_t *scalar, + uint8_t *r_x, uint8_t *r_y, uint8_t num_bytes, bool verify_first) +{ + int ret = -1; + ecc_mode_t work_mode = verify_first ? ECC_MODE_VERIFY_THEN_POINT_MUL : ECC_MODE_POINT_MUL; + + esp_tinycrypt_acquire_ecc_hardware(); + + ecc_hal_write_mul_param(scalar, p_x, p_y, num_bytes); + ecc_hal_set_mode(work_mode); + /* + * Enable constant-time point multiplication operations for the ECC hardware accelerator, + * if supported for the given target. This protects the ECC multiplication operation from + * timing attacks. This increases the time taken (by almost 50%) for some point + * multiplication operations performed by the ECC hardware accelerator. + */ + ecc_hal_enable_constant_time_point_mul(true); + ecc_hal_start_calc(); + + while (!ecc_hal_is_calc_finished()); + + ret = ecc_hal_read_mul_result(r_x, r_y, num_bytes); + + esp_tinycrypt_release_ecc_hardware(); + + return ret; +} +#endif /* SOC_ECC_SUPPORTED */ diff --git a/components/bt/common/tinycrypt/port/esp_tinycrypt_port.h b/components/bt/common/tinycrypt/port/esp_tinycrypt_port.h new file mode 100644 index 0000000000..4fdf82c2f9 --- /dev/null +++ b/components/bt/common/tinycrypt/port/esp_tinycrypt_port.h @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include "soc/soc_caps.h" + +#if SOC_ECC_SUPPORTED +int esp_tinycrypt_verify_ecc_point(const uint8_t *pk_x, const uint8_t *pk_y, uint8_t length); + +int esp_tinycrypt_calc_ecc_mult(const uint8_t *p_x, const uint8_t *p_y, const uint8_t *scalar, + uint8_t *r_x, uint8_t *r_y, uint8_t num_bytes, bool verify_first); +#endif /* SOC_ECC_SUPPORTED */ diff --git a/components/bt/porting/ext/tinycrypt/src/aes_decrypt.c b/components/bt/common/tinycrypt/src/aes_decrypt.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/aes_decrypt.c rename to components/bt/common/tinycrypt/src/aes_decrypt.c index 993a6180ce..7da523491f 100644 --- a/components/bt/porting/ext/tinycrypt/src/aes_decrypt.c +++ b/components/bt/common/tinycrypt/src/aes_decrypt.c @@ -1,4 +1,8 @@ -/* aes_decrypt.c - TinyCrypt implementation of AES decryption procedure */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -30,6 +34,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* aes_decrypt.c - TinyCrypt implementation of AES decryption procedure */ + #include #include #include diff --git a/components/bt/porting/ext/tinycrypt/src/aes_encrypt.c b/components/bt/common/tinycrypt/src/aes_encrypt.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/aes_encrypt.c rename to components/bt/common/tinycrypt/src/aes_encrypt.c index 8991aee522..7095695dfa 100644 --- a/components/bt/porting/ext/tinycrypt/src/aes_encrypt.c +++ b/components/bt/common/tinycrypt/src/aes_encrypt.c @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* aes_encrypt.c - TinyCrypt implementation of AES encryption procedure */ /* diff --git a/components/bt/porting/ext/tinycrypt/src/cbc_mode.c b/components/bt/common/tinycrypt/src/cbc_mode.c similarity index 96% rename from components/bt/porting/ext/tinycrypt/src/cbc_mode.c rename to components/bt/common/tinycrypt/src/cbc_mode.c index 62d7879ebd..86a00c8da6 100644 --- a/components/bt/porting/ext/tinycrypt/src/cbc_mode.c +++ b/components/bt/common/tinycrypt/src/cbc_mode.c @@ -1,4 +1,8 @@ -/* cbc_mode.c - TinyCrypt implementation of CBC mode encryption & decryption */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/src/ccm_mode.c b/components/bt/common/tinycrypt/src/ccm_mode.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/ccm_mode.c rename to components/bt/common/tinycrypt/src/ccm_mode.c index 929adac630..4017d249df 100644 --- a/components/bt/porting/ext/tinycrypt/src/ccm_mode.c +++ b/components/bt/common/tinycrypt/src/ccm_mode.c @@ -1,4 +1,8 @@ -/* ccm_mode.c - TinyCrypt implementation of CCM mode */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -30,6 +34,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* ccm_mode.c - TinyCrypt implementation of CCM mode */ + #include #include #include diff --git a/components/bt/porting/ext/tinycrypt/src/cmac_mode.c b/components/bt/common/tinycrypt/src/cmac_mode.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/cmac_mode.c rename to components/bt/common/tinycrypt/src/cmac_mode.c index 96d147e809..c3e2c4ee31 100644 --- a/components/bt/porting/ext/tinycrypt/src/cmac_mode.c +++ b/components/bt/common/tinycrypt/src/cmac_mode.c @@ -1,4 +1,8 @@ -/* cmac_mode.c - TinyCrypt CMAC mode implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/src/ctr_mode.c b/components/bt/common/tinycrypt/src/ctr_mode.c similarity index 96% rename from components/bt/porting/ext/tinycrypt/src/ctr_mode.c rename to components/bt/common/tinycrypt/src/ctr_mode.c index 1dfb92dfec..96d03a5bed 100644 --- a/components/bt/porting/ext/tinycrypt/src/ctr_mode.c +++ b/components/bt/common/tinycrypt/src/ctr_mode.c @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* ctr_mode.c - TinyCrypt CTR mode implementation */ /* diff --git a/components/bt/porting/ext/tinycrypt/src/ctr_prng.c b/components/bt/common/tinycrypt/src/ctr_prng.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/ctr_prng.c rename to components/bt/common/tinycrypt/src/ctr_prng.c index 5090c3975e..009c7de20a 100644 --- a/components/bt/porting/ext/tinycrypt/src/ctr_prng.c +++ b/components/bt/common/tinycrypt/src/ctr_prng.c @@ -1,4 +1,8 @@ -/* ctr_prng.c - TinyCrypt implementation of CTR-PRNG */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (c) 2016, Chris Morrison diff --git a/components/bt/porting/ext/tinycrypt/src/ecc.c b/components/bt/common/tinycrypt/src/ecc.c similarity index 96% rename from components/bt/porting/ext/tinycrypt/src/ecc.c rename to components/bt/common/tinycrypt/src/ecc.c index 03d9187f3a..1027c9a293 100644 --- a/components/bt/porting/ext/tinycrypt/src/ecc.c +++ b/components/bt/common/tinycrypt/src/ecc.c @@ -1,4 +1,8 @@ -/* ecc.c - TinyCrypt implementation of common ECC functions */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (c) 2014, Kenneth MacKay @@ -55,6 +59,9 @@ #include #include #include +#include + +#include "esp_tinycrypt_port.h" /* IMPORTANT: Make sure a cryptographically-secure PRNG is set and the platform * has access to enough entropy in order to feed the PRNG regularly. */ @@ -635,6 +642,7 @@ void apply_z(uECC_word_t * X1, uECC_word_t * Y1, const uECC_word_t * const Z, uECC_vli_modMult_fast(Y1, Y1, t1, curve); /* y1 * z^3 */ } +#if !SOC_ECC_SUPPORTED /* P = (x1, y1) => 2P, (x2, y2) => P' */ static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1, uECC_word_t * X2, uECC_word_t * Y2, @@ -658,31 +666,6 @@ static void XYcZ_initial_double(uECC_word_t * X1, uECC_word_t * Y1, apply_z(X2, Y2, z, curve); } -void XYcZ_add(uECC_word_t * X1, uECC_word_t * Y1, - uECC_word_t * X2, uECC_word_t * Y2, - uECC_Curve curve) -{ - /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ - uECC_word_t t5[NUM_ECC_WORDS]; - wordcount_t num_words = curve->num_words; - - uECC_vli_modSub(t5, X2, X1, curve->p, num_words); /* t5 = x2 - x1 */ - uECC_vli_modSquare_fast(t5, t5, curve); /* t5 = (x2 - x1)^2 = A */ - uECC_vli_modMult_fast(X1, X1, t5, curve); /* t1 = x1*A = B */ - uECC_vli_modMult_fast(X2, X2, t5, curve); /* t3 = x2*A = C */ - uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y2 - y1 */ - uECC_vli_modSquare_fast(t5, Y2, curve); /* t5 = (y2 - y1)^2 = D */ - - uECC_vli_modSub(t5, t5, X1, curve->p, num_words); /* t5 = D - B */ - uECC_vli_modSub(t5, t5, X2, curve->p, num_words); /* t5 = D - B - C = x3 */ - uECC_vli_modSub(X2, X2, X1, curve->p, num_words); /* t3 = C - B */ - uECC_vli_modMult_fast(Y1, Y1, X2, curve); /* t2 = y1*(C - B) */ - uECC_vli_modSub(X2, X1, t5, curve->p, num_words); /* t3 = B - x3 */ - uECC_vli_modMult_fast(Y2, Y2, X2, curve); /* t4 = (y2 - y1)*(B - x3) */ - uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y3 */ - - uECC_vli_set(X2, t5, num_words); -} /* Input P = (x1, y1, Z), Q = (x2, y2, Z) Output P + Q = (x3, y3, Z3), P - Q = (x3', y3', Z3) @@ -725,12 +708,49 @@ static void XYcZ_addC(uECC_word_t * X1, uECC_word_t * Y1, uECC_vli_set(X1, t7, num_words); } +#endif /* !SOC_ECC_SUPPORTED */ + +void XYcZ_add(uECC_word_t * X1, uECC_word_t * Y1, + uECC_word_t * X2, uECC_word_t * Y2, + uECC_Curve curve) +{ + /* t1 = X1, t2 = Y1, t3 = X2, t4 = Y2 */ + uECC_word_t t5[NUM_ECC_WORDS]; + wordcount_t num_words = curve->num_words; + + uECC_vli_modSub(t5, X2, X1, curve->p, num_words); /* t5 = x2 - x1 */ + uECC_vli_modSquare_fast(t5, t5, curve); /* t5 = (x2 - x1)^2 = A */ + uECC_vli_modMult_fast(X1, X1, t5, curve); /* t1 = x1*A = B */ + uECC_vli_modMult_fast(X2, X2, t5, curve); /* t3 = x2*A = C */ + uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y2 - y1 */ + uECC_vli_modSquare_fast(t5, Y2, curve); /* t5 = (y2 - y1)^2 = D */ + + uECC_vli_modSub(t5, t5, X1, curve->p, num_words); /* t5 = D - B */ + uECC_vli_modSub(t5, t5, X2, curve->p, num_words); /* t5 = D - B - C = x3 */ + uECC_vli_modSub(X2, X2, X1, curve->p, num_words); /* t3 = C - B */ + uECC_vli_modMult_fast(Y1, Y1, X2, curve); /* t2 = y1*(C - B) */ + uECC_vli_modSub(X2, X1, t5, curve->p, num_words); /* t3 = B - x3 */ + uECC_vli_modMult_fast(Y2, Y2, X2, curve); /* t4 = (y2 - y1)*(B - x3) */ + uECC_vli_modSub(Y2, Y2, Y1, curve->p, num_words); /* t4 = y3 */ + + uECC_vli_set(X2, t5, num_words); +} void EccPoint_mult(uECC_word_t * result, const uECC_word_t * point, const uECC_word_t * scalar, const uECC_word_t * initial_Z, bitcount_t num_bits, uECC_Curve curve) { +#if SOC_ECC_SUPPORTED + wordcount_t num_words = curve->num_words; + + /* Only p256r1 is supported currently. */ + assert (curve == uECC_secp256r1()); + + esp_tinycrypt_calc_ecc_mult((const uint8_t *)&point[0], (const uint8_t *)&point[num_words], + (uint8_t *)scalar, (uint8_t *)&result[0], (uint8_t *)&result[num_words], + num_words * uECC_WORD_SIZE, false); +#else /* R0 and R1 */ uECC_word_t Rx[2][NUM_ECC_WORDS]; uECC_word_t Ry[2][NUM_ECC_WORDS]; @@ -769,6 +789,7 @@ void EccPoint_mult(uECC_word_t * result, const uECC_word_t * point, uECC_vli_set(result, Rx[0], num_words); uECC_vli_set(result + num_words, Ry[0], num_words); +#endif /* SOC_ECC_SUPPORTED */ } uECC_word_t regularize_k(const uECC_word_t * const k, uECC_word_t *k0, @@ -862,8 +883,6 @@ int uECC_generate_random_int(uECC_word_t *random, const uECC_word_t *top, int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve) { - uECC_word_t tmp1[NUM_ECC_WORDS]; - uECC_word_t tmp2[NUM_ECC_WORDS]; wordcount_t num_words = curve->num_words; /* The point at infinity is invalid. */ @@ -877,19 +896,34 @@ int uECC_valid_point(const uECC_word_t *point, uECC_Curve curve) return -2; } +#if SOC_ECC_SUPPORTED + /* Only p256r1 is supported currently. */ + if (curve != uECC_secp256r1()) { + return -5; + } + + if (esp_tinycrypt_verify_ecc_point((const uint8_t *)&point[0], + (const uint8_t *)&point[num_words], + num_words * uECC_WORD_SIZE)) { + return -3; + } +#else + uECC_word_t tmp1[NUM_ECC_WORDS]; + uECC_word_t tmp2[NUM_ECC_WORDS]; + uECC_vli_modSquare_fast(tmp1, point + num_words, curve); curve->x_side(tmp2, point, curve); /* tmp2 = x^3 + ax + b */ /* Make sure that y^2 == x^3 + ax + b */ if (uECC_vli_equal(tmp1, tmp2, num_words) != 0) return -3; +#endif /* SOC_ECC_SUPPORTED */ return 0; } int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve) { - uECC_word_t _public[NUM_ECC_WORDS * 2]; uECC_vli_bytesToNative(_public, public_key, curve->num_bytes); @@ -908,7 +942,6 @@ int uECC_valid_public_key(const uint8_t *public_key, uECC_Curve curve) int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key, uECC_Curve curve) { - uECC_word_t _private[NUM_ECC_WORDS]; uECC_word_t _public[NUM_ECC_WORDS * 2]; diff --git a/components/bt/porting/ext/tinycrypt/src/ecc_dh.c b/components/bt/common/tinycrypt/src/ecc_dh.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/ecc_dh.c rename to components/bt/common/tinycrypt/src/ecc_dh.c index ecd8df3b70..fab692da80 100644 --- a/components/bt/porting/ext/tinycrypt/src/ecc_dh.c +++ b/components/bt/common/tinycrypt/src/ecc_dh.c @@ -1,4 +1,8 @@ -/* ec_dh.c - TinyCrypt implementation of EC-DH */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (c) 2014, Kenneth MacKay diff --git a/components/bt/porting/ext/tinycrypt/src/ecc_dsa.c b/components/bt/common/tinycrypt/src/ecc_dsa.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/ecc_dsa.c rename to components/bt/common/tinycrypt/src/ecc_dsa.c index 02424d4ea6..03a91f09dd 100644 --- a/components/bt/porting/ext/tinycrypt/src/ecc_dsa.c +++ b/components/bt/common/tinycrypt/src/ecc_dsa.c @@ -1,4 +1,8 @@ -/* ec_dsa.c - TinyCrypt implementation of EC-DSA */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* Copyright (c) 2014, Kenneth MacKay * All rights reserved. diff --git a/components/bt/porting/ext/tinycrypt/src/ecc_platform_specific.c b/components/bt/common/tinycrypt/src/ecc_platform_specific.c similarity index 97% rename from components/bt/porting/ext/tinycrypt/src/ecc_platform_specific.c rename to components/bt/common/tinycrypt/src/ecc_platform_specific.c index ca7650d89a..b76ea994c2 100644 --- a/components/bt/porting/ext/tinycrypt/src/ecc_platform_specific.c +++ b/components/bt/common/tinycrypt/src/ecc_platform_specific.c @@ -1,3 +1,9 @@ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + /* uECC_platform_specific.c - Implementation of platform specific functions*/ /* Copyright (c) 2014, Kenneth MacKay diff --git a/components/bt/porting/ext/tinycrypt/src/hmac.c b/components/bt/common/tinycrypt/src/hmac.c similarity index 97% rename from components/bt/porting/ext/tinycrypt/src/hmac.c rename to components/bt/common/tinycrypt/src/hmac.c index 89878cec78..7723243475 100644 --- a/components/bt/porting/ext/tinycrypt/src/hmac.c +++ b/components/bt/common/tinycrypt/src/hmac.c @@ -1,4 +1,8 @@ -/* hmac.c - TinyCrypt implementation of the HMAC algorithm */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/src/hmac_prng.c b/components/bt/common/tinycrypt/src/hmac_prng.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/hmac_prng.c rename to components/bt/common/tinycrypt/src/hmac_prng.c index 68b5b1fafb..1e3a52fb46 100644 --- a/components/bt/porting/ext/tinycrypt/src/hmac_prng.c +++ b/components/bt/common/tinycrypt/src/hmac_prng.c @@ -1,4 +1,8 @@ -/* hmac_prng.c - TinyCrypt implementation of HMAC-PRNG */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -30,6 +34,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* hmac_prng.c - TinyCrypt implementation of HMAC-PRNG */ + #include #include #include diff --git a/components/bt/porting/ext/tinycrypt/src/sha256.c b/components/bt/common/tinycrypt/src/sha256.c similarity index 98% rename from components/bt/porting/ext/tinycrypt/src/sha256.c rename to components/bt/common/tinycrypt/src/sha256.c index b4efd20445..53fd6191e7 100644 --- a/components/bt/porting/ext/tinycrypt/src/sha256.c +++ b/components/bt/common/tinycrypt/src/sha256.c @@ -1,4 +1,8 @@ -/* sha256.c - TinyCrypt SHA-256 crypto hash algorithm implementation */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. diff --git a/components/bt/porting/ext/tinycrypt/src/utils.c b/components/bt/common/tinycrypt/src/utils.c similarity index 95% rename from components/bt/porting/ext/tinycrypt/src/utils.c rename to components/bt/common/tinycrypt/src/utils.c index 13cc495123..8f8278bb4a 100644 --- a/components/bt/porting/ext/tinycrypt/src/utils.c +++ b/components/bt/common/tinycrypt/src/utils.c @@ -1,4 +1,8 @@ -/* utils.c - TinyCrypt platform-dependent run-time operations */ +/* + * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ /* * Copyright (C) 2017 by Intel Corporation, All Rights Reserved. @@ -30,6 +34,8 @@ * POSSIBILITY OF SUCH DAMAGE. */ +/* utils.c - TinyCrypt platform-dependent run-time operations */ + #include #include diff --git a/components/bt/controller/esp32c6/Kconfig.in b/components/bt/controller/esp32c6/Kconfig.in index 70165672f6..18b4039895 100644 --- a/components/bt/controller/esp32c6/Kconfig.in +++ b/components/bt/controller/esp32c6/Kconfig.in @@ -228,6 +228,16 @@ config BT_LE_POWER_CONTROL_ENABLED help Set this option to enable the Power Control feature on controller +config BT_LE_CTE_FEATURE_ENABLED + bool "Enable Bluetooth LE Direction Finding (AoA/AoD)" + depends on BT_LE_50_FEATURE_SUPPORT && SOC_BLE_CTE_SUPPORTED + default n + help + Enable this option to activate Bluetooth LE Direction Finding (AoA/AoD) feature. + Note: + This feature allows devices to determine the direction of a Bluetooth CTE signal, + enabling Angle of Arrival (AoA) and Angle of Departure (AoD) functionality. + menu "Memory Settings" depends on !BT_NIMBLE_ENABLED diff --git a/components/bt/controller/esp32h2/Kconfig.in b/components/bt/controller/esp32h2/Kconfig.in index d270ca4913..858a772217 100644 --- a/components/bt/controller/esp32h2/Kconfig.in +++ b/components/bt/controller/esp32h2/Kconfig.in @@ -228,6 +228,19 @@ config BT_LE_POWER_CONTROL_ENABLED help Set this option to enable the Power Control feature on controller +config BT_LE_CTE_FEATURE_ENABLED + bool "Enable Bluetooth LE Direction Finding (AoA/AoD)" + depends on BT_LE_50_FEATURE_SUPPORT && SOC_BLE_CTE_SUPPORTED && !(BT_LE_SECURITY_ENABLE) + default n + help + Enable this option to activate Bluetooth LE Direction Finding (AoA/AoD) feature. + Note: + This feature allows devices to determine the direction of a Bluetooth CTE signal, + enabling Angle of Arrival (AoA) and Angle of Departure (AoD) functionality. + In chip esp32h2, Direction Finding is not supported in encrypted + communication scenarios. If you are using chip esp32h2, ensure that encryption is + disabled when using this feature. + menu "Memory Settings" depends on !BT_NIMBLE_ENABLED diff --git a/components/bt/host/nimble/nimble b/components/bt/host/nimble/nimble index fc098022e7..330b3df62d 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit fc098022e7965ddbabb33cfdf38f1f9235b71538 +Subproject commit 330b3df62daaf3b699901ee7cc93dc4fb1c26e26 diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index a56cd00db4..2eb010c7c0 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -569,6 +569,7 @@ // #define SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED (1) /*!< Support For BLE Periodic Adv Enhancements */ // #define SOC_BLUFI_SUPPORTED (1) /*!< Support BLUFI */ // #define SOC_BLE_MULTI_CONN_OPTIMIZATION (1) /*!< Support multiple connections optimization */ +// #define SOC_BLE_CTE_SUPPORTED (1) /*!< Support Bluetooth LE Constant Tone Extension (CTE) */ // #define SOC_BLE_USE_WIFI_PWR_CLK_WORKAROUND (1) diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 3810b08805..186e61f030 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -1446,3 +1446,7 @@ config SOC_BLE_MULTI_CONN_OPTIMIZATION config SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED bool default y + +config SOC_BLE_CTE_SUPPORTED + bool + default y diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 8f2a768613..a5c11c8b15 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -587,3 +587,4 @@ #define SOC_BLE_POWER_CONTROL_SUPPORTED (1) /*!< Support Bluetooth Power Control */ #define SOC_BLE_MULTI_CONN_OPTIMIZATION (1) /*!< Support multiple connections optimization */ #define SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED (1) /*!< Support For BLE Periodic Adv Enhancements */ +#define SOC_BLE_CTE_SUPPORTED (1) /*!< Support Bluetooth LE Constant Tone Extension (CTE) */ diff --git a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild index ca160813fe..7922ff8131 100644 --- a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild @@ -171,4 +171,14 @@ menu "Example Configuration" help Used for internal test ONLY. Use this option to advertise in a specific random address. + + config EXAMPLE_SLEEP_WAKEUP + bool "Enable Vendor-Specific Sleep Wake-Up Event" + depends on BT_NIMBLE_VS_SUPPORT + default n + help + When enabled, the Nimble Host allows setting a Vendor-Specific + Event Mask for processing sleep wake-up events from the controller. + The controller sends a wake-up event (HCI_LE_SLEEP_WAKE_UP 0xFF 0xC3) + when it resumes from sleep. endmenu diff --git a/examples/bluetooth/nimble/power_save/main/main.c b/examples/bluetooth/nimble/power_save/main/main.c index 47a5144cc9..3700c34c83 100644 --- a/examples/bluetooth/nimble/power_save/main/main.c +++ b/examples/bluetooth/nimble/power_save/main/main.c @@ -56,6 +56,10 @@ static uint8_t own_addr_type; void ble_store_config_init(void); +#if MYNEWT_VAL(BLE_HCI_VS) +static struct ble_gap_event_listener vs_event_listener; +#endif + #if MYNEWT_VAL(BLE_POWER_CONTROL) static struct ble_gap_event_listener power_control_event_listener; #endif @@ -144,6 +148,13 @@ ext_bleprph_advertise(void) /* start advertising */ rc = ble_gap_ext_adv_start(instance, 0, 0); assert (rc == 0); + +#if CONFIG_EXAMPLE_SLEEP_WAKEUP + rc = ble_hs_send_vs_event_mask(ESP_BLE_VENDOR_SLEEP_WAKEUP_EVT_MASK); + + rc = ble_gap_event_listener_register(&vs_event_listener, + bleprph_gap_event,NULL); +#endif } #else /** @@ -443,6 +454,20 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } return 0; +#if CONFIG_EXAMPLE_SLEEP_WAKEUP + case BLE_GAP_EVENT_VS_HCI: + const struct ble_hci_ev_vs *ev = event->vs_hci.ev; + + switch(ev->id) { + case BLE_HCI_VS_SUBEV_LE_SLEEP_WAKE_UP: + MODLOG_DFLT(INFO, "Got Sleep wake up "); + break; + + default: + break; + } +#endif + } return 0;