fix(bt/bluedroid): Fixed BLE connection active count getting

This commit is contained in:
chenjianhua
2025-02-20 19:19:25 +08:00
parent 443f3bda3e
commit 412c535f98
6 changed files with 34 additions and 32 deletions

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
*/
@ -146,6 +146,18 @@ uint32_t btc_get_ble_status(void)
status |= BIT(BTC_BLE_STATUS_CONN);
}
// Number of active ACL connection
extern uint8_t btm_ble_acl_active_count(void);
if (btm_ble_acl_active_count()) {
status |= BIT(BTC_BLE_STATUS_CONN);
}
// Number of active L2C plcb
extern uint8_t l2cu_ble_plcb_active_count(void);
if (l2cu_ble_plcb_active_count()) {
status |= BIT(BTC_BLE_STATUS_CONN);
}
// Address resolve status
extern uint8_t btm_get_ble_addr_resolve_disable_status(void);
if (btm_get_ble_addr_resolve_disable_status()) {
@ -182,18 +194,6 @@ uint32_t btc_get_ble_status(void)
}
#endif
// Number of active ACL connection
extern uint8_t btm_acl_active_count(void);
if (btm_acl_active_count()) {
status |= BIT(BTC_BLE_STATUS_CONN);
}
// Number of active L2C plcb
extern uint8_t l2cu_plcb_active_count(void);
if (l2cu_plcb_active_count()) {
status |= BIT(BTC_BLE_STATUS_CONN);
}
#if (GATTC_INCLUDED == TRUE)
// Number of registered GATTC APP
extern uint8_t bta_gattc_cl_rcb_active_count(void);

View File

