Skip to content

Commit 638577b

Browse files
committed
Merge branch 'bugfix/fix_some_ble_bugs_cjh_v5.3' into 'release/v5.3'
Fixed some BLE bugs 240620 (backport v5.3) See merge request espressif/esp-idf!31646
2 parents d0eccc2 + 2845990 commit 638577b

File tree

14 files changed

+166
-107
lines changed

14 files changed

+166
-107
lines changed

components/bt/controller/esp32c3/bt.c

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ do{\
115115
} while(0)
116116

117117
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
118-
#define OSI_VERSION 0x00010008
118+
#define OSI_VERSION 0x00010009
119119
#define OSI_MAGIC_VALUE 0xFADEBEAD
120120

121121
/* Types definition
@@ -142,15 +142,24 @@ typedef struct {
142142

143143
typedef void (* osi_intr_handler)(void);
144144

145+
typedef struct {
146+
int source; /*!< ISR source */
147+
int flags; /*!< ISR alloc flag */
148+
void (*fn)(void *); /*!< ISR function */
149+
void *arg; /*!< ISR function args*/
150+
intr_handle_t *handle; /*!< ISR handle */
151+
esp_err_t ret;
152+
} btdm_isr_alloc_t;
153+
145154
/* OSI function */
146155
struct osi_funcs_t {
147156
uint32_t _magic;
148157
uint32_t _version;
149-
void (*_interrupt_set)(int cpu_no, int intr_source, int interrupt_no, int interrpt_prio);
150-
void (*_interrupt_clear)(int interrupt_source, int interrupt_no);
151-
void (*_interrupt_handler_set)(int interrupt_no, intr_handler_t fn, void *arg);
152-
void (*_interrupt_disable)(void);
153-
void (*_interrupt_restore)(void);
158+
int (* _interrupt_alloc)(int cpu_id, int source, intr_handler_t handler, void *arg, void **ret_handle);
159+
int (* _interrupt_free)(void *handle);
160+
void (*_interrupt_handler_set_rsv)(int interrupt_no, intr_handler_t fn, void *arg);
161+
void (*_global_intr_disable)(void);
162+
void (*_global_intr_restore)(void);
154163
void (*_task_yield)(void);
155164
void (*_task_yield_from_isr)(void);
156165
void *(*_semphr_create)(uint32_t max, uint32_t init);
@@ -195,8 +204,8 @@ struct osi_funcs_t {
195204
uint32_t (* _coex_schm_interval_get)(void);
196205
uint8_t (* _coex_schm_curr_period_get)(void);
197206
void *(* _coex_schm_curr_phase_get)(void);
198-
void (* _interrupt_on)(int intr_num);
199-
void (* _interrupt_off)(int intr_num);
207+
int (* _interrupt_enable)(void *handle);
208+
int (* _interrupt_disable)(void *handle);
200209
void (* _esp_hw_power_down)(void);
201210
void (* _esp_hw_power_up)(void);
202211
void (* _ets_backup_dma_copy)(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_rem);
@@ -277,11 +286,10 @@ extern uint32_t _bt_controller_data_end;
277286
/* Local Function Declare
278287
*********************************************************************
279288
*/
280-
static void interrupt_set_wrapper(int cpu_no, int intr_source, int intr_num, int intr_prio);
281-
static void interrupt_clear_wrapper(int intr_source, int intr_num);
282-
static void interrupt_handler_set_wrapper(int n, intr_handler_t fn, void *arg);
283-
static void interrupt_disable(void);
284-
static void interrupt_restore(void);
289+
static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handler, void *arg, void **ret_handle);
290+
static int interrupt_free_wrapper(void *handle);
291+
static void global_interrupt_disable(void);
292+
static void global_interrupt_restore(void);
285293
static void task_yield_from_isr(void);
286294
static void *semphr_create_wrapper(uint32_t max, uint32_t init);
287295
static void semphr_delete_wrapper(void *semphr);
@@ -319,8 +327,8 @@ static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status);
319327
static uint32_t coex_schm_interval_get_wrapper(void);
320328
static uint8_t coex_schm_curr_period_get_wrapper(void);
321329
static void * coex_schm_curr_phase_get_wrapper(void);
322-
static void interrupt_on_wrapper(int intr_num);
323-
static void interrupt_off_wrapper(int intr_num);
330+
static int interrupt_enable_wrapper(void *handle);
331+
static int interrupt_disable_wrapper(void *handle);
324332
static void btdm_hw_mac_power_up_wrapper(void);
325333
static void btdm_hw_mac_power_down_wrapper(void);
326334
static void btdm_backup_dma_copy_wrapper(uint32_t reg, uint32_t mem_addr, uint32_t num, bool to_mem);
@@ -341,11 +349,11 @@ static void bt_controller_deinit_internal(void);
341349
static const struct osi_funcs_t osi_funcs_ro = {
342350
._magic = OSI_MAGIC_VALUE,
343351
._version = OSI_VERSION,
344-
._interrupt_set = interrupt_set_wrapper,
345-
._interrupt_clear = interrupt_clear_wrapper,
346-
._interrupt_handler_set = interrupt_handler_set_wrapper,
347-
._interrupt_disable = interrupt_disable,
348-
._interrupt_restore = interrupt_restore,
352+
._interrupt_alloc = interrupt_alloc_wrapper,
353+
._interrupt_free = interrupt_free_wrapper,
354+
._interrupt_handler_set_rsv = NULL,
355+
._global_intr_disable = global_interrupt_disable,
356+
._global_intr_restore = global_interrupt_restore,
349357
._task_yield = vPortYield,
350358
._task_yield_from_isr = task_yield_from_isr,
351359
._semphr_create = semphr_create_wrapper,
@@ -390,8 +398,8 @@ static const struct osi_funcs_t osi_funcs_ro = {
390398
._coex_schm_interval_get = coex_schm_interval_get_wrapper,
391399
._coex_schm_curr_period_get = coex_schm_curr_period_get_wrapper,
392400
._coex_schm_curr_phase_get = coex_schm_curr_phase_get_wrapper,
393-
._interrupt_on = interrupt_on_wrapper,
394-
._interrupt_off = interrupt_off_wrapper,
401+
._interrupt_enable = interrupt_enable_wrapper,
402+
._interrupt_disable = interrupt_disable_wrapper,
395403
._esp_hw_power_down = btdm_hw_mac_power_down_wrapper,
396404
._esp_hw_power_up = btdm_hw_mac_power_up_wrapper,
397405
._ets_backup_dma_copy = btdm_backup_dma_copy_wrapper,
@@ -478,35 +486,44 @@ static inline void esp_bt_power_domain_off(void)
478486
esp_wifi_bt_power_domain_off();
479487
}
480488

481-
static void interrupt_set_wrapper(int cpu_no, int intr_source, int intr_num, int intr_prio)
489+
static void btdm_intr_alloc(void *arg)
482490
{
483-
esp_rom_route_intr_matrix(cpu_no, intr_source, intr_num);
484-
#if __riscv
485-
esprv_int_set_priority(intr_num, intr_prio);
486-
esprv_int_set_type(intr_num, 0);
487-
#endif
491+
btdm_isr_alloc_t *p = arg;
492+
p->ret = esp_intr_alloc(p->source, p->flags, p->fn, p->arg, p->handle);
488493
}
489494

490-
static void interrupt_clear_wrapper(int intr_source, int intr_num)
495+
static int interrupt_alloc_wrapper(int cpu_id, int source, intr_handler_t handler, void *arg, void **ret_handle)
491496
{
497+
btdm_isr_alloc_t p;
498+
p.source = source;
499+
p.flags = ESP_INTR_FLAG_LEVEL3 | ESP_INTR_FLAG_IRAM;
500+
p.fn = handler;
501+
p.arg = arg;
502+
p.handle = (intr_handle_t *)ret_handle;
503+
#if CONFIG_FREERTOS_UNICORE
504+
btdm_intr_alloc(&p);
505+
#else
506+
esp_ipc_call_blocking(cpu_id, btdm_intr_alloc, &p);
507+
#endif
508+
return p.ret;
492509
}
493510

494-
static void interrupt_handler_set_wrapper(int n, intr_handler_t fn, void *arg)
511+
static int interrupt_free_wrapper(void *handle)
495512
{
496-
esp_cpu_intr_set_handler(n, fn, arg);
513+
return esp_intr_free((intr_handle_t)handle);
497514
}
498515

499-
static void interrupt_on_wrapper(int intr_num)
516+
static int interrupt_enable_wrapper(void *handle)
500517
{
501-
esp_cpu_intr_enable(1 << intr_num);
518+
return esp_intr_enable((intr_handle_t)handle);
502519
}
503520

504-
static void interrupt_off_wrapper(int intr_num)
521+
static int interrupt_disable_wrapper(void *handle)
505522
{
506-
esp_cpu_intr_disable(1<<intr_num);
523+
return esp_intr_disable((intr_handle_t)handle);
507524
}
508525

509-
static void IRAM_ATTR interrupt_disable(void)
526+
static void IRAM_ATTR global_interrupt_disable(void)
510527
{
511528
if (xPortInIsrContext()) {
512529
portENTER_CRITICAL_ISR(&global_int_mux);
@@ -515,7 +532,7 @@ static void IRAM_ATTR interrupt_disable(void)
515532
}
516533
}
517534

518-
static void IRAM_ATTR interrupt_restore(void)
535+
static void IRAM_ATTR global_interrupt_restore(void)
519536
{
520537
if (xPortInIsrContext()) {
521538
portEXIT_CRITICAL_ISR(&global_int_mux);

components/bt/host/bluedroid/Kconfig.in

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ config BT_A2DP_ENABLE
8585
depends on BT_CLASSIC_ENABLED
8686
default n
8787
help
88-
Advanced Audio Distrubution Profile
88+
Advanced Audio Distribution Profile
8989

9090
config BT_SPP_ENABLED
9191
bool "SPP"
@@ -140,7 +140,7 @@ config BT_HFP_WBS_ENABLE
140140
default y
141141
help
142142
This enables Wide Band Speech. Should disable it when SCO data path is PCM.
143-
Otherwise there will be no data transmited via GPIOs.
143+
Otherwise there will be no data transmitted via GPIOs.
144144

145145

146146
menuconfig BT_HID_ENABLED
@@ -312,6 +312,17 @@ config BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE
312312
In order to reduce the pairing time, slave actively initiates connection parameters
313313
update during pairing.
314314

315+
config BT_BLE_SMP_ID_RESET_ENABLE
316+
bool "Reset device identity when all bonding records are deleted"
317+
depends on BT_BLE_SMP_ENABLE
318+
default n
319+
help
320+
There are tracking risks associated with using a fixed or static IRK.
321+
If enabled this option, Bluedroid will assign a new randomly-generated IRK
322+
when all pairing and bonding records are deleted. This would decrease the ability
323+
of a previously paired peer to be used to determine whether a device
324+
with which it previously shared an IRK is within range.
325+
315326
config BT_STACK_NO_LOG
316327
bool "Disable BT debug logs (minimize bin size)"
317328
depends on BT_BLUEDROID_ENABLED

components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,21 +661,55 @@ typedef struct {
661661
esp_bt_octet16_t oob_r; /*!< the 128 bits of randomizer value */
662662
} esp_ble_local_oob_data_t;
663663

664+
/**
665+
* @brief Definition of the authentication failed reason
666+
*/
667+
typedef enum {
668+
// Failure reason defined in Bluetooth Core Spec 5.0 Vol3, Part H, 3.5.5
669+
ESP_AUTH_SMP_PASSKEY_FAIL = 78, /*!< The user input of passkey failed */
670+
ESP_AUTH_SMP_OOB_FAIL, /*!< The OOB data is not available */
671+
ESP_AUTH_SMP_PAIR_AUTH_FAIL, /*!< The authentication requirements cannot be met */
672+
ESP_AUTH_SMP_CONFIRM_VALUE_FAIL, /*!< The confirm value does not match the calculated comparison value */
673+
ESP_AUTH_SMP_PAIR_NOT_SUPPORT, /*!< Pairing is not supported by the device */
674+
ESP_AUTH_SMP_ENC_KEY_SIZE, /*!< The resultant encryption key size is not long enough */
675+
ESP_AUTH_SMP_INVALID_CMD, /*!< The SMP command received is not supported by this device */
676+
ESP_AUTH_SMP_UNKNOWN_ERR, /*!< Pairing failed due to an unspecified reason */
677+
ESP_AUTH_SMP_REPEATED_ATTEMPT, /*!< Pairing or authentication procedure is disallowed */
678+
ESP_AUTH_SMP_INVALID_PARAMETERS, /*!< The command length is invalid or that a parameter is outside the specified range */
679+
ESP_AUTH_SMP_DHKEY_CHK_FAIL, /*!< The DHKey Check value received doesn’t match the one calculated by the local device */
680+
ESP_AUTH_SMP_NUM_COMP_FAIL, /*!< The confirm values in the numeric comparison protocol do not match */
681+
ESP_AUTH_SMP_BR_PARING_IN_PROGR, /*!< Pairing Request sent over the BR/EDR transport is in progress */
682+
ESP_AUTH_SMP_XTRANS_DERIVE_NOT_ALLOW, /*!< The BR/EDR Link Key or BLE LTK cannot be used to derive */
683+
684+
// Failure reason defined in Bluedroid Host
685+
ESP_AUTH_SMP_INTERNAL_ERR, /*!< Internal error in pairing procedure */
686+
ESP_AUTH_SMP_UNKNOWN_IO, /*!< Unknown IO capability, unable to decide association model */
687+
ESP_AUTH_SMP_INIT_FAIL, /*!< SMP pairing initiation failed */
688+
ESP_AUTH_SMP_CONFIRM_FAIL, /*!< The confirm value does not match */
689+
ESP_AUTH_SMP_BUSY, /*!< Pending security request on going */
690+
ESP_AUTH_SMP_ENC_FAIL, /*!< The Controller failed to start encryption */
691+
ESP_AUTH_SMP_STARTED, /*!< SMP pairing process started */
692+
ESP_AUTH_SMP_RSP_TIMEOUT, /*!< Security Manager timeout due to no SMP command being received */
693+
ESP_AUTH_SMP_DIV_NOT_AVAIL, /*!< Encrypted Diversifier value not available */
694+
ESP_AUTH_SMP_UNSPEC_ERR, /*!< Unspecified failed reason */
695+
ESP_AUTH_SMP_CONN_TOUT, /*!< Pairing process failed due to connection timeout */
696+
} esp_ble_auth_fail_rsn_t;
697+
664698
/**
665699
* @brief Structure associated with ESP_AUTH_CMPL_EVT
666700
*/
667701
typedef struct
668702
{
669-
esp_bd_addr_t bd_addr; /*!< BD address peer device. */
670-
bool key_present; /*!< Valid link key value in key element */
671-
esp_link_key key; /*!< Link key associated with peer device. */
672-
uint8_t key_type; /*!< The type of Link Key */
673-
bool success; /*!< TRUE of authentication succeeded, FALSE if failed. */
674-
uint8_t fail_reason; /*!< The HCI reason/error code for when success=FALSE */
675-
esp_ble_addr_type_t addr_type; /*!< Peer device address type */
676-
esp_bt_dev_type_t dev_type; /*!< Device type */
677-
esp_ble_auth_req_t auth_mode; /*!< authentication mode */
678-
} esp_ble_auth_cmpl_t; /*!< The ble authentication complete cb type */
703+
esp_bd_addr_t bd_addr; /*!< BD address of peer device */
704+
bool key_present; /*!< True if the link key value is valid; false otherwise */
705+
esp_link_key key; /*!< Link key associated with peer device */
706+
uint8_t key_type; /*!< The type of link key */
707+
bool success; /*!< True if authentication succeeded; false otherwise */
708+
esp_ble_auth_fail_rsn_t fail_reason; /*!< The HCI reason/error code for failure when success is false */
709+
esp_ble_addr_type_t addr_type; /*!< Peer device address type */
710+
esp_bt_dev_type_t dev_type; /*!< Device type */
711+
esp_ble_auth_req_t auth_mode; /*!< Authentication mode */
712+
} esp_ble_auth_cmpl_t; /*!< The ble authentication complete cb type */
679713

680714
/**
681715
* @brief union associated with ble security

components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,13 @@
218218
#define UC_BT_SMP_MAX_BONDS 8
219219
#endif
220220

221-
//Device Nane Maximum Length
221+
#ifdef CONFIG_BT_BLE_SMP_ID_RESET_ENABLE
222+
#define UC_BT_BLE_SMP_ID_RESET_ENABLE CONFIG_BT_BLE_SMP_ID_RESET_ENABLE
223+
#else
224+
#define UC_BT_BLE_SMP_ID_RESET_ENABLE FALSE
225+
#endif
226+
227+
//Device Name Maximum Length
222228
#ifdef CONFIG_BT_MAX_DEVICE_NAME_LEN
223229
#define UC_MAX_LOC_BD_NAME_LEN CONFIG_BT_MAX_DEVICE_NAME_LEN
224230
#else

components/bt/host/bluedroid/common/include/common/bt_target.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@
290290
#define SMP_SLAVE_CON_PARAMS_UPD_ENABLE FALSE
291291
#endif /* UC_BT_SMP_SLAVE_CON_PARAMS_UPD_ENABLE */
292292

293+
#if (UC_BT_BLE_SMP_ID_RESET_ENABLE)
294+
#define BLE_SMP_ID_RESET_ENABLE TRUE
295+
#else
296+
#define BLE_SMP_ID_RESET_ENABLE FALSE
297+
#endif
298+
293299
#ifdef UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
294300
#define BLE_ADV_REPORT_FLOW_CONTROL (UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP && BLE_INCLUDED)
295301
#endif /* UC_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP */
@@ -569,7 +575,7 @@
569575
#define BT_CLASSIC_BQB_INCLUDED FALSE
570576
#endif
571577

572-
/* This feature is used to eanble interleaved scan*/
578+
/* This feature is used to enable interleaved scan*/
573579
#ifndef BTA_HOST_INTERLEAVE_SEARCH
574580
#define BTA_HOST_INTERLEAVE_SEARCH FALSE
575581
#endif
@@ -1385,7 +1391,7 @@
13851391
#define GATT_CONFORMANCE_TESTING FALSE
13861392
#endif
13871393

1388-
/* number of background connection device allowence, ideally to be the same as WL size
1394+
/* number of background connection device allowance, ideally to be the same as WL size
13891395
*/
13901396
#ifndef GATT_MAX_BG_CONN_DEV
13911397
#define GATT_MAX_BG_CONN_DEV 8 /*MAX is 32*/

components/bt/host/bluedroid/stack/btm/btm_ble_privacy.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ void btm_ble_remove_resolving_list_entry_complete(UINT8 *p, UINT16 evt_len)
330330
BTM_TRACE_DEBUG("%s status = %d", __func__, status);
331331

332332
if (!btm_ble_deq_resolving_pending(pseudo_bda)) {
333-
BTM_TRACE_ERROR("%s no pending resolving list operation", __func__);
333+
BTM_TRACE_DEBUG("%s no pending resolving list operation", __func__);
334334
return;
335335
}
336336

@@ -1147,6 +1147,9 @@ void btm_ble_add_default_entry_to_resolving_list(void)
11471147
BD_ADDR peer_addr = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
11481148
BT_OCTET16 peer_irk = {0x0};
11491149

1150+
// Remove the existing entry in resolving list When resetting the device identity
1151+
btsnd_hcic_ble_rm_device_resolving_list(BLE_ADDR_PUBLIC, peer_addr);
1152+
11501153
btsnd_hcic_ble_add_device_resolving_list (BLE_ADDR_PUBLIC, peer_addr, peer_irk, btm_cb.devcb.id_keys.irk);
11511154
}
11521155
#endif

0 commit comments

Comments
 (0)