diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 01edccfefc..2ffb421282 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -628,23 +628,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 77ad51cf02..73b4ea08bd 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 92299131fe..031f26d183 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 a9a4c70198..330b3df62d 160000 --- a/components/bt/host/nimble/nimble +++ b/components/bt/host/nimble/nimble @@ -1 +1 @@ -Subproject commit a9a4c701981b86c91fdc63fce4cb7bc05c69caac +Subproject commit 330b3df62daaf3b699901ee7cc93dc4fb1c26e26 diff --git a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in index 3eede8f818..af53020502 100644 --- a/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32c61/include/soc/Kconfig.soc_caps.in @@ -1111,6 +1111,10 @@ config SOC_BLE_MULTI_CONN_OPTIMIZATION bool default y +config SOC_BLE_CTE_SUPPORTED + bool + default y + config SOC_PHY_COMBO_MODULE bool default y diff --git a/components/soc/esp32c61/include/soc/soc_caps.h b/components/soc/esp32c61/include/soc/soc_caps.h index 220b336270..1f1c0c3349 100644 --- a/components/soc/esp32c61/include/soc/soc_caps.h +++ b/components/soc/esp32c61/include/soc/soc_caps.h @@ -494,6 +494,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) */ /*------------------------------------- PHY CAPS -------------------------------------*/ #define SOC_PHY_COMBO_MODULE (1) /*!< Support Wi-Fi, BLE and 15.4*/ diff --git a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in index 3d3693cad9..1d45cbb31d 100644 --- a/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in +++ b/components/soc/esp32h2/include/soc/Kconfig.soc_caps.in @@ -1519,6 +1519,10 @@ config SOC_BLE_PERIODIC_ADV_ENH_SUPPORTED bool default y +config SOC_BLE_CTE_SUPPORTED + bool + default y + config SOC_DEBUG_HAVE_OCD_STUB_BINS bool default y diff --git a/components/soc/esp32h2/include/soc/soc_caps.h b/components/soc/esp32h2/include/soc/soc_caps.h index 2239cb9c01..43adc89c11 100644 --- a/components/soc/esp32h2/include/soc/soc_caps.h +++ b/components/soc/esp32h2/include/soc/soc_caps.h @@ -608,6 +608,7 @@ #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) */ /*------------------------------------- DEBUG CAPS -------------------------------------*/ #define SOC_DEBUG_HAVE_OCD_STUB_BINS (1) diff --git a/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c b/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c index dfacbcd9cf..768415fd8c 100644 --- a/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_cts/cts_cent/main/main.c @@ -373,19 +373,19 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) ble_cts_cent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -398,17 +398,17 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->link_estab.conn_handle); + rc = ble_gap_security_initiate(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->link_estab.conn_handle, + return ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_cts_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -418,7 +418,7 @@ ble_cts_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); ble_cts_cent_scan(); } diff --git a/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c b/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c index 24b643cb19..2da3a66ad6 100644 --- a/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_cts/cts_prph/main/main.c @@ -178,13 +178,13 @@ static int ble_cts_prph_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_cts_prph_advertise(); diff --git a/examples/bluetooth/nimble/ble_dynamic_service/main/main.c b/examples/bluetooth/nimble/ble_dynamic_service/main/main.c index 3000624f4f..d99326f81d 100644 --- a/examples/bluetooth/nimble/ble_dynamic_service/main/main.c +++ b/examples/bluetooth/nimble/ble_dynamic_service/main/main.c @@ -136,19 +136,19 @@ dynamic_service_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); dynamic_service_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ dynamic_service_advertise(); } diff --git a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c index 98a95dd893..4427dede0b 100644 --- a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_cent/main/main.c @@ -424,13 +424,13 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) enc_adv_data_cent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, ""); @@ -440,29 +440,29 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - rc = ble_gattc_exchange_mtu(event->link_estab.conn_handle, NULL, NULL); + rc = ble_gattc_exchange_mtu(event->connect.conn_handle, NULL, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to negotiate MTU; rc = %d", rc); } /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } - rc = peer_set_addr(event->link_estab.conn_handle, desc.peer_id_addr.val); + rc = peer_set_addr(event->connect.conn_handle, desc.peer_id_addr.val); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to set peer addr; rc=%d\n", rc); return 0; } /** Authorization is required for this characterisitc */ - rc = ble_gap_security_initiate(event->link_estab.conn_handle); + rc = ble_gap_security_initiate(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->link_estab.conn_handle, + return ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); @@ -471,7 +471,7 @@ enc_adv_data_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); enc_adv_data_cent_scan(); } diff --git a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c index cd09b6521a..e0c8790258 100644 --- a/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_enc_adv_data/enc_adv_data_prph/main/main.c @@ -185,19 +185,19 @@ enc_adv_data_prph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); enc_adv_data_prph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ enc_adv_data_prph_advertise(); } diff --git a/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c b/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c index ad8ab5e980..cb948cb7fb 100644 --- a/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_htp/htp_cent/main/main.c @@ -488,19 +488,19 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) ble_htp_cent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -513,17 +513,17 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->link_estab.conn_handle); + rc = ble_gap_security_initiate(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->link_estab.conn_handle, + return ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_htp_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -533,7 +533,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); ble_htp_cent_scan(); } @@ -566,7 +566,7 @@ ble_htp_cent_gap_event(struct ble_gap_event *event, void *arg) print_conn_desc(&desc); #if CONFIG_EXAMPLE_ENCRYPTION /*** Go for service discovery after encryption has been successfully enabled ***/ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_htp_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); diff --git a/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c b/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c index f9b48b9c01..01bece43a4 100644 --- a/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_htp/htp_prph/main/main.c @@ -230,13 +230,13 @@ static int ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_htp_prph_advertise(); @@ -245,7 +245,7 @@ ble_htp_prph_gap_event(struct ble_gap_event *event, void *arg) #endif } - conn_handle = event->link_estab.conn_handle; + conn_handle = event->connect.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c index eef5030a9b..0999d925a2 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c @@ -412,32 +412,32 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) blecent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) >= 1 - conn_handle_coc = event->link_estab.conn_handle; + conn_handle_coc = event->connect.conn_handle; disc_cb = blecent_l2cap_coc_on_disc_complete; #else disc_cb = blecent_on_disc_complete; #endif /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, disc_cb, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -446,7 +446,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c index 8e90bfc021..a126c9a99e 100644 --- a/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c +++ b/examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c @@ -315,19 +315,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -335,7 +335,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) bleprph_advertise(); #endif } else { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); #if MYNEWT_VAL(BLE_L2CAP_COC_MAX_NUM) >= 1 diff --git a/examples/bluetooth/nimble/ble_multi_adv/main/main.c b/examples/bluetooth/nimble/ble_multi_adv/main/main.c index 495ba7a083..f54e382dcc 100644 --- a/examples/bluetooth/nimble/ble_multi_adv/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_adv/main/main.c @@ -337,13 +337,13 @@ ble_multi_adv_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); ble_multi_adv_print_conn_desc(&desc); diff --git a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c index 85c382a0a8..4b5c47f1bc 100644 --- a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_cent/main/main.c @@ -93,17 +93,17 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg) return 0; - case BLE_GAP_EVENT_LINK_ESTAB: - if (event->link_estab.status == 0) { - ESP_LOGI(TAG, "Connection established. Handle:%d, Total:%d", event->link_estab.conn_handle, + case BLE_GAP_EVENT_CONNECT: + if (event->connect.status == 0) { + ESP_LOGI(TAG, "Connection established. Handle:%d, Total:%d", event->connect.conn_handle, ++s_ble_multi_conn_num); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { ESP_LOGE(TAG, "Failed to add peer; rc=%d\n", rc); } else { /* Perform service discovery */ - rc = peer_disc_svc_by_uuid(event->link_estab.conn_handle, remote_svc_uuid, + rc = peer_disc_svc_by_uuid(event->connect.conn_handle, remote_svc_uuid, ble_cent_on_disc_complete, NULL); if(rc != 0) { ESP_LOGE(TAG, "Failed to discover services; rc=%d\n", rc); @@ -111,7 +111,7 @@ ble_cent_client_gap_event(struct ble_gap_event *event, void *arg) } } else { /* Connection attempt failed; resume scanning. */ - ESP_LOGE(TAG, "Central: Connection failed; status=0x%x\n", event->link_estab.status); + ESP_LOGE(TAG, "Central: Connection failed; status=0x%x\n", event->connect.status); } ble_cent_scan(); return 0; @@ -174,12 +174,12 @@ static int ble_cent_server_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* The connectable adv has been established. We will act as the peripheral. */ - if (event->link_estab.status == 0) { - ESP_LOGI(TAG, "Peripheral connected to central. Handle:%d", event->link_estab.conn_handle); + if (event->connect.status == 0) { + ESP_LOGI(TAG, "Peripheral connected to central. Handle:%d", event->connect.conn_handle); } else { - ESP_LOGE(TAG, "Peripheral: Connection failed; status=0x%x\n", event->link_estab.status); + ESP_LOGE(TAG, "Peripheral: Connection failed; status=0x%x\n", event->connect.status); ble_cent_advertise(); } return 0; diff --git a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c index dfdc5edcff..47f6461572 100644 --- a/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_multi_conn/ble_multi_conn_prph/main/main.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -189,10 +189,10 @@ static int ble_prph_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: - if (event->link_estab.status == 0) { + case BLE_GAP_EVENT_CONNECT: + if (event->connect.status == 0) { /* A new connection was established. */ - ESP_LOGI(TAG, "Connection established. Handle:%d. Total:%d", event->link_estab.conn_handle, + ESP_LOGI(TAG, "Connection established. Handle:%d. Total:%d", event->connect.conn_handle, ++s_ble_prph_conn_num); #if CONFIG_EXAMPLE_RESTART_ADV_AFTER_CONNECTED ble_prph_restart_adv(); diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c index 425de7e90a..bf034cf142 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_adv_conn/main/main.c @@ -73,10 +73,10 @@ gap_event_cb(struct ble_gap_event *event, void *arg) switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: - if (event->link_estab.status == 0) { - ESP_LOGI(TAG, "[Connection established], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + case BLE_GAP_EVENT_CONNECT: + if (event->connect.status == 0) { + ESP_LOGI(TAG, "[Connection established], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle, event->connect.adv_handle, event->connect.status); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); if (rc == 0) { print_conn_desc(&desc); } @@ -84,7 +84,7 @@ gap_event_cb(struct ble_gap_event *event, void *arg) ESP_LOGE(TAG,"Failed to find Conn Information"); } } else { - ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.adv_handle, event->link_estab.status); + ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, Adv handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle, event->connect.adv_handle, event->connect.status); conn = 0; } diff --git a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c index a67d24a765..967d7c9e3f 100644 --- a/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c +++ b/examples/bluetooth/nimble/ble_pawr_adv_conn/ble_pawr_sync_conn/main/main.c @@ -65,10 +65,10 @@ gap_event_cb(struct ble_gap_event *event, void *arg) struct ble_gap_ext_disc_desc *disc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: - if (event->link_estab.status == 0) { - ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + case BLE_GAP_EVENT_CONNECT: + if (event->connect.status == 0) { + ESP_LOGI(TAG, "Connection established, conn_handle = 0x%0x, sync handle= 0x%02x, status = 0x%0x\n",event->connect.conn_handle, event->connect.sync_handle, event->connect.status); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); if (rc == 0) { print_conn_desc(&desc); } @@ -76,7 +76,7 @@ gap_event_cb(struct ble_gap_event *event, void *arg) ESP_LOGE(TAG,"Failed to find Conn Information"); } } else{ - ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, sync handle = 0x%0x, status = 0x%0x\n",event->link_estab.conn_handle, event->link_estab.sync_handle, event->link_estab.status); + ESP_LOGW(TAG, "[Connection Failed], conn_handle = 0x%02x, sync handle = 0x%0x, status = 0x%0x\n",event->connect.conn_handle, event->connect.sync_handle, event->connect.status); } return 0; diff --git a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c index d04eb194e4..bb0ab4a754 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c @@ -347,9 +347,9 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ switch (s_current_phy) { @@ -367,20 +367,20 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) break; } - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, blecent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -389,7 +389,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c index 4a953c70f3..b43e8f649f 100644 --- a/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c @@ -183,19 +183,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ ext_bleprph_advertise(); } diff --git a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c index 3fdb0405c3..68c3d91d24 100644 --- a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c +++ b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_cent/main/main.c @@ -405,13 +405,13 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) ble_prox_cent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); @@ -419,7 +419,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) link_supervision_timeout = 8 * desc.conn_itvl; /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; @@ -445,17 +445,17 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->link_estab.conn_handle); + rc = ble_gap_security_initiate(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->link_estab.conn_handle, + return ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_prox_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -465,7 +465,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); } ble_prox_cent_scan(); return 0; @@ -514,7 +514,7 @@ ble_prox_cent_gap_event(struct ble_gap_event *event, void *arg) print_conn_desc(&desc); #if CONFIG_EXAMPLE_ENCRYPTION /*** Go for service discovery after encryption has been successfully enabled ***/ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_prox_cent_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); diff --git a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c index 21220948eb..7eb301cdb2 100644 --- a/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c +++ b/examples/bluetooth/nimble/ble_proximity_sensor/proximity_sensor_prph/main/main.c @@ -177,13 +177,13 @@ static int ble_prox_prph_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed, resume advertising */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_ble_prox_prph_advertise(); diff --git a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c index 7fd5f7ff0a..894b24fc09 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_client/main/main.c @@ -271,27 +271,27 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg) ble_spp_client_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); - memcpy(&connected_addr[event->link_estab.conn_handle].val, desc.peer_id_addr.val, + memcpy(&connected_addr[event->connect.conn_handle].val, desc.peer_id_addr.val, PEER_ADDR_VAL_SIZE); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, ble_spp_client_on_disc_complete, NULL); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -300,7 +300,7 @@ ble_spp_client_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); ble_spp_client_scan(); } diff --git a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c index 18eeb93b07..b61cc2247d 100644 --- a/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c +++ b/examples/bluetooth/nimble/ble_spp/spp_server/main/main.c @@ -141,18 +141,18 @@ ble_spp_server_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); ble_spp_server_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0 || CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1) { + if (event->connect.status != 0 || CONFIG_BT_NIMBLE_MAX_CONNECTIONS > 1) { /* Connection failed or if multiple connection allowed; resume advertising. */ ble_spp_server_advertise(); } diff --git a/examples/bluetooth/nimble/blecent/main/main.c b/examples/bluetooth/nimble/blecent/main/main.c index 6b05b9aef2..8d504f636f 100644 --- a/examples/bluetooth/nimble/blecent/main/main.c +++ b/examples/bluetooth/nimble/blecent/main/main.c @@ -703,32 +703,32 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) blecent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ MODLOG_DFLT(INFO, "Connection established "); - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); MODLOG_DFLT(INFO, "\n"); /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(ERROR, "Failed to add peer; rc=%d\n", rc); return 0; } #if MYNEWT_VAL(BLE_POWER_CONTROL) - blecent_power_control(event->link_estab.conn_handle); + blecent_power_control(event->connect.conn_handle); #endif #if MYNEWT_VAL(BLE_HCI_VS) #if MYNEWT_VAL(BLE_POWER_CONTROL) memset(¶ms, 0x0, sizeof(struct ble_gap_set_auto_pcl_params)); - params.conn_handle = event->link_estab.conn_handle; + params.conn_handle = event->connect.conn_handle; rc = ble_gap_set_auto_pcl_param(¶ms); if (rc != 0) { MODLOG_DFLT(INFO, "Failed to send VSC %x \n", rc); @@ -747,17 +747,17 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) * Encryption (Enable encryption) * Will invoke event BLE_GAP_EVENT_ENC_CHANGE **/ - rc = ble_gap_security_initiate(event->link_estab.conn_handle); + rc = ble_gap_security_initiate(event->connect.conn_handle); if (rc != 0) { MODLOG_DFLT(INFO, "Security could not be initiated, rc = %d\n", rc); - return ble_gap_terminate(event->link_estab.conn_handle, + return ble_gap_terminate(event->connect.conn_handle, BLE_ERR_REM_USER_CONN_TERM); } else { MODLOG_DFLT(INFO, "Connection secured\n"); } #else /* Perform service discovery */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, blecent_on_disc_complete, NULL); if(rc != 0) { MODLOG_DFLT(ERROR, "Failed to discover services; rc=%d\n", rc); @@ -767,7 +767,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ MODLOG_DFLT(ERROR, "Error: Connection failed; status=%d\n", - event->link_estab.status); + event->connect.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/blecsc/main/main.c b/examples/bluetooth/nimble/blecsc/main/main.c index a813c03781..3b69a930dc 100644 --- a/examples/bluetooth/nimble/blecsc/main/main.c +++ b/examples/bluetooth/nimble/blecsc/main/main.c @@ -213,19 +213,19 @@ static int blecsc_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising */ blecsc_advertise(); conn_handle = 0; } else { - conn_handle = event->link_estab.conn_handle; + conn_handle = event->connect.conn_handle; } break; diff --git a/examples/bluetooth/nimble/blehr/main/main.c b/examples/bluetooth/nimble/blehr/main/main.c index 49e2d53a07..b9c7ea991f 100644 --- a/examples/bluetooth/nimble/blehr/main/main.c +++ b/examples/bluetooth/nimble/blehr/main/main.c @@ -184,17 +184,17 @@ static int blehr_gap_event(struct ble_gap_event *event, void *arg) { switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ MODLOG_DFLT(INFO, "connection %s; status=%d\n", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising */ blehr_advertise(); } - conn_handle = event->link_estab.conn_handle; + conn_handle = event->connect.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: diff --git a/examples/bluetooth/nimble/bleprph/main/main.c b/examples/bluetooth/nimble/bleprph/main/main.c index 2726a4bdb0..ec155a2752 100644 --- a/examples/bluetooth/nimble/bleprph/main/main.c +++ b/examples/bluetooth/nimble/bleprph/main/main.c @@ -240,19 +240,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -262,7 +262,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->link_estab.conn_handle); + bleprph_power_control(event->connect.conn_handle); #endif return 0; diff --git a/examples/bluetooth/nimble/bleprph_host_only/main/main.c b/examples/bluetooth/nimble/bleprph_host_only/main/main.c index 277c03537e..7459f2f78a 100644 --- a/examples/bluetooth/nimble/bleprph_host_only/main/main.c +++ b/examples/bluetooth/nimble/bleprph_host_only/main/main.c @@ -223,19 +223,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -245,7 +245,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->link_estab.conn_handle); + bleprph_power_control(event->connect.conn_handle); #endif return 0; diff --git a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c index af7c7b16d8..bd2af71daa 100644 --- a/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c +++ b/examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c @@ -389,18 +389,18 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ ESP_LOGI(TAG, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ bleprph_advertise(); } diff --git a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild index 3baf775104..a6bc42ed40 100644 --- a/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/power_save/main/Kconfig.projbuild @@ -177,4 +177,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 b194608f6c..4028b29f6e 100644 --- a/examples/bluetooth/nimble/power_save/main/main.c +++ b/examples/bluetooth/nimble/power_save/main/main.c @@ -58,6 +58,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 @@ -146,6 +150,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 /** @@ -284,19 +295,19 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ MODLOG_DFLT(INFO, "connection %s; status=%d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); - if (event->link_estab.status == 0) { - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); + if (event->connect.status == 0) { + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); bleprph_print_conn_desc(&desc); } MODLOG_DFLT(INFO, "\n"); - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising. */ #if CONFIG_EXAMPLE_EXTENDED_ADV ext_bleprph_advertise(); @@ -306,7 +317,7 @@ bleprph_gap_event(struct ble_gap_event *event, void *arg) } #if MYNEWT_VAL(BLE_POWER_CONTROL) - bleprph_power_control(event->link_estab.conn_handle); + bleprph_power_control(event->connect.conn_handle); ble_gap_event_listener_register(&power_control_event_listener, bleprph_gap_power_event, NULL); @@ -445,6 +456,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; diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c index 3dfe261c74..c4672f1a8c 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c @@ -538,13 +538,13 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) blecent_connect_if_interesting(&event->disc); return 0; - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed. */ - if (event->link_estab.status == 0) { + if (event->connect.status == 0) { /* Connection successfully established. */ /* XXX Set packet length in controller for better throughput */ ESP_LOGI(tag, "Connection established "); - rc = ble_hs_hci_util_set_data_len(event->link_estab.conn_handle, + rc = ble_hs_hci_util_set_data_len(event->connect.conn_handle, LL_PACKET_LENGTH, LL_PACKET_TIME); if (rc != 0) { ESP_LOGE(tag, "Set packet length failed; rc = %d", rc); @@ -555,29 +555,29 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - rc = ble_gattc_exchange_mtu(event->link_estab.conn_handle, NULL, NULL); + rc = ble_gattc_exchange_mtu(event->connect.conn_handle, NULL, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to negotiate MTU; rc = %d", rc); } - rc = ble_gap_conn_find(event->link_estab.conn_handle, &desc); + rc = ble_gap_conn_find(event->connect.conn_handle, &desc); assert(rc == 0); print_conn_desc(&desc); - rc = ble_gap_update_params(event->link_estab.conn_handle, &conn_params); + rc = ble_gap_update_params(event->connect.conn_handle, &conn_params); if (rc != 0) { ESP_LOGE(tag, "Failed to update params; rc = %d", rc); } /* Remember peer. */ - rc = peer_add(event->link_estab.conn_handle); + rc = peer_add(event->connect.conn_handle); if (rc != 0) { ESP_LOGE(tag, "Failed to add peer; rc = %d", rc); return 0; } /* Perform service discovery. */ - rc = peer_disc_all(event->link_estab.conn_handle, + rc = peer_disc_all(event->connect.conn_handle, blecent_on_disc_complete, NULL); if (rc != 0) { ESP_LOGE(tag, "Failed to discover services; rc = %d", rc); @@ -586,7 +586,7 @@ blecent_gap_event(struct ble_gap_event *event, void *arg) } else { /* Connection attempt failed; resume scanning. */ ESP_LOGE(tag, "Error: Connection failed; status = %d", - event->link_estab.status); + event->connect.status); blecent_scan(); } diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c index da0d7916ce..a21e9756f8 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c @@ -239,29 +239,29 @@ gatts_gap_event(struct ble_gap_event *event, void *arg) int rc; switch (event->type) { - case BLE_GAP_EVENT_LINK_ESTAB: + case BLE_GAP_EVENT_CONNECT: /* A new connection was established or a connection attempt failed */ ESP_LOGI(tag, "connection %s; status = %d ", - event->link_estab.status == 0 ? "established" : "failed", - event->link_estab.status); + event->connect.status == 0 ? "established" : "failed", + event->connect.status); rc = ble_att_set_preferred_mtu(PREFERRED_MTU_VALUE); if (rc != 0) { ESP_LOGE(tag, "Failed to set preferred MTU; rc = %d", rc); } - if (event->link_estab.status != 0) { + if (event->connect.status != 0) { /* Connection failed; resume advertising */ gatts_advertise(); } - rc = ble_hs_hci_util_set_data_len(event->link_estab.conn_handle, + rc = ble_hs_hci_util_set_data_len(event->connect.conn_handle, LL_PACKET_LENGTH, LL_PACKET_TIME); if (rc != 0) { ESP_LOGE(tag, "Set packet length failed"); } - conn_handle = event->link_estab.conn_handle; + conn_handle = event->connect.conn_handle; break; case BLE_GAP_EVENT_DISCONNECT: