OSDN Git Service

Refactor LE disconnnect reason
authorHansong Zhang <hsz@google.com>
Wed, 13 Jan 2021 03:06:44 +0000 (19:06 -0800)
committerHansong Zhang <hsz@google.com>
Wed, 13 Jan 2021 19:45:37 +0000 (11:45 -0800)
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

bta/gatt/bta_gatts_act.cc
bta/hh/bta_hh_le.cc
main/shim/l2c_api.cc
stack/gatt/gatt_main.cc
stack/include/l2c_api.h
stack/l2cap/l2c_ble.cc

index 17fd6ad..79644c3 100644 (file)
@@ -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;
index 27875ce..29fa489 100755 (executable)
@@ -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;
+  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
index 8c52951..b93dcae 100644 (file)
@@ -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) {
index 60c3707..6ccf9af 100644 (file)
@@ -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 */
index ab5e7c4..ac5872b 100644 (file)
@@ -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);
index e17e904..ab8da97 100644 (file)
@@ -203,28 +203,6 @@ hci_role_t L2CA_GetBleConnRole(const RawAddress& bd_addr) {
 
 /*******************************************************************************
  *
- * Function         L2CA_GetDisconnectReason
- *
- * Description      This function returns the disconnect reason code.
- *
- * Returns          disconnect reason
- *
- ******************************************************************************/
-uint16_t L2CA_GetDisconnectReason(const RawAddress& remote_bda,
-                                  tBT_TRANSPORT transport) {
-  tL2C_LCB* p_lcb;
-  uint16_t reason = 0;
-
-  p_lcb = l2cu_find_lcb_by_bd_addr(remote_bda, transport);
-  if (p_lcb != NULL) reason = p_lcb->DisconnectReason();
-
-  L2CAP_TRACE_DEBUG("L2CA_GetDisconnectReason=%d ", reason);
-
-  return reason;
-}
-
-/*******************************************************************************
- *
  * Function l2cble_notify_le_connection
  *
  * Description This function notifiy the l2cap connection to the app layer