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

Commit 925f621f authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Assert on null callback in BTA_JvL2capConnect and BTA_JvL2capConnectLE

Passing null as callback should never happen in any scenario.

Bug: 68359837
Test: compilation test
Change-Id: I29702219183eae9d1782438f99d01534fbe44d73
parent 85457765
Loading
Loading
Loading
Loading
+11 −18
Original line number Diff line number Diff line
@@ -515,15 +515,11 @@ tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle);
 *                  When the connection is established or failed,
 *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
 *
 * Returns          BTA_JV_SUCCESS, if the request is being processed.
 *                  BTA_JV_FAILURE, otherwise.
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
void BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                          const tL2CAP_ERTM_INFO* ertm_info,
                          uint16_t remote_chan, uint16_t rx_mtu,
                                    tL2CAP_CFG_INFO* cfg,
                                    const RawAddress& peer_bd_addr,
                          tL2CAP_CFG_INFO* cfg, const RawAddress& peer_bd_addr,
                          tBTA_JV_L2CAP_CBACK* p_cback,
                          uint32_t l2cap_socket_id);

@@ -538,14 +534,11 @@ tBTA_JV_STATUS BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
 *                  When the connection is established or failed,
 *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
 *
 * Returns          BTA_JV_SUCCESS, if the request is being processed.
 *                  BTA_JV_FAILURE, otherwise.
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capConnect(
    int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
    const tL2CAP_ERTM_INFO* ertm_info, uint16_t remote_psm, uint16_t rx_mtu,
    tL2CAP_CFG_INFO* cfg, const RawAddress& peer_bd_addr,
void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                        const tL2CAP_ERTM_INFO* ertm_info, uint16_t remote_psm,
                        uint16_t rx_mtu, tL2CAP_CFG_INFO* cfg,
                        const RawAddress& peer_bd_addr,
                        tBTA_JV_L2CAP_CBACK* p_cback, uint32_t l2cap_socket_id);

/*******************************************************************************
+14 −26
Original line number Diff line number Diff line
@@ -242,25 +242,17 @@ tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
 *                  When the connection is established or failed,
 *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
 *
 * Returns          BTA_JV_SUCCESS, if the request is being processed.
 *                  BTA_JV_FAILURE, otherwise.
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE,
                                    const tL2CAP_ERTM_INFO*,
                                    uint16_t remote_chan, uint16_t,
                                    tL2CAP_CFG_INFO*,
void BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE,
                          const tL2CAP_ERTM_INFO*, uint16_t remote_chan,
                          uint16_t, tL2CAP_CFG_INFO*,
                          const RawAddress& peer_bd_addr,
                          tBTA_JV_L2CAP_CBACK* p_cback,
                          uint32_t l2cap_socket_id) {
  VLOG(2) << __func__;

  if (p_cback == NULL) return BTA_JV_FAILURE; /* Nothing to do */

  CHECK(p_cback);
  do_in_bta_thread(FROM_HERE, Bind(&bta_jv_l2cap_connect_le, remote_chan,
                                   peer_bd_addr, p_cback, l2cap_socket_id));

  return BTA_JV_SUCCESS;
}

/*******************************************************************************
@@ -274,18 +266,15 @@ tBTA_JV_STATUS BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE,
 *                  When the connection is established or failed,
 *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
 *
 * Returns          BTA_JV_SUCCESS, if the request is being processed.
 *                  BTA_JV_FAILURE, otherwise.
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvL2capConnect(
    int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
    const tL2CAP_ERTM_INFO* ertm_info, uint16_t remote_psm, uint16_t rx_mtu,
    tL2CAP_CFG_INFO* cfg, const RawAddress& peer_bd_addr,
    tBTA_JV_L2CAP_CBACK* p_cback, uint32_t l2cap_socket_id) {
void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
                        const tL2CAP_ERTM_INFO* ertm_info, uint16_t remote_psm,
                        uint16_t rx_mtu, tL2CAP_CFG_INFO* cfg,
                        const RawAddress& peer_bd_addr,
                        tBTA_JV_L2CAP_CBACK* p_cback,
                        uint32_t l2cap_socket_id) {
  VLOG(2) << __func__;

  if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
  CHECK(p_cback);

  std::unique_ptr<tL2CAP_CFG_INFO> cfg_copy;
  if (cfg) cfg_copy = std::make_unique<tL2CAP_CFG_INFO>(*cfg);
@@ -298,7 +287,6 @@ tBTA_JV_STATUS BTA_JvL2capConnect(
      FROM_HERE, Bind(&bta_jv_l2cap_connect, conn_type, sec_mask, role,
                      remote_psm, rx_mtu, peer_bd_addr, base::Passed(&cfg_copy),
                      base::Passed(&ertm_info_copy), p_cback, l2cap_socket_id));
  return BTA_JV_SUCCESS;
}

/*******************************************************************************
+23 −37
Original line number Diff line number Diff line
@@ -868,7 +868,6 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name,
                                                  int channel, int* sock_fd,
                                                  int flags, char listen,
                                                  int app_uid) {
  bt_status_t stat;
  int fixed_chan = 1;
  l2cap_socket* sock;
  tL2CAP_CFG_INFO cfg;
@@ -900,10 +899,7 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name,
  sock->app_uid = app_uid;
  sock->is_le_coc = is_le_coc;

  stat = BT_STATUS_SUCCESS;

  /* Setup ETM settings:
   *  mtu will be set below */
  /* Setup ETM settings: mtu will be set below */
  memset(&cfg, 0, sizeof(tL2CAP_CFG_INFO));

  cfg.fcr_present = true;
