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

Commit 8a0504ed authored by Liang Li's avatar Liang Li
Browse files

Fix app_fd and mtu for offload RFCOMM socket

In on_srv_rfc_connect_offload it should not assign INVALID_FD to app_fd, which would block the socket from opening.
Instead it assigns INVALID_FD to app_fd in on_btsocket_rfc_opened_complete after sending the app connect signal.

Updated the selection of local mtu for offload socket by skipping the guardrail of L2CAP_MTU_SIZE in non-offload stack.

Also removed several redundant function calls in on_srv_rfc_connect_offload and on_btsocket_rfc_opened_complete.

Flag: com.android.bluetooth.flags.socket_settings_api
Bug: 342012881
Bug: 374358112
Test: m com.android.btservices && OEM device tests
Change-Id: Ie71ee75c3e05f8531f11b6b86871d0be2474db17
parent 90cef83f
Loading
Loading
Loading
Loading
+6 −20
Original line number Diff line number Diff line
@@ -1536,16 +1536,9 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn, const RawAddre
            0);
  }

  uint16_t mtu = BTA_JV_DEF_RFC_MTU;
  if (com::android::bluetooth::flags::socket_settings_api()) {
    if (cfg.rx_mtu_present) {
      mtu = cfg.rx_mtu;
    }
  }

  if (RFCOMM_CreateConnectionWithSecurity(UUID_SERVCLASS_SERIAL_PORT, remote_scn, false, mtu,
                                          peer_bd_addr, &handle, bta_jv_port_mgmt_cl_cback,
                                          sec_mask, cfg) != PORT_SUCCESS) {
  if (RFCOMM_CreateConnectionWithSecurity(
              UUID_SERVCLASS_SERIAL_PORT, remote_scn, false, BTA_JV_DEF_RFC_MTU, peer_bd_addr,
              &handle, bta_jv_port_mgmt_cl_cback, sec_mask, cfg) != PORT_SUCCESS) {
    log::error("RFCOMM_CreateConnection failed");
    bta_jv.rfc_cl_init.status = tBTA_JV_STATUS::FAILURE;
  } else {
@@ -1863,17 +1856,10 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn, uint8_t ma
  memset(&evt_data, 0, sizeof(evt_data));
  evt_data.status = tBTA_JV_STATUS::FAILURE;

  uint16_t mtu = BTA_JV_DEF_RFC_MTU;
  if (com::android::bluetooth::flags::socket_settings_api()) {
    if (cfg.rx_mtu_present) {
      mtu = cfg.rx_mtu;
    }
  }

  do {
    if (RFCOMM_CreateConnectionWithSecurity(0, local_scn, true, mtu, RawAddress::kAny, &handle,
                                            bta_jv_port_mgmt_sr_cback, sec_mask,
                                            cfg) != PORT_SUCCESS) {
    if (RFCOMM_CreateConnectionWithSecurity(0, local_scn, true, BTA_JV_DEF_RFC_MTU,
                                            RawAddress::kAny, &handle, bta_jv_port_mgmt_sr_cback,
                                            sec_mask, cfg) != PORT_SUCCESS) {
      log::error("RFCOMM_CreateConnection failed");
      break;
    }
+1 −7
Original line number Diff line number Diff line
@@ -683,8 +683,6 @@ static uint32_t on_srv_rfc_connect_offload(tBTA_JV_RFCOMM_SRV_OPEN* p_open, uint

  // Start monitoring the socket.
  btsock_thread_add_fd(pth, srv_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_EXCEPTION, srv_rs->id);
  btsock_thread_add_fd(pth, accept_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, accept_rs->id);
  accept_rs->app_fd = INVALID_FD;  // Ownership of the application fd has been transferred.
  // start monitoring the socketpair to get call back when app is accepting on server socket
  btsock_thread_add_fd(pth, srv_rs->fd, BTSOCK_RFCOMM, SOCK_THREAD_FD_RD, srv_rs->id);
  return srv_rs->id;
@@ -847,12 +845,8 @@ void on_btsocket_rfc_opened_complete(uint64_t socket_id, bool success) {
    // The fd is closed after sent to app in send_app_connect_signal()
    slot->app_fd = -1;
  } else {
    if (!send_app_scn(slot)) {
      log::error("Unable to send rfcomm socket to application socket_id: {}", slot->id);
      return;
    }
    if (!send_app_connect_signal(slot->fd, &slot->addr, slot->scn, 0, -1, slot->socket_id)) {
      log::error("Unable to connect l2cap socket to application socket_id: {}", slot->id);
      log::error("Unable to connect rfcomm socket to application socket_id: {}", slot->id);
      return;
    }

+10 −6
Original line number Diff line number Diff line
@@ -189,12 +189,6 @@ int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn, bool is_serv
  p_port->scn = scn;
  p_port->ev_mask = 0;

  // Set the optional configuration for future use when the server or client negotiates the
  // parameters with the peer device.
  if (com::android::bluetooth::flags::socket_settings_api()) {
    p_port->rfc_cfg_info = cfg;
  }

  // Find MTU
  // If the MTU is not specified (0), keep MTU decision until the PN frame has
  // to be send at that time connection should be established and we will know
@@ -206,6 +200,16 @@ int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn, bool is_serv
    p_port->mtu = rfcomm_mtu;
  }

  // Set the optional configuration for future use when the server or client negotiates the
  // parameters with the peer device.
  if (com::android::bluetooth::flags::socket_settings_api()) {
    p_port->rfc_cfg_info = cfg;
    // Update the local mtu with the optional configuration if set by the app
    if (p_port->rfc_cfg_info.rx_mtu_present) {
      p_port->mtu = p_port->rfc_cfg_info.rx_mtu;
    }
  }

  // Other states
  // server doesn't need to release port when closing
  if (is_server) {
+0 −7
Original line number Diff line number Diff line
@@ -305,13 +305,6 @@ void PORT_ParNegInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint8_t cl, uin

  p_port->bd_addr = p_mcb->bd_addr;

  /* Update the local mtu with the optional configuration if set by the app */
  if (com::android::bluetooth::flags::socket_settings_api()) {
    if (p_port->rfc_cfg_info.rx_mtu_present) {
      p_port->mtu = p_port->rfc_cfg_info.rx_mtu;
    }
  }

  /* Connection is up and we know local and remote features, select MTU */
  port_select_mtu(p_port);