Răsfoiți Sursa

Merge branch 'bugfix/btdm_ble_update_conn_params_issues' into 'master'

component/bt: Modifed the update connection method to fixed the bug of connectio…

See merge request !889

Jiang Jiang Jian 8 ani în urmă
părinte
comite
3dd2861e2a

+ 7 - 0
components/bt/bluedroid/include/bt_target.h

@@ -953,6 +953,13 @@
 #define BLE_LLT_INCLUDED    TRUE
 #endif
 
+/* Added this marco to fixed the android 7.0 will lead to update connection parameters
+   collision when the slave sent the HCI_BLE_UPD_LL_CONN_PARAMS comment to the controller
+   request the master to update connection parameters directly. */
+#ifndef BLE_SLAVE_UPD_CONN_PARAMS
+#define BLE_SLAVE_UPD_CONN_PARAMS FALSE
+#endif
+
 #ifndef ATT_INCLUDED
 #define ATT_INCLUDED         TRUE
 #endif

+ 33 - 28
components/bt/bluedroid/stack/l2cap/l2c_ble.c

@@ -33,7 +33,7 @@
 #include "controller.h"
 
 #if (BLE_INCLUDED == TRUE)
-static void l2cble_start_conn_update (tL2C_LCB *p_lcb);
+static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb);
 
 /*******************************************************************************
 **
@@ -123,7 +123,9 @@ BOOLEAN L2CA_UpdateBleConnParams (BD_ADDR rem_bda, UINT16 min_int, UINT16 max_in
     p_lcb->timeout = timeout;
     p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
 
-    l2cble_start_conn_update(p_lcb);
+    if(l2cble_start_conn_update(p_lcb) == TRUE) {
+        btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
+    }
 
     return (TRUE);
 }
@@ -171,7 +173,9 @@ BOOLEAN L2CA_EnableUpdateBleConnParams (BD_ADDR rem_bda, BOOLEAN enable)
         p_lcb->conn_update_mask |= L2C_BLE_CONN_UPDATE_DISABLE;
     }
 
-    l2cble_start_conn_update(p_lcb);
+    if (l2cble_start_conn_update(p_lcb) == TRUE) {
+        btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
+    }
 
     return (TRUE);
 }
@@ -456,24 +460,20 @@ void l2cble_conn_comp(UINT16 handle, UINT8 role, BD_ADDR bda, tBLE_ADDR_TYPE typ
 **
 **  Parameters:     lcb : l2cap link control block
 **
-**  Return value:   none
+**  Return value:   true if successfully sending the request to peer device, else false.
 **
 *******************************************************************************/
-static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
+static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb)
 {
     UINT16 min_conn_int, max_conn_int, slave_latency, supervision_tout;
+#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE)
     tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
+#endif    /* defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE */
     UINT8 status;
-    btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
 
     if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) {
-        if (p_acl_cb != NULL && p_acl_cb->update_conn_param_cb != NULL) {
-            status = HCI_ERR_ILLEGAL_COMMAND;
-            L2CAP_TRACE_ERROR("%s, staus = %x", __func__, status);
-            btu_stop_timer(&p_lcb->upda_con_timer);
-            l2c_send_update_conn_params_cb(p_lcb, status);
-        }
-        return;
+        L2CAP_TRACE_ERROR("%s, the last connection update command still pending.", __func__);
+        return FALSE;
     }
 
     if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) {
@@ -490,51 +490,50 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb)
 
             /* if both side 4.1, or we are master device, send HCI command */
             if (p_lcb->link_role == HCI_ROLE_MASTER
-#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
+#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE)
                     || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) &&
                         HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features))
 #endif
                ) {
                 btsnd_hcic_ble_upd_ll_conn_params(p_lcb->handle, min_conn_int, max_conn_int,
                                                   slave_latency, supervision_tout, 0, 0);
-                p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
             } else {
                 l2cu_send_peer_ble_par_req (p_lcb, min_conn_int, max_conn_int, slave_latency, supervision_tout);
             }
+            p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
             p_lcb->conn_update_mask &= ~L2C_BLE_NOT_DEFAULT_PARAM;
             p_lcb->conn_update_mask |=  L2C_BLE_NEW_CONN_PARAM;
