component/bt: add link role param for gatt disconnection event(backport v4.4)

This commit is contained in:
xiewenxiang
2021-11-13 19:21:05 +08:00
committed by BOT
parent 469e2e540b
commit 3176c707da
11 changed files with 45 additions and 5 deletions

View File

@ -220,6 +220,7 @@ typedef union {
struct gattc_disconnect_evt_param { struct gattc_disconnect_evt_param {
esp_gatt_conn_reason_t reason; /*!< disconnection reason */ esp_gatt_conn_reason_t reason; /*!< disconnection reason */
uint16_t conn_id; /*!< Connection id */ uint16_t conn_id; /*!< Connection id */
uint8_t link_role; /*!< Link role : master role = 0 ; slave role = 1*/
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
} disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */ } disconnect; /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */
/** /**

View File

@ -206,6 +206,7 @@ typedef union {
*/ */
struct gatts_disconnect_evt_param { struct gatts_disconnect_evt_param {
uint16_t conn_id; /*!< Connection id */ uint16_t conn_id; /*!< Connection id */
uint8_t link_role; /*!< Link role : master role = 0 ; slave role = 1*/
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */ esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
esp_gatt_conn_reason_t reason; /*!< Indicate the reason of disconnection */ esp_gatt_conn_reason_t reason; /*!< Indicate the reason of disconnection */
} disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */ } disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */

View File

@ -763,7 +763,8 @@ void bta_gattc_disconncback(tBTA_GATTC_RCB *p_rcb, tBTA_GATTC_DATA *p_data)
bta_gattc_send_disconnect_cback(p_rcb, bta_gattc_send_disconnect_cback(p_rcb,
p_data->int_conn.reason, p_data->int_conn.reason,
p_data->int_conn.remote_bda, p_data->int_conn.remote_bda,
p_data->int_conn.hdr.layer_specific); p_data->int_conn.hdr.layer_specific,
p_data->int_conn.role);
} }
} }
@ -1716,7 +1717,7 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, BD_ADDR bda, UINT16 conn_id,
} }
p_buf->int_conn.hdr.layer_specific = conn_id; p_buf->int_conn.hdr.layer_specific = conn_id;
p_buf->int_conn.client_if = gattc_if; p_buf->int_conn.client_if = gattc_if;
p_buf->int_conn.role = L2CA_GetBleConnRole(bda); p_buf->int_conn.role = l2cu_find_link_role_by_bd_addr(bda, BT_TRANSPORT_LE);
p_buf->int_conn.reason = reason; p_buf->int_conn.reason = reason;
p_buf->int_conn.transport = transport; p_buf->int_conn.transport = transport;
bdcpy(p_buf->int_conn.remote_bda, bda); bdcpy(p_buf->int_conn.remote_bda, bda);

View File

@ -794,7 +794,7 @@ void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda,
** **
*******************************************************************************/ *******************************************************************************/
void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason, void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason,
BD_ADDR remote_bda, UINT16 conn_id) BD_ADDR remote_bda, UINT16 conn_id, UINT8 link_role)
{ {
tBTA_GATTC cb_data; tBTA_GATTC cb_data;
@ -804,6 +804,7 @@ void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REA
cb_data.disconnect.reason = reason; cb_data.disconnect.reason = reason;
cb_data.disconnect.client_if = p_clreg->client_if; cb_data.disconnect.client_if = p_clreg->client_if;
cb_data.disconnect.conn_id = conn_id; cb_data.disconnect.conn_id = conn_id;
cb_data.disconnect.link_role = link_role;
bdcpy(cb_data.disconnect.remote_bda, remote_bda); bdcpy(cb_data.disconnect.remote_bda, remote_bda);
(*p_clreg->p_cback)(BTA_GATTC_DISCONNECT_EVT, &cb_data); (*p_clreg->p_cback)(BTA_GATTC_DISCONNECT_EVT, &cb_data);

View File

@ -996,17 +996,18 @@ static void bta_gatts_conn_cback (tGATT_IF gatt_if, BD_ADDR bda, UINT16 conn_id,
bta_sys_conn_close( BTA_ID_GATTS , BTA_ALL_APP_ID, bda); bta_sys_conn_close( BTA_ID_GATTS , BTA_ALL_APP_ID, bda);
} }
} }
if(evt == BTA_GATTS_CONNECT_EVT) { if(evt == BTA_GATTS_CONNECT_EVT) {
tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE); tL2C_LCB *p_lcb = l2cu_find_lcb_by_bd_addr(bda, BT_TRANSPORT_LE);
if(p_lcb != NULL) { if(p_lcb != NULL) {
cb_data.conn.conn_params.interval = p_lcb->current_used_conn_interval; cb_data.conn.conn_params.interval = p_lcb->current_used_conn_interval;
cb_data.conn.conn_params.latency = p_lcb->current_used_conn_latency; cb_data.conn.conn_params.latency = p_lcb->current_used_conn_latency;
cb_data.conn.conn_params.timeout = p_lcb->current_used_conn_timeout; cb_data.conn.conn_params.timeout = p_lcb->current_used_conn_timeout;
cb_data.conn.link_role = p_lcb->link_role;
}else { }else {
APPL_TRACE_WARNING("%s not found connection parameters of the device ", __func__); APPL_TRACE_WARNING("%s not found connection parameters of the device ", __func__);
} }
} }
cb_data.conn.link_role = l2cu_find_link_role_by_bd_addr(bda, BT_TRANSPORT_LE);
cb_data.conn.conn_id = conn_id; cb_data.conn.conn_id = conn_id;
cb_data.conn.server_if = gatt_if; cb_data.conn.server_if = gatt_if;
cb_data.conn.reason = reason; cb_data.conn.reason = reason;

