diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc index daa3627b1db51e45d9a75cae20228997798a4fee..1d828858668aa7769e6f6e7b26c232a91223f423 100644 --- a/system/bta/dm/bta_dm_act.cc +++ b/system/bta/dm/bta_dm_act.cc @@ -76,7 +76,8 @@ static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr, const LinkKey& key, uint8_t key_type); static void bta_dm_authentication_complete_cback(const RawAddress& bd_addr, DEV_CLASS dev_class, - BD_NAME bd_name, int result); + BD_NAME bd_name, + tHCI_REASON result); static void bta_dm_local_name_cback(void* p_name); static void bta_dm_check_av(); @@ -2059,30 +2060,40 @@ static uint8_t bta_dm_new_link_key_cback(const RawAddress& bd_addr, ******************************************************************************/ static void bta_dm_authentication_complete_cback( const RawAddress& bd_addr, UNUSED_ATTR DEV_CLASS dev_class, BD_NAME bd_name, - int result) { - tBTA_DM_SEC sec_event; - - if (result != BTM_SUCCESS) { - memset(&sec_event, 0, sizeof(tBTA_DM_SEC)); - sec_event.auth_cmpl.bd_addr = bd_addr; - - memcpy(sec_event.auth_cmpl.bd_name, bd_name, BD_NAME_LEN); - sec_event.auth_cmpl.bd_name[BD_NAME_LEN] = 0; + tHCI_REASON reason) { + if (reason != HCI_SUCCESS) { + if (bta_dm_cb.p_sec_cback) { + // Build out the security event data structure + tBTA_DM_SEC sec_event = { + .auth_cmpl = + { + .bd_addr = bd_addr, + }, + }; + memcpy(sec_event.auth_cmpl.bd_name, bd_name, BD_NAME_LEN); + sec_event.auth_cmpl.bd_name[BD_NAME_LEN] = 0; - // Report the BR link key based on the BR/EDR address and type - BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, - &sec_event.auth_cmpl.addr_type); - sec_event.auth_cmpl.fail_reason = (uint8_t)result; + // Report the BR link key based on the BR/EDR address and type + BTM_ReadDevInfo(bd_addr, &sec_event.auth_cmpl.dev_type, + &sec_event.auth_cmpl.addr_type); + sec_event.auth_cmpl.fail_reason = reason; - if (bta_dm_cb.p_sec_cback) bta_dm_cb.p_sec_cback(BTA_DM_AUTH_CMPL_EVT, &sec_event); + } - if (result == HCI_ERR_AUTH_FAILURE || result == HCI_ERR_KEY_MISSING || - result == HCI_ERR_HOST_REJECT_SECURITY || - result == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) { - APPL_TRACE_WARNING("%s deleting %s - result: 0x%02x", __func__, - bd_addr.ToString().c_str(), result); - bta_dm_remove_sec_dev_entry(bd_addr); + switch (reason) { + case HCI_ERR_AUTH_FAILURE: + case HCI_ERR_KEY_MISSING: + case HCI_ERR_HOST_REJECT_SECURITY: + case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE: + LOG_WARN( + "Deleting device record as authentication failed entry:%s " + "reason:%s", + PRIVATE_ADDRESS(bd_addr), hci_reason_code_text(reason).c_str()); + break; + + default: + break; } } } @@ -3452,9 +3463,11 @@ static uint8_t bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda, else sec_event.auth_cmpl.bd_name[0] = 0; - if (p_data->complt.reason != 0) { + if (p_data->complt.reason != HCI_SUCCESS) { + // TODO This is not a proper use of this type sec_event.auth_cmpl.fail_reason = - BTA_DM_AUTH_CONVERT_SMP_CODE(((uint8_t)p_data->complt.reason)); + static_cast<tHCI_STATUS>(BTA_DM_AUTH_CONVERT_SMP_CODE( + (static_cast<uint8_t>(p_data->complt.reason)))); if (btm_sec_is_a_bonded_dev(bda) && p_data->complt.reason == SMP_CONN_TOUT) { diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h index 0e6ef0b3f464a9c806fe22285edd748ef4833e98..6289546b00acab30ea9aefb8b9d614951f1d114e 100644 --- a/system/bta/include/bta_api.h +++ b/system/bta/include/bta_api.h @@ -34,6 +34,7 @@ #include "stack/include/bt_types.h" #include "stack/include/btm_api_types.h" #include "stack/include/btm_ble_api_types.h" +#include "stack/include/hci_error_code.h" #include "stack/include/sdp_api.h" #include "types/ble_address_with_type.h" #include "types/bluetooth/uuid.h" @@ -291,7 +292,8 @@ typedef struct { LinkKey key; /* Link key associated with peer device. */ uint8_t key_type; /* The type of Link Key */ bool success; /* true of authentication succeeded, false if failed. */ - uint8_t fail_reason; /* The HCI reason/error code for when success=false */ + tHCI_REASON + fail_reason; /* The HCI reason/error code for when success=false */ tBLE_ADDR_TYPE addr_type; /* Peer device address type */ tBT_DEVICE_TYPE dev_type; } tBTA_DM_AUTH_CMPL; diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc index 8201ab1cecc1fed624c65e1e3ae3ad81adb2ae8e..5f4025196e1779d2d48aeff1f7e9b80403d39985 100644 --- a/system/btif/src/btif_dm.cc +++ b/system/btif/src/btif_dm.cc @@ -2416,7 +2416,9 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { } } else { /*Map the HCI fail reason to bt status */ - switch (p_auth_cmpl->fail_reason) { + // TODO This is not a proper use of the type + uint8_t fail_reason = static_cast<uint8_t>(p_auth_cmpl->fail_reason); + switch (fail_reason) { case BTA_DM_AUTH_SMP_PAIR_AUTH_FAIL: case BTA_DM_AUTH_SMP_CONFIRM_VALUE_FAIL: case BTA_DM_AUTH_SMP_UNKNOWN_ERR: diff --git a/system/main/shim/btm_api.cc b/system/main/shim/btm_api.cc index 36c014a2052ac977ba7a44185e0677e2edbf2bb8..dedc9283ce1c3c0e93a990d5d6dfe666eea970fc 100644 --- a/system/main/shim/btm_api.cc +++ b/system/main/shim/btm_api.cc @@ -456,7 +456,7 @@ class ShimBondListener : public bluetooth::security::ISecurityManagerListener { } if (*bta_callbacks_->p_auth_complete_callback) { (*bta_callbacks_->p_auth_complete_callback)( - bluetooth::ToRawAddress(device.GetAddress()), 0, name, BTM_SUCCESS); + bluetooth::ToRawAddress(device.GetAddress()), 0, name, HCI_SUCCESS); } } MetricIdAllocator::GetInstance().AllocateId( @@ -489,7 +489,7 @@ class ShimBondListener : public bluetooth::security::ISecurityManagerListener { if (bta_callbacks_->p_auth_complete_callback) { (*bta_callbacks_->p_auth_complete_callback)( bluetooth::ToRawAddress(device.GetAddress()), 0, name, - BTM_NOT_AUTHORIZED); + HCI_ERR_AUTH_FAILURE); } } diff --git a/system/stack/include/security_client_callbacks.h b/system/stack/include/security_client_callbacks.h index 7af39e45198b2df0f337e356ddffc484e2dc9074..04c5d2aac2be067f8a696fb36fe4e87f66da2040 100644 --- a/system/stack/include/security_client_callbacks.h +++ b/system/stack/include/security_client_callbacks.h @@ -18,6 +18,7 @@ #include "stack/include/btm_api_types.h" #include "stack/include/btm_ble_api_types.h" +#include "stack/include/hci_error_code.h" /**************************************** * Security Manager Callback Functions @@ -63,7 +64,8 @@ typedef void(tBTM_RMT_NAME_CALLBACK)(const RawAddress& bd_addr, DEV_CLASS dc, */ typedef void(tBTM_AUTH_COMPLETE_CALLBACK)(const RawAddress& bd_addr, DEV_CLASS dev_class, - tBTM_BD_NAME bd_name, int result); + tBTM_BD_NAME bd_name, + tHCI_REASON reason); struct tBTM_APPL_INFO { tBTM_PIN_CALLBACK* p_pin_callback{nullptr};