Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dbda6b2c authored by Hui Peng's avatar Hui Peng Committed by Automerger Merge Worker
Browse files

Merge "[Invisalign2] Clean up logging statemetns in btm_ble_sec.cc" into main am: e7d0e513

parents 2fb194b1 e7d0e513
Loading
Loading
Loading
Loading
+89 −95
Original line number Diff line number Diff line
@@ -15,13 +15,13 @@
 *
 */

#include <cstddef>
#include <optional>
#define LOG_TAG "ble_sec"

#include <base/strings/stringprintf.h>

#include <cstddef>
#include <cstdint>
#include <optional>

#include "btif/include/btif_storage.h"
#include "crypto_toolbox/crypto_toolbox.h"
@@ -126,7 +126,8 @@ void BTM_SecAddBleDevice(const RawAddress& bd_addr, tBT_DEVICE_TYPE dev_type,
 *
 ******************************************************************************/
bool BTM_GetRemoteDeviceName(const RawAddress& bd_addr, BD_NAME bd_name) {
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("bd_addr:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));

  bool ret = FALSE;
  bt_bdname_t bdname;
  bt_property_t prop_name;
@@ -135,7 +136,7 @@ bool BTM_GetRemoteDeviceName(const RawAddress& bd_addr, BD_NAME bd_name) {

  if (btif_storage_get_remote_device_property(&bd_addr, &prop_name) ==
      BT_STATUS_SUCCESS) {
    LOG_VERBOSE("%s, NV name = %s", __func__, bdname.name);
    LOG_VERBOSE("NV name=%s", bdname.name);
    strncpy((char*)bd_name, (char*)bdname.name, BD_NAME_LEN + 1);
    ret = TRUE;
  }
@@ -164,9 +165,8 @@ void BTM_SecAddBleKey(const RawAddress& bd_addr, tBTM_LE_KEY_VALUE* p_le_key,
      (key_type != BTM_LE_KEY_PENC && key_type != BTM_LE_KEY_PID &&
       key_type != BTM_LE_KEY_PCSRK && key_type != BTM_LE_KEY_LENC &&
       key_type != BTM_LE_KEY_LCSRK && key_type != BTM_LE_KEY_LID)) {
    LOG(WARNING) << __func__
                 << " Wrong Type, or No Device record for bdaddr: " << bd_addr
                 << ", Type: " << key_type;
    LOG_WARN("Wrong Type, or No Device record for bdaddr:%s, Type:0%hhu",
             ADDRESS_TO_LOGGABLE_CSTR(bd_addr), key_type);
    return;
  }

@@ -196,7 +196,7 @@ void BTM_SecAddBleKey(const RawAddress& bd_addr, tBTM_LE_KEY_VALUE* p_le_key,
 ******************************************************************************/
void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key) {
  tBTM_SEC_DEVCB* p_devcb = &btm_sec_cb.devcb;
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("type:%d", key_type);
  if (p_key != NULL) {
    switch (key_type) {
      case BTM_BLE_KEY_TYPE_ID:
@@ -209,7 +209,7 @@ void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key) {
        break;

      default:
        LOG_ERROR("unknown local key type: %d", key_type);
        LOG_ERROR("unknown key type:%d", key_type);
        break;
    }
  }
@@ -243,11 +243,12 @@ const Octet16& BTM_GetDeviceDHK() { return btm_sec_cb.devcb.id_keys.dhk; }
void BTM_SecurityGrant(const RawAddress& bd_addr, uint8_t res) {
  const tSMP_STATUS res_smp =
      (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_REPEATED_ATTEMPTS;
  LOG_VERBOSE("bd_addr:%s, res:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
              smp_status_text(res_smp).c_str());
  BTM_LogHistory(kBtmLogTag, bd_addr, "Granted",
                 base::StringPrintf("passkey_status:%s",
                                    smp_status_text(res_smp).c_str()));

  LOG_VERBOSE("BTM_SecurityGrant");
  SMP_SecurityGrant(bd_addr, res_smp);
}

@@ -268,8 +269,9 @@ void BTM_SecurityGrant(const RawAddress& bd_addr, uint8_t res) {
void BTM_BlePasskeyReply(const RawAddress& bd_addr, uint8_t res,
                         uint32_t passkey) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  LOG_VERBOSE("bd_addr:%s, res:%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), res);
  if (p_dev_rec == NULL) {
    LOG_ERROR("Passkey reply to Unknown device");
    LOG_ERROR("Unknown device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return;
  }

@@ -281,7 +283,6 @@ void BTM_BlePasskeyReply(const RawAddress& bd_addr, uint8_t res,
                                    smp_status_text(res_smp).c_str()));

  p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED;
  LOG_VERBOSE("BTM_BlePasskeyReply");
  SMP_PasskeyReply(bd_addr, res_smp, passkey);
}

@@ -299,8 +300,9 @@ void BTM_BlePasskeyReply(const RawAddress& bd_addr, uint8_t res,
 ******************************************************************************/
void BTM_BleConfirmReply(const RawAddress& bd_addr, uint8_t res) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  LOG_VERBOSE("bd_addr:%s, res:%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), res);
  if (p_dev_rec == NULL) {
    LOG_ERROR("Passkey reply to Unknown device");
    LOG_ERROR("Unknown device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return;
  }
  const tSMP_STATUS res_smp =
@@ -313,7 +315,6 @@ void BTM_BleConfirmReply(const RawAddress& bd_addr, uint8_t res) {
                     smp_status_text(res_smp).c_str()));

  p_dev_rec->sec_flags |= BTM_SEC_LE_AUTHENTICATED;
  LOG_VERBOSE("%s", __func__);
  SMP_ConfirmReply(bd_addr, res_smp);
}

@@ -336,7 +337,7 @@ void BTM_BleOobDataReply(const RawAddress& bd_addr, uint8_t res, uint8_t len,
                         uint8_t* p_data) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
    LOG_ERROR("%s: Unknown device", __func__);
    LOG_ERROR("Unknown device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return;
  }

@@ -367,7 +368,7 @@ void BTM_BleSecureConnectionOobDataReply(const RawAddress& bd_addr,
                                         uint8_t* p_c, uint8_t* p_r) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
    LOG_ERROR("%s: Unknown device", __func__);
    LOG_ERROR("Unknown device:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));
    return;
  }

@@ -413,9 +414,8 @@ void BTM_BleSetPrefConnParams(const RawAddress& bd_addr, uint16_t min_conn_int,
                              uint16_t supervision_tout) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);

  LOG_VERBOSE(
      "BTM_BleSetPrefConnParams min: %u  max: %u  latency: %u tout: %u",
      min_conn_int, max_conn_int, peripheral_latency, supervision_tout);
  LOG_VERBOSE("min:%u,max:%u,latency:%u,tout:%u", min_conn_int, max_conn_int,
              peripheral_latency, supervision_tout);

  if (BTM_BLE_ISVALID_PARAM(min_conn_int, BTM_BLE_CONN_INT_MIN,
                            BTM_BLE_CONN_INT_MAX) &&
@@ -488,7 +488,7 @@ void BTM_ReadDevInfo(const RawAddress& remote_bda, tBT_DEVICE_TYPE* p_dev_type,
      *p_addr_type = p_inq_info->results.ble_addr_type;
    } else {
      /* unknown device, assume BR/EDR */
      LOG_VERBOSE("btm_find_dev_type - unknown device, BR/EDR assumed");
      LOG_VERBOSE("unknown device, BR/EDR assumed");
    }
  } else /* there is a security device record existing */
  {
@@ -520,7 +520,7 @@ void BTM_ReadDevInfo(const RawAddress& remote_bda, tBT_DEVICE_TYPE* p_dev_type,
      *p_addr_type = BLE_ADDR_PUBLIC;
    }
  }
  LOG_DEBUG("Determining device_type:%s addr_type:%s",
  LOG_DEBUG("Determined device_type:%s addr_type:%s",
            DeviceTypeText(*p_dev_type).c_str(),
            AddressTypeText(*p_addr_type).c_str());
}
@@ -571,11 +571,12 @@ bool BTM_ReadConnectedTransportAddress(RawAddress* remote_bda,
tBTM_STATUS BTM_SetBleDataLength(const RawAddress& bd_addr,
                                 uint16_t tx_pdu_length) {
  if (!controller_get_interface()->supports_ble_packet_extension()) {
    LOG_INFO("Local controller unable to support le packet extension");
    LOG_INFO("Local controller does not support le packet extension");
    return BTM_ILLEGAL_VALUE;
  }

  LOG_INFO("%s, %d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), tx_pdu_length);
  LOG_INFO("bd_addr:%s, tx_pdu_length:%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
           tx_pdu_length);

  auto p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == NULL) {
@@ -648,7 +649,7 @@ tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator,
  if (is_originator) {
    if ((security_required & BTM_SEC_OUT_FLAGS) == 0 &&
        (security_required & BTM_SEC_OUT_MITM) == 0) {
      LOG_VERBOSE("%s No security required for outgoing connection", __func__);
      LOG_INFO("No security required for outgoing connection");
      return BTM_SEC_OK;
    }

@@ -656,7 +657,7 @@ tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator,
  } else {
    if ((security_required & BTM_SEC_IN_FLAGS) == 0 &&
        (security_required & BTM_SEC_IN_MITM) == 0) {
      LOG_VERBOSE("%s No security required for incoming connection", __func__);
      LOG_VERBOSE("No security required for incoming connection");
      return BTM_SEC_OK;
    }

@@ -666,7 +667,7 @@ tBTM_SEC_ACTION btm_ble_determine_security_act(bool is_originator,
  tBTM_BLE_SEC_REQ_ACT ble_sec_act = {BTM_BLE_SEC_REQ_ACT_NONE};
  btm_ble_link_sec_check(bdaddr, auth_req, &ble_sec_act);

  LOG_VERBOSE("%s ble_sec_act %d", __func__, ble_sec_act);
  LOG_VERBOSE("ble_sec_act %d", ble_sec_act);

  if (ble_sec_act == BTM_BLE_SEC_REQ_ACT_DISCARD) return BTM_SEC_ENC_PENDING;

@@ -829,7 +830,7 @@ void btm_ble_increment_sign_ctr(const RawAddress& bd_addr, bool is_local) {
bool btm_ble_get_enc_key_type(const RawAddress& bd_addr, uint8_t* p_key_types) {
  tBTM_SEC_DEV_REC* p_dev_rec;

  LOG_VERBOSE("btm_ble_get_enc_key_type");
  LOG_VERBOSE("bd_addr:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr));

  p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec != NULL) {
@@ -858,7 +859,7 @@ bool btm_get_local_div(const RawAddress& bd_addr, uint16_t* p_div) {
    status = true;
    *p_div = p_dev_rec->ble_keys.div;
  }
  LOG_VERBOSE("btm_get_local_div status=%d (1-OK) DIV=0x%x", status, *p_div);
  LOG_VERBOSE("status=%d (1-OK) DIV=0x%x", status, *p_div);
  return status;
}

@@ -881,8 +882,8 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type,
  tBTM_SEC_DEV_REC* p_rec;
  tBTM_LE_EVT_DATA cb_data;

  LOG_VERBOSE("btm_sec_save_le_key key_type=0x%x pass_to_application=%d",
              key_type, pass_to_application);
  LOG_VERBOSE("key_type=0x%x pass_to_application=%d", key_type,
              pass_to_application);
  /* Store the updated key in the device database */

  if ((p_rec = btm_find_dev(bd_addr)) != NULL &&
@@ -916,10 +917,9 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type,
            p_keys->pid_key.identity_addr_type;
        p_rec->ble_keys.key_type |= BTM_LE_KEY_PID;
        LOG_VERBOSE(
            "%s: BTM_LE_KEY_PID key_type=0x%x save peer IRK, change bd_addr=%s "
            "BTM_LE_KEY_PID key_type=0x%x save peer IRK, change bd_addr=%s "
            "to id_addr=%s id_addr_type=0x%x",
            __func__, p_rec->ble_keys.key_type,
            ADDRESS_TO_LOGGABLE_CSTR(p_rec->bd_addr),
            p_rec->ble_keys.key_type, ADDRESS_TO_LOGGABLE_CSTR(p_rec->bd_addr),
            ADDRESS_TO_LOGGABLE_CSTR(p_keys->pid_key.identity_addr),
            p_keys->pid_key.identity_addr_type);
        /* update device record address as identity address */
@@ -982,8 +982,8 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type,
        return;
    }

    VLOG(1) << "BLE key type 0x" << loghex(key_type)
            << " updated for BDA: " << bd_addr << " (btm_sec_save_le_key)";
    LOG_VERBOSE("BLE key type 0x%x, updated for BDA:%s", key_type,
                ADDRESS_TO_LOGGABLE_CSTR(bd_addr));

    /* Notify the application that one of the BLE keys has been updated
       If link key is in progress, it will get sent later.*/
@@ -996,9 +996,8 @@ void btm_sec_save_le_key(const RawAddress& bd_addr, tBTM_LE_KEY_TYPE key_type,
    return;
  }

  LOG(WARNING) << "BLE key type 0x" << loghex(key_type)
               << " called for Unknown BDA or type: " << bd_addr
               << "(btm_sec_save_le_key)";
  LOG_WARN("BLE key type 0x%x, called for Unknown BDA or type:%s", key_type,
           ADDRESS_TO_LOGGABLE_CSTR(bd_addr));

  if (p_rec) {
    LOG_VERBOSE("sec_flags=0x%x", p_rec->sec_flags);
@@ -1018,7 +1017,8 @@ void btm_ble_update_sec_key_size(const RawAddress& bd_addr,
                                 uint8_t enc_key_size) {
  tBTM_SEC_DEV_REC* p_rec;

  LOG_VERBOSE("btm_ble_update_sec_key_size enc_key_size = %d", enc_key_size);
  LOG_VERBOSE("bd_addr:%s, enc_key_size=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
              enc_key_size);

  p_rec = btm_find_dev(bd_addr);
  if (p_rec != NULL) {
@@ -1060,10 +1060,11 @@ void btm_ble_link_sec_check(const RawAddress& bd_addr,
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  uint8_t req_sec_level = SMP_SEC_NONE, cur_sec_level = SMP_SEC_NONE;

  LOG_VERBOSE("btm_ble_link_sec_check auth_req =0x%x", auth_req);
  LOG_VERBOSE("bd_addr:%s, auth_req=0x%x", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
              auth_req);

  if (p_dev_rec == NULL) {
    LOG_ERROR("btm_ble_link_sec_check received for unknown device");
    LOG_ERROR("received for unknown device");
    return;
  }

@@ -1131,13 +1132,11 @@ tBTM_STATUS btm_ble_set_encryption(const RawAddress& bd_addr,
  tBTM_LE_AUTH_REQ auth_req;

  if (p_rec == NULL) {
    LOG_WARN("btm_ble_set_encryption (NULL device record!! sec_act=0x%x",
             sec_act);
    LOG_WARN("NULL device record!! sec_act=0x%x", sec_act);
    return (BTM_WRONG_MODE);
  }

  LOG_VERBOSE("btm_ble_set_encryption sec_act=0x%x role_central=%d", sec_act,
              p_rec->role_central);
  LOG_VERBOSE("sec_act=0x%x role_central=%d", sec_act, p_rec->role_central);

  if (sec_act == BTM_BLE_SEC_ENCRYPT_MITM) {
    p_rec->security_required |= BTM_SEC_IN_MITM;
@@ -1161,7 +1160,7 @@ tBTM_STATUS btm_ble_set_encryption(const RawAddress& bd_addr,
      btm_ble_link_sec_check(bd_addr, auth_req, &sec_req_act);
      if (sec_req_act == BTM_BLE_SEC_REQ_ACT_NONE ||
          sec_req_act == BTM_BLE_SEC_REQ_ACT_DISCARD) {
        LOG_VERBOSE("%s, no action needed. Ignore", __func__);
        LOG_VERBOSE("no action needed. Ignore");
        cmd = BTM_SUCCESS;
        break;
      }
@@ -1200,7 +1199,7 @@ void btm_ble_ltk_request(uint16_t handle, uint8_t rand[8], uint16_t ediv) {
  tBTM_SEC_CB* p_cb = &btm_sec_cb;
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev_by_handle(handle);

  LOG_VERBOSE("btm_ble_ltk_request");
  LOG_VERBOSE("handle:0x%x", handle);

  p_cb->ediv = ediv;

@@ -1222,7 +1221,7 @@ tBTM_STATUS btm_ble_start_encrypt(const RawAddress& bda, bool use_stk,
  tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bda);
  BT_OCTET8 dummy_rand = {0};

  LOG_VERBOSE("btm_ble_start_encrypt");
  LOG_VERBOSE("bd_addr:%s, use_stk:%d", ADDRESS_TO_LOGGABLE_CSTR(bda), use_stk);

  if (!p_rec) {
    LOG_ERROR("Link is not active, can not encrypt!");
@@ -1300,14 +1299,14 @@ void btm_ble_link_encrypted(const RawAddress& bd_addr, uint8_t encr_enable) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  bool enc_cback;

  if (!p_dev_rec) {
    LOG_WARN("btm_ble_link_encrypted (No Device Found!) encr_enable=%d",
  LOG_VERBOSE("bd_addr:%s, encr_enable=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
              encr_enable);

  if (!p_dev_rec) {
    LOG_WARN("No Device Found!");
    return;
  }

  LOG_VERBOSE("btm_ble_link_encrypted encr_enable=%d", encr_enable);

  enc_cback = p_dev_rec->is_security_state_le_encrypting();

  smp_link_encrypted(bd_addr, encr_enable);
@@ -1362,12 +1361,13 @@ void btm_ble_ltk_request_reply(const RawAddress& bda, bool use_stk,
  tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bda);
  tBTM_SEC_CB* p_cb = &btm_sec_cb;

  LOG_VERBOSE("bd_addr:%s, use_stk:%d", ADDRESS_TO_LOGGABLE_CSTR(bda), use_stk);

  if (p_rec == NULL) {
    LOG_ERROR("btm_ble_ltk_request_reply received for unknown device");
    LOG_ERROR("unknown device");
    return;
  }

  LOG_VERBOSE("btm_ble_ltk_request_reply");
  p_cb->enc_handle = p_rec->ble_hci_handle;
  p_cb->key_size = p_rec->ble_keys.key_size;

@@ -1413,7 +1413,8 @@ void btm_ble_ltk_request_reply(const RawAddress& bda, bool use_stk,
uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec,
                                    tBTM_LE_IO_REQ* p_data) {
  uint8_t callback_rc = BTM_SUCCESS;
  LOG_VERBOSE("btm_ble_io_capabilities_req");
  LOG_VERBOSE("p_dev_rec->bd_addr:%s",
              ADDRESS_TO_LOGGABLE_CSTR(p_dev_rec->bd_addr));
  if (btm_sec_cb.api.p_le_callback) {
    /* the callback function implementation may change the IO capability... */
    callback_rc = (*btm_sec_cb.api.p_le_callback)(
@@ -1422,13 +1423,9 @@ uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec,
  if ((callback_rc == BTM_SUCCESS) || (BTM_OOB_UNKNOWN != p_data->oob_data)) {
    p_data->auth_req &= BTM_LE_AUTH_REQ_MASK;

    LOG_VERBOSE(
        "btm_ble_io_capabilities_req 1: p_dev_rec->security_required = %d "
        "auth_req:%d",
    LOG_VERBOSE("1:p_dev_rec->security_required=%d, auth_req:%d",
                p_dev_rec->security_required, p_data->auth_req);
    LOG_VERBOSE(
        "btm_ble_io_capabilities_req 2: i_keys=0x%x r_keys=0x%x (bit 0-LTK "
        "1-IRK 2-CSRK)",
    LOG_VERBOSE("2:i_keys=0x%x r_keys=0x%x (bit 0-LTK 1-IRK 2-CSRK)",
                p_data->init_keys, p_data->resp_keys);

    /* if authentication requires MITM protection, put on the mask */
@@ -1441,13 +1438,12 @@ uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec,
      p_data->resp_keys = 0;
    }

    LOG_VERBOSE("btm_ble_io_capabilities_req 3: auth_req:%d", p_data->auth_req);
    LOG_VERBOSE("btm_ble_io_capabilities_req 4: i_keys=0x%x r_keys=0x%x",
                p_data->init_keys, p_data->resp_keys);
    LOG_VERBOSE("3:auth_req:%d", p_data->auth_req);
    LOG_VERBOSE("4:i_keys=0x%x r_keys=0x%x", p_data->init_keys,
                p_data->resp_keys);

    LOG_VERBOSE(
        "btm_ble_io_capabilities_req 5: p_data->io_cap = %d auth_req:%d",
        p_data->io_cap, p_data->auth_req);
    LOG_VERBOSE("5:p_data->io_cap=%d auth_req:%d", p_data->io_cap,
                p_data->auth_req);

    /* remove MITM protection requirement if IO cap does not allow it */
    if ((p_data->io_cap == BTM_IO_CAP_NONE) && p_data->oob_data == SMP_OOB_NONE)
@@ -1458,16 +1454,14 @@ uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec,
      ** and keypress notifications.
      */
      LOG_VERBOSE(
          "%s-SC not supported -> No LK derivation, no keypress notifications",
          __func__);
          "SC not supported -> No LK derivation, no keypress notifications");
      p_data->auth_req &= ~SMP_KP_SUPPORT_BIT;
      p_data->init_keys &= ~SMP_SEC_KEY_TYPE_LK;
      p_data->resp_keys &= ~SMP_SEC_KEY_TYPE_LK;
    }

    LOG_VERBOSE(
        "btm_ble_io_capabilities_req 6: IO_CAP:%d oob_data:%d auth_req:0x%02x",
        p_data->io_cap, p_data->oob_data, p_data->auth_req);
    LOG_VERBOSE("6:IO_CAP:%d oob_data:%d auth_req:0x%02x", p_data->io_cap,
                p_data->oob_data, p_data->auth_req);
  }
  return callback_rc;
}
@@ -1485,7 +1479,8 @@ uint8_t btm_ble_io_capabilities_req(tBTM_SEC_DEV_REC* p_dev_rec,
uint8_t btm_ble_br_keys_req(tBTM_SEC_DEV_REC* p_dev_rec,
                            tBTM_LE_IO_REQ* p_data) {
  uint8_t callback_rc = BTM_SUCCESS;
  LOG_VERBOSE("%s", __func__);
  LOG_VERBOSE("p_dev_rec->bd_addr:%s",
              ADDRESS_TO_LOGGABLE_CSTR(p_dev_rec->bd_addr));
  *p_data = tBTM_LE_IO_REQ{
      .io_cap = BTM_IO_CAP_UNKNOWN,
      .oob_data = false,
@@ -1519,7 +1514,8 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
                       bool can_read_discoverable_characteristics) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda);

  LOG_INFO("Updating device record timestamp for the ble connection");
  LOG_INFO("Update timestamp for ble connection:%s",
           ADDRESS_TO_LOGGABLE_CSTR(bda));
  // TODO() Why is timestamp a counter ?
  p_dev_rec->timestamp = btm_sec_cb.dev_rec_count++;

@@ -1552,7 +1548,7 @@ void btm_ble_connected(const RawAddress& bda, uint16_t handle, uint8_t enc_mode,
 *****************************************************************************/
tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
                               const tSMP_EVT_DATA* p_data) {
  LOG_VERBOSE("btm_proc_smp_cback event = %d", event);
  LOG_VERBOSE("bd_addr:%s, event=%d", ADDRESS_TO_LOGGABLE_CSTR(bd_addr), event);

  if (event == SMP_SC_LOC_OOB_DATA_UP_EVT) {
    btm_sec_cr_loc_oob_data_cback_event(RawAddress{}, p_data->loc_oob_data);
@@ -1585,7 +1581,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
      case SMP_SEC_REQUEST_EVT:
        if (event == SMP_SEC_REQUEST_EVT &&
            btm_sec_cb.pairing_state != BTM_PAIR_STATE_IDLE) {
          LOG_VERBOSE("%s: Ignoring SMP Security request", __func__);
          LOG_VERBOSE("Ignoring SMP Security request");
          break;
        }
        btm_sec_cb.pairing_bda = bd_addr;
@@ -1608,7 +1604,7 @@ tBTM_STATUS btm_proc_smp_cback(tSMP_EVT event, const RawAddress& bd_addr,
        if (event == SMP_COMPLT_EVT) {
          p_dev_rec = btm_find_dev(bd_addr);
          if (p_dev_rec == NULL) {
            LOG_ERROR("%s: p_dev_rec is NULL", __func__);
            LOG_ERROR("p_dev_rec is NULL");
            return BTM_SUCCESS;
          }
          LOG_VERBOSE(
@@ -1725,9 +1721,8 @@ bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text,
                          uint16_t len, BLE_SIGNATURE signature) {
  tBTM_SEC_DEV_REC* p_rec = btm_find_dev(bd_addr);

  LOG_VERBOSE("%s", __func__);
  if (p_rec == NULL) {
    LOG_ERROR("%s-data signing can not be done from unknown device", __func__);
    LOG_ERROR("data signing can not be done from unknown device");
    return false;
  }

@@ -1735,7 +1730,6 @@ bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text,
  uint8_t* pp;
  uint8_t* p_buf = (uint8_t*)osi_malloc(len + 4);

  LOG_VERBOSE("%s-Start to generate Local CSRK", __func__);
  pp = p_buf;
  /* prepare plain text */
  if (p_text) {
@@ -1750,7 +1744,7 @@ bool BTM_BleDataSignature(const RawAddress& bd_addr, uint8_t* p_text,
                           BTM_CMAC_TLEN_SIZE, p_mac);
  btm_ble_increment_sign_ctr(bd_addr, true);

  LOG_VERBOSE("%s p_mac = %p", __func__, p_mac);
  LOG_VERBOSE("p_mac = %p", p_mac);
  LOG_VERBOSE(
      "p_mac[0]=0x%02x p_mac[1]=0x%02x p_mac[2]=0x%02x p_mac[3]="
      "0x%02x",
@@ -1792,7 +1786,7 @@ bool BTM_BleVerifySignature(const RawAddress& bd_addr, uint8_t* p_orig,
  } else if (p_orig == NULL) {
    LOG_ERROR("No signature to verify");
  } else {
    LOG_VERBOSE("%s rcv_cnt=%d >= expected_cnt=%d", __func__, counter,
    LOG_VERBOSE("rcv_cnt=%d >= expected_cnt=%d", counter,
                p_rec->ble_keys.counter);

    crypto_toolbox::aes_cmac(p_rec->ble_keys.pcsrk, p_orig, len,
@@ -1821,7 +1815,8 @@ void BTM_BleSirkConfirmDeviceReply(const RawAddress& bd_addr, uint8_t res) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  tSMP_STATUS res_smp = (res == BTM_SUCCESS) ? SMP_SUCCESS : SMP_FAIL;

  LOG_INFO("Confirmation result: %s", smp_status_text(res_smp).c_str());
  LOG_INFO("bd_addr:%s, result:%s", ADDRESS_TO_LOGGABLE_CSTR(bd_addr),
           smp_status_text(res_smp).c_str());

  if (p_dev_rec == NULL) {
    LOG_ERROR("Confirmation of Unknown device");
@@ -1831,7 +1826,6 @@ void BTM_BleSirkConfirmDeviceReply(const RawAddress& bd_addr, uint8_t res) {
  BTM_LogHistory(
      kBtmLogTag, bd_addr, "SIRK confirmation",
      base::StringPrintf("status:%s", smp_status_text(res_smp).c_str()));
  LOG_DEBUG("");
  SMP_SirkConfirmDeviceReply(bd_addr, res_smp);
}

@@ -1842,7 +1836,7 @@ void BTM_BleSirkConfirmDeviceReply(const RawAddress& bd_addr, uint8_t res) {
static void btm_notify_new_key(uint8_t key_type) {
  tBTM_BLE_LOCAL_KEYS* p_local_keys = NULL;

  LOG_VERBOSE("btm_notify_new_key key_type=%d", key_type);
  LOG_VERBOSE("key_type=%d", key_type);

  if (btm_sec_cb.api.p_le_key_callback) {
    switch (key_type) {