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

Commit 67820499 authored by Henri Chataing's avatar Henri Chataing
Browse files

system/stack/bnep: Migrate to libbluetooth_log

Test: m com.android.btservices
Bug: 305066880
Flag: EXEMPT, mechanical refactor
Change-Id: Ifa083a24ea6f6a460f997d231c77a40fffe93bbd
parent 1c560c4a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -339,6 +339,7 @@ cc_defaults {
        "libchrome",
    ],
    shared_libs: [
        "libbase",
        "liblog",
    ],
    target: {
+10 −10
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

#include "bnep_api.h"

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

#include "bnep_int.h"
@@ -37,6 +37,7 @@
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

using namespace bluetooth;
using bluetooth::Uuid;

/*******************************************************************************
@@ -136,7 +137,7 @@ tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid,
  uint16_t cid;
  tBNEP_CONN* p_bcb = bnepu_find_bcb_by_bd_addr(p_rem_bda);

  VLOG(0) << __func__ << " BDA:" << p_rem_bda;
  log::verbose("BDA:{}", ADDRESS_TO_LOGGABLE_STR(p_rem_bda));

  if (!bnep_cb.profile_registered) return BNEP_WRONG_STATE;

@@ -162,7 +163,7 @@ tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid,
     */
    p_bcb->con_state = BNEP_STATE_SEC_CHECKING;

    LOG_VERBOSE("BNEP initiating security procedures for src uuid %s",
    log::verbose("BNEP initiating security procedures for src uuid {}",
                 p_bcb->src_uuid.ToString().c_str());

    bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb);
@@ -177,7 +178,7 @@ tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid,
      p_bcb->l2cap_cid = cid;

    } else {
      LOG_ERROR("BNEP - Originate failed");
      log::error("BNEP - Originate failed");
      if (bnep_cb.p_conn_state_cb)
        (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda,
                                   BNEP_CONN_FAILED, false);
@@ -221,7 +222,7 @@ tBNEP_RESULT BNEP_ConnectResp(uint16_t handle, tBNEP_RESULT resp) {
      (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)))
    return (BNEP_WRONG_STATE);

  LOG_DEBUG("handle %d, responce %d", handle, resp);
  log::debug("handle {}, responce {}", handle, resp);

  /* Form appropriate responce based on profile responce */
  if (resp == BNEP_CONN_FAILED_SRC_UUID)