+            return TRUE;
         } else {
             status = HCI_ERR_ILLEGAL_COMMAND;
-            L2CAP_TRACE_DEBUG("%s, staus = %x", __func__, status);
+            L2CAP_TRACE_ERROR("%s, staus = %x, line = %d", __func__, status, __LINE__);
             btu_stop_timer(&p_lcb->upda_con_timer);
             l2c_send_update_conn_params_cb(p_lcb, status);
-            return;
+            return FALSE;
         }
     } else {
         /* application allows to do update, if we were delaying one do it now */
         if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) {
             /* if both side 4.1, or we are master device, send HCI command */
             if (p_lcb->link_role == HCI_ROLE_MASTER
-#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
+#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) && (BLE_SLAVE_UPD_CONN_PARAMS == TRUE)
                     || (HCI_LE_CONN_PARAM_REQ_SUPPORTED(controller_get_interface()->get_features_ble()->as_array) &&
                         HCI_LE_CONN_PARAM_REQ_SUPPORTED(p_acl_cb->peer_le_features))
 #endif
                ) {
                 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;
             } else {
                 l2cu_send_peer_ble_par_req (p_lcb, p_lcb->min_interval, p_lcb->max_interval,
                                             p_lcb->latency, p_lcb->timeout);
             }
+            p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
             p_lcb->conn_update_mask &= ~L2C_BLE_NEW_CONN_PARAM;
             p_lcb->conn_update_mask |= L2C_BLE_NOT_DEFAULT_PARAM;
+            return TRUE;
         } else {
-            status = HCI_ERR_ILLEGAL_COMMAND;
-            L2CAP_TRACE_DEBUG("%s, staus = %x", __func__, status);
             btu_stop_timer(&p_lcb->upda_con_timer);
-            l2c_send_update_conn_params_cb(p_lcb, status);
-            return;
+            return FALSE;
         }
     }
 }
@@ -555,7 +554,7 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_in
     tL2C_LCB *p_lcb;
 
     L2CAP_TRACE_DEBUG("l2cble_process_conn_update_evt");
-
+    L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: status: %d", status);
     /* See if we have a link control block for the remote device */
     p_lcb = l2cu_find_lcb_by_handle(handle);
     if (!p_lcb) {
@@ -563,6 +562,9 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_in
         return;
     }
 
+    p_lcb->conn_int = conn_interval;
+    p_lcb->latency = conn_latency;
+    p_lcb->timeout = conn_timeout;
     tACL_CONN *p_acl_cb = btm_bda_to_acl(p_lcb->remote_bd_addr, BT_TRANSPORT_LE);
     p_lcb->conn_update_mask &= ~L2C_BLE_UPDATE_PENDING;
 
@@ -570,10 +572,11 @@ void l2cble_process_conn_update_evt (UINT16 handle, UINT8 status, UINT16 conn_in
         L2CAP_TRACE_WARNING("l2cble_process_conn_update_evt: Error status: %d", status);
     }
 
-    l2cble_start_conn_update(p_lcb);
+    if (l2cble_start_conn_update(p_lcb) == TRUE) {
+        btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
+    }
 
     btu_stop_timer (&p_lcb->timer_entry);
-    btu_stop_timer (&p_lcb->upda_con_timer);
     
     if (p_acl_cb->update_conn_param_cb != NULL) {
         l2c_send_update_conn_params_cb(p_lcb, status);
@@ -652,7 +655,9 @@ void l2cble_process_sig_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len)
                 p_lcb->timeout = timeout;
                 p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM;
 
-                l2cble_start_conn_update(p_lcb);
+                if (l2cble_start_conn_update(p_lcb) == TRUE) {
+                    btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT);
+                }
             }
         } else {
             l2cu_send_peer_cmd_reject (p_lcb, L2CAP_CMD_REJ_NOT_UNDERSTOOD, id, 0, 0);
@@ -945,9 +950,9 @@ void l2cble_process_rc_param_request_evt(UINT16 handle, UINT16 int_min, UINT16 i
         p_lcb->max_interval = int_max;
         p_lcb->latency = latency;
         p_lcb->timeout = timeout;
-
         /* if update is enabled, always accept connection parameter update */
         if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) {
+            p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING;
             btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, timeout, 0, 0);
         } else {
             L2CAP_TRACE_EVENT ("L2CAP - LE - update currently disabled");

+ 3 - 2
examples/bluetooth/gatt_server/main/gatts_demo.c

@@ -179,8 +179,8 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param
         }
         break;
     case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT:
-         ESP_LOGI(GATTS_TAG, "update connetion params status = %d, min_int = %x, max_int = %x,\
-                  conn_int = %d,latency = %d, timeout = %d", param->update_conn_params.status,
+         ESP_LOGI(GATTS_TAG, "update connetion params status = %d, min_int = %d, max_int = %d,conn_int = %d,latency = %d, timeout = %d",
+                  param->update_conn_params.status,
                   param->update_conn_params.min_int,
                   param->update_conn_params.max_int,
                   param->update_conn_params.conn_int,
@@ -345,6 +345,7 @@ static void gatts_profile_a_event_handler(esp_gatts_cb_event_t event, esp_gatt_i
     case ESP_GATTS_CONNECT_EVT: {
         esp_ble_conn_update_params_t conn_params = {0};
         memcpy(conn_params.bda, param->connect.remote_bda, sizeof(esp_bd_addr_t));
+        /* For the IOS system, please reference the apple official documents about the ble connection parameters restrictions. */
         conn_params.latency = 0;
         conn_params.max_int = 0x50;    // max_int = 0x50*1.25ms = 100ms
         conn_params.min_int = 0x30;    // min_int = 0x30*1.25ms = 60ms