Merge branch 'fix/ble_issue_10032025_v5.4' into 'release/v5.4'

fix(nimble): Fix some nimble issues ble_issue_10032025_v5.4

See merge request espressif/esp-idf!37625
This commit is contained in:
Rahul Tank
2025-04-01 12:47:00 +08:00
75 changed files with 604 additions and 259 deletions

View File

@@ -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)

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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.

View File

@@ -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 */
/*

View File

@@ -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

View File

@@ -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

View File

@@ -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 */
/*

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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 */
/*

View File

@@ -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 */
/*

View File

@@ -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 */

View File

@@ -0,0 +1,15 @@
/*
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#include <stdbool.h>
#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 */

View File

@@ -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 <tinycrypt/aes.h>
#include <tinycrypt/constants.h>
#include <tinycrypt/utils.h>

View File

@@ -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 */
/*

View File

@@ -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.

View File

@@ -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 <tinycrypt/ccm_mode.h>
#include <tinycrypt/constants.h>
#include <tinycrypt/utils.h>

View File

@@ -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.

View File

@@ -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 */
/*

View File

@@ -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

View File

@@ -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 <tinycrypt/ecc.h>
#include <tinycrypt/ecc_platform_specific.h>
#include <string.h>
#include <stdio.h>
#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];

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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.

View File

@@ -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 <tinycrypt/hmac_prng.h>
#include <tinycrypt/hmac.h>
#include <tinycrypt/constants.h>

View File

@@ -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.

View File

@@ -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 <tinycrypt/utils.h>
#include <tinycrypt/constants.h>

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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*/

View File

@@ -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

View File

@@ -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)

View File

@@ -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();
}

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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:

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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();

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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(&params, 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(&params);
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();
}

View File

@@ -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;

View File

@@ -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:

View File

@@ -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;

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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: