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

Commit 3d9c5c5f authored by Liang Li's avatar Liang Li
Browse files

Notify offloaded RFCOMM socket channel info to socket hal

Flag: com.android.bluetooth.flags.socket_settings_api
Bug: 342012881
Bug: 374358112
Test: m com.android.btservices
Change-Id: I09148ac7544876110c9cd56f0f9ca7bd9de43c4b
parent d06faff0
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -331,6 +331,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 +348,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 */
+21 −0
Original line number Diff line number Diff line
@@ -1441,6 +1441,16 @@ static void bta_jv_port_mgmt_cl_cback(const tPORT_RESULT code, uint16_t port_han
                            .rem_bda = rem_bda,
                    },
    };
    if (com::android::bluetooth::flags::socket_settings_api()) {
      if (PORT_GetChannelInfo(port_handle, &evt_data.rfc_open.rx_mtu, &evt_data.rfc_open.tx_mtu,
                              &evt_data.rfc_open.local_credit, &evt_data.rfc_open.remote_credit,
                              &evt_data.rfc_open.local_cid, &evt_data.rfc_open.remote_cid,
                              &evt_data.rfc_open.dlci, &evt_data.rfc_open.max_frame_size,
                              &evt_data.rfc_open.acl_handle,
                              &evt_data.rfc_open.mux_initiator) != PORT_SUCCESS) {
        log::warn("Unable to get RFCOMM channel info peer:{} handle:{}", rem_bda, port_handle);
      }
    }
    p_pcb->state = BTA_JV_ST_CL_OPEN;
    p_cb->p_cback(BTA_JV_RFCOMM_OPEN_EVT, &evt_data, p_pcb->rfcomm_slot_id);
  } else {
@@ -1648,6 +1658,17 @@ static void bta_jv_port_mgmt_sr_cback(const tPORT_RESULT code, uint16_t port_han
    evt_data.rfc_srv_open.handle = p_pcb->handle;
    evt_data.rfc_srv_open.status = tBTA_JV_STATUS::SUCCESS;
    evt_data.rfc_srv_open.rem_bda = rem_bda;
    if (com::android::bluetooth::flags::socket_settings_api()) {
      if (PORT_GetChannelInfo(port_handle, &evt_data.rfc_srv_open.rx_mtu,
                              &evt_data.rfc_srv_open.tx_mtu, &evt_data.rfc_srv_open.local_credit,
                              &evt_data.rfc_srv_open.remote_credit,
                              &evt_data.rfc_srv_open.local_cid, &evt_data.rfc_srv_open.remote_cid,
                              &evt_data.rfc_srv_open.dlci, &evt_data.rfc_srv_open.max_frame_size,
                              &evt_data.rfc_srv_open.acl_handle,
                              &evt_data.rfc_srv_open.mux_initiator) != PORT_SUCCESS) {
        log::warn("Unable to get RFCOMM channel info peer:{} handle:{}", rem_bda, port_handle);
      }
    }
    tBTA_JV_PCB* p_pcb_new_listen = bta_jv_add_rfc_port(p_cb, p_pcb);
    if (p_pcb_new_listen) {
      evt_data.rfc_srv_open.new_listen_handle = p_pcb_new_listen->handle;
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ void on_l2cap_psm_assigned(int id, int psm);
bt_status_t btsock_l2cap_disconnect(const RawAddress* bd_addr);
bt_status_t btsock_l2cap_get_l2cap_local_cid(bluetooth::Uuid& conn_uuid, uint16_t* cid);
bt_status_t btsock_l2cap_get_l2cap_remote_cid(bluetooth::Uuid& conn_uuid, uint16_t* cid);
bool btsock_l2cap_in_use(uint64_t socket_id);
void on_btsocket_l2cap_opened_complete(uint64_t socket_id, bool success);
void on_btsocket_l2cap_close(uint64_t socket_id);

+3 −0
Original line number Diff line number Diff line
@@ -47,5 +47,8 @@ bt_status_t btsock_rfc_connect(const RawAddress* bd_addr, const bluetooth::Uuid*
                               int max_rx_packet_size);
void btsock_rfc_signaled(int fd, int flags, uint32_t user_id);
bt_status_t btsock_rfc_disconnect(const RawAddress* bd_addr);
bool btsock_rfc_in_use(uint64_t socket_id);
void on_btsocket_rfc_opened_complete(uint64_t socket_id, bool success);
void on_btsocket_rfc_close(uint64_t socket_id);

#endif
+17 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include "btif/include/btif_sock_hal.h"

#include "btif/include/btif_sock_l2cap.h"
#include "btif/include/btif_sock_rfc.h"
#include "lpp/lpp_offload_interface.h"
#include "main/shim/entry.h"
#include "stack/include/main_thread.h"
@@ -29,13 +30,26 @@ class BtifSocketHalCallback : public hal::SocketHalCallback {
public:
  void SocketOpenedComplete(uint64_t socket_id, hal::SocketStatus status) const override {
    log::info("socket_id: {}, status: {}", socket_id, static_cast<int>(status));
    if (btsock_l2cap_in_use(socket_id)) {
      do_in_main_thread(base::BindOnce(on_btsocket_l2cap_opened_complete, socket_id,
                                       (status == hal::SocketStatus::SUCCESS)));
    } else if (btsock_rfc_in_use(socket_id)) {
      do_in_main_thread(base::BindOnce(on_btsocket_rfc_opened_complete, socket_id,
                                       (status == hal::SocketStatus::SUCCESS)));
    } else {
      log::error("Unable to find socket with socket_id:{}", socket_id);
    }
  }

  void SocketClose(uint64_t socket_id) const override {
    log::info("socket_id: {}", socket_id);
    if (btsock_l2cap_in_use(socket_id)) {
      do_in_main_thread(base::BindOnce(on_btsocket_l2cap_close, socket_id));
    } else if (btsock_rfc_in_use(socket_id)) {
      do_in_main_thread(base::BindOnce(on_btsocket_rfc_close, socket_id));
    } else {
      log::error("Unable to find socket with socket_id:{}", socket_id);
    }
  }
};

Loading