OSDN Git Service

DO NOT MERGE ANYWHERE LE Connection Parameter Update Callback
authorJacky Cheung <jackyc@google.com>
Fri, 28 Oct 2016 18:47:11 +0000 (11:47 -0700)
committerJacky Cheung <jackyc@google.com>
Thu, 3 Nov 2016 20:25:31 +0000 (13:25 -0700)
The callback ends at the btif layer and does not go up to the HAL layer.
Event logging is added to track success rate.

BUG: 28800115

Change-Id: I73ad281437760e1d61dd4e504401b270eb77e3e6

EventLogTags.logtags
bta/dm/bta_dm_act.c
bta/dm/bta_dm_api.c
bta/dm/bta_dm_int.h
bta/hh/bta_hh_le.c
bta/include/bta_api.h
bta/include/bta_gatt_api.h
btif/src/btif_gatt_client.c
stack/include/l2c_api.h
stack/l2cap/l2c_ble.c
stack/l2cap/l2c_int.h

index dc1d239..79f49e7 100644 (file)
@@ -36,3 +36,4 @@
 1010000 bt_hci_timeout (opcode|1)
 1010001 bt_config_source (opcode|1)
 1010002 bt_hci_unknown_type (hci_type|1)
+1010003 bt_conn_param_update_status (status|1)
index acda747..76b42fc 100644 (file)
@@ -4651,10 +4651,11 @@ void bta_dm_ble_set_conn_scan_params (tBTA_DM_MSG *p_data)
 void bta_dm_ble_update_conn_params (tBTA_DM_MSG *p_data)
 {
     if (!L2CA_UpdateBleConnParams(p_data->ble_update_conn_params.bd_addr,
-                                 p_data->ble_update_conn_params.min_int,
-                                 p_data->ble_update_conn_params.max_int,
-                                 p_data->ble_update_conn_params.latency,
-                                 p_data->ble_update_conn_params.timeout))
+                                  p_data->ble_update_conn_params.min_int,
+                                  p_data->ble_update_conn_params.max_int,
+                                  p_data->ble_update_conn_params.latency,
+                                  p_data->ble_update_conn_params.timeout,
+                                  p_data->ble_update_conn_params.p_conn_param_update_cback))
     {
         APPL_TRACE_ERROR("Update connection parameters failed!");
     }
index 82dd8b2..323e58e 100644 (file)
@@ -1311,39 +1311,6 @@ void BTA_DmSearchExt(tBTA_DM_INQ *p_dm_inq, tBTA_SERVICE_MASK_EXT *p_services, t
     UNUSED(p_cback);
 #endif
 }
-/*******************************************************************************
-**
-** Function         BTA_DmBleUpdateConnectionParam
-**
-** Description      Update connection parameters, can only be used when connection is up.
-**
-** Parameters:      bd_addr          - BD address of the peer
-**                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
-**                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
-**                  latency   -     slave latency [0 ~ 500]
-**                  timeout   -     supervision timeout [0x000a ~ 0xc80]
-**
-** Returns          void
-**
-*******************************************************************************/
-void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
-                                    UINT16 max_int, UINT16 latency,
-                                    UINT16 timeout)
-{
-#if BLE_INCLUDED == TRUE
-    tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
-        (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
-
-    p_msg->hdr.event = BTA_DM_API_UPDATE_CONN_PARAM_EVT;
-    bdcpy(p_msg->bd_addr, bd_addr);
-    p_msg->min_int = min_int;
-    p_msg->max_int = max_int;
-    p_msg->latency = latency;
-    p_msg->timeout = timeout;
-
-    bta_sys_sendmsg(p_msg);
-#endif
-}
 
 /*******************************************************************************
 **
@@ -1746,17 +1713,19 @@ void BTA_DmEnableScanFilter(UINT8 action, tBTA_DM_BLE_PF_STATUS_CBACK *p_cmpl_cb
 **
 ** Description      Update connection parameters, can only be used when connection is up.
 **
-** Parameters:      bd_addr   - BD address of the peer
+** Parameters:      bd_addr   -     BD address of the peer
 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
 **                  latency   -     slave latency [0 ~ 500]
 **                  timeout   -     supervision timeout [0x000a ~ 0xc80]
+                    p_cback   -     callback on connection parameters updated
 **
 ** Returns          void
 **
 *******************************************************************************/
-void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
-                                    UINT16 latency, UINT16 timeout)
+void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int,
+                                     UINT16 max_int, UINT16 latency, UINT16 timeout,
+                                     tBTA_DM_BLE_CONN_PARAM_CBACK *p_cback)
 {
     tBTA_DM_API_UPDATE_CONN_PARAM *p_msg =
         (tBTA_DM_API_UPDATE_CONN_PARAM *)osi_calloc(sizeof(tBTA_DM_API_UPDATE_CONN_PARAM));
@@ -1767,6 +1736,7 @@ void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max
     p_msg->max_int = max_int;
     p_msg->latency = latency;
     p_msg->timeout = timeout;
+    p_msg->p_conn_param_update_cback = p_cback;
 
     bta_sys_sendmsg(p_msg);
 }
