From 137d407e665fe6f34644ceba9e58e27275ba5e35 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 16 Jan 2018 12:14:11 +0800 Subject: [PATCH] Component/bt: send data length request by host after read feature complete --- components/bt/bluedroid/device/controller.c | 12 +++++++++++- components/bt/bluedroid/device/include/controller.h | 1 + components/bt/bluedroid/hci/hci_packet_parser.c | 6 ++++-- .../bt/bluedroid/hci/include/hci_packet_parser.h | 3 ++- components/bt/bluedroid/stack/btm/btm_acl.c | 5 +++++ components/bt/bluedroid/stack/btm/btm_ble.c | 2 +- components/bt/bluedroid/stack/btm/btm_ble_gap.c | 5 +++++ components/bt/bluedroid/stack/gatt/gatt_cl.c | 6 ++++-- components/bt/bluedroid/stack/gatt/gatt_sr.c | 7 ++++--- components/bt/lib | 2 +- 10 files changed, 38 insertions(+), 11 deletions(-) diff --git a/components/bt/bluedroid/device/controller.c b/components/bt/bluedroid/device/controller.c index 08564052d8..176eb8f29b 100644 --- a/components/bt/bluedroid/device/controller.c +++ b/components/bt/bluedroid/device/controller.c @@ -66,6 +66,7 @@ static uint8_t ble_resolving_list_max_size; static uint8_t ble_supported_states[BLE_SUPPORTED_STATES_SIZE]; static bt_device_features_t features_ble; static uint16_t ble_suggested_default_data_length; +static uint16_t ble_suggested_default_data_txtime; static bool readable; static bool ble_supported; @@ -228,7 +229,8 @@ static void start_up(void) response = AWAIT_COMMAND(packet_factory->make_ble_read_suggested_default_data_length()); packet_parser->parse_ble_read_suggested_default_data_length_response( response, - &ble_suggested_default_data_length); + &ble_suggested_default_data_length, + &ble_suggested_default_data_txtime); } // Set the ble event mask next @@ -404,6 +406,13 @@ static uint16_t get_ble_suggested_default_data_length(void) return ble_suggested_default_data_length; } +static uint16_t get_ble_suggested_default_data_txtime(void) +{ + assert(readable); + assert(ble_supported); + return ble_suggested_default_data_txtime; +} + static uint16_t get_acl_buffer_count_classic(void) { assert(readable); @@ -472,6 +481,7 @@ static const controller_t interface = { get_acl_packet_size_classic, get_acl_packet_size_ble, get_ble_suggested_default_data_length, + get_ble_suggested_default_data_txtime, get_acl_buffer_count_classic, get_acl_buffer_count_ble, diff --git a/components/bt/bluedroid/device/include/controller.h b/components/bt/bluedroid/device/include/controller.h index 6d6e5a8ca3..bffa714f43 100644 --- a/components/bt/bluedroid/device/include/controller.h +++ b/components/bt/bluedroid/device/include/controller.h @@ -69,6 +69,7 @@ typedef struct controller_t { uint16_t (*get_acl_packet_size_ble)(void); uint16_t (*get_ble_default_data_packet_length)(void); + uint16_t (*get_ble_default_data_packet_txtime)(void); // Get the number of acl packets the controller can buffer. uint16_t (*get_acl_buffer_count_classic)(void); diff --git a/components/bt/bluedroid/hci/hci_packet_parser.c b/components/bt/bluedroid/hci/hci_packet_parser.c index b0e5e4b434..613113d690 100644 --- a/components/bt/bluedroid/hci/hci_packet_parser.c +++ b/components/bt/bluedroid/hci/hci_packet_parser.c @@ -183,11 +183,13 @@ static void parse_ble_read_resolving_list_size_response( static void parse_ble_read_suggested_default_data_length_response( BT_HDR *response, - uint16_t *ble_default_packet_length_ptr) + uint16_t *ble_default_packet_length_ptr, + uint16_t *ble_default_packet_txtime_ptr) { uint8_t *stream = read_command_complete_header(response, HCI_BLE_READ_DEFAULT_DATA_LENGTH, 2 /* bytes after */); - STREAM_TO_UINT8(*ble_default_packet_length_ptr, stream); + STREAM_TO_UINT16(*ble_default_packet_length_ptr, stream); + STREAM_TO_UINT16(*ble_default_packet_txtime_ptr, stream); buffer_allocator->free(response); } diff --git a/components/bt/bluedroid/hci/include/hci_packet_parser.h b/components/bt/bluedroid/hci/include/hci_packet_parser.h index 916ea313f6..7090708f0d 100644 --- a/components/bt/bluedroid/hci/include/hci_packet_parser.h +++ b/components/bt/bluedroid/hci/include/hci_packet_parser.h @@ -90,7 +90,8 @@ typedef struct { void (*parse_ble_read_suggested_default_data_length_response)( BT_HDR *response, - uint16_t *ble_default_packet_length_ptr + uint16_t *ble_default_packet_length_ptr, + uint16_t *ble_default_packet_txtime_ptr ); } hci_packet_parser_t; diff --git a/components/bt/bluedroid/stack/btm/btm_acl.c b/components/bt/bluedroid/stack/btm/btm_acl.c index 239d6d6507..08ed2fcdd2 100644 --- a/components/bt/bluedroid/stack/btm/btm_acl.c +++ b/components/bt/bluedroid/stack/btm/btm_acl.c @@ -907,6 +907,11 @@ void btm_read_remote_version_complete (UINT8 *p) } #if BLE_INCLUDED == TRUE if (p_acl_cb->transport == BT_TRANSPORT_LE) { + 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(); + btsnd_hcic_ble_set_data_length(p_acl_cb->hci_handle, data_length, data_txtime); + } l2cble_notify_le_connection (p_acl_cb->remote_addr); } #endif diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index 95f15e3a65..7c9e438084 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -812,7 +812,7 @@ tBTM_STATUS BTM_SetBleDataLength(BD_ADDR bd_addr, UINT16 tx_pdu_length) } if (!HCI_LE_DATA_LEN_EXT_SUPPORTED(p_acl->peer_le_features)) { - BTM_TRACE_DEBUG("%s failed, peer does not support request", __FUNCTION__); + BTM_TRACE_ERROR("%s failed, peer does not support request", __FUNCTION__); return BTM_PEER_LE_DATA_LEN_UNSUPPORTED; } diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index a632972a6b..d0eee7b87c 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -3350,6 +3350,11 @@ void btm_ble_read_remote_features_complete(UINT8 *p) else{ if (p_acl_cb->transport == BT_TRANSPORT_LE) { + 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(); + 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/bluedroid/stack/gatt/gatt_cl.c b/components/bt/bluedroid/stack/gatt/gatt_cl.c index cefa32f852..9c0584313c 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_cl.c +++ b/components/bt/bluedroid/stack/gatt/gatt_cl.c @@ -989,8 +989,10 @@ void gatt_process_mtu_rsp(tGATT_TCB *p_tcb, tGATT_CLCB *p_clcb, UINT16 len, UINT p_tcb->payload_size = mtu; } } - - l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); + /* host will set packet data length to 251 automatically if remote device support set packet data length, + so l2cble_set_fixed_channel_tx_data_length() is not necessary. + l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); + */ gatt_end_operation(p_clcb, status, NULL); } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/gatt/gatt_sr.c b/components/bt/bluedroid/stack/gatt/gatt_sr.c index 3d8259840f..7a53afa851 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_sr.c +++ b/components/bt/bluedroid/stack/gatt/gatt_sr.c @@ -929,9 +929,10 @@ static void gatts_process_mtu_req (tGATT_TCB *p_tcb, UINT16 len, UINT8 *p_data) p_tcb->payload_size = mtu; } - GATT_TRACE_ERROR("MTU request PDU with MTU size %d\n", p_tcb->payload_size); - - l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); + /* host will set packet data length to 251 automatically if remote device support set packet data length, + so l2cble_set_fixed_channel_tx_data_length() is not necessary. + l2cble_set_fixed_channel_tx_data_length(p_tcb->peer_bda, L2CAP_ATT_CID, p_tcb->payload_size); + */ if ((p_buf = attp_build_sr_msg(p_tcb, GATT_RSP_MTU, (tGATT_SR_MSG *) &p_tcb->payload_size)) != NULL) { attp_send_sr_msg (p_tcb, p_buf); diff --git a/components/bt/lib b/components/bt/lib index 4c0d1e8941..459d8f8e19 160000 --- a/components/bt/lib +++ b/components/bt/lib @@ -1 +1 @@ -Subproject commit 4c0d1e8941ebc2d43962d92509c17b664db2c7da +Subproject commit 459d8f8e1921c9e82d8f0a9b1ecf44fc3699139d