@ -126,7 +126,8 @@ void btm_free(void)
#endif
}
uint8_t btm_acl_active_count(void)
#if (BLE_INCLUDED == TRUE)
uint8_t btm_ble_acl_active_count(void)
{
list_node_t *p_node = NULL;
tACL_CONN *p_acl_conn = NULL;
@ -134,14 +135,14 @@ uint8_t btm_acl_active_count(void)
for (p_node = list_begin(btm_cb.p_acl_db_list); p_node; p_node = list_next(p_node)) {
p_acl_conn = list_node(p_node);
if (p_acl_conn && p_acl_conn->in_use) {
if (p_acl_conn && p_acl_conn->in_use && p_acl_conn->transport == BT_TRANSPORT_LE) {
count++;
}
}
return count;
}
#if (BLE_INCLUDED == TRUE)
// Address resolution status
uint8_t btm_get_ble_addr_resolve_disable_status(void)
{

View File

@ -1244,7 +1244,8 @@ uint8_t gatt_tcb_active_count(void)
for(p_node = list_begin(gatt_cb.p_tcb_list); p_node; p_node = list_next(p_node)) {
p_tcb = list_node(p_node);
if (p_tcb && p_tcb->in_use && (p_tcb->ch_state != GATT_CH_CLOSE)) {
if (p_tcb && p_tcb->in_use && (p_tcb->transport == BT_TRANSPORT_LE) &&
(p_tcb->ch_state != GATT_CH_CLOSE)) {
count++;
}
}

View File

@ -65,7 +65,7 @@
#define L2CAP_WAIT_UNPARK_TOUT 2 /* 2 seconds */
#define L2CAP_LINK_INFO_RESP_TOUT 2 /* 2 seconds */
#define L2CAP_UPDATE_CONN_PARAM_TOUT 6 /* 6 seconds */
#define L2CAP_BLE_LINK_CONNECT_TOUT BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT // configed in menuconfig
#define L2CAP_BLE_LINK_CONNECT_TOUT BLE_ESTABLISH_LINK_CONNECTION_TIMEOUT // configured in menuconfig
#define L2CAP_BLE_CONN_PARAM_UPD_TOUT 30 /* 30 seconds */
/* quick timer uses millisecond unit */
@ -80,10 +80,10 @@
** the Bluetooth specification.
*/
typedef enum {
CST_CLOSED, /* Channel is in clodes state */
CST_CLOSED, /* Channel is in closed state */
CST_ORIG_W4_SEC_COMP, /* Originator waits security clearence */
CST_TERM_W4_SEC_COMP, /* Acceptor waits security clearence */
CST_W4_L2CAP_CONNECT_RSP, /* Waiting for peer conenct response */
CST_W4_L2CAP_CONNECT_RSP, /* Waiting for peer connect response */
CST_W4_L2CA_CONNECT_RSP, /* Waiting for upper layer connect rsp */
CST_CONFIG, /* Negotiating configuration */
CST_OPEN, /* Data transfer state */
@ -208,8 +208,8 @@ typedef struct {
UINT32 controller_idle; /* # of times less than 2 packets in controller */
/* when the xmit window was closed */
UINT32 pkts_retransmitted; /* # of packets that were retransmitted */
UINT32 retrans_touts; /* # of retransmission timouts */
UINT32 xmit_ack_touts; /* # of xmit ack timouts */
UINT32 retrans_touts; /* # of retransmission timeouts */
UINT32 xmit_ack_touts; /* # of xmit ack timeouts */
#define L2CAP_ERTM_STATS_NUM_AVG 10
#define L2CAP_ERTM_STATS_AVG_NUM_SAMPLES 100
@ -386,7 +386,7 @@ typedef struct t_l2c_linkcb {
tL2C_CCB *p_pending_ccb; /* ccb of waiting channel during link disconnect */
TIMER_LIST_ENT info_timer_entry; /* Timer entry for info resp timeout evt */
TIMER_LIST_ENT upda_con_timer; /* Timer entry for update connection parametr */
TIMER_LIST_ENT upda_con_timer; /* Timer entry for update connection parameter */
BD_ADDR remote_bd_addr; /* The BD address of the remote */
UINT8 link_role; /* Master or slave */
@ -599,7 +599,7 @@ extern BOOLEAN l2cu_start_post_bond_timer (UINT16 handle);
extern void l2cu_release_lcb (tL2C_LCB *p_lcb);
extern tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport);
extern tL2C_LCB *l2cu_find_lcb_by_handle (UINT16 handle);
extern uint8_t l2cu_plcb_active_count(void);
extern uint8_t l2cu_ble_plcb_active_count(void);
extern void l2cu_update_lcb_4_bonding (BD_ADDR p_bd_addr, BOOLEAN is_bonding);
extern UINT8 l2cu_get_conn_role (tL2C_LCB *p_this_lcb);

View File

@ -242,7 +242,7 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
return (FALSE);
}
bool is_disable = (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE);
if(l2cu_plcb_active_count() >1 && !(enable && is_disable)) {
if(l2cu_ble_plcb_active_count() >1 && !(enable && is_disable)) {
return FALSE;
}

View File

@ -336,14 +336,14 @@ tL2C_LCB *l2cu_find_free_lcb (void)
return (NULL);
}
uint8_t l2cu_plcb_active_count(void)
uint8_t l2cu_ble_plcb_active_count(void)
{
list_node_t *p_node = NULL;
tL2C_LCB *p_lcb = NULL;
uint8_t active_count = 0;
for (p_node = list_begin(l2cb.p_lcb_pool); p_node; p_node = list_next(p_node)) {
p_lcb = list_node(p_node);
if (p_lcb && p_lcb->in_use) {
if (p_lcb && p_lcb->in_use && p_lcb->transport == BT_TRANSPORT_LE) {
active_count ++;
}
}
@ -615,7 +615,7 @@ void l2cu_send_peer_connect_rsp (tL2C_CCB *p_ccb, UINT16 result, UINT16 status)
**
** Description Build and send an L2CAP "connection response neg" message
** to the peer. This function is called when there is no peer
** CCB (non-existant PSM or no resources).
** CCB (non-existent PSM or no resources).
**
** Returns void
**
@ -1737,7 +1737,7 @@ void l2cu_release_ccb (tL2C_CCB *p_ccb)
) {
l2cu_dequeue_ccb (p_ccb);
/* Delink the CCB from the LCB */
/* Unlink the CCB from the LCB */
p_ccb->p_lcb = NULL;
}
@ -1960,7 +1960,7 @@ tL2C_RCB *l2cu_find_ble_rcb_by_psm (UINT16 psm)
**
** Returns UINT8 - L2CAP_PEER_CFG_OK if passed to upper layer,
** L2CAP_PEER_CFG_UNACCEPTABLE if automatically responded to
** because parameters are unnacceptable from a specification
** because parameters are unacceptable from a specification
** point of view.
** L2CAP_PEER_CFG_DISCONNECT if no compatible channel modes
** between the two devices, and shall be closed.
@ -2558,7 +2558,7 @@ BOOLEAN l2cu_set_acl_priority (BD_ADDR bd_addr, UINT8 priority, BOOLEAN reset_af
**
** Function l2cu_set_non_flushable_pbf
**
** Description set L2CAP_PKT_START_NON_FLUSHABLE if controller supoorts
** Description set L2CAP_PKT_START_NON_FLUSHABLE if controller supports
**
** Returns void
**
@ -3328,7 +3328,7 @@ static tL2C_CCB *l2cu_get_next_channel_in_rr(tL2C_LCB *p_lcb)
for ( i = 0; (i < L2CAP_NUM_CHNL_PRIORITY) && (!p_serve_ccb); i++ ) {
/* scan all channel within serving priority group until finding a channel to serve */
for ( j = 0; (j < p_lcb->rr_serv[p_lcb->rr_pri].num_ccb) && (!p_serve_ccb); j++) {
/* scaning from next serving channel */
/* scanning from next serving channel */
p_ccb = p_lcb->rr_serv[p_lcb->rr_pri].p_serve_ccb;
if (!p_ccb) {