From d8474a92bfd5d682f662c605a35ee7631e9e3394 Mon Sep 17 00:00:00 2001 From: zwj Date: Fri, 11 Jun 2021 16:29:52 +0800 Subject: [PATCH] - fix data length update failed - fix no callback when the value being used is the same as the value to be set --- .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 26 +++++++++++++++-- .../bt/host/bluedroid/stack/btm/btm_acl.c | 1 + .../bt/host/bluedroid/stack/btm/btm_ble_gap.c | 1 + .../bluedroid/stack/btm/include/btm_int.h | 5 ++++ .../bt/host/bluedroid/stack/l2cap/l2c_ble.c | 28 ++++++++++++++++--- 5 files changed, 54 insertions(+), 7 deletions(-) diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index fe4aff3a3a..018723a0eb 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -5354,19 +5354,39 @@ void bta_dm_ble_set_scan_rsp_raw (tBTA_DM_MSG *p_data) *******************************************************************************/ void bta_dm_ble_set_data_length(tBTA_DM_MSG *p_data) { + UINT8 status = BTM_SUCCESS; tACL_CONN *p_acl_cb = btm_bda_to_acl(p_data->ble_set_data_length.remote_bda, BT_TRANSPORT_LE); if (p_acl_cb == NULL) { APPL_TRACE_ERROR("%s error: Invalid connection remote_bda.", __func__); return; + } + if(p_acl_cb->data_len_updating) { + // aleady have one cmd + if(p_acl_cb->data_len_waiting) { + status = BTM_ILLEGAL_ACTION; + } else { + // save the command + p_acl_cb->p_set_data_len_cback_waiting = p_data->ble_set_data_length.p_set_pkt_data_cback; + p_acl_cb->tx_len_waiting = p_data->ble_set_data_length.tx_data_length; + p_acl_cb->data_len_waiting = true; + return; + } } else { p_acl_cb->p_set_pkt_data_cback = p_data->ble_set_data_length.p_set_pkt_data_cback; - } - UINT8 status = BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, + // if the value of the data length is same, triger callback directly + if(p_data->ble_set_data_length.tx_data_length == p_acl_cb->data_length_params.tx_len) { + if(p_data->ble_set_data_length.p_set_pkt_data_cback) { + (*p_data->ble_set_data_length.p_set_pkt_data_cback)(status, &p_acl_cb->data_length_params); + } + return; + } + status = BTM_SetBleDataLength(p_data->ble_set_data_length.remote_bda, p_data->ble_set_data_length.tx_data_length); + } if (status != BTM_SUCCESS) { APPL_TRACE_ERROR("%s failed\n", __FUNCTION__); } - if (p_data->ble_set_data_length.p_set_pkt_data_cback) { + if (p_data->ble_set_data_length.p_set_pkt_data_cback && status != BTM_SUCCESS) { if (p_acl_cb->data_length_params.tx_len == 0){ uint16_t length = controller_get_interface()->get_acl_data_size_ble(); p_acl_cb->data_length_params.rx_len = length; diff --git a/components/bt/host/bluedroid/stack/btm/btm_acl.c b/components/bt/host/bluedroid/stack/btm/btm_acl.c index 322508892a..bb8b4ac33e 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/host/bluedroid/stack/btm/btm_acl.c @@ -954,6 +954,7 @@ void btm_read_remote_version_complete (UINT8 *p) if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) { uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length(); uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime(); + p_acl_cb->data_len_updating = true; btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime); } l2cble_notify_le_connection (p_acl_cb->remote_addr); diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c index 96b0118e78..6d1ba22186 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_gap.c @@ -4199,6 +4199,7 @@ void btm_ble_read_remote_features_complete(UINT8 *p) if (HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl_cb->peer_le_features)) { uint16_t data_length = controller_get_interface()->get_ble_default_data_packet_length(); uint16_t data_txtime = controller_get_interface()->get_ble_default_data_packet_txtime(); + p_acl_cb->data_len_updating = true; btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime); } l2cble_notify_le_connection (p_acl_cb->remote_addr); diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index dfffe1dea0..ade758a81b 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -158,6 +158,11 @@ UINT8 active_remote_addr_type; /* local device address type fo BD_FEATURES peer_le_features; /* Peer LE Used features mask for the device */ tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_pkt_data_cback; tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params; +BOOLEAN data_len_updating; +// data len update cmd cache +BOOLEAN data_len_waiting; +tBTM_SET_PKT_DATA_LENGTH_CBACK *p_set_data_len_cback_waiting; +UINT16 tx_len_waiting; #endif tBTM_PM_MCB *p_pm_mode_db; /* Pointer to PM mode control block per ACL link */ diff --git a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c index 3080c4484a..9fe8dfea07 100644 --- a/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c +++ b/components/bt/host/bluedroid/stack/l2cap/l2c_ble.c @@ -1217,13 +1217,33 @@ void l2cble_process_data_length_change_event(UINT16 handle, UINT16 tx_data_len, } tACL_CONN *p_acl = btm_handle_to_acl(handle); + tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params; + data_length_params.rx_len = rx_data_len; + data_length_params.tx_len = tx_data_len; + p_acl->data_length_params = data_length_params; if (p_acl != NULL && p_acl->p_set_pkt_data_cback){ - tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS data_length_params; - data_length_params.rx_len = tx_data_len; - data_length_params.tx_len = rx_data_len; - p_acl->data_length_params = data_length_params; (*p_acl->p_set_pkt_data_cback)(BTM_SUCCESS, &data_length_params); } + + if(p_acl) { + p_acl->data_len_updating = false; + if(p_acl->data_len_waiting) { + p_acl->data_len_waiting = false; + p_acl->p_set_pkt_data_cback = p_acl->p_set_data_len_cback_waiting; + p_acl->p_set_data_len_cback_waiting = NULL; + // if value is same, triger callback directly + if(p_acl->tx_len_waiting == p_acl->data_length_params.tx_len) { + if(p_acl->p_set_pkt_data_cback) { + (*p_acl->p_set_pkt_data_cback)(BTM_SUCCESS, &p_acl->data_length_params); + } + return; + } + p_acl->data_len_updating = true; + /* always set the TxTime to be max, as controller does not care for now */ + btsnd_hcic_ble_set_data_length(handle, p_acl->tx_len_waiting, + BTM_BLE_DATA_TX_TIME_MAX); + } + } } /*******************************************************************************