@@ -911,48 +907,38 @@ static bt_status_t btsock_l2cap_listen_or_connect(const char* name,

  /* "role" is never initialized in rfcomm code */
  if (listen) {
    stat = btSock_start_l2cap_server_l(sock);
    bt_status_t stat = btSock_start_l2cap_server_l(sock);
    if (stat != BT_STATUS_SUCCESS) {
      btsock_l2cap_free_l(sock);
    }
  } else {
    if (fixed_chan) {
      if (BTA_JvL2capConnectLE(sock->security, 0, NULL, channel,
                               L2CAP_DEFAULT_MTU, NULL, sock->addr,
                               btsock_l2cap_cbk, sock->id) != BTA_JV_SUCCESS)
        stat = BT_STATUS_FAIL;

      BTA_JvL2capConnectLE(sock->security, 0, NULL, channel, L2CAP_DEFAULT_MTU,
                           NULL, sock->addr, btsock_l2cap_cbk, sock->id);
    } else {
      if (sock->is_le_coc) {
        if (BTA_JvL2capConnect(BTA_JV_CONN_TYPE_L2CAP_LE, sock->security, 0,
                               NULL, channel, L2CAP_MAX_SDU_LENGTH, &cfg,
                               sock->addr, btsock_l2cap_cbk,
                               sock->id) != BTA_JV_SUCCESS)
          stat = BT_STATUS_FAIL;
        BTA_JvL2capConnect(BTA_JV_CONN_TYPE_L2CAP_LE, sock->security, 0, NULL,
                           channel, L2CAP_MAX_SDU_LENGTH, &cfg, sock->addr,
                           btsock_l2cap_cbk, sock->id);
      } else {
        if (BTA_JvL2capConnect(BTA_JV_CONN_TYPE_L2CAP, sock->security, 0,
        BTA_JvL2capConnect(BTA_JV_CONN_TYPE_L2CAP, sock->security, 0,
                           &obex_l2c_etm_opt, channel, L2CAP_MAX_SDU_LENGTH,
                               &cfg, sock->addr, btsock_l2cap_cbk,
                               sock->id) != BTA_JV_SUCCESS)
          stat = BT_STATUS_FAIL;
                           &cfg, sock->addr, btsock_l2cap_cbk, sock->id);
      }
    }
  }

  if (stat == BT_STATUS_SUCCESS) {
  *sock_fd = sock->app_fd;
  /* We pass the FD to JAVA, but since it runs in another process, we need to
     * also close
     * it in native, either straight away, as done when accepting an incoming
     * connection,
     * or when doing cleanup after this socket */
    sock->app_fd =
        -1; /*This leaks the file descriptor. The FD should be closed in
              JAVA but it apparently do not work */
   * also close it in native, either straight away, as done when accepting an
   * incoming connection, or when doing cleanup after this socket */
  sock->app_fd = -1;
  /*This leaks the file descriptor. The FD should be closed in JAVA but it
   * apparently do not work */
  btsock_thread_add_fd(pth, sock->our_fd, BTSOCK_L2CAP,
                       SOCK_THREAD_FD_EXCEPTION, sock->id);
  } else {
    btsock_l2cap_free_l(sock);
  }

  return stat;
  return BT_STATUS_SUCCESS;
}

bt_status_t btsock_l2cap_listen(const char* name, int channel, int* sock_fd,