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

Commit 2bb67e61 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/bta/hf_client: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: I60696496f49ff93f74bec4dcd1dee9717a844327
parent 9eacd34b
Loading
Loading
Loading
Loading
+22 −30
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@
 *
 ******************************************************************************/

#include <bluetooth/log.h>

#include "bta/hf_client/bta_hf_client_int.h"
#include "bta/include/bta_dm_api.h"
#include "os/log.h"
@@ -31,6 +33,8 @@
#include "stack/include/sdp_status.h"
#include "types/raw_address.h"

using namespace bluetooth;

/*****************************************************************************
 *  Constants
 ****************************************************************************/
@@ -52,8 +56,7 @@ void bta_hf_client_start_close(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: wrong handle to control block %d", __func__,
              p_data->hdr.layer_specific);
    log::error("wrong handle to control block {}", p_data->hdr.layer_specific);
    return;
  }

@@ -86,8 +89,7 @@ void bta_hf_client_start_open(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: wrong handle to control block %d", __func__,
              p_data->hdr.layer_specific);
    log::error("wrong handle to control block {}", p_data->hdr.layer_specific);
    return;
  }

@@ -125,12 +127,11 @@ void bta_hf_client_start_open(tBTA_HF_CLIENT_DATA* p_data) {
 *
 ******************************************************************************/
void bta_hf_client_rfc_open(tBTA_HF_CLIENT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -151,25 +152,24 @@ void bta_hf_client_rfc_open(tBTA_HF_CLIENT_DATA* p_data) {
 *
 ******************************************************************************/
void bta_hf_client_rfc_acp_open(tBTA_HF_CLIENT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }
  /* set role */
  client_cb->role = BTA_HF_CLIENT_ACP;

  LOG_VERBOSE("%s: conn_handle %d", __func__, client_cb->conn_handle);
  log::verbose("conn_handle {}", client_cb->conn_handle);

  /* get bd addr of peer */
  uint16_t lcid = 0;
  RawAddress dev_addr = RawAddress::kEmpty;
  int status = PORT_CheckConnection(client_cb->conn_handle, &dev_addr, &lcid);
  if (status != PORT_SUCCESS) {
    LOG_ERROR("PORT_CheckConnection returned status:%d", status);
    log::error("PORT_CheckConnection returned status:{}", status);
  }

  /* Collision Handling */
@@ -209,8 +209,7 @@ void bta_hf_client_rfc_fail(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -239,8 +238,7 @@ void bta_hf_client_disc_fail(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }
}
@@ -259,8 +257,7 @@ void bta_hf_client_open_fail(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }
}
@@ -279,8 +276,7 @@ void bta_hf_client_rfc_close(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -322,12 +318,11 @@ void bta_hf_client_rfc_close(tBTA_HF_CLIENT_DATA* p_data) {
void bta_hf_client_disc_int_res(tBTA_HF_CLIENT_DATA* p_data) {
  uint16_t event = BTA_HF_CLIENT_DISC_FAIL_EVT;

  LOG_VERBOSE("%s: Status: %d", __func__, p_data->disc_result.status);
  log::verbose("Status: {}", p_data->disc_result.status);
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -361,8 +356,7 @@ void bta_hf_client_disc_acp_res(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -391,8 +385,7 @@ void bta_hf_client_rfc_data(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -427,12 +420,11 @@ void bta_hf_client_rfc_data(tBTA_HF_CLIENT_DATA* p_data) {
 *
 ******************************************************************************/
void bta_hf_client_svc_conn_open(tBTA_HF_CLIENT_DATA* p_data) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

+5 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "bta/include/bta_hf_client_api.h"

#include <android_bluetooth_sysprop.h>
#include <bluetooth/log.h>

#include <cstdint>

@@ -38,6 +39,8 @@
#include "stack/include/bt_hdr.h"
#include "types/raw_address.h"

using namespace bluetooth;

/*****************************************************************************
 *  External Function Declarations
 ****************************************************************************/
@@ -85,12 +88,12 @@ void BTA_HfClientDisable(void) { bta_hf_client_api_disable(); }
 *
 ******************************************************************************/
bt_status_t BTA_HfClientOpen(const RawAddress& bd_addr, uint16_t* p_handle) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");
  tBTA_HF_CLIENT_API_OPEN* p_buf =
      (tBTA_HF_CLIENT_API_OPEN*)osi_malloc(sizeof(tBTA_HF_CLIENT_API_OPEN));

  if (!bta_hf_client_allocate_handle(bd_addr, p_handle)) {
    LOG_ERROR("%s: could not allocate handle", __func__);
    log::error("could not allocate handle");
    return BT_STATUS_FAIL;
  }

+114 −115

File changed.

Preview size limit exceeded, changes collapsed.

+48 −49
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
 ******************************************************************************/

#include <base/logging.h>
#include <bluetooth/log.h>

#include <cstdint>
#include <cstdio>
@@ -33,6 +34,7 @@
#include "types/raw_address.h"

using namespace bluetooth::legacy::stack::sdp;
using namespace bluetooth;

static const char* bta_hf_client_evt_str(uint16_t event);
static const char* bta_hf_client_state_str(uint8_t state);
@@ -300,7 +302,7 @@ void bta_hf_client_cb_arr_init() {
 *
 ******************************************************************************/
void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  // Free any memory we need to explicity release
  alarm_free(client_cb->collision_timer);
@@ -330,7 +332,7 @@ void bta_hf_client_cb_init(tBTA_HF_CLIENT_CB* client_cb, uint16_t handle) {
 *
 ******************************************************************************/
void bta_hf_client_resume_open(tBTA_HF_CLIENT_CB* client_cb) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");

  /* resume opening process.  */
  if (client_cb->state == BTA_HF_CLIENT_INIT_ST) {
@@ -353,7 +355,7 @@ void bta_hf_client_resume_open(tBTA_HF_CLIENT_CB* client_cb) {
 *
 ******************************************************************************/
static void bta_hf_client_collision_timer_cback(void* data) {
  LOG_VERBOSE("%s", __func__);
  log::verbose("");
  tBTA_HF_CLIENT_CB* client_cb = (tBTA_HF_CLIENT_CB*)data;

  /* If the peer haven't opened connection, restart opening process */
@@ -377,12 +379,12 @@ void bta_hf_client_collision_cback(UNUSED_ATTR tBTA_SYS_CONN_STATUS status,
  if (client_cb != NULL && client_cb->state == BTA_HF_CLIENT_OPENING_ST) {
    if (id == BTA_ID_SYS) /* ACL collision */
    {
      LOG_WARN("HF Client found collision (ACL) ...");
      log::warn("HF Client found collision (ACL) ...");
    } else if (id == BTA_ID_HS) /* RFCOMM collision */
    {
      LOG_WARN("HF Client found collision (RFCOMM) ...");
      log::warn("HF Client found collision (RFCOMM) ...");
    } else {
      LOG_WARN("HF Client found collision (\?\?\?) ...");
      log::warn("HF Client found collision (\?\?\?) ...");
    }

    client_cb->state = BTA_HF_CLIENT_INIT_ST;
@@ -420,7 +422,7 @@ tBTA_STATUS bta_hf_client_api_enable(tBTA_HF_CLIENT_CBACK* p_cback,
                                     const char* p_service_name) {
  /* If already registered then return error */
  if (bta_sys_is_register(BTA_ID_HS)) {
    LOG_ERROR("BTA HF Client is already enabled, ignoring ...");
    log::error("BTA HF Client is already enabled, ignoring ...");
    return BTA_FAILURE;
  }

@@ -472,8 +474,8 @@ tBTA_STATUS bta_hf_client_api_enable(tBTA_HF_CLIENT_CBACK* p_cback,
tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_handle(uint16_t handle) {
  // Handles are limited from 1 through HF_CLIENT_MAX_DEVICES
  if (handle < 1 || handle > HF_CLIENT_MAX_DEVICES) {
    LOG_ERROR("%s: handle out of range (%d, %d) %d", __func__, 1,
              HF_CLIENT_MAX_DEVICES, handle);
    log::error("handle out of range ({}, {}) {}", 1, HF_CLIENT_MAX_DEVICES,
               handle);
    return NULL;
  }

@@ -481,7 +483,7 @@ tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_handle(uint16_t handle) {
  if (bta_hf_client_cb_arr.cb[handle - 1].is_allocated)
    return &(bta_hf_client_cb_arr.cb[handle - 1]);

  LOG_ERROR("%s: block not found for handle %d", __func__, handle);
  log::error("block not found for handle {}", handle);
  return NULL;
}

@@ -506,11 +508,11 @@ tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_bda(const RawAddress& peer_addr) {
    if (client_cb->is_allocated && peer_addr == client_cb->peer_addr) {
      return client_cb;
    } else {
      LOG_WARN("%s: bdaddr mismatch for handle %d alloc %d", __func__, i,
      log::warn("bdaddr mismatch for handle {} alloc {}", i,
                client_cb->is_allocated);
    }
  }
  LOG_ERROR("%s: block not found", __func__);
  log::error("block not found");
  return NULL;
}

@@ -533,18 +535,18 @@ tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_rfc_handle(uint16_t handle) {
    bool is_allocated = client_cb->is_allocated;
    uint16_t conn_handle = client_cb->conn_handle;

    LOG_VERBOSE("%s: cb rfc_handle %d alloc %d conn_handle %d", __func__,
                handle, is_allocated, conn_handle);
    log::verbose("cb rfc_handle {} alloc {} conn_handle {}", handle,
                 is_allocated, conn_handle);

    if (is_allocated && conn_handle == handle) {
      return client_cb;
    }

    LOG_WARN("%s: no cb yet %d alloc %d conn_handle %d", __func__, handle,
             is_allocated, conn_handle);
    log::warn("no cb yet {} alloc {} conn_handle {}", handle, is_allocated,
              conn_handle);
  }

  LOG_ERROR("%s: no cb found for rfc handle %d", __func__, handle);
  log::error("no cb found for rfc handle {}", handle);
  return NULL;
}

@@ -568,7 +570,7 @@ tBTA_HF_CLIENT_CB* bta_hf_client_find_cb_by_sco_handle(uint16_t handle) {
      return client_cb;
    }
  }
  LOG_ERROR("%s: block not found for handle %d", __func__, handle);
  log::error("block not found for handle {}", handle);
  return NULL;
}

@@ -593,8 +595,7 @@ bool bta_hf_client_allocate_handle(const RawAddress& bd_addr,
                                   uint16_t* p_handle) {
  tBTA_HF_CLIENT_CB* existing_cb = bta_hf_client_find_cb_by_bda(bd_addr);
  if (existing_cb != NULL) {
    LOG_ERROR("%s: cannot allocate handle since BDADDR already exists",
              __func__);
    log::error("cannot allocate handle since BDADDR already exists");
    return false;
  }
  /* Check that we do not have a request to for same device in the control
@@ -602,7 +603,7 @@ bool bta_hf_client_allocate_handle(const RawAddress& bd_addr,
  for (int i = 0; i < HF_CLIENT_MAX_DEVICES; i++) {
    tBTA_HF_CLIENT_CB* client_cb = &bta_hf_client_cb_arr.cb[i];
    if (client_cb->is_allocated) {
      LOG_WARN("%s: control block already used index %d", __func__, i);
      log::warn("control block already used index {}", i);
      continue;
    }

@@ -610,8 +611,7 @@ bool bta_hf_client_allocate_handle(const RawAddress& bd_addr,
    bta_hf_client_cb_init(client_cb, client_cb->handle);

    *p_handle = client_cb->handle;
    LOG_VERBOSE("%s: marking CB handle %d to true", __func__,
                client_cb->handle);
    log::verbose("marking CB handle {} to true", client_cb->handle);

    client_cb->is_allocated = true;
    client_cb->peer_addr = bd_addr;
@@ -620,7 +620,7 @@ bool bta_hf_client_allocate_handle(const RawAddress& bd_addr,
  }

  return false;
  LOG_ERROR("%s: all control blocks in use!", __func__);
  log::error("all control blocks in use!");
}

/*******************************************************************************
@@ -651,7 +651,7 @@ void bta_hf_client_app_callback(uint16_t event, tBTA_HF_CLIENT* data) {
 ******************************************************************************/
void bta_hf_client_api_disable() {
  if (!bta_sys_is_register(BTA_ID_HS)) {
    LOG_WARN("BTA HF Client is already disabled, ignoring ...");
    log::warn("BTA HF Client is already disabled, ignoring ...");
    return;
  }

@@ -688,7 +688,7 @@ void bta_hf_client_api_disable() {
 *
 ******************************************************************************/
bool bta_hf_client_hdl_event(const BT_HDR_RIGID* p_msg) {
  LOG_VERBOSE("%s: %s (0x%x)", __func__, bta_hf_client_evt_str(p_msg->event),
  log::verbose("{} (0x{:x})", bta_hf_client_evt_str(p_msg->event),
               p_msg->event);
  bta_hf_client_sm_execute(p_msg->event, (tBTA_HF_CLIENT_DATA*)p_msg);
  return true;
@@ -708,8 +708,7 @@ void bta_hf_client_sm_execute(uint16_t event, tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -723,14 +722,14 @@ void bta_hf_client_sm_execute(uint16_t event, tBTA_HF_CLIENT_DATA* p_data) {
  /* Ignore displaying of AT results when not connected (Ignored in state
   * machine) */
  if (client_cb->state == BTA_HF_CLIENT_OPEN_ST) {
    LOG_VERBOSE("HF Client evt : State %d (%s), Event 0x%04x (%s)",
    log::verbose("HF Client evt : State {} ({}), Event 0x{:04x} ({})",
                 client_cb->state, bta_hf_client_state_str(client_cb->state),
                 event, bta_hf_client_evt_str(event));
  }

  event &= 0x00FF;
  if (event >= (BTA_HF_CLIENT_MAX_EVT & 0x00FF)) {
    LOG_ERROR("HF Client evt out of range, ignoring...");
    log::error("HF Client evt out of range, ignoring...");
    return;
  }

@@ -752,15 +751,15 @@ void bta_hf_client_sm_execute(uint16_t event, tBTA_HF_CLIENT_DATA* p_data) {

  /* If the state has changed then notify the app of the corresponding change */
  if (in_state != client_cb->state) {
    VLOG(1) << __func__ << ": notifying state change to " << in_state << " -> "
            << client_cb->state << " device " << client_cb->peer_addr;
    log::verbose("notifying state change to {} -> {} device {}", in_state,
                 client_cb->state,
                 ADDRESS_TO_LOGGABLE_STR(client_cb->peer_addr));
    tBTA_HF_CLIENT evt;
    memset(&evt, 0, sizeof(evt));
    evt.bd_addr = client_cb->peer_addr;
    if (client_cb->state == BTA_HF_CLIENT_INIT_ST) {
      bta_hf_client_app_callback(BTA_HF_CLIENT_CLOSE_EVT, &evt);
      LOG_VERBOSE("%s: marking CB handle %d to false", __func__,
                  client_cb->handle);
      log::verbose("marking CB handle {} to false", client_cb->handle);
      client_cb->is_allocated = false;
    } else if (client_cb->state == BTA_HF_CLIENT_OPEN_ST) {
      evt.open.handle = client_cb->handle;
@@ -768,10 +767,11 @@ void bta_hf_client_sm_execute(uint16_t event, tBTA_HF_CLIENT_DATA* p_data) {
    }
  }

  VLOG(2) << __func__ << ": device " << client_cb->peer_addr
          << "state change: [" << bta_hf_client_state_str(in_state) << "] -> ["
          << bta_hf_client_state_str(client_cb->state) << "] after Event ["
          << bta_hf_client_evt_str(in_event) << "]";
  log::verbose("device {} state change: [{}] -> [{}] after Event [{}]",
               ADDRESS_TO_LOGGABLE_STR(client_cb->peer_addr),
               bta_hf_client_state_str(in_state),
               bta_hf_client_state_str(client_cb->state),
               bta_hf_client_evt_str(in_event));
}

static void send_post_slc_cmd(tBTA_HF_CLIENT_CB* client_cb) {
@@ -799,12 +799,12 @@ static void send_post_slc_cmd(tBTA_HF_CLIENT_CB* client_cb) {
 *
 ******************************************************************************/
void bta_hf_client_slc_seq(tBTA_HF_CLIENT_CB* client_cb, bool error) {
  LOG_VERBOSE("bta_hf_client_slc_seq cmd: %u", client_cb->at_cb.current_cmd);
  log::verbose("bta_hf_client_slc_seq cmd: {}", client_cb->at_cb.current_cmd);

  if (error) {
    /* SLC establishment error, sent close rfcomm event */
    LOG_ERROR(
        "HFPClient: Failed to create SLC due to AT error, disconnecting (%u)",
    log::error(
        "HFPClient: Failed to create SLC due to AT error, disconnecting ({})",
        client_cb->at_cb.current_cmd);

    tBTA_HF_CLIENT_DATA msg;
@@ -814,8 +814,7 @@ void bta_hf_client_slc_seq(tBTA_HF_CLIENT_CB* client_cb, bool error) {
  }

  if (client_cb->svc_conn) {
    LOG_WARN("%s: SLC already connected for CB handle %d", __func__,
             client_cb->handle);
    log::warn("SLC already connected for CB handle {}", client_cb->handle);
    return;
  }

@@ -890,9 +889,9 @@ void bta_hf_client_slc_seq(tBTA_HF_CLIENT_CB* client_cb, bool error) {

    default: {
      /* If happen there is a bug in SLC creation procedure... */
      LOG_ERROR(
      log::error(
          "HFPClient: Failed to create SLCdue to unexpected AT command, "
          "disconnecting (%u)",
          "disconnecting ({})",
          client_cb->at_cb.current_cmd);

      tBTA_HF_CLIENT_DATA msg;
+23 −25
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@
 ******************************************************************************/

#include <base/logging.h>
#include <bluetooth/log.h>

#include <cstdint>

@@ -38,6 +39,7 @@
#include "types/raw_address.h"

using namespace bluetooth::legacy::stack::sdp;
using namespace bluetooth;

/*******************************************************************************
 *
@@ -56,7 +58,7 @@ static void bta_hf_client_port_cback(UNUSED_ATTR uint32_t code,
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_rfc_handle(port_handle);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__, port_handle);
    log::error("cb not found for handle {}", port_handle);
    return;
  }

@@ -81,13 +83,13 @@ static void bta_hf_client_mgmt_cback(uint32_t code, uint16_t port_handle) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_rfc_handle(port_handle);

  LOG_VERBOSE("%s: code = %d, port_handle = %d serv = %d", __func__, code,
              port_handle, bta_hf_client_cb_arr.serv_handle);
  log::verbose("code = {}, port_handle = {} serv = {}", code, port_handle,
               bta_hf_client_cb_arr.serv_handle);

  /* ignore close event for port handles other than connected handle */
  if (code != PORT_SUCCESS && client_cb != NULL &&
      port_handle != client_cb->conn_handle) {
    LOG_VERBOSE("bta_hf_client_mgmt_cback ignoring handle:%d", port_handle);
    log::verbose("bta_hf_client_mgmt_cback ignoring handle:{}", port_handle);
    return;
  }

@@ -100,13 +102,13 @@ static void bta_hf_client_mgmt_cback(uint32_t code, uint16_t port_handle) {
    } else if (port_handle == bta_hf_client_cb_arr.serv_handle) {
      p_buf->hdr.event = BTA_HF_CLIENT_RFC_OPEN_EVT;

      LOG_VERBOSE("%s: allocating a new CB for incoming connection", __func__);
      log::verbose("allocating a new CB for incoming connection");
      // Find the BDADDR of the peer device
      RawAddress peer_addr = RawAddress::kEmpty;
      uint16_t lcid = 0;
      int status = PORT_CheckConnection(port_handle, &peer_addr, &lcid);
      if (status != PORT_SUCCESS) {
        LOG(ERROR) << __func__ << ": PORT_CheckConnection returned " << status;
        log::error("PORT_CheckConnection returned {}", status);
      }

      // Since we accepted a remote request we should allocate a handle first.
@@ -116,7 +118,7 @@ static void bta_hf_client_mgmt_cback(uint32_t code, uint16_t port_handle) {

      // If allocation fails then we abort.
      if (client_cb == NULL) {
        LOG_ERROR("%s: error allocating a new handle", __func__);
        log::error("error allocating a new handle");
        p_buf->hdr.event = BTA_HF_CLIENT_RFC_CLOSE_EVT;
        RFCOMM_RemoveConnection(port_handle);
      } else {
@@ -130,15 +132,14 @@ static void bta_hf_client_mgmt_cback(uint32_t code, uint16_t port_handle) {
        bta_hf_client_start_server();
      }
    } else {
      LOG_ERROR("%s: PORT_SUCCESS, ignoring handle = %d", __func__,
                port_handle);
      log::error("PORT_SUCCESS, ignoring handle = {}", port_handle);
      osi_free(p_buf);
      return;
    }
  } else if (client_cb != NULL &&
             port_handle == client_cb->conn_handle) { /* code != PORT_SUC */
    LOG(ERROR) << __func__ << ": closing port handle " << port_handle << "dev "
               << client_cb->peer_addr;
    log::error("closing port handle {} dev {}", port_handle,
               ADDRESS_TO_LOGGABLE_STR(client_cb->peer_addr));

    RFCOMM_RemoveServer(port_handle);
    p_buf->hdr.event = BTA_HF_CLIENT_RFC_CLOSE_EVT;
@@ -181,7 +182,7 @@ void bta_hf_client_start_server() {
  int port_status;

  if (bta_hf_client_cb_arr.serv_handle > 0) {
    LOG_VERBOSE("%s: already started, handle: %d", __func__,
    log::verbose("already started, handle: {}",
                 bta_hf_client_cb_arr.serv_handle);
    return;
  }
@@ -191,14 +192,13 @@ void bta_hf_client_start_server() {
      BTA_HF_CLIENT_MTU, RawAddress::kAny, &(bta_hf_client_cb_arr.serv_handle),
      bta_hf_client_mgmt_cback, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);

  LOG_VERBOSE("%s: started rfcomm server with handle %d", __func__,
  log::verbose("started rfcomm server with handle {}",
               bta_hf_client_cb_arr.serv_handle);

  if (port_status == PORT_SUCCESS) {
    bta_hf_client_setup_port(bta_hf_client_cb_arr.serv_handle);
  } else {
    LOG_VERBOSE("%s: RFCOMM_CreateConnection returned error:%d", __func__,
                port_status);
    log::verbose("RFCOMM_CreateConnection returned error:{}", port_status);
  }
}

@@ -213,10 +213,10 @@ void bta_hf_client_start_server() {
 *
 ******************************************************************************/
void bta_hf_client_close_server() {
  LOG_VERBOSE("%s: %d", __func__, bta_hf_client_cb_arr.serv_handle);
  log::verbose("{}", bta_hf_client_cb_arr.serv_handle);

  if (bta_hf_client_cb_arr.serv_handle == 0) {
    LOG_VERBOSE("%s: already stopped", __func__);
    log::verbose("already stopped");
    return;
  }

@@ -238,8 +238,7 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

@@ -249,7 +248,7 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) {
          bta_hf_client_mgmt_cback,
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT) == PORT_SUCCESS) {
    bta_hf_client_setup_port(client_cb->conn_handle);
    LOG_VERBOSE("bta_hf_client_rfc_do_open : conn_handle = %d",
    log::verbose("bta_hf_client_rfc_do_open : conn_handle = {}",
                 client_cb->conn_handle);
  }
  /* RFCOMM create connection failed; send ourselves RFCOMM close event */
@@ -272,8 +271,7 @@ void bta_hf_client_rfc_do_close(tBTA_HF_CLIENT_DATA* p_data) {
  tBTA_HF_CLIENT_CB* client_cb =
      bta_hf_client_find_cb_by_handle(p_data->hdr.layer_specific);
  if (client_cb == NULL) {
    LOG_ERROR("%s: cb not found for handle %d", __func__,
              p_data->hdr.layer_specific);
    log::error("cb not found for handle {}", p_data->hdr.layer_specific);
    return;
  }

Loading