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

Commit f59aa227 authored by Stanley Tng's avatar Stanley Tng
Browse files

Added support for new Android API for LE CoC

Added support for the new Android API including the management of the
LE_PSM values.
Also fixed a bug when de-registering the L2CAP CoC, the RCB is not
freed correctly.

Test: Ran the new ACTS Tests for LE CoC and existing ACTS for RfComm
Bug: 70683224
Change-Id: I5a545656bece667e7ba942d7b2334e3f5b49b283
parent d73ef572
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include "port_api.h"
#include "rfcdefs.h"
#include "sdp_api.h"
#include "stack/l2cap/l2c_int.h"
#include "utl.h"

#include "osi/include/osi.h"
@@ -687,6 +688,10 @@ void bta_jv_get_channel_id(
      }
      break;
    case BTA_JV_CONN_TYPE_L2CAP_LE:
      psm = L2CA_AllocateLePSM();
      if (psm == 0) {
        LOG(ERROR) << __func__ << ": Error: No free LE PSM available";
      }
      break;
    default:
      break;
@@ -715,7 +720,8 @@ void bta_jv_free_scn(int32_t type /* One of BTA_JV_CONN_TYPE_ */,
      bta_jv_set_free_psm(scn);
      break;
    case BTA_JV_CONN_TYPE_L2CAP_LE:
      // TODO: Not yet implemented...
      VLOG(2) << __func__ << ": type=BTA_JV_CONN_TYPE_L2CAP_LE. psm=" << scn;
      L2CA_FreeLePSM(scn);
      break;
    default:
      break;
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ bool BTA_JvIsEncrypted(const RawAddress& bd_addr) {
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
  VLOG(2) << __func__;
  VLOG(2) << __func__ << ": conn_type=" << conn_type;

  if (conn_type != BTA_JV_CONN_TYPE_RFCOMM &&
      conn_type != BTA_JV_CONN_TYPE_L2CAP &&
+27 −1
Original line number Diff line number Diff line
@@ -130,6 +130,7 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,

  *sock_fd = INVALID_FD;
  bt_status_t status = BT_STATUS_FAIL;
  int original_channel = channel;

  switch (type) {
    case BTSOCK_RFCOMM:
@@ -140,7 +141,22 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name,
      status =
          btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
      break;

    case BTSOCK_L2CAP_LE:
      if (flags & BTSOCK_FLAG_NO_SDP) {
        channel = L2CAP_MASK_LE_COC_CHANNEL;
      } else if (channel > 0) {
        channel |= L2CAP_MASK_LE_COC_CHANNEL;
      } else {
        LOG_ERROR(LOG_TAG, "%s: type BTSOCK_L2CAP_LE: invalid channel=%d",
                  __func__, channel);
        break;
      }
      LOG_DEBUG(LOG_TAG,
                "%s: type=BTSOCK_L2CAP_LE, channel=0x%x, original=0x%x",
                __func__, channel, original_channel);
      status =
          btsock_l2cap_listen(service_name, channel, sock_fd, flags, app_uid);
      break;
    case BTSOCK_SCO:
      status = btsock_sco_listen(sock_fd, flags);
      break;
@@ -173,6 +189,13 @@ static bt_status_t btsock_connect(const RawAddress* bd_addr, btsock_type_t type,
      status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid);
      break;

    case BTSOCK_L2CAP_LE:
      channel |= L2CAP_MASK_LE_COC_CHANNEL;
      LOG_DEBUG(LOG_TAG, "%s: type=BTSOCK_L2CAP_LE, channel=0x%x", __func__,
                channel);
      status = btsock_l2cap_connect(bd_addr, channel, sock_fd, flags, app_uid);
      break;

    case BTSOCK_SCO:
      status = btsock_sco_connect(bd_addr, sock_fd, flags);
      break;
@@ -192,6 +215,9 @@ static void btsock_signaled(int fd, int type, int flags, uint32_t user_id) {
      btsock_rfc_signaled(fd, flags, user_id);
      break;
    case BTSOCK_L2CAP:
    case BTSOCK_L2CAP_LE:
      /* Note: The caller may not distinguish between BTSOCK_L2CAP and
       * BTSOCK_L2CAP_LE correctly */
      btsock_l2cap_signaled(fd, flags, user_id);
      break;
    default:
+7 −3
Original line number Diff line number Diff line
@@ -245,7 +245,7 @@ static void btsock_l2cap_free_l(l2cap_socket* sock) {
      BTA_JvL2capClose(sock->handle);
    }
    if ((sock->channel >= 0) && (sock->server)) {
      BTA_JvFreeChannel(sock->channel, BTA_JV_CONN_TYPE_L2CAP);
      BTA_JvFreeChannel(sock->channel, BTA_JV_CONN_TYPE_L2CAP_LE);
    }
  } else {
    // Only call if we are non server connections
@@ -339,7 +339,7 @@ fail_sockpair:
}

bt_status_t btsock_l2cap_init(int handle, uid_set_t* set) {
  APPL_TRACE_DEBUG("%s handle = %d", __func__);
  APPL_TRACE_DEBUG("%s: handle = %d", __func__, handle);
  std::unique_lock<std::mutex> lock(state_lock);
  pth = handle;
  socks = NULL;
@@ -355,6 +355,7 @@ bt_status_t btsock_l2cap_cleanup() {
}

static inline bool send_app_psm_or_chan_l(l2cap_socket* sock) {
  APPL_TRACE_DEBUG("%s: channel=%d", __func__, sock->channel);
  return sock_send_all(sock->our_fd, (const uint8_t*)&sock->channel,
                       sizeof(sock->channel)) == sizeof(sock->channel);
}
@@ -799,6 +800,9 @@ static bt_status_t btSock_start_l2cap_server_l(l2cap_socket* sock) {
  cfg.fcr_present = true;
  cfg.fcr = obex_l2c_fcr_opts_def;

  APPL_TRACE_DEBUG("%s: fixed_chan=%d, channel=%d, is_le_coc=%d", __func__,
                   sock->fixed_chan, sock->channel, sock->is_le_coc);

  if (sock->fixed_chan) {
    if (BTA_JvL2capStartServerLE(sock->security, 0, NULL, sock->channel,
                                 L2CAP_DEFAULT_MTU, NULL, btsock_l2cap_cbk,
@@ -808,7 +812,7 @@ static bt_status_t btSock_start_l2cap_server_l(l2cap_socket* sock) {
  } else {
    /* If we have a channel specified in the request, just start the server,
     * else we request a PSM and start the server after we receive a PSM. */
    if (sock->channel < 0) {
    if (sock->channel <= 0) {
      if (sock->is_le_coc) {
        if (BTA_JvGetChannelId(BTA_JV_CONN_TYPE_L2CAP_LE, sock->id, 0) !=
            BTA_JV_SUCCESS)
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ __BEGIN_DECLS
typedef enum {
  BTSOCK_RFCOMM = 1,
  BTSOCK_SCO = 2,
  BTSOCK_L2CAP = 3
  BTSOCK_L2CAP = 3,
  BTSOCK_L2CAP_LE = 4
} btsock_type_t;

/** Represents the standard BT SOCKET interface. */
Loading