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

Commit 90cef83f authored by Liang Li's avatar Liang Li Committed by Gerrit Code Review
Browse files

Merge changes from topic "rfcomm_offload_socket" into main

* changes:
  Determine local mtu for offload RFCOMM socket
  Set the initial local credits to 0 for offload RFCOMM socket
  Notify offloaded RFCOMM socket channel info to socket hal
  Send signal to indicate if app is accepting incoming connection on RFCOMM listen socket
  Add RFCOMM socket offload capabilities
  Add helper functions to get RFCOMM channel and L2CAP local mtu information
parents 403bfc31 304911f3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -135,7 +135,7 @@ class AdapterProperties {
    private boolean mIsLeChannelSoundingSupported;

    private int mNumberOfSupportedOffloadedLeCocSockets;
    private int mNumberOfSupportedOffloadedRfcommSockets = 0;
    private int mNumberOfSupportedOffloadedRfcommSockets;

    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
@@ -1044,12 +1044,12 @@ class AdapterProperties {
    }

    private void updateLppOffloadFeatureSupport(byte[] val) {
        if (val.length < 1) {
        if (val == null || val.length < 2) {
            Log.e(TAG, "BT_PROPERTY_LPP_OFFLOAD_FEATURES: invalid value length");
            return;
        }
        // TODO(b/342012881) Read mNumberOfSupportedOffloadedRfcommSockets from host stack
        mNumberOfSupportedOffloadedLeCocSockets = (0xFF & ((int) val[0]));
        mNumberOfSupportedOffloadedRfcommSockets = (0xFF & ((int) val[1]));

        Log.d(
                TAG,
+10 −7
Original line number Diff line number Diff line
@@ -116,11 +116,8 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {

        if (dataPath != BluetoothSocketSettings.DATA_PATH_NO_OFFLOAD) {
            mService.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            if (type != BluetoothSocket.TYPE_LE || !mService.isLeCocSocketOffloadSupported()) {
                throw new IllegalStateException("Unsupported socket type for offload " + type);
            }
            enforceSocketOffloadSupport(type);
        }

        String brEdrAddress =
                Flags.identityAddressNullIfNotKnown()
                        ? Utils.getBrEdrAddress(device)
@@ -228,9 +225,7 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {

        if (dataPath != BluetoothSocketSettings.DATA_PATH_NO_OFFLOAD) {
            mService.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            if (type != BluetoothSocket.TYPE_LE || !mService.isLeCocSocketOffloadSupported()) {
                throw new IllegalStateException("Unsupported socket type for offload " + type);
            }
            enforceSocketOffloadSupport(type);
        }

        Log.i(
@@ -318,6 +313,14 @@ class BluetoothSocketManagerBinder extends IBluetoothSocketManager.Stub {
        }
    }

    private void enforceSocketOffloadSupport(int type) {
        if (!(type == BluetoothSocket.TYPE_LE && mService.isLeCocSocketOffloadSupported())
                && !(type == BluetoothSocket.TYPE_RFCOMM
                        && mService.isRfcommSocketOffloadSupported())) {
            throw new IllegalStateException("Unsupported socket type for offload " + type);
        }
    }

    private static ParcelFileDescriptor marshalFd(int fd) {
        if (fd == INVALID_FD) {
            return null;
+2 −2
Original line number Diff line number Diff line
@@ -253,7 +253,7 @@ void bta_ag_start_servers(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK services) {
      int status = RFCOMM_CreateConnectionWithSecurity(
              bta_ag_uuid[i], bta_ag_cb.profile[i].scn, true, BTA_AG_MTU, RawAddress::kAny,
              &(p_scb->serv_handle[i]), bta_ag_mgmt_cback_tbl[management_callback_index],
              BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
              BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT, RfcommCfgInfo{});
      if (status == PORT_SUCCESS) {
        bta_ag_setup_port(p_scb, p_scb->serv_handle[i]);
      } else {
@@ -330,7 +330,7 @@ void bta_ag_rfc_do_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
  int status = RFCOMM_CreateConnectionWithSecurity(
          bta_ag_uuid[p_scb->conn_service], p_scb->peer_scn, false, BTA_AG_MTU, p_scb->peer_addr,
          &(p_scb->conn_handle), bta_ag_mgmt_cback_tbl[management_callback_index],
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT, RfcommCfgInfo{});
  log::verbose("p_scb=0x{}, conn_handle={}, mgmt_cback_index={}, status={}", std::format_ptr(p_scb),
               p_scb->conn_handle, management_callback_index, status);
  if (status == PORT_SUCCESS) {
+5 −5
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ void bta_hf_client_start_server() {
  port_status = RFCOMM_CreateConnectionWithSecurity(
          UUID_SERVCLASS_HF_HANDSFREE, bta_hf_client_cb_arr.scn, true, BTA_HF_CLIENT_MTU,
          RawAddress::kAny, &(bta_hf_client_cb_arr.serv_handle), bta_hf_client_mgmt_cback,
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT, RfcommCfgInfo{});

  log::verbose("started rfcomm server with handle {}", bta_hf_client_cb_arr.serv_handle);

@@ -240,10 +240,10 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) {
    return;
  }

  if (RFCOMM_CreateConnectionWithSecurity(UUID_SERVCLASS_HF_HANDSFREE, client_cb->peer_scn, false,
                                          BTA_HF_CLIENT_MTU, client_cb->peer_addr,
                                          &(client_cb->conn_handle), bta_hf_client_mgmt_cback,
                                          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT) == PORT_SUCCESS) {
  if (RFCOMM_CreateConnectionWithSecurity(
              UUID_SERVCLASS_HF_HANDSFREE, client_cb->peer_scn, false, BTA_HF_CLIENT_MTU,
              client_cb->peer_addr, &(client_cb->conn_handle), bta_hf_client_mgmt_cback,
              BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT, RfcommCfgInfo{}) == PORT_SUCCESS) {
    bta_hf_client_setup_port(client_cb->conn_handle);
    log::verbose("bta_hf_client_rfc_do_open : conn_handle = {}", client_cb->conn_handle);
  } else {
+27 −5
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@
#include "internal_include/bt_target.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/l2cap_types.h"
#include "stack/include/port_api.h"
#include "stack/include/rfcdefs.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
@@ -331,6 +332,16 @@ typedef struct {
  tBTA_JV_STATUS status;   /* Whether the operation succeeded or failed. */
  uint32_t handle;         /* The connection handle */
  RawAddress rem_bda;      /* The peer address */
  uint16_t rx_mtu;         /* The receive (local) L2CAP MTU */
  uint16_t tx_mtu;         /* The transmit (remote) L2CAP MTU */
  uint16_t local_credit;   /* The local RFCOMM credit */
  uint16_t remote_credit;  /* The remote RFCOMM credit */
  uint16_t local_cid;      /* The local L2CAP CID */
  uint16_t remote_cid;     /* The remote L2CAP CID */
  uint16_t dlci;           /* DLCI */
  uint16_t max_frame_size; /* The max frame size for RFCOMM */
  uint16_t acl_handle;     /* The ACL handle */
  bool mux_initiator;      /* Is the initiator of the RFCOMM multiplexer control channel */
} tBTA_JV_RFCOMM_OPEN;
/* data associated with BTA_JV_RFCOMM_SRV_OPEN_EVT */
typedef struct {
@@ -338,6 +349,16 @@ typedef struct {
  uint32_t handle;            /* The connection handle */
  uint32_t new_listen_handle; /* The new listen handle */
  RawAddress rem_bda;         /* The peer address */
  uint16_t rx_mtu;            /* The receive (local) L2CAP MTU */
  uint16_t tx_mtu;            /* The transmit (remote) L2CAP MTU */
  uint16_t local_credit;      /* The local RFCOMM credit */
  uint16_t remote_credit;     /* The remote RFCOMM credit */
  uint16_t local_cid;         /* The local L2CAP CID */
  uint16_t remote_cid;        /* The remote L2CAP CID */
  uint16_t dlci;              /* DLCI */
  uint16_t max_frame_size;    /* The max frame size for RFCOMM */
  uint16_t acl_handle;        /* The ACL handle */
  bool mux_initiator;         /* Is the initiator of the RFCOMM multiplexer control channel */
} tBTA_JV_RFCOMM_SRV_OPEN;

/* data associated with BTA_JV_RFCOMM_CLOSE_EVT */
@@ -677,7 +698,7 @@ tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg, u
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, uint8_t remote_scn,
                                   const RawAddress& peer_bd_addr, tBTA_JV_RFCOMM_CBACK* p_cback,
                                   uint32_t rfcomm_slot_id);
                                   uint32_t rfcomm_slot_id, RfcommCfgInfo cfg);

/*******************************************************************************
 *
@@ -707,7 +728,8 @@ tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id);
 *
 ******************************************************************************/
tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, uint8_t local_scn, uint8_t max_session,
                                       tBTA_JV_RFCOMM_CBACK* p_cback, uint32_t rfcomm_slot_id);
                                       tBTA_JV_RFCOMM_CBACK* p_cback, uint32_t rfcomm_slot_id,
                                       RfcommCfgInfo cfg);

/*******************************************************************************
 *
Loading