Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 75dcc97f authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Refactor LE disconnnect reason

When we initiate a disconnection, the reason should always be terminated
by local host.  We only need to check the reason when there is a
disconnection complete HCI event.  Therefore, we can get rid of
L2CA_GetDisconnectReason().

The only GATT app using disconnect reason is HOGP, and the only
interesting state is connection timeout.  Send this event from shim.

Test: cert/run
Tag: #gd-refactor
Bug: 141555841
Change-Id: I89973ece3ab5f24f3d1bc015daaf758d0600d002
parent 025bdbf6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -588,7 +588,7 @@ static void bta_gatts_send_request_cback(uint16_t conn_id, uint32_t trans_id,
 ******************************************************************************/
static void bta_gatts_conn_cback(tGATT_IF gatt_if, const RawAddress& bdaddr,
                                 uint16_t conn_id, bool connected,
                                 tGATT_DISCONN_REASON reason,
                                 tGATT_DISCONN_REASON,
                                 tBT_TRANSPORT transport) {
  tBTA_GATTS cb_data;
  uint8_t evt = connected ? BTA_GATTS_CONNECT_EVT : BTA_GATTS_DISCONNECT_EVT;
+5 −8
Original line number Diff line number Diff line
@@ -1613,13 +1613,10 @@ void bta_hh_le_open_fail(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
  conn_dat.bda = p_cb->addr;
  conn_dat.le_hid = true;
  conn_dat.scps_supported = p_cb->scps_supported;

  if (p_cb->status == BTA_HH_OK)
    conn_dat.status = (p_data->le_close.reason == GATT_CONN_UNKNOWN)
                          ? p_cb->status
                          : BTA_HH_ERR;
  else
  conn_dat.status = p_cb->status;
  if (p_data->le_close.reason != GATT_CONN_OK) {
    conn_dat.status = BTA_HH_ERR;
  }

  /* Report OPEN fail event */
  (*bta_hh_cb.p_cback)(BTA_HH_OPEN_EVT, (tBTA_HH*)&conn_dat);
@@ -1655,7 +1652,7 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB* p_cb, tBTA_HH_DATA* p_data) {
    bta_hh_disc_cmpl();
  } else {
#if (BTA_HH_LE_RECONN == TRUE)
    if (p_data->le_close.reason == GATT_CONN_TIMEOUT) {
    if (p_data->le_close.reason == HCI_ERR_CONNECTION_TOUT) {
      bta_hh_le_add_dev_bg_conn(p_cb, false);
    }
#endif
+2 −1
Original line number Diff line number Diff line
@@ -803,7 +803,8 @@ struct LeFixedChannelHelper {
    channel_enqueue_buffer_[device] = nullptr;
    channels_[device]->GetQueueUpEnd()->UnregisterDequeue();
    channels_[device] = nullptr;
    (freg_.pL2CA_FixedConn_Cb)(cid_, address, false, 0, BT_TRANSPORT_LE);
    uint8_t error = static_cast<uint8_t>(error_code);
    (freg_.pL2CA_FixedConn_Cb)(cid_, address, false, error, BT_TRANSPORT_LE);
  }

  void on_channel_open(std::unique_ptr<le::FixedChannel> channel) {
+5 −17
Original line number Diff line number Diff line
@@ -629,8 +629,7 @@ static void gatt_on_l2cap_error(uint16_t lcid, uint16_t result) {
  tGATT_TCB* p_tcb = gatt_find_tcb_by_cid(lcid);
  if (p_tcb == nullptr) return;
  if (gatt_get_ch_state(p_tcb) == GATT_CH_CONN) {
    gatt_cleanup_upon_disc(p_tcb->peer_bda,
                           static_cast<tGATT_DISCONN_REASON>(result),
    gatt_cleanup_upon_disc(p_tcb->peer_bda, GATT_CONN_L2C_FAILURE,
                           BT_TRANSPORT_BR_EDR);
  } else {
    gatt_l2cif_disconnect(lcid);
@@ -707,14 +706,9 @@ void gatt_l2cif_disconnect_ind_cback(uint16_t lcid, bool ack_needed) {
    if (btm_sec_is_a_bonded_dev(p_tcb->peer_bda))
      gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda);
  }
  /* if ACL link is still up, no reason is logged, l2cap is disconnect from
   * peer */
  tGATT_DISCONN_REASON reason = static_cast<tGATT_DISCONN_REASON>(
      L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport));
  if (reason == GATT_CONN_OK) reason = GATT_CONN_TERMINATE_PEER_USER;

  /* send disconnect callback */
  gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, BT_TRANSPORT_BR_EDR);
  gatt_cleanup_upon_disc(p_tcb->peer_bda, GATT_CONN_TERMINATE_PEER_USER,
                         BT_TRANSPORT_BR_EDR);
}

static void gatt_l2cif_disconnect(uint16_t lcid) {
@@ -730,14 +724,8 @@ static void gatt_l2cif_disconnect(uint16_t lcid) {
      gatt_add_a_bonded_dev_for_srv_chg(p_tcb->peer_bda);
  }

  /* send disconnect callback */
  /* if ACL link is still up, no reason is logged, l2cap is disconnect from
   * peer */
  tGATT_DISCONN_REASON reason = static_cast<tGATT_DISCONN_REASON>(
      L2CA_GetDisconnectReason(p_tcb->peer_bda, p_tcb->transport));
  if (reason == GATT_CONN_OK) reason = GATT_CONN_TERMINATE_LOCAL_HOST;

  gatt_cleanup_upon_disc(p_tcb->peer_bda, reason, BT_TRANSPORT_BR_EDR);
  gatt_cleanup_upon_disc(p_tcb->peer_bda, GATT_CONN_TERMINATE_LOCAL_HOST,
                         BT_TRANSPORT_BR_EDR);
}

/** This is the L2CAP data indication callback function */
+0 −15
Original line number Diff line number Diff line
@@ -803,21 +803,6 @@ extern bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda,
 ******************************************************************************/
extern uint8_t L2CA_GetBleConnRole(const RawAddress& bd_addr);

/*******************************************************************************
 *
 * Function         L2CA_GetDisconnectReason
 *
 * Description      This function returns the disconnect reason code.
 *
 *  Parameters:     BD Address of remote
 *                  Physical transport for the L2CAP connection (BR/EDR or LE)
 *
 * Returns          disconnect reason
 *
 ******************************************************************************/
extern uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda,
                                         tBT_TRANSPORT transport);

extern void L2CA_AdjustConnectionIntervals(uint16_t* min_interval,
                                           uint16_t* max_interval,
                                           uint16_t floor_interval);
Loading