index a5fe0ad..796d4a5 100644 (file)
@@ -436,7 +436,6 @@ typedef struct
     UINT16                  conn_int_max;
     UINT16                  supervision_tout;
     UINT16                  slave_latency;
-
 }tBTA_DM_API_BLE_CONN_PARAMS;
 
 typedef struct
@@ -611,6 +610,8 @@ typedef struct
     tBTA_DM_LINK_TYPE link_type;
 
 } tBTA_DM_API_REMOVE_ALL_ACL;
+
+/* data type for BTA_DM_API_UPDATE_CONN_PARAM_EVT */
 typedef struct
 {
     BT_HDR      hdr;
@@ -619,7 +620,8 @@ typedef struct
     UINT16      max_int;
     UINT16      latency;
     UINT16      timeout;
-}tBTA_DM_API_UPDATE_CONN_PARAM;
+    tBTA_DM_BLE_CONN_PARAM_CBACK *p_conn_param_update_cback;
+} tBTA_DM_API_UPDATE_CONN_PARAM;
 
 #if BLE_ANDROID_CONTROLLER_SCAN_FILTER == TRUE
 typedef struct
index b538470..a21df35 100644 (file)
@@ -1804,8 +1804,8 @@ void bta_hh_w4_le_read_char_cmpl(tBTA_HH_DEV_CB *p_dev_cb, tBTA_HH_DATA *p_buf)
         if (tout < BTM_BLE_CONN_TIMEOUT_MIN_DEF)
             tout = BTM_BLE_CONN_TIMEOUT_MIN_DEF;
 
