From 01705166bc049c69d8ada2edec7f72917d56cca6 Mon Sep 17 00:00:00 2001 From: Yulong Date: Mon, 19 Jun 2017 03:22:25 -0400 Subject: [PATCH 1/3] component/bt: Modifed the update connection method to fixed the bug of connection parameters not correct. --- components/bt/bluedroid/include/bt_target.h | 7 +++++++ components/bt/bluedroid/stack/l2cap/l2c_ble.c | 20 +++++++++---------- .../bluetooth/gatt_server/main/gatts_demo.c | 5 +++-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/components/bt/bluedroid/include/bt_target.h b/components/bt/bluedroid/include/bt_target.h index 02c0486a82..5abec32ef9 100644 --- a/components/bt/bluedroid/include/bt_target.h +++ b/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 diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/bluedroid/stack/l2cap/l2c_ble.c index a50efc8ed2..ccfaf46967 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_ble.c @@ -122,7 +122,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; - + btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT); l2cble_start_conn_update(p_lcb); return (TRUE); @@ -464,12 +464,11 @@ 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); 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); + 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); } @@ -490,7 +489,7 @@ 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 @@ -505,7 +504,7 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) p_lcb->conn_update_mask |= L2C_BLE_NEW_CONN_PARAM; } 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; @@ -515,7 +514,7 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) 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 @@ -530,10 +529,6 @@ 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; } 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; } } @@ -555,7 +550,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 +558,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; diff --git a/examples/bluetooth/gatt_server/main/gatts_demo.c b/examples/bluetooth/gatt_server/main/gatts_demo.c index 50b9939938..274d4c08b6 100644 --- a/examples/bluetooth/gatt_server/main/gatts_demo.c +++ b/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 From 328e93ddc46f7246abc6852f361d9a99195f3fd5 Mon Sep 17 00:00:00 2001 From: Yulong Date: Wed, 21 Jun 2017 02:39:36 -0400 Subject: [PATCH 2/3] component/bt: Change the l2cble_start_conn_update return value to BOOLEAN. --- components/bt/bluedroid/stack/l2cap/l2c_ble.c | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/bluedroid/stack/l2cap/l2c_ble.c index ccfaf46967..8d8edbb344 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ble.c +++ b/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); /******************************************************************************* ** @@ -122,8 +122,10 @@ 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; - btu_start_timer(&p_lcb->upda_con_timer, BTU_TTYPE_L2CAP_UPDA_CONN_PARAMS, L2CAP_UPDATE_CONN_PARAM_TOUT); - 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,23 +460,19 @@ 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; 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, 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; } if (p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) { @@ -496,18 +496,19 @@ static void l2cble_start_conn_update (tL2C_LCB *p_lcb) ) { 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_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 */ @@ -521,15 +522,17 @@ 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; } 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 { - return; + btu_stop_timer(&p_lcb->upda_con_timer); + return FALSE; } } } @@ -568,10 +571,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); @@ -650,7 +654,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); @@ -943,7 +949,7 @@ 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; - + p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; /* if update is enabled, always accept connection parameter update */ if ((p_lcb->conn_update_mask & L2C_BLE_CONN_UPDATE_DISABLE) == 0) { btsnd_hcic_ble_rc_param_req_reply(handle, int_min, int_max, latency, timeout, 0, 0); From d79aeab3aaeb2843003ed7e97b21cba10cd27537 Mon Sep 17 00:00:00 2001 From: Yulong Date: Thu, 22 Jun 2017 03:53:27 -0400 Subject: [PATCH 3/3] component/bt: Added the error log to the l2cble_start_conn_update func. --- components/bt/bluedroid/stack/l2cap/l2c_ble.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/bt/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/bluedroid/stack/l2cap/l2c_ble.c index 8d8edbb344..6d2c008119 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_ble.c @@ -472,6 +472,7 @@ static BOOLEAN l2cble_start_conn_update (tL2C_LCB *p_lcb) UINT8 status; if (p_lcb->conn_update_mask & L2C_BLE_UPDATE_PENDING) { + L2CAP_TRACE_ERROR("%s, the last connection update command still pending.", __func__); return FALSE; } @@ -949,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; - p_lcb->conn_update_mask |= L2C_BLE_UPDATE_PENDING; /* 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");