View File

@ -477,7 +477,7 @@ extern void bta_gattc_send_open_cback( tBTA_GATTC_RCB *p_clreg, tBTA_GATT_STATUS
BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu); BD_ADDR remote_bda, UINT16 conn_id, tBTA_TRANSPORT transport, UINT16 mtu);
extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id, tBTA_GATT_CONN_PARAMS conn_params, UINT8 link_role); extern void bta_gattc_send_connect_cback( tBTA_GATTC_RCB *p_clreg, BD_ADDR remote_bda, UINT16 conn_id, tBTA_GATT_CONN_PARAMS conn_params, UINT8 link_role);
extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason, extern void bta_gattc_send_disconnect_cback( tBTA_GATTC_RCB *p_clreg, tGATT_DISCONN_REASON reason,
BD_ADDR remote_bda, UINT16 conn_id); BD_ADDR remote_bda, UINT16 conn_id, UINT8 link_role);
extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); extern void bta_gattc_process_api_refresh(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_process_api_cache_clean(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); extern void bta_gattc_process_api_cache_clean(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);
extern void bta_gattc_process_api_cache_assoc(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg); extern void bta_gattc_process_api_cache_assoc(tBTA_GATTC_CB *p_cb, tBTA_GATTC_DATA *p_msg);

View File

@ -415,6 +415,7 @@ typedef struct {
typedef struct { typedef struct {
tGATT_DISCONN_REASON reason; tGATT_DISCONN_REASON reason;
UINT16 conn_id; UINT16 conn_id;
UINT8 link_role;
tBTA_GATTC_IF client_if; tBTA_GATTC_IF client_if;
BD_ADDR remote_bda; BD_ADDR remote_bda;
} tBTA_GATTC_DISCONNECT; } tBTA_GATTC_DISCONNECT;

View File

@ -932,6 +932,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
gattc_if = disconnect->client_if; gattc_if = disconnect->client_if;
param.disconnect.reason = disconnect->reason; param.disconnect.reason = disconnect->reason;
param.disconnect.link_role = disconnect->link_role;
param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(disconnect->conn_id); param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(disconnect->conn_id);
memcpy(param.disconnect.remote_bda, disconnect->remote_bda, sizeof(esp_bd_addr_t)); memcpy(param.disconnect.remote_bda, disconnect->remote_bda, sizeof(esp_bd_addr_t));
btc_gattc_cb_to_app(ESP_GATTC_DISCONNECT_EVT, gattc_if, &param); btc_gattc_cb_to_app(ESP_GATTC_DISCONNECT_EVT, gattc_if, &param);

View File

@ -903,6 +903,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
gatts_if = p_data->conn.server_if; gatts_if = p_data->conn.server_if;
param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id); param.disconnect.conn_id = BTC_GATT_GET_CONN_ID(p_data->conn.conn_id);
param.disconnect.reason = p_data->conn.reason; param.disconnect.reason = p_data->conn.reason;
param.disconnect.link_role = p_data->conn.link_role;
memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN); memcpy(param.disconnect.remote_bda, p_data->conn.remote_bda, ESP_BD_ADDR_LEN);
btc_gatts_cb_to_app(ESP_GATTS_DISCONNECT_EVT, gatts_if, &param); btc_gatts_cb_to_app(ESP_GATTS_DISCONNECT_EVT, gatts_if, &param);

View File

@ -597,6 +597,7 @@ extern void l2c_process_held_packets (BOOLEAN timed_out);
extern tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, BOOLEAN is_bonding, tBT_TRANSPORT transport); extern tL2C_LCB *l2cu_allocate_lcb (BD_ADDR p_bd_addr, BOOLEAN is_bonding, tBT_TRANSPORT transport);
extern BOOLEAN l2cu_start_post_bond_timer (UINT16 handle); extern BOOLEAN l2cu_start_post_bond_timer (UINT16 handle);
extern void l2cu_release_lcb (tL2C_LCB *p_lcb); extern void l2cu_release_lcb (tL2C_LCB *p_lcb);
extern UINT8 l2cu_find_link_role_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport);
extern tL2C_LCB *l2cu_find_lcb_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport); 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 tL2C_LCB *l2cu_find_lcb_by_handle (UINT16 handle);
extern uint8_t l2cu_plcb_active_count(void); extern uint8_t l2cu_plcb_active_count(void);

View File

@ -288,6 +288,37 @@ void l2cu_release_lcb (tL2C_LCB *p_lcb)
#endif ///BLE_INCLUDED == TRUE #endif ///BLE_INCLUDED == TRUE
} }
/*******************************************************************************
**
** Function l2cu_find_link_role_by_bd_addr
**
** Description Look through all active Link Role for a match based on the
** remote BD address.
**
** Returns Link Role, or HCI_ROLE_UNKNOWN if no match
**
*******************************************************************************/
UINT8 l2cu_find_link_role_by_bd_addr (BD_ADDR p_bd_addr, tBT_TRANSPORT transport)
{
list_node_t *p_node = NULL;
tL2C_LCB *p_lcb = NULL;
UINT8 link_role = HCI_ROLE_UNKNOWN;
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) &&
#if BLE_INCLUDED == TRUE
p_lcb->transport == transport &&
#endif
(!memcmp (p_lcb->remote_bd_addr, p_bd_addr, BD_ADDR_LEN))) {
link_role = p_lcb->link_role;
}
}
/* If here, no match found */
return link_role;
}
/******************************************************************************* /*******************************************************************************
** **