-        BTM_BleSetPrefConnParams (p_dev_cb->addr, min, max, latency, tout);
-        L2CA_UpdateBleConnParams(p_dev_cb->addr, min, max, latency, tout);
+        BTM_BleSetPrefConnParams(p_dev_cb->addr, min, max, latency, tout);
+        L2CA_UpdateBleConnParams(p_dev_cb->addr, min, max, latency, tout, NULL);
     }
     else
     {
index b20c271..8fdd6ec 100644 (file)
@@ -933,6 +933,9 @@ typedef void (tBTA_DM_BLE_PF_PARAM_CBACK) (UINT8 action_type, tBTA_DM_BLE_PF_AVB
 typedef void (tBTA_DM_BLE_PF_STATUS_CBACK) (UINT8 action, tBTA_STATUS status,
                                             tBTA_DM_BLE_REF_VALUE ref_value);
 
+/* Connection update callback */
+typedef void (tBTA_DM_BLE_CONN_PARAM_CBACK) (BD_ADDR bd_addr, UINT16 interval, UINT16 latency,
+                                             UINT16 timeout, tBTA_STATUS status);
 
 #define BTA_DM_BLE_PF_BRDCAST_ADDR_FILT  1
 #define BTA_DM_BLE_PF_SERV_DATA_CHG_FILT 2
@@ -2110,7 +2113,7 @@ extern void BTA_BleDisableAdvInstance(UINT8 inst_id);
 **
 ** Description      Update connection parameters, can only be used when connection is up.
 **
-** Parameters:      bd_addr   - BD address of the peer
+** Parameters:      bd_addr   -     BD address of the peer
 **                  min_int   -     minimum connection interval, [0x0004~ 0x4000]
 **                  max_int   -     maximum connection interval, [0x0004~ 0x4000]
 **                  latency   -     slave latency [0 ~ 500]
@@ -2119,8 +2122,9 @@ extern void BTA_BleDisableAdvInstance(UINT8 inst_id);
 ** Returns          void
 **
 *******************************************************************************/
-extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int,
-                                   UINT16 max_int, UINT16 latency, UINT16 timeout);
+extern void BTA_DmBleUpdateConnectionParams(BD_ADDR bd_addr, UINT16 min_int, UINT16 max_int,
+                                            UINT16 latency, UINT16 timeout,
+                                            tBTA_DM_BLE_CONN_PARAM_CBACK p_cback);
 
 /*******************************************************************************
 **
index 4c9f76c..0d0a1fc 100644 (file)
@@ -146,6 +146,7 @@ typedef UINT8 tBTA_GATT_STATUS;
 #define BTA_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
 #define BTA_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
 #define BTA_GATTC_ADV_VSC_EVT         34 /* ADV VSC event */
+#define BTA_GATTC_CONN_PARAM_UPD_EVT 35 /* Connection parameter update event */
 
 typedef UINT8 tBTA_GATTC_EVT;
 
index 7ad4f08..7058101 100644 (file)
@@ -69,6 +69,7 @@
 #define BLE_RESOLVE_ADDR_MSB                 0x40   /* bit7, bit6 is 01 to be resolvable random */
 #define BLE_RESOLVE_ADDR_MASK                0xc0   /* bit 6, and bit7 */
 #define BTM_BLE_IS_RESOLVE_BDA(x)           ((x[0] & BLE_RESOLVE_ADDR_MASK) == BLE_RESOLVE_ADDR_MSB)
+#define BT_CONN_PARAM_UPDATE_STATUS          1010003
 
 typedef enum {
     BTIF_GATTC_REGISTER_APP = 1000,
@@ -206,12 +207,15 @@ typedef struct
 
 typedef struct
 {
+    uint8_t     client_if;
     bt_bdaddr_t bd_addr;
-    uint16_t    min_interval;
-    uint16_t    max_interval;
+    uint16_t    requested_min_interval;
+    uint16_t    requested_max_interval;
+    uint16_t    configured_interval;
     uint16_t    timeout;
     uint16_t    latency;
-} btif_conn_param_cb_t;
+    uint8_t     status;
+}__attribute__((packed)) btif_conn_param_cb_t;
 
 typedef struct
 {
@@ -799,6 +803,17 @@ static void btif_gattc_upstreams_evt(uint16_t event, char* p_param)
             break;
         }
 
+        case BTA_GATTC_CONN_PARAM_UPD_EVT:
+        {
+            btif_conn_param_cb_t *p_btif_cb = (btif_conn_param_cb_t *)p_param;
+            /* Log update failures */
+            if (p_btif_cb->status != 0)
+            {
+                LOG_EVENT_INT(BT_CONN_PARAM_UPDATE_STATUS, p_btif_cb->status);
+            }
+            break;
+        }
+
         case BTIF_GATTC_SCAN_PARAM_EVT:
         {
             btif_gattc_cb_t *p_btif_cb = (btif_gattc_cb_t *)p_param;
@@ -1092,6 +1107,20 @@ static void bta_scan_filt_status_cb(UINT8 action, tBTA_STATUS status,
                           (char*) &btif_cb, sizeof(btgatt_adv_filter_cb_t), NULL);
 }
 
+static void bta_gattc_conn_param_update_cback(BD_ADDR bd_addr, UINT16 interval,
+                                              UINT16 latency, UINT16 timeout, tBTA_STATUS status)
+{
+    btif_conn_param_cb_t btif_cb;
+
+    bdcpy(btif_cb.bd_addr.address, bd_addr);
+    btif_cb.configured_interval = interval;
+    btif_cb.latency = latency;
+    btif_cb.timeout = timeout;
+    btif_cb.status = status;
+    btif_transfer_context(btif_gattc_upstreams_evt, BTA_GATTC_CONN_PARAM_UPD_EVT,
+                          (char*) &btif_cb, sizeof(btif_conn_param_cb_t), NULL);
+}
+
 static void btgattc_free_event_data(UINT16 event, char *event_data)
 {
     switch (event)
@@ -1553,11 +1582,14 @@ static void btgattc_handle_event(uint16_t event, char* p_param)
             if (BTA_DmGetConnectionState(p_conn_param_cb->bd_addr.address))
             {
                 BTA_DmBleUpdateConnectionParams(p_conn_param_cb->bd_addr.address,
-                               p_conn_param_cb->min_interval, p_conn_param_cb->max_interval,
-                               p_conn_param_cb->latency, p_conn_param_cb->timeout);
+                               p_conn_param_cb->requested_min_interval,
+                               p_conn_param_cb->requested_max_interval,
+                               p_conn_param_cb->latency, p_conn_param_cb->timeout,
+                               bta_gattc_conn_param_update_cback);
             } else {
                 BTA_DmSetBlePrefConnParams(p_conn_param_cb->bd_addr.address,
-                               p_conn_param_cb->min_interval, p_conn_param_cb->max_interval,
+                               p_conn_param_cb->requested_min_interval,
+                               p_conn_param_cb->requested_max_interval,
                                p_conn_param_cb->latency, p_conn_param_cb->timeout);
             }
             break;
@@ -1874,12 +1906,12 @@ static bt_status_t btif_gattc_configure_mtu(int conn_id, int mtu)
 }
 
 static bt_status_t btif_gattc_conn_parameter_update(const bt_bdaddr_t *bd_addr, int min_interval,
-                    int max_interval, int latency, int timeout)
+                                                    int max_interval, int latency, int timeout)
 {
     CHECK_BTGATT_INIT();
     btif_conn_param_cb_t btif_cb;
-    btif_cb.min_interval = min_interval;
-    btif_cb.max_interval = max_interval;
+    btif_cb.requested_min_interval = min_interval;
+    btif_cb.requested_max_interval = max_interval;
     btif_cb.latency = latency;
     btif_cb.timeout = timeout;
     bdcpy(btif_cb.bd_addr.address, bd_addr->address);
index e8b21fe..3175a50 100644 (file)
@@ -29,6 +29,7 @@
 #include "bt_target.h"
 #include "l2cdefs.h"
 #include "hcidefs.h"
+#include "bta_api.h"
 
 /*****************************************************************************
 **  Constants
@@ -1188,8 +1189,9 @@ extern BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda);
 **  Return value:   TRUE if update started
 **
 *******************************************************************************/
-extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int,
-                                         UINT16 max_int, UINT16 latency, UINT16 timeout);
+extern BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bdRa, UINT16 min_int, UINT16 max_int,
+                                         UINT16 latency, UINT16 timeout,
+                                         tBTA_DM_BLE_CONN_PARAM_CBACK *p_cback);
 
 /*******************************************************************************
 **
index 4cd7454..62318df 100644 (file)
@@ -102,8 +102,9 @@ BOOLEAN L2CA_CancelBleConnectReq (BD_ADDR rem_bda)
 **  Return value:   TRUE if update started
 **
 *******************************************************************************/
-BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_int,
-                                            UINT16 latency, UINT16 timeout)
+BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int,
+                                  UINT16 max_int, UINT16 latency, UINT16 timeout,
+                                  tBTA_DM_BLE_CONN_PARAM_CBACK *p_callback)
 {
     tL2C_LCB            *p_lcb;
     tACL_CONN           *p_acl_cb = btm_bda_to_acl(rem_bda, BT_TRANSPORT_LE);
@@ -133,6 +134,7 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
     p_lcb->latency = latency;
     p_lcb->timeout = timeout;
     p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
+    p_lcb->p_conn_param_update_cb = p_callback;
 
     l2cble_start_conn_update(p_lcb);
 
@@ -502,7 +504,6 @@ void l2cble_conn_comp(UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE typ
 *******************************************************************************/
 static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
 {
-    UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout;
     tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
 
     // TODO(armansito): The return value of this call wasn't being used but the
@@ -514,6 +515,7 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
 
     if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE)
     {
+        UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout;
         /* application requests to disable parameters update.
            If parameters are already updated, lets set them
            up to what has been requested during connection establishement */
@@ -562,6 +564,12 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
                 btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, p_lcb->min_interval,
                     p_lcb->max_interval, p_lcb->latency, p_lcb->timeout, 0, 0);
                 p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
+
+                /* Record the BLE connection update request if the role is master device */
+                bt_bdaddr_t bd_addr;
+                bdcpy(bd_addr.address, p_lcb->remote_bd_addr);
+                btif_debug_ble_connection_update_request(bd_addr, p_lcb->min_interval, p_lcb->max_interval,
+                    p_lcb->latency, p_lcb->timeout);
             }
             else
             {
@@ -570,16 +578,10 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
             }
             p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM;
             p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM;
-        }
-    }
 
-    /* Record the BLE connection update request. */
-    if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) {
-      bt_bdaddr_t bd_addr;
-      bdcpy(bd_addr.address, p_lcb->remote_bd_addr);
-      btif_debug_ble_connection_update_request(bd_addr, min_conn_int, max_conn_int, slave_latency,
-          supervision_tout);
+       }
     }
+
 }
 
 /*******************************************************************************
@@ -614,6 +616,12 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status,
 
     l2cble_start_conn_update(p_lcb);
 
+    /* Callback to upper layer */
+    if (p_lcb->p_conn_param_update_cb) {
+        p_lcb->p_conn_param_update_cb(p_lcb->remote_bd_addr, interval, latency,
+                                      timeout, status);
+    }
+
     /* Record the BLE connection update response. */
     bt_bdaddr_t bd_addr;
     bdcpy(bd_addr.address, p_lcb->remote_bd_addr);
index 8af47d7..0611ff8 100644 (file)
@@ -441,6 +441,7 @@ typedef struct t_l2c_linkcb
     UINT16              latency;
     UINT16              timeout;
 
+    tBTA_DM_BLE_CONN_PARAM_CBACK *p_conn_param_update_cb;
 #endif
 
 #if (L2CAP_ROUND_ROBIN_CHANNEL_SERVICE == TRUE)