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

Commit 4752a653 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge changes I7a3e9ee7,I29702219

* changes:
  Remove dead code - dump_bin
  Assert on null callback in BTA_JvL2capConnect and BTA_JvL2capConnectLE
parents af1205d2 17333175
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;
}

/*******************************************************************************
+0 −2
Original line number Diff line number Diff line
@@ -29,8 +29,6 @@

#include <stdint.h>

void dump_bin(const char* title, const char* data, int size);

int sock_send_fd(int sock_fd, const uint8_t* buffer, int len, int send_fd);
int sock_send_all(int sock_fd, const uint8_t* buf, int len);
int sock_recv_all(int sock_fd, uint8_t* buf, int len);
+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,
+0 −86
Original line number Diff line number Diff line
@@ -145,89 +145,3 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) {
  close(send_fd);
  return ret_len;
}

static const char* hex_table = "0123456789abcdef";
static inline void byte2hex(const char* data, char** str) {
  **str = hex_table[(*data >> 4) & 0xf];
  ++*str;
  **str = hex_table[*data & 0xf];
  ++*str;
}
static inline void byte2char(const char* data, char** str) {
  **str = *data < ' ' ? '.' : *data > '~' ? '.' : *data;
  ++(*str);
}
static inline void word2hex(const char* data, char** hex) {
  byte2hex(&data[1], hex);
  byte2hex(&data[0], hex);
}
void dump_bin(const char* title, const char* data, int size) {
  char line_buff[256];
  char* line;
  int i, j, addr;
  const int width = 16;
  LOG_DEBUG(LOG_TAG, "%s, size:%d, dump started {", title, size);
  if (size <= 0) return;
  // write offset
  line = line_buff;
  *line++ = ' ';
  *line++ = ' ';
  *line++ = ' ';
  *line++ = ' ';
  *line++ = ' ';
  *line++ = ' ';
  for (j = 0; j < width; j++) {
    byte2hex((const char*)&j, &line);
    *line++ = ' ';
  }
  *line = 0;
  LOG_DEBUG(LOG_TAG, "%s", line_buff);

  for (i = 0; i < size / width; i++) {
    line = line_buff;
    // write address:
    addr = i * width;
    word2hex((const char*)&addr, &line);
    *line++ = ':';
    *line++ = ' ';
    // write hex of data
    for (j = 0; j < width; j++) {
      byte2hex(&data[j], &line);
      *line++ = ' ';
    }
    // write char of data
    for (j = 0; j < width; j++) byte2char(data++, &line);
    // wirte the end of line
    *line = 0;
    // output the line
    LOG_DEBUG(LOG_TAG, "%s", line_buff);
  }
  // last line of left over if any
  int leftover = size % width;
  if (leftover > 0) {
    line = line_buff;
    // write address:
    addr = i * width;
    word2hex((const char*)&addr, &line);
    *line++ = ':';
    *line++ = ' ';
    // write hex of data
    for (j = 0; j < leftover; j++) {
      byte2hex(&data[j], &line);
      *line++ = ' ';
    }
    // write hex padding
    for (; j < width; j++) {
      *line++ = ' ';
      *line++ = ' ';
      *line++ = ' ';
    }
    // write char of data
    for (j = 0; j < leftover; j++) byte2char(data++, &line);
    // write the end of line
    *line = 0;
    // output the line
    LOG_DEBUG(LOG_TAG, "%s", line_buff);
  }
  LOG_DEBUG(LOG_TAG, "%s, size:%d, dump ended }", title, size);
}