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

Commit 0f802d7e authored by Chris Manton's avatar Chris Manton
Browse files

[14/25] stack::bnep Use stack::l2cap::get_interface()

Bug: 343808590
Test: m .
Flag: EXEMPT, Mechanical Refactor

Change-Id: If043f1a781fc2879e8bfc743948a0e563ce14299
parent d216cb01
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -30,10 +30,10 @@
#include "bnep_int.h"
#include "bta/include/bta_sec_api.h"
#include "internal_include/bt_target.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_psm_types.h"
#include "stack/include/l2cap_interface.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

@@ -112,7 +112,7 @@ void BNEP_Deregister(void) {
  bnep_cb.p_mfilter_ind_cb = NULL;

  bnep_cb.profile_registered = false;
  L2CA_Deregister(BT_PSM_BNEP);
  stack::l2cap::get_interface().L2CA_Deregister(BT_PSM_BNEP);
}

/*******************************************************************************
@@ -175,8 +175,8 @@ tBNEP_RESULT BNEP_Connect(const RawAddress& p_rem_bda, const Uuid& src_uuid, con
     */
    p_bcb->con_state = BNEP_STATE_CONN_START;

    cid = L2CA_ConnectReqWithSecurity(BT_PSM_BNEP, p_bcb->rem_bda,
                                      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
    cid = stack::l2cap::get_interface().L2CA_ConnectReqWithSecurity(
            BT_PSM_BNEP, p_bcb->rem_bda, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
    if (cid != 0) {
      p_bcb->l2cap_cid = cid;

@@ -308,7 +308,7 @@ tBNEP_RESULT BNEP_Disconnect(uint16_t handle) {

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

  if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
  if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
    log::warn("Unable to send L2CAP disconnect request peer:{} cid:{}", p_bcb->rem_bda,
              p_bcb->l2cap_cid);
  }
+1 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
#include "osi/include/alarm.h"
#include "osi/include/fixed_queue.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/l2cap_interface.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

+13 −11
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_psm_types.h"
#include "stack/include/bt_types.h"
#include "stack/include/l2cap_interface.h"
#include "types/raw_address.h"

using namespace bluetooth;
@@ -88,9 +89,9 @@ tBNEP_RESULT bnep_register_with_l2cap(void) {
  bnep_cb.reg_info.pL2CA_Error_Cb = bnep_on_l2cap_error;

  /* Now, register with L2CAP */
  if (!L2CA_RegisterWithSecurity(BT_PSM_BNEP, bnep_cb.reg_info, false /* enable_snoop */, nullptr,
                                 BNEP_MTU_SIZE, BNEP_MTU_SIZE,
                                 BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
  if (!stack::l2cap::get_interface().L2CA_RegisterWithSecurity(
              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");
    return BNEP_SECURITY_FAIL;
  }
@@ -116,7 +117,7 @@ static void bnep_connect_ind(const RawAddress& bd_addr, uint16_t l2cap_cid, uint
  /* If we are not acting as server, or already have a connection, or have */
  /* no more resources to handle the connection, reject the connection.    */
  if (!(bnep_cb.profile_registered) || (p_bcb) || ((p_bcb = bnepu_allocate_bcb(bd_addr)) == NULL)) {
    if (!L2CA_DisconnectReq(l2cap_cid)) {
    if (!stack::l2cap::get_interface().L2CA_DisconnectReq(l2cap_cid)) {
      log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", bd_addr, l2cap_cid);
    }
    return;
@@ -145,7 +146,7 @@ static void bnep_on_l2cap_error(uint16_t l2cap_cid, uint16_t /* result */) {
    (*bnep_cb.p_conn_state_cb)(p_bcb->handle, p_bcb->rem_bda, BNEP_CONN_FAILED, false);
  }

  if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
  if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
    log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda, l2cap_cid);
  }

@@ -296,7 +297,8 @@ static void bnep_congestion_ind(uint16_t l2cap_cid, bool is_congested) {
        break;
      }

      if (L2CA_DataWrite(l2cap_cid, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
      if (stack::l2cap::get_interface().L2CA_DataWrite(l2cap_cid, p_buf) !=
          tL2CAP_DW_RESULT::SUCCESS) {
        log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_bcb->rem_bda, l2cap_cid,
                  p_buf->len);
      }
@@ -538,7 +540,7 @@ void bnep_conn_timer_timeout(void* data) {
    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)) {
      if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
        log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                  p_bcb->l2cap_cid);
      }
@@ -550,7 +552,7 @@ void bnep_conn_timer_timeout(void* data) {
      bnep_send_conn_req(p_bcb);
      alarm_set_on_mloop(p_bcb->conn_timer, BNEP_CONN_TIMEOUT_MS, bnep_conn_timer_timeout, p_bcb);
    } else {
      if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
        log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                  p_bcb->l2cap_cid);
      }
@@ -565,7 +567,7 @@ void bnep_conn_timer_timeout(void* data) {
  } else if (p_bcb->con_state != BNEP_STATE_CONNECTED) {
    log::debug("BNEP - CCB timeout in state: {}  CID: 0x{:x}", p_bcb->con_state, p_bcb->l2cap_cid);

    if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
    if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                p_bcb->l2cap_cid);
    }
@@ -582,7 +584,7 @@ void bnep_conn_timer_timeout(void* data) {
      alarm_set_on_mloop(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, bnep_conn_timer_timeout,
                         p_bcb);
    } else {
      if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
        log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                  p_bcb->l2cap_cid);
      }
@@ -601,7 +603,7 @@ void bnep_conn_timer_timeout(void* data) {
      alarm_set_on_mloop(p_bcb->conn_timer, BNEP_FILTER_SET_TIMEOUT_MS, bnep_conn_timer_timeout,
                         p_bcb);
    } else {
      if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
        log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                  p_bcb->l2cap_cid);
      }
+4 −3
Original line number Diff line number Diff line
@@ -30,10 +30,10 @@
#include "internal_include/bt_target.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
#include "os/log.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_types.h"
#include "stack/include/l2cap_interface.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"

@@ -408,7 +408,8 @@ void bnepu_check_send_packet(tBNEP_CONN* p_bcb, BT_HDR* p_buf) {
      fixed_queue_enqueue(p_bcb->xmit_q, p_buf);
    }
  } else {
    if (L2CA_DataWrite(p_bcb->l2cap_cid, p_buf) != tL2CAP_DW_RESULT::SUCCESS) {
    if (stack::l2cap::get_interface().L2CA_DataWrite(p_bcb->l2cap_cid, p_buf) !=
        tL2CAP_DW_RESULT::SUCCESS) {
      log::warn("Unable to write L2CAP data peer:{} cid:{} len:{}", p_bcb->rem_bda,
                p_bcb->l2cap_cid, p_buf->len);
    }
@@ -673,7 +674,7 @@ void bnep_process_setup_conn_response(tBNEP_CONN* p_bcb, uint8_t* p_setup) {
    } else {
      log::error("BNEP - setup response {} is not OK", resp_code);

      if (!L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
      if (!stack::l2cap::get_interface().L2CA_DisconnectReq(p_bcb->l2cap_cid)) {
        log::warn("Unable to request L2CAP disconnect peer:{} cid:{}", p_bcb->rem_bda,
                  p_bcb->l2cap_cid);
      }
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@

#include "l2c_api.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/l2cap_types.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"