@@ -294,7 +295,7 @@ tBNEP_RESULT BNEP_Disconnect(uint16_t handle) {

  if (p_bcb->con_state == BNEP_STATE_IDLE) return (BNEP_WRONG_HANDLE);

  LOG_VERBOSE("BNEP_Disconnect()  for handle %d", handle);
  log::verbose("BNEP_Disconnect()  for handle {}", handle);

  L2CA_DisconnectReq(p_bcb->l2cap_cid);

@@ -340,8 +341,7 @@ tBNEP_RESULT BNEP_WriteBuf(uint16_t handle, const RawAddress& dest_addr,
  p_bcb = &(bnep_cb.bcb[handle - 1]);
  /* Check MTU size */
  if (p_buf->len > BNEP_MTU_SIZE) {
    LOG_ERROR("%s length %d exceeded MTU %d", __func__, p_buf->len,
              BNEP_MTU_SIZE);
    log::error("length {} exceeded MTU {}", p_buf->len, BNEP_MTU_SIZE);
    osi_free(p_buf);
    return (BNEP_MTU_EXCEDED);
  }
@@ -445,7 +445,7 @@ tBNEP_RESULT BNEP_Write(uint16_t handle, const RawAddress& dest_addr,

  /* Check MTU size. Consider the possibility of having extension headers */
  if (len > BNEP_MTU_SIZE) {
    LOG_ERROR("%s length %d exceeded MTU %d", __func__, len, BNEP_MTU_SIZE);
    log::error("length {} exceeded MTU {}", len, BNEP_MTU_SIZE);
    return (BNEP_MTU_EXCEDED);
  }

+30 −26
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@

#define LOG_TAG "bluetooth"

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

#include "bnep_api.h"
@@ -42,6 +42,8 @@
#include "stack/include/bt_types.h"
#include "types/raw_address.h"

using namespace bluetooth;

/******************************************************************************/
/*                     G L O B A L    B N E P       D A T A                   */
/******************************************************************************/
@@ -90,7 +92,7 @@ tBNEP_RESULT bnep_register_with_l2cap(void) {
  if (!L2CA_Register2(BT_PSM_BNEP, bnep_cb.reg_info, false /* enable_snoop */,
                      nullptr, BNEP_MTU_SIZE, BNEP_MTU_SIZE,
                      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
    LOG_ERROR("BNEP - Registration failed");
    log::error("BNEP - Registration failed");
    return BNEP_SECURITY_FAIL;
  }

@@ -130,7 +132,7 @@ static void bnep_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid,
  alarm_set_on_mloop(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
                     bnep_conn_timer_timeout, p_bcb);

  LOG_DEBUG("BNEP - Rcvd L2CAP conn ind, CID: 0x%x", p_bcb->l2cap_cid);
  log::debug("BNEP - Rcvd L2CAP conn ind, CID: 0x{:x}", p_bcb->l2cap_cid);
}

static void bnep_on_l2cap_error(uint16_t l2cap_cid, uint16_t result) {
@@ -165,7 +167,7 @@ static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result) {
  /* Find CCB based on CID */
  p_bcb = bnepu_find_bcb_by_cid(l2cap_cid);
  if (p_bcb == NULL) {
    LOG_WARN("BNEP - Rcvd conn cnf for unknown CID 0x%x", l2cap_cid);
    log::warn("BNEP - Rcvd conn cnf for unknown CID 0x{:x}", l2cap_cid);
    return;
  }

@@ -179,9 +181,10 @@ static void bnep_connect_cfm(uint16_t l2cap_cid, uint16_t result) {
    alarm_set_on_mloop(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS,
                       bnep_conn_timer_timeout, p_bcb);

    LOG_DEBUG("BNEP - got conn cnf, sent cfg req, CID: 0x%x", p_bcb->l2cap_cid);
    log::debug("BNEP - got conn cnf, sent cfg req, CID: 0x{:x}",
               p_bcb->l2cap_cid);
  } else {
    LOG(ERROR) << __func__ << ": invoked with non OK status";
    log::error("invoked with non OK status");
  }
}

@@ -199,12 +202,12 @@ static void bnep_config_cfm(uint16_t l2cap_cid, uint16_t initiator,
                            tL2CAP_CFG_INFO* p_cfg) {
  tBNEP_CONN* p_bcb;

  LOG_DEBUG("BNEP - Rcvd cfg cfm, CID: 0x%x", l2cap_cid);
  log::debug("BNEP - Rcvd cfg cfm, CID: 0x{:x}", l2cap_cid);

  /* Find CCB based on CID */
  p_bcb = bnepu_find_bcb_by_cid(l2cap_cid);
  if (p_bcb == NULL) {
    LOG_WARN("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x%x", l2cap_cid);
    log::warn("BNEP - Rcvd L2CAP cfg ind, unknown CID: 0x{:x}", l2cap_cid);
    return;
  }

@@ -236,11 +239,11 @@ static void bnep_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
  /* Find CCB based on CID */
  p_bcb = bnepu_find_bcb_by_cid(l2cap_cid);
  if (p_bcb == NULL) {
    LOG_WARN("BNEP - Rcvd L2CAP disc, unknown CID: 0x%x", l2cap_cid);
    log::warn("BNEP - Rcvd L2CAP disc, unknown CID: 0x{:x}", l2cap_cid);
    return;
  }

  LOG_DEBUG("BNEP - Rcvd L2CAP disc, CID: 0x%x", l2cap_cid);
  log::debug("BNEP - Rcvd L2CAP disc, CID: 0x{:x}", l2cap_cid);

  /* Tell the user if there is a callback */
  if (p_bcb->con_state == BNEP_STATE_CONNECTED) {
@@ -272,7 +275,7 @@ static void bnep_congestion_ind(uint16_t l2cap_cid, bool is_congested) {
  /* Find BCB based on CID */
  p_bcb = bnepu_find_bcb_by_cid(l2cap_cid);
  if (p_bcb == NULL) {
    LOG_WARN("BNEP - Rcvd L2CAP cong, unknown CID: 0x%x", l2cap_cid);
    log::warn("BNEP - Rcvd L2CAP cong, unknown CID: 0x{:x}", l2cap_cid);
    return;
  }

@@ -329,7 +332,7 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
  /* Find CCB based on CID */
  p_bcb = bnepu_find_bcb_by_cid(l2cap_cid);
  if (p_bcb == NULL) {
    LOG_WARN("BNEP - Rcvd L2CAP data, unknown CID: 0x%x", l2cap_cid);
    log::warn("BNEP - Rcvd L2CAP data, unknown CID: 0x{:x}", l2cap_cid);
    osi_free(p_buf);
    return;
  }
@@ -339,12 +342,13 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
  extension_present = type >> 7;
  type &= 0x7f;
  if (type >= sizeof(bnep_frame_hdr_sizes) / sizeof(bnep_frame_hdr_sizes[0])) {
    LOG_INFO("BNEP - rcvd frame, bad type: 0x%02x", type);
    log::info("BNEP - rcvd frame, bad type: 0x{:02x}", type);
    osi_free(p_buf);
    return;
  }
  if ((rem_len <= bnep_frame_hdr_sizes[type]) || (rem_len > BNEP_MTU_SIZE)) {
    LOG_DEBUG("BNEP - rcvd frame, bad len: %d  type: 0x%02x", p_buf->len, type);
    log::debug("BNEP - rcvd frame, bad len: {}  type: 0x{:02x}", p_buf->len,
               type);
    osi_free(p_buf);
    return;
  }
@@ -354,7 +358,7 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
  if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
      (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED)) &&
      (type != BNEP_FRAME_CONTROL)) {
    LOG_WARN("BNEP - Ignored L2CAP data while in state: %d, CID: 0x%x",
    log::warn("BNEP - Ignored L2CAP data while in state: {}, CID: 0x{:x}",
              p_bcb->con_state, l2cap_cid);

    if (extension_present) {
@@ -398,12 +402,12 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
  }

  if (type > BNEP_FRAME_COMPRESSED_ETHERNET_DEST_ONLY) {
    LOG_DEBUG("BNEP - rcvd frame, unknown type: 0x%02x", type);
    log::debug("BNEP - rcvd frame, unknown type: 0x{:02x}", type);
    osi_free(p_buf);
    return;
  }

  LOG_DEBUG("BNEP - rcv frame, type: %d len: %d Ext: %d", type, p_buf->len,
  log::debug("BNEP - rcv frame, type: {} len: {} Ext: {}", type, p_buf->len,
             extension_present);

  /* Initialize addresses to 'not supplied' */
@@ -476,7 +480,7 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {

    /* if unknown extension present stop processing */
    if (ext_type) {
      LOG_DEBUG("Data extension type 0x%x found", ext_type);
      log::debug("Data extension type 0x{:x} found", ext_type);
      break;
    }

@@ -524,13 +528,13 @@ static void bnep_data_ind(uint16_t l2cap_cid, BT_HDR* p_buf) {
void bnep_conn_timer_timeout(void* data) {
  tBNEP_CONN* p_bcb = (tBNEP_CONN*)data;

  LOG_DEBUG(
      "BNEP - CCB timeout in state: %d  CID: 0x%x flags %x, re_transmit %d",
  log::debug(
      "BNEP - CCB timeout in state: {}  CID: 0x{:x} flags {:x}, re_transmit {}",
      p_bcb->con_state, p_bcb->l2cap_cid, p_bcb->con_flags,
      p_bcb->re_transmits);

  if (p_bcb->con_state == BNEP_STATE_CONN_SETUP) {
    LOG_DEBUG("BNEP - CCB timeout in state: %d  CID: 0x%x", p_bcb->con_state,
    log::debug("BNEP - CCB timeout in state: {}  CID: 0x{:x}", p_bcb->con_state,
               p_bcb->l2cap_cid);

    if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) {
@@ -555,7 +559,7 @@ void bnep_conn_timer_timeout(void* data) {
      return;
    }
  } else if (p_bcb->con_state != BNEP_STATE_CONNECTED) {
    LOG_DEBUG("BNEP - CCB timeout in state: %d  CID: 0x%x", p_bcb->con_state,
    log::debug("BNEP - CCB timeout in state: {}  CID: 0x{:x}", p_bcb->con_state,
               p_bcb->l2cap_cid);

    L2CA_DisconnectReq(p_bcb->l2cap_cid);
+78 −84
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@
 *
 ******************************************************************************/

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

@@ -36,6 +36,7 @@
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

using namespace bluetooth;
using bluetooth::Uuid;

/******************************************************************************/
@@ -169,7 +170,7 @@ void bnep_send_conn_req(tBNEP_CONN* p_bcb) {
  BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
  uint8_t *p, *p_start;

  LOG_VERBOSE("%s: sending setup req with dst uuid %s", __func__,
  log::verbose("sending setup req with dst uuid {}",
               p_bcb->dst_uuid.ToString().c_str());

  p_buf->offset = L2CAP_MIN_OFFSET;
@@ -198,7 +199,7 @@ void bnep_send_conn_req(tBNEP_CONN* p_bcb) {
    memcpy(p, p_bcb->src_uuid.To128BitBE().data(), Uuid::kNumBytes128);
    p += Uuid::kNumBytes128;
  } else {
    LOG_ERROR("%s: uuid: %s, invalid length: %zu", __func__,
    log::error("uuid: {}, invalid length: {}",
               p_bcb->dst_uuid.ToString().c_str(),
               p_bcb->dst_uuid.GetShortestRepresentationSize());
  }
@@ -221,7 +222,8 @@ void bnep_send_conn_response(tBNEP_CONN* p_bcb, uint16_t resp_code) {
  BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
  uint8_t* p;

  LOG_DEBUG("BNEP - bnep_send_conn_response for CID: 0x%x", p_bcb->l2cap_cid);
  log::debug("BNEP - bnep_send_conn_response for CID: 0x{:x}",
             p_bcb->l2cap_cid);

  p_buf->offset = L2CAP_MIN_OFFSET;
  p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -253,7 +255,7 @@ void bnepu_send_peer_our_filters(tBNEP_CONN* p_bcb) {
  uint8_t* p;
  uint16_t xx;

  LOG_VERBOSE("BNEP sending peer our filters");
  log::verbose("BNEP sending peer our filters");

  p_buf->offset = L2CAP_MIN_OFFSET;
  p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -295,7 +297,7 @@ void bnepu_send_peer_our_multi_filters(tBNEP_CONN* p_bcb) {
  uint8_t* p;
  uint16_t xx;

  LOG_VERBOSE("BNEP sending peer our multicast filters");
  log::verbose("BNEP sending peer our multicast filters");

  p_buf->offset = L2CAP_MIN_OFFSET;
  p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -338,7 +340,7 @@ void bnepu_send_peer_filter_rsp(tBNEP_CONN* p_bcb, uint16_t response_code) {
  BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
  uint8_t* p;

  LOG_VERBOSE("BNEP sending filter response");
  log::verbose("BNEP sending filter response");

  p_buf->offset = L2CAP_MIN_OFFSET;
  p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -369,7 +371,8 @@ void bnep_send_command_not_understood(tBNEP_CONN* p_bcb, uint8_t cmd_code) {
  BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
  uint8_t* p;

  LOG_VERBOSE("BNEP - bnep_send_command_not_understood for CID: 0x%x, cmd 0x%x",
  log::verbose(
      "BNEP - bnep_send_command_not_understood for CID: 0x{:x}, cmd 0x{:x}",
      p_bcb->l2cap_cid, cmd_code);

  p_buf->offset = L2CAP_MIN_OFFSET;
@@ -400,10 +403,12 @@ void bnep_send_command_not_understood(tBNEP_CONN* p_bcb, uint8_t cmd_code) {
 *
 ******************************************************************************/
void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf) {
  LOG_DEBUG("BNEP - bnepu_check_send_packet for CID: 0x%x", p_bcb->l2cap_cid);
  log::debug("BNEP - bnepu_check_send_packet for CID: 0x{:x}",
             p_bcb->l2cap_cid);
  if (p_bcb->con_flags & BNEP_FLAGS_L2CAP_CONGESTED) {
    if (fixed_queue_length(p_bcb->xmit_q) >= BNEP_MAX_XMITQ_DEPTH) {
      LOG_WARN("BNEP - congested, dropping buf, CID: 0x%x", p_bcb->l2cap_cid);
      log::warn("BNEP - congested, dropping buf, CID: 0x{:x}",
                p_bcb->l2cap_cid);

      osi_free(p_buf);
    } else {
@@ -531,12 +536,12 @@ static uint8_t* bnepu_init_hdr(BT_HDR* p_buf, uint16_t hdr_len,
 ******************************************************************************/
void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
                                 uint8_t len) {
  LOG_DEBUG("BNEP - for CID: 0x%x", p_bcb->l2cap_cid);
  log::debug("BNEP - for CID: 0x{:x}", p_bcb->l2cap_cid);

  if (p_bcb->con_state != BNEP_STATE_CONN_SETUP &&
      p_bcb->con_state != BNEP_STATE_SEC_CHECKING &&
      p_bcb->con_state != BNEP_STATE_CONNECTED) {
    LOG_ERROR("BNEP - setup request in bad state %d", p_bcb->con_state);
    log::error("BNEP - setup request in bad state {}", p_bcb->con_state);
    bnep_send_conn_response(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED);
    return;
  }
@@ -544,7 +549,7 @@ void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
  /* Check if we already initiated security check or if waiting for user
   * responce */
  if (p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD) {
    LOG_WARN(
    log::warn(
        "BNEP - Duplicate Setup message received while doing security check");
    return;
  }
@@ -553,7 +558,7 @@ void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
  if (p_bcb->con_state != BNEP_STATE_CONNECTED &&
      (!(p_bcb->con_flags & BNEP_FLAGS_SETUP_RCVD)) &&
      (p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) {
    LOG_ERROR("BNEP - setup request when we are originator state:%hu",
    log::error("BNEP - setup request when we are originator state:{}",
               p_bcb->con_state);
    bnep_send_conn_response(p_bcb, BNEP_SETUP_CONN_NOT_ALLOWED);
    return;
@@ -596,7 +601,7 @@ void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
    p_bcb->dst_uuid = Uuid::From128BitBE(p_setup);
    p_setup += len;
  } else {
    LOG_ERROR("BNEP - Bad UID len %d in ConnReq", len);
    log::error("BNEP - Bad UID len {} in ConnReq", len);
    bnep_send_conn_response(p_bcb, BNEP_SETUP_INVALID_UUID_SIZE);
    return;
  }
@@ -604,7 +609,7 @@ void bnep_process_setup_conn_req(tBNEP_CONN* p_bcb, uint8_t* p_setup,
  p_bcb->con_state = BNEP_STATE_SEC_CHECKING;
  p_bcb->con_flags |= BNEP_FLAGS_SETUP_RCVD;

  LOG_DEBUG("BNEP initiating security check for incoming call for uuid %s",
  log::debug("BNEP initiating security check for incoming call for uuid {}",
             p_bcb->src_uuid.ToString().c_str());
  bnep_sec_check_complete(&p_bcb->rem_bda, BT_TRANSPORT_BR_EDR, p_bcb);
}
@@ -624,17 +629,17 @@ void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, uint8_t* p_setup) {
  tBNEP_RESULT resp;
  uint16_t resp_code;

  LOG_VERBOSE("BNEP received setup responce");
  log::verbose("BNEP received setup responce");
  /* The state should be either SETUP or CONNECTED */
  if (p_bcb->con_state != BNEP_STATE_CONN_SETUP) {
    /* Should we disconnect ? */
    LOG_ERROR("BNEP - setup response in bad state %d", p_bcb->con_state);
    log::error("BNEP - setup response in bad state {}", p_bcb->con_state);
    return;
  }

  /* Check if we are the originator */
  if (!(p_bcb->con_flags & BNEP_FLAGS_IS_ORIG)) {
    LOG_ERROR("BNEP - setup response when we are not originator");
    log::error("BNEP - setup response when we are not originator");
    return;
  }

@@ -662,7 +667,7 @@ void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, uint8_t* p_setup) {
  /* Check the responce code */
  if (resp_code != BNEP_SETUP_CONN_OK) {
    if (p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED) {
      LOG_VERBOSE("BNEP - role change response is %d", resp_code);
      log::verbose("BNEP - role change response is {}", resp_code);

      /* Restore the earlier BNEP status */
      p_bcb->con_state = BNEP_STATE_CONNECTED;
@@ -680,7 +685,7 @@ void bnep_process_setup_conn_responce(tBNEP_CONN* p_bcb, uint8_t* p_setup) {

      return;
    } else {
      LOG_ERROR("BNEP - setup response %d is not OK", resp_code);
      log::error("BNEP - setup response {} is not OK", resp_code);

      L2CA_DisconnectReq(p_bcb->l2cap_cid);

@@ -715,8 +720,8 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

  if (p == NULL || rem_len == NULL) {
    if (rem_len != NULL) *rem_len = 0;
    LOG_VERBOSE("%s: invalid packet: p = %p rem_len = %p", __func__, p,
                rem_len);
    log::verbose("invalid packet: p = {} rem_len = {}", fmt::ptr(p),
                 fmt::ptr(rem_len));
    return NULL;
  }
  uint16_t rem_len_orig = *rem_len;
@@ -731,37 +736,33 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,
  control_type = *p++;
  *rem_len = *rem_len - 1;

  LOG_VERBOSE(
      "%s: BNEP processing control packet rem_len %d, is_ext %d, ctrl_type %d",
      __func__, *rem_len, is_ext, control_type);
  log::verbose(
      "BNEP processing control packet rem_len {}, is_ext {}, ctrl_type {}",
      *rem_len, is_ext, control_type);

  switch (control_type) {
    case BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD:
      if (*rem_len < 1) {
        LOG_ERROR(
            "%s: Received BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD with bad length",
            __func__);
        log::error(
            "Received BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD with bad length");
        goto bad_packet_length;
      }
      LOG_ERROR(
          "%s: Received BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD for pkt type: %d",
          __func__, *p);
      log::error(
          "Received BNEP_CONTROL_COMMAND_NOT_UNDERSTOOD for pkt type: {}", *p);
      p++;
      *rem_len = *rem_len - 1;
      break;

    case BNEP_SETUP_CONNECTION_REQUEST_MSG:
      if (*rem_len < 1) {
        LOG_ERROR(
            "%s: Received BNEP_SETUP_CONNECTION_REQUEST_MSG with bad length",
            __func__);
        log::error(
            "Received BNEP_SETUP_CONNECTION_REQUEST_MSG with bad length");
        goto bad_packet_length;
      }
      len = *p++;
      if (*rem_len < ((2 * len) + 1)) {
        LOG_ERROR(
            "%s: Received BNEP_SETUP_CONNECTION_REQUEST_MSG with bad length",
            __func__);
        log::error(
            "Received BNEP_SETUP_CONNECTION_REQUEST_MSG with bad length");
        goto bad_packet_length;
      }
      if (!is_ext) bnep_process_setup_conn_req(p_bcb, p, (uint8_t)len);
@@ -771,9 +772,8 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

    case BNEP_SETUP_CONNECTION_RESPONSE_MSG:
      if (*rem_len < 2) {
        LOG_ERROR(
            "%s: Received BNEP_SETUP_CONNECTION_RESPONSE_MSG with bad length",
            __func__);
        log::error(
            "Received BNEP_SETUP_CONNECTION_RESPONSE_MSG with bad length");
        goto bad_packet_length;
      }
      if (!is_ext) bnep_process_setup_conn_responce(p_bcb, p);
@@ -783,14 +783,12 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

    case BNEP_FILTER_NET_TYPE_SET_MSG:
      if (*rem_len < 2) {
        LOG_ERROR("%s: Received BNEP_FILTER_NET_TYPE_SET_MSG with bad length",
                  __func__);
        log::error("Received BNEP_FILTER_NET_TYPE_SET_MSG with bad length");
        goto bad_packet_length;
      }
      BE_STREAM_TO_UINT16(len, p);
      if (*rem_len < (len + 2)) {
        LOG_ERROR("%s: Received BNEP_FILTER_NET_TYPE_SET_MSG with bad length",
                  __func__);
        log::error("Received BNEP_FILTER_NET_TYPE_SET_MSG with bad length");
        goto bad_packet_length;
      }
      bnepu_process_peer_filter_set(p_bcb, p, len);
@@ -800,9 +798,8 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

    case BNEP_FILTER_NET_TYPE_RESPONSE_MSG:
      if (*rem_len < 2) {
        LOG_ERROR(
            "%s: Received BNEP_FILTER_NET_TYPE_RESPONSE_MSG with bad length",
            __func__);
        log::error(
            "Received BNEP_FILTER_NET_TYPE_RESPONSE_MSG with bad length");
        goto bad_packet_length;
      }
      bnepu_process_peer_filter_rsp(p_bcb, p);
@@ -812,14 +809,12 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

    case BNEP_FILTER_MULTI_ADDR_SET_MSG:
      if (*rem_len < 2) {
        LOG_ERROR("%s: Received BNEP_FILTER_MULTI_ADDR_SET_MSG with bad length",
                  __func__);
        log::error("Received BNEP_FILTER_MULTI_ADDR_SET_MSG with bad length");
        goto bad_packet_length;
      }
      BE_STREAM_TO_UINT16(len, p);
      if (*rem_len < (len + 2)) {
        LOG_ERROR("%s: Received BNEP_FILTER_MULTI_ADDR_SET_MSG with bad length",
                  __func__);
        log::error("Received BNEP_FILTER_MULTI_ADDR_SET_MSG with bad length");
        goto bad_packet_length;
      }
      bnepu_process_peer_multicast_filter_set(p_bcb, p, len);
@@ -829,9 +824,8 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,

    case BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG:
      if (*rem_len < 2) {
        LOG_ERROR(
            "%s: Received BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG with bad length",
            __func__);
        log::error(
            "Received BNEP_FILTER_MULTI_ADDR_RESPONSE_MSG with bad length");
        goto bad_packet_length;
      }
      bnepu_process_multicast_filter_rsp(p_bcb, p);
@@ -840,7 +834,7 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,
      break;

    default:
      LOG_ERROR("%s: BNEP - bad ctl pkt type: %d", __func__, control_type);
      log::error("BNEP - bad ctl pkt type: {}", control_type);
      bnep_send_command_not_understood(p_bcb, control_type);
      if (is_ext && (ext_len > 0)) {
        if (*rem_len < (ext_len - 1)) {
@@ -854,7 +848,7 @@ uint8_t* bnep_process_control_packet(tBNEP_CONN* p_bcb, uint8_t* p,
  return p;

bad_packet_length:
  LOG_ERROR("%s: bad control packet length: original=%d remaining=%d", __func__,
  log::error("bad control packet length: original={} remaining={}",
             rem_len_orig, *rem_len);
  *rem_len = 0;
  return NULL;
@@ -880,15 +874,15 @@ void bnepu_process_peer_filter_set(tBNEP_CONN* p_bcb, uint8_t* p_filters,

  if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
      (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) {
    LOG_VERBOSE(
    log::verbose(
        "BNEP received filter set from peer when there is no connection");
    return;
  }

  LOG_VERBOSE("BNEP received filter set from peer");
  log::verbose("BNEP received filter set from peer");
  /* Check for length not a multiple of 4 */
  if (len & 3) {
    LOG_VERBOSE("BNEP - bad filter len: %d", len);
    log::verbose("BNEP - bad filter len: {}", len);
    bnepu_send_peer_filter_rsp(p_bcb, BNEP_FILTER_CRL_BAD_RANGE);
    return;
  }
@@ -944,17 +938,17 @@ void bnepu_process_peer_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data) {
  uint16_t resp_code;
  tBNEP_RESULT result;

  LOG_VERBOSE("BNEP received filter responce");
  log::verbose("BNEP received filter responce");
  /* The state should be  CONNECTED */
  if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
      (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) {
    LOG_ERROR("BNEP - filter response in bad state %d", p_bcb->con_state);
    log::error("BNEP - filter response in bad state {}", p_bcb->con_state);
    return;
  }

  /* Check if we are the originator */
  if (!(p_bcb->con_flags & BNEP_FLAGS_FILTER_RESP_PEND)) {
    LOG_ERROR("BNEP - filter response when not expecting");
    log::error("BNEP - filter response when not expecting");
    return;
  }

@@ -986,18 +980,18 @@ void bnepu_process_multicast_filter_rsp(tBNEP_CONN* p_bcb, uint8_t* p_data) {
  uint16_t resp_code;
  tBNEP_RESULT result;

  LOG_VERBOSE("BNEP received multicast filter responce");
  log::verbose("BNEP received multicast filter responce");
  /* The state should be  CONNECTED */
  if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
      (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) {
    LOG_ERROR("BNEP - multicast filter response in bad state %d",
    log::error("BNEP - multicast filter response in bad state {}",
               p_bcb->con_state);
    return;
  }

  /* Check if we are the originator */
  if (!(p_bcb->con_flags & BNEP_FLAGS_MULTI_RESP_PEND)) {
    LOG_ERROR("BNEP - multicast filter response when not expecting");
    log::error("BNEP - multicast filter response when not expecting");
    return;
  }

@@ -1034,20 +1028,20 @@ void bnepu_process_peer_multicast_filter_set(tBNEP_CONN* p_bcb,

  if ((p_bcb->con_state != BNEP_STATE_CONNECTED) &&
      (!(p_bcb->con_flags & BNEP_FLAGS_CONN_COMPLETED))) {
    LOG_VERBOSE(
    log::verbose(
        "BNEP received multicast filter set from peer when there is no "
        "connection");
    return;
  }

  if (len % 12) {
    LOG_VERBOSE("BNEP - bad filter len: %d", len);
    log::verbose("BNEP - bad filter len: {}", len);
    bnepu_send_peer_multicast_filter_rsp(p_bcb, BNEP_FILTER_CRL_BAD_RANGE);
    return;
  }

  if (len > (BNEP_MAX_MULTI_FILTERS * 2 * BD_ADDR_LEN)) {
    LOG_VERBOSE("BNEP - Too many filters");
    log::verbose("BNEP - Too many filters");
    bnepu_send_peer_multicast_filter_rsp(p_bcb, BNEP_FILTER_CRL_MAX_REACHED);
    return;
  }
@@ -1088,7 +1082,7 @@ void bnepu_process_peer_multicast_filter_set(tBNEP_CONN* p_bcb,
    }
  }

  LOG_VERBOSE("BNEP multicast filters %d", p_bcb->rcvd_mcast_filters);
  log::verbose("BNEP multicast filters {}", p_bcb->rcvd_mcast_filters);
  bnepu_send_peer_multicast_filter_rsp(p_bcb, resp_code);

  if (bnep_cb.p_mfilter_ind_cb)
@@ -1109,7 +1103,7 @@ void bnepu_send_peer_multicast_filter_rsp(tBNEP_CONN* p_bcb,
  BT_HDR* p_buf = (BT_HDR*)osi_malloc(BNEP_BUF_SIZE);
  uint8_t* p;

  LOG_VERBOSE("BNEP sending multicast filter response %d", response_code);
  log::verbose("BNEP sending multicast filter response {}", response_code);

  p_buf->offset = L2CAP_MIN_OFFSET;
  p = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
@@ -1150,7 +1144,7 @@ void bnep_sec_check_complete(const RawAddress* bd_addr, tBT_TRANSPORT trasnport,

  /* check if the port is still waiting for security to complete */
  if (p_bcb->con_state != BNEP_STATE_SEC_CHECKING) {
    LOG_ERROR("BNEP Connection in wrong state %d when security is completed",
    log::error("BNEP Connection in wrong state {} when security is completed",
               p_bcb->con_state);
    return;
  }
@@ -1230,7 +1224,7 @@ tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
    }

    if (i == p_bcb->rcvd_num_filters) {
      LOG_VERBOSE("Ignoring protocol 0x%x in BNEP data write", proto);
      log::verbose("Ignoring protocol 0x{:x} in BNEP data write", proto);
      return BNEP_IGNORE_CMD;
    }
  }
@@ -1258,8 +1252,8 @@ tBNEP_RESULT bnep_is_packet_allowed(tBNEP_CONN* p_bcb,
    */
    if ((p_bcb->rcvd_mcast_filters == 0xFFFF) ||
        (i == p_bcb->rcvd_mcast_filters)) {
      VLOG(1) << "Ignoring multicast address " << dest_addr
              << " in BNEP data write";
      log::verbose("Ignoring multicast address {} in BNEP data write",
                   ADDRESS_TO_LOGGABLE_STR(dest_addr));
      return BNEP_IGNORE_CMD;
    }
  }