diff options
author | Treehugger Robot <treehugger-gerrit@google.com> | 2021-01-13 20:38:03 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2021-01-13 20:38:03 +0000 |
commit | 955366c80448cf01ba3c315d446bd677907563e4 (patch) | |
tree | 6b193013389997307a4a33e440f9ee8e6b6761f1 | |
parent | 989fd4a1dfbca39dc2096282c4bf4d35d7f94d3c (diff) | |
parent | be243ba928ae62d7d14ed6d6577e05e4ca532a26 (diff) | |
download | bt-955366c80448cf01ba3c315d446bd677907563e4.tar.gz |
Merge changes I9f667570,I056a3fdc,I685a3220,I81cdee3a,I7e053cff
* changes:
Properly use tHCI_STATUS and hci error code equivalence
Use proper stack/btm/btm_sec::btm_status_text
gd: Include hci handle in unsuccessful mode change event
Use proper bta/gatt/bta_gattc_act::gatt_disconnection_reason_text
Add gatt_disconnection_reason_text
-rw-r--r-- | bta/dm/bta_dm_act.cc | 4 | ||||
-rw-r--r-- | bta/gatt/bta_gattc_act.cc | 4 | ||||
-rw-r--r-- | bta/include/bta_dm_acl.h | 3 | ||||
-rw-r--r-- | bta/sys/bta_sys.h | 3 | ||||
-rw-r--r-- | bta/sys/bta_sys_conn.cc | 2 | ||||
-rw-r--r-- | gd/hci/acl_manager/classic_impl.h | 9 | ||||
-rw-r--r-- | main/shim/l2c_api.cc | 5 | ||||
-rw-r--r-- | stack/acl/btm_acl.cc | 18 | ||||
-rw-r--r-- | stack/btm/btm_ble_gap.cc | 2 | ||||
-rw-r--r-- | stack/btm/btm_sco.cc | 4 | ||||
-rw-r--r-- | stack/btm/btm_sec.cc | 8 | ||||
-rw-r--r-- | stack/include/gatt_api.h | 23 | ||||
-rw-r--r-- | stack/include/hci_error_code.h | 19 | ||||
-rw-r--r-- | stack/include/sco_hci_link_interface.h | 3 | ||||
-rw-r--r-- | stack/test/common/mock_bta_dm_act.cc | 2 | ||||
-rw-r--r-- | stack/test/common/mock_bta_sys_conn.cc | 2 |
16 files changed, 77 insertions, 34 deletions
diff --git a/bta/dm/bta_dm_act.cc b/bta/dm/bta_dm_act.cc index ed0574a84..1093c6251 100644 --- a/bta/dm/bta_dm_act.cc +++ b/bta/dm/bta_dm_act.cc @@ -2183,7 +2183,7 @@ static void bta_dm_local_name_cback(UNUSED_ATTR void* p_name) { } static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role, - uint8_t hci_status) { + tHCI_STATUS hci_status) { tBTA_DM_PEER_DEVICE* p_dev = bta_dm_find_peer_device(bd_addr); if (!p_dev) { LOG_WARN( @@ -2230,7 +2230,7 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role, } void BTA_dm_report_role_change(const RawAddress bd_addr, uint8_t new_role, - uint8_t hci_status) { + tHCI_STATUS hci_status) { do_in_main_thread( FROM_HERE, base::Bind(handle_role_change, bd_addr, new_role, hci_status)); } diff --git a/bta/gatt/bta_gattc_act.cc b/bta/gatt/bta_gattc_act.cc index 5d1f77f28..e280ab8a3 100644 --- a/bta/gatt/bta_gattc_act.cc +++ b/bta/gatt/bta_gattc_act.cc @@ -1068,12 +1068,12 @@ static void bta_gattc_conn_cback(tGATT_IF gattc_if, const RawAddress& bdaddr, if (connected) { LOG_INFO("Connected att_id:%hhu transport:%s reason:%s", gattc_if, BtTransportText(transport).c_str(), - hci_error_code_text(reason).c_str()); + gatt_disconnection_reason_text(reason).c_str()); btif_debug_conn_state(bdaddr, BTIF_DEBUG_CONNECTED, GATT_CONN_UNKNOWN); } else { LOG_INFO("Disconnected att_id:%hhu transport:%s reason:%s", gattc_if, BtTransportText(transport).c_str(), - hci_error_code_text(reason).c_str()); + gatt_disconnection_reason_text(reason).c_str()); btif_debug_conn_state(bdaddr, BTIF_DEBUG_DISCONNECTED, GATT_CONN_UNKNOWN); } diff --git a/bta/include/bta_dm_acl.h b/bta/include/bta_dm_acl.h index b5d2be151..ba32e99fd 100644 --- a/bta/include/bta_dm_acl.h +++ b/bta/include/bta_dm_acl.h @@ -19,11 +19,12 @@ #include <cstdint> #include "stack/include/bt_types.h" +#include "stack/include/hci_error_code.h" #include "types/bt_transport.h" #include "types/raw_address.h" void BTA_dm_acl_up(const RawAddress bd_addr, tBT_TRANSPORT transport); void BTA_dm_acl_down(const RawAddress bd_addr, tBT_TRANSPORT transport); void BTA_dm_report_role_change(const RawAddress bd_addr, uint8_t new_role, - uint8_t hci_status); + tHCI_STATUS hci_status); void BTA_dm_notify_remote_features_complete(const RawAddress bd_addr); diff --git a/bta/sys/bta_sys.h b/bta/sys/bta_sys.h index 3055adb9d..486cfb4ec 100644 --- a/bta/sys/bta_sys.h +++ b/bta/sys/bta_sys.h @@ -27,6 +27,7 @@ #include "bt_common.h" #include "bt_target.h" #include "osi/include/alarm.h" +#include "stack/include/hci_error_code.h" #include <base/logging.h> #include <base/threading/thread.h> @@ -232,7 +233,7 @@ extern void bta_sys_chg_ssr_config(uint8_t id, uint8_t app_id, extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK* p_cback); extern void bta_sys_notify_role_chg(const RawAddress& peer_addr, - uint8_t new_role, uint8_t hci_status); + uint8_t new_role, tHCI_STATUS hci_status); extern void bta_sys_collision_register(uint8_t bta_id, tBTA_SYS_CONN_CBACK* p_cback); extern void bta_sys_notify_collision(const RawAddress& peer_addr); diff --git a/bta/sys/bta_sys_conn.cc b/bta/sys/bta_sys_conn.cc index 075f0552c..271f05a14 100644 --- a/bta/sys/bta_sys_conn.cc +++ b/bta/sys/bta_sys_conn.cc @@ -85,7 +85,7 @@ void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK* p_cback) { * ******************************************************************************/ void bta_sys_notify_role_chg(const RawAddress& peer_addr, uint8_t new_role, - uint8_t hci_status) { + tHCI_STATUS hci_status) { LOG_DEBUG("Role changed peer:%s new_role:%s hci_status:%s", PRIVATE_ADDRESS(peer_addr), RoleText(new_role).c_str(), hci_error_code_text(hci_status).c_str()); diff --git a/gd/hci/acl_manager/classic_impl.h b/gd/hci/acl_manager/classic_impl.h index 9f2f21df5..8a36e75e1 100644 --- a/gd/hci/acl_manager/classic_impl.h +++ b/gd/hci/acl_manager/classic_impl.h @@ -407,13 +407,14 @@ struct classic_impl : public security::ISecurityManagerListener { if (!mode_change_view.IsValid()) { LOG_ERROR("Received on_mode_change with invalid packet"); return; - } else if (mode_change_view.GetStatus() != ErrorCode::SUCCESS) { - auto status = mode_change_view.GetStatus(); + } + auto status = mode_change_view.GetStatus(); + uint16_t handle = mode_change_view.GetConnectionHandle(); + if (status != ErrorCode::SUCCESS) { std::string error_code = ErrorCodeText(status); - LOG_ERROR("Received on_mode_change with error code %s", error_code.c_str()); + LOG_ERROR("Received on_mode_change on handle 0x0%04hx with error code %s", handle, error_code.c_str()); return; } - uint16_t handle = mode_change_view.GetConnectionHandle(); auto callbacks = get_callbacks(handle); if (callbacks == nullptr) { LOG_WARN("Unknown connection handle 0x%04hx", handle); diff --git a/main/shim/l2c_api.cc b/main/shim/l2c_api.cc index e6d9d74f1..8517077ac 100644 --- a/main/shim/l2c_api.cc +++ b/main/shim/l2c_api.cc @@ -598,8 +598,9 @@ bool L2CA_ReadRemoteVersion(const RawAddress& addr, uint8_t* lmp_version, } static void on_sco_disconnect(uint16_t handle, uint8_t reason) { - GetGdShimHandler()->Post( - base::BindOnce(base::IgnoreResult(&btm_sco_removed), handle, reason)); + GetGdShimHandler()->Post(base::BindOnce(base::IgnoreResult(&btm_sco_removed), + handle, + static_cast<tHCI_REASON>(reason))); } void L2CA_UseLegacySecurityModule() { diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 72af05621..e24d94616 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -320,7 +320,7 @@ void btm_acl_process_sca_cmpl_pkt(uint8_t len, uint8_t* data) { if (status != HCI_SUCCESS) { LOG_WARN("Peer SCA Command complete failed:%s", - hci_error_code_text(status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(status)).c_str()); return; } @@ -920,7 +920,7 @@ void btm_read_remote_features_complete_raw(uint8_t* p) { if (status != HCI_SUCCESS) { LOG_WARN("Uanble to read remote features status:%s", - hci_error_code_text(status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(status)).c_str()); return; } @@ -1841,7 +1841,8 @@ void btm_read_tx_power_complete(uint8_t* p, bool is_ble) { } LOG_DEBUG("Transmit power complete: tx_power:%d hci status:%s", result.tx_power, - hci_error_code_text(result.hci_status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(result.hci_status)) + .c_str()); } else { result.status = BTM_ERR_PROCESSING; } @@ -1895,7 +1896,8 @@ void btm_read_rssi_complete(uint8_t* p) { STREAM_TO_UINT8(result.rssi, p); LOG_DEBUG("Read rrsi complete rssi:%hhd hci status:%s", result.rssi, - hci_error_code_text(result.hci_status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(result.hci_status)) + .c_str()); tACL_CONN* p_acl_cb = internal_.acl_get_connection_from_handle(handle); if (p_acl_cb != nullptr) { @@ -2018,7 +2020,8 @@ void btm_read_automatic_flush_timeout_complete(uint8_t* p) { LOG_DEBUG( "Read automatic flush timeout complete timeout:%hu hci_status:%s", result.automatic_flush_timeout, - hci_error_code_text(result.hci_status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(result.hci_status)) + .c_str()); tACL_CONN* p_acl_cb = internal_.acl_get_connection_from_handle(handle); if (p_acl_cb != nullptr) { @@ -2074,7 +2077,8 @@ void btm_read_link_quality_complete(uint8_t* p) { STREAM_TO_UINT8(result.link_quality, p); LOG_DEBUG("BTM Link Quality Complete: Link Quality %d, hci status:%s", result.link_quality, - hci_error_code_text(result.hci_status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(result.hci_status)) + .c_str()); tACL_CONN* p_acl_cb = internal_.acl_get_connection_from_handle(handle); if (p_acl_cb != nullptr) { @@ -2721,7 +2725,7 @@ void btm_acl_connected(const RawAddress& bda, uint16_t handle, } void btm_acl_disconnected(tHCI_STATUS status, uint16_t handle, - tHCI_STATUS reason) { + tHCI_REASON reason) { if (status != HCI_SUCCESS) { LOG_WARN("Received disconnect with error:%s", hci_error_code_text(status).c_str()); diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc index d57a63f0d..e1350a3b4 100644 --- a/stack/btm/btm_ble_gap.cc +++ b/stack/btm/btm_ble_gap.cc @@ -2189,7 +2189,7 @@ void btm_ble_read_remote_features_complete(uint8_t* p) { if (status != HCI_SUCCESS) { if (status != HCI_ERR_UNSUPPORTED_REM_FEATURE) { LOG_ERROR("Failed to read remote features status:%s", - hci_error_code_text(status).c_str()); + hci_error_code_text(static_cast<tHCI_STATUS>(status)).c_str()); return; } LOG_WARN("Remote does not support reading remote feature"); diff --git a/stack/btm/btm_sco.cc b/stack/btm/btm_sco.cc index 236c6c413..b5f9dd1c3 100644 --- a/stack/btm/btm_sco.cc +++ b/stack/btm/btm_sco.cc @@ -799,7 +799,7 @@ void BTM_RemoveSco(const RawAddress& bda) { * Returns true if the link is known about, else false * ******************************************************************************/ -bool btm_sco_removed(uint16_t hci_handle, uint8_t reason) { +bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason) { tSCO_CONN* p = &btm_cb.sco_cb.sco_db[0]; uint16_t xx; @@ -816,7 +816,7 @@ bool btm_sco_removed(uint16_t hci_handle, uint8_t reason) { btm_cb.sco_cb.sco_disc_reason = reason; (*p->p_disc_cb)(xx); LOG_DEBUG("Disconnected SCO link handle:%hu reason:%s", hci_handle, - hci_error_code_text(reason).c_str()); + hci_reason_code_text(reason).c_str()); return true; } } diff --git a/stack/btm/btm_sec.cc b/stack/btm/btm_sec.cc index b619a4bf9..2873f66e3 100644 --- a/stack/btm/btm_sec.cc +++ b/stack/btm/btm_sec.cc @@ -4798,11 +4798,11 @@ void btm_sec_set_peer_sec_caps(uint16_t hci_handle, bool ssp_supported, if (!(p_dev_rec->sec_flags & BTM_SEC_NAME_KNOWN) || p_dev_rec->is_originator) { - uint8_t status = btm_sec_execute_procedure(p_dev_rec); - if (status != BTM_CMD_STARTED) { + tBTM_STATUS btm_status = btm_sec_execute_procedure(p_dev_rec); + if (btm_status != BTM_CMD_STARTED) { LOG_WARN("Security procedure not started! status:%s", - hci_error_code_text(status).c_str()); - btm_sec_dev_rec_cback_event(p_dev_rec, status, false); + btm_status_text(btm_status).c_str()); + btm_sec_dev_rec_cback_event(p_dev_rec, btm_status, false); } } diff --git a/stack/include/gatt_api.h b/stack/include/gatt_api.h index c23899327..ee256535c 100644 --- a/stack/include/gatt_api.h +++ b/stack/include/gatt_api.h @@ -18,6 +18,9 @@ #ifndef GATT_API_H #define GATT_API_H +#include <base/strings/stringprintf.h> +#include <string> + #include "bt_target.h" #include "btm_ble_api.h" #include "gattdefs.h" @@ -206,6 +209,26 @@ typedef enum : uint16_t { GATT_CONN_LMP_TIMEOUT = HCI_ERR_LMP_RESPONSE_TIMEOUT, } tGATT_DISCONN_REASON; +inline std::string gatt_disconnection_reason_text( + const tGATT_DISCONN_REASON& reason) { + switch (reason) { + case GATT_CONN_OK: + return std::string("ok/unknown"); + case GATT_CONN_L2C_FAILURE: + return std::string("l2cap_failure"); + case GATT_CONN_TIMEOUT: + return std::string("timeout"); + case GATT_CONN_TERMINATE_PEER_USER: + return std::string("remote_terminated"); + case GATT_CONN_TERMINATE_LOCAL_HOST: + return std::string("local_terminated"); + case GATT_CONN_LMP_TIMEOUT: + return std::string("lmp_response_timeout"); + default: + return base::StringPrintf("UNKNOWN:[0x%04hx]", reason); + } +} + /* MAX GATT MTU size */ #ifndef GATT_MAX_MTU_SIZE diff --git a/stack/include/hci_error_code.h b/stack/include/hci_error_code.h index 26d1d223c..625acd19a 100644 --- a/stack/include/hci_error_code.h +++ b/stack/include/hci_error_code.h @@ -16,6 +16,7 @@ #pragma once +#include <base/strings/stringprintf.h> #include <string> /* @@ -63,10 +64,9 @@ typedef enum : uint8_t { HCI_ERR_MAX_ERR = 0x43, // TODO remove. randomly used HCI_ERR_UNDEFINED = 0xff, -} tHCI_STATUS; +} tHCI_ERROR_CODE; -// TODO Change type to tHCI_STATUS -inline std::string hci_error_code_text(uint8_t error_code) { +inline std::string hci_error_code_text(const tHCI_ERROR_CODE& error_code) { switch (error_code) { case HCI_SUCCESS: return std::string("Success"); @@ -143,6 +143,17 @@ inline std::string hci_error_code_text(uint8_t error_code) { case HCI_ERR_LIMIT_REACHED: return std::string("Limit Reached"); default: - return std::string("Unknown Error"); + return base::StringPrintf("Unknown Error[%02hx]", error_code); } } + +// Context equivalence +using tHCI_STATUS = tHCI_ERROR_CODE; +inline std::string hci_status_code_text(const tHCI_STATUS& status_code) { + return hci_error_code_text(status_code); +} + +using tHCI_REASON = tHCI_ERROR_CODE; +inline std::string hci_reason_code_text(const tHCI_REASON& reason_code) { + return hci_error_code_text(reason_code); +} diff --git a/stack/include/sco_hci_link_interface.h b/stack/include/sco_hci_link_interface.h index 04b5b4365..f1bb83e01 100644 --- a/stack/include/sco_hci_link_interface.h +++ b/stack/include/sco_hci_link_interface.h @@ -21,6 +21,7 @@ #include <cstdint> +#include "stack/include/hci_error_code.h" #include "types/raw_address.h" extern void btm_esco_proc_conn_chg(uint8_t status, uint16_t handle, @@ -33,4 +34,4 @@ extern void btm_sco_conn_req(const RawAddress& bda, DEV_CLASS dev_class, uint8_t link_type); extern void btm_sco_connected(uint8_t hci_status, const RawAddress* bda, uint16_t hci_handle, tBTM_ESCO_DATA* p_esco_data); -extern bool btm_sco_removed(uint16_t hci_handle, uint8_t reason); +extern bool btm_sco_removed(uint16_t hci_handle, tHCI_REASON reason); diff --git a/stack/test/common/mock_bta_dm_act.cc b/stack/test/common/mock_bta_dm_act.cc index 47a8e421b..227641a20 100644 --- a/stack/test/common/mock_bta_dm_act.cc +++ b/stack/test/common/mock_bta_dm_act.cc @@ -44,7 +44,7 @@ void BTA_dm_notify_remote_features_complete(const RawAddress bd_addr) { void BTA_dm_on_hw_off() { mock_function_count_map[__func__]++; } void BTA_dm_on_hw_on() { mock_function_count_map[__func__]++; } void BTA_dm_report_role_change(const RawAddress bd_addr, uint8_t new_role, - uint8_t hci_status) { + tHCI_STATUS hci_status) { mock_function_count_map[__func__]++; } void bta_dm_add_device(std::unique_ptr<tBTA_DM_API_ADD_DEVICE> msg) { diff --git a/stack/test/common/mock_bta_sys_conn.cc b/stack/test/common/mock_bta_sys_conn.cc index 669d67bc6..cc5147b1c 100644 --- a/stack/test/common/mock_bta_sys_conn.cc +++ b/stack/test/common/mock_bta_sys_conn.cc @@ -64,7 +64,7 @@ void bta_sys_notify_collision(const RawAddress& peer_addr) { mock_function_count_map[__func__]++; } void bta_sys_notify_role_chg(const RawAddress& peer_addr, uint8_t new_role, - uint8_t hci_status) { + tHCI_STATUS hci_status) { mock_function_count_map[__func__]++; } void bta_sys_pm_register(tBTA_SYS_CONN_CBACK* p_cback) { |