OSDN Git Service

Fix GATT Server disconnecting for no reason
authorJakub Pawlowski <jpawlowski@google.com>
Thu, 25 May 2017 16:09:12 +0000 (09:09 -0700)
committerJakub Pawlowski <jpawlowski@google.com>
Fri, 26 May 2017 02:23:34 +0000 (19:23 -0700)
Connections created by GAP profile should be ephemeral, and not
interfere with the connection timeout.

When a device is bonded, listing services through DM would cause a
DM APP to create a connection, and later to disconnect. This causes
connection to timeout. In case a device was already connected, this
should not happen.

Bug: 34951749
Test: manual
Change-Id: Iad04fd9eed4c664f35131442e3f83a704497a067
(cherry picked from commit 16bb48b320cde54a1a06a525f4d9be1421689649)

bta/dm/bta_dm_act.cc
bta/gatt/bta_gattc_act.cc
bta/gatt/bta_gattc_api.cc
bta/gatt/bta_gattc_int.h
bta/hh/bta_hh_le.cc
bta/include/bta_gatt_api.h
stack/gap/gap_ble.cc

index 31877af..c63f762 100644 (file)
@@ -4639,9 +4639,15 @@ void btm_dm_start_gatt_discovery(BD_ADDR bd_addr) {
     memset(bta_dm_search_cb.pending_close_bda, 0, BD_ADDR_LEN);
     alarm_cancel(bta_dm_search_cb.gatt_close_timer);
     btm_dm_start_disc_gatt_services(bta_dm_search_cb.conn_id);
-  } else
-    BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true,
-                   BTA_GATT_TRANSPORT_LE);
+  } else {
+    if (BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
+      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true,
+                     BTA_GATT_TRANSPORT_LE, true);
+    } else {
+      BTA_GATTC_Open(bta_dm_search_cb.client_if, bd_addr, true,
+                     BTA_GATT_TRANSPORT_LE, false);
+    }
+  }
 }
 
 /*******************************************************************************
index 3ff6457..1a7c279 100644 (file)
@@ -432,7 +432,7 @@ void bta_gattc_open(tBTA_GATTC_CLCB* p_clcb, tBTA_GATTC_DATA* p_data) {
 
   /* open/hold a connection */
   if (!GATT_Connect(p_clcb->p_rcb->client_if, p_data->api_conn.remote_bda, true,
-                    p_data->api_conn.transport, false,
+                    p_data->api_conn.transport, p_data->api_conn.opportunistic,
                     p_data->api_conn.initiating_phys)) {
     APPL_TRACE_ERROR("Connection open failure");
 
index bd1738f..aaf410f 100644 (file)
@@ -127,16 +127,20 @@ void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if) {
  *                  transport: Transport to be used for GATT connection
  *                             (BREDR/LE)
  *                  initiating_phys: LE PHY to use, optional
+ *                  opportunistic: wether the connection shall be opportunistic,
+ *                                 and don't impact the disconnection timer
  *
  ******************************************************************************/
 void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, bool is_direct,
-                    tBTA_GATT_TRANSPORT transport) {
+                    tBTA_GATT_TRANSPORT transport, bool opportunistic) {
   uint8_t phy = controller_get_interface()->get_le_all_initiating_phys();
-  BTA_GATTC_Open(client_if, remote_bda, is_direct, transport, phy);
+  BTA_GATTC_Open(client_if, remote_bda, is_direct, transport, phy,
+                 opportunistic);
 }
 
 void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, bool is_direct,
-                    tBTA_GATT_TRANSPORT transport, uint8_t initiating_phys) {
+                    tBTA_GATT_TRANSPORT transport, uint8_t initiating_phys,
+                    bool opportunistic) {
   tBTA_GATTC_API_OPEN* p_buf =
       (tBTA_GATTC_API_OPEN*)osi_malloc(sizeof(tBTA_GATTC_API_OPEN));
 
@@ -145,6 +149,7 @@ void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, bool is_direct,
   p_buf->is_direct = is_direct;
   p_buf->transport = transport;
   p_buf->initiating_phys = initiating_phys;
+  p_buf->opportunistic = opportunistic;
   memcpy(p_buf->remote_bda, remote_bda, BD_ADDR_LEN);
 
   bta_sys_sendmsg(p_buf);
index 68cf5a0..7a1158b 100644 (file)
@@ -102,6 +102,7 @@ typedef struct {
   bool is_direct;
   tBTA_TRANSPORT transport;
   uint8_t initiating_phys;
+  bool opportunistic;
 } tBTA_GATTC_API_OPEN;
 
 typedef tBTA_GATTC_API_OPEN tBTA_GATTC_API_CANCEL_OPEN;
index e9727d8..a30f8b8 100644 (file)
@@ -400,7 +400,8 @@ void bta_hh_le_open_conn(tBTA_HH_DEV_CB* p_cb, BD_ADDR remote_bda) {
   bta_hh_cb.le_cb_index[BTA_HH_GET_LE_CB_IDX(p_cb->hid_handle)] = p_cb->index;
   p_cb->in_use = true;
 
-  BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, true, BTA_GATT_TRANSPORT_LE);
+  BTA_GATTC_Open(bta_hh_cb.gatt_if, remote_bda, true, BTA_GATT_TRANSPORT_LE,
+                 false);
 }
 
 /*******************************************************************************
@@ -2113,7 +2114,8 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB* p_cb, bool check_bond) {
   if (/*p_cb->dscp_info.flag & BTA_HH_LE_NORMAL_CONN &&*/
       !p_cb->in_bg_conn && to_add) {
     /* add device into BG connection to accept remote initiated connection */
-    BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, BTA_GATT_TRANSPORT_LE);
+    BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, BTA_GATT_TRANSPORT_LE,
+                   false);
     p_cb->in_bg_conn = true;
 
     BTA_DmBleStartAutoConn();
index 39c45b3..d850eab 100644 (file)
@@ -639,10 +639,11 @@ extern void BTA_GATTC_AppDeregister(tBTA_GATTC_IF client_if);
  *
  ******************************************************************************/
 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
-                           bool is_direct, tBTA_GATT_TRANSPORT transport);
+                           bool is_direct, tBTA_GATT_TRANSPORT transport,
+                           bool opportunistic);
 extern void BTA_GATTC_Open(tBTA_GATTC_IF client_if, BD_ADDR remote_bda,
                            bool is_direct, tBTA_GATT_TRANSPORT transport,
-                           uint8_t initiating_phys);
+                           uint8_t initiating_phys, bool opportunistic);
 
 /*******************************************************************************
  *
index 6e42ad5..ea9f861 100644 (file)
@@ -684,8 +684,7 @@ bool gap_ble_accept_cl_operation(BD_ADDR peer_bda, uint16_t uuid,
                                 BT_TRANSPORT_LE))
     p_clcb->connected = true;
 
-  /* hold the link here */
-  if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, true, BT_TRANSPORT_LE, false))
+  if (!GATT_Connect(gap_cb.gatt_if, p_clcb->bda, true, BT_TRANSPORT_LE, true))
     return started;
 
   /* enqueue the request */