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

Commit 6fa9d175 authored by Zach Johnson's avatar Zach Johnson
Browse files

Add RFCOMM_CreateConnectionWithSecurity

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I97d1635051556b65022e7d0ee78978c905b6a2dc
parent 59053d12
Loading
Loading
Loading
Loading
+9 −13
Original line number Diff line number Diff line
@@ -248,9 +248,6 @@ void bta_ag_start_servers(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK services) {
  for (int i = 0; i < BTA_AG_NUM_IDX && services != 0; i++, services >>= 1) {
    /* if service is set in mask */
    if (services & 1) {
      BTM_SetSecurityLevel(false, "", bta_ag_sec_id[i], p_scb->serv_sec_mask,
                           BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM,
                           bta_ag_cb.profile[i].scn);
      int management_callback_index = bta_ag_scb_to_idx(p_scb) - 1;
      CHECK_GE(management_callback_index, 0)
          << "invalid callback index, services=" << loghex(services)
@@ -260,16 +257,18 @@ void bta_ag_start_servers(tBTA_AG_SCB* p_scb, tBTA_SERVICE_MASK services) {
                                sizeof(bta_ag_mgmt_cback_tbl[0])))
          << "callback index out of bound, services=" << loghex(services)
          << ", bd_addr" << p_scb->peer_addr;
      int status = RFCOMM_CreateConnection(
      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_ag_mgmt_cback_tbl[management_callback_index], bta_ag_sec_id[i],
          p_scb->serv_sec_mask);
      if (status == PORT_SUCCESS) {
        bta_ag_setup_port(p_scb, p_scb->serv_handle[i]);
      } else {
        /* TODO: CR#137125 to handle to error properly */
        LOG(ERROR) << __func__ << ": RFCOMM_CreateConnection ERROR " << status
                   << ", p_scb=" << p_scb << ", services=" << loghex(services)
        LOG(ERROR) << __func__ << ": RFCOMM_CreateConnectionWithSecurity ERROR "
                   << status << ", p_scb=" << p_scb
                   << ", services=" << loghex(services)
                   << ", mgmt_cback_index=" << management_callback_index;
      }
      APPL_TRACE_DEBUG("%s: p_scb=0x%08x, services=0x%04x, mgmt_cback_index=%d",
@@ -331,15 +330,12 @@ bool bta_ag_is_server_closed(tBTA_AG_SCB* p_scb) {
 *
 ******************************************************************************/
void bta_ag_rfc_do_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
  BTM_SetSecurityLevel(true, "", bta_ag_sec_id[p_scb->conn_service],
                       p_scb->cli_sec_mask, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM,
                       p_scb->peer_scn);

  int management_callback_index = bta_ag_scb_to_idx(p_scb) - 1;
  int status = RFCOMM_CreateConnection(
  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_ag_mgmt_cback_tbl[management_callback_index],
      bta_ag_sec_id[p_scb->conn_service], p_scb->cli_sec_mask);
  APPL_TRACE_DEBUG(
      "%s: p_scb=0x%08x, conn_handle=%d, mgmt_cback_index=%d,"
      " status=%d",
+8 −13
Original line number Diff line number Diff line
@@ -182,14 +182,11 @@ void bta_hf_client_start_server() {
    return;
  }

  BTM_SetSecurityLevel(false, "", BTM_SEC_SERVICE_HF_HANDSFREE,
                       bta_hf_client_cb_arr.serv_sec_mask, BT_PSM_RFCOMM,
                       BTM_SEC_PROTO_RFCOMM, bta_hf_client_cb_arr.scn);

  port_status = RFCOMM_CreateConnection(
  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_hf_client_mgmt_cback, BTM_SEC_SERVICE_HF_HANDSFREE,
      bta_hf_client_cb_arr.serv_sec_mask);

  APPL_TRACE_DEBUG("%s: started rfcomm server with handle %d", __func__,
                   bta_hf_client_cb_arr.serv_handle);
@@ -243,13 +240,11 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) {
    return;
  }

  BTM_SetSecurityLevel(true, "", BTM_SEC_SERVICE_HF_HANDSFREE,
                       client_cb->cli_sec_mask, BT_PSM_RFCOMM,
                       BTM_SEC_PROTO_RFCOMM, client_cb->peer_scn);
  if (RFCOMM_CreateConnection(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) == 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, BTM_SEC_SERVICE_HF_HANDSFREE,
          client_cb->cli_sec_mask) == PORT_SUCCESS) {
    bta_hf_client_setup_port(client_cb->conn_handle);
    APPL_TRACE_DEBUG("bta_hf_client_rfc_do_open : conn_handle = %d",
                     client_cb->conn_handle);
+11 −14
Original line number Diff line number Diff line
@@ -1330,19 +1330,17 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  memset(&evt_data, 0, sizeof(evt_data));
  evt_data.sec_id = sec_id;
  evt_data.status = BTA_JV_SUCCESS;
  if (0 == sec_id ||
      !BTM_SetSecurityLevel(true, "", sec_id, sec_mask, BT_PSM_RFCOMM,
                            BTM_SEC_PROTO_RFCOMM, remote_scn)) {
  if (0 == sec_id) {
    evt_data.status = BTA_JV_FAILURE;
    LOG(ERROR) << __func__ << ": sec_id=" << +sec_id
               << " is zero or BTM_SetSecurityLevel failed, remote_scn:"
               << +remote_scn;
               << " is zero, remote_scn:" << +remote_scn;
  }

  if (evt_data.status == BTA_JV_SUCCESS &&
      RFCOMM_CreateConnection(UUID_SERVCLASS_SERIAL_PORT, remote_scn, false,
                              BTA_JV_DEF_RFC_MTU, peer_bd_addr, &handle,
                              bta_jv_port_mgmt_cl_cback) != PORT_SUCCESS) {
      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_id,
          sec_mask) != PORT_SUCCESS) {
    LOG(ERROR) << __func__ << ": RFCOMM_CreateConnection failed";
    evt_data.status = BTA_JV_FAILURE;
  }
@@ -1642,16 +1640,15 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  do {
    sec_id = bta_jv_alloc_sec_id();

    if (0 == sec_id ||
        !BTM_SetSecurityLevel(false, "JV PORT", sec_id, sec_mask, BT_PSM_RFCOMM,
                              BTM_SEC_PROTO_RFCOMM, local_scn)) {
    if (0 == sec_id) {
      LOG(ERROR) << __func__ << ": run out of sec_id";
      break;
    }

    if (RFCOMM_CreateConnection(sec_id, local_scn, true, BTA_JV_DEF_RFC_MTU,
                                RawAddress::kAny, &handle,
                                bta_jv_port_mgmt_sr_cback) != PORT_SUCCESS) {
    if (RFCOMM_CreateConnectionWithSecurity(
            sec_id, local_scn, true, BTA_JV_DEF_RFC_MTU, RawAddress::kAny,
            &handle, bta_jv_port_mgmt_sr_cback, sec_id,
            sec_mask) != PORT_SUCCESS) {
      LOG(ERROR) << __func__ << ": RFCOMM_CreateConnection failed";
      break;
    }
+5 −0
Original line number Diff line number Diff line
@@ -181,6 +181,11 @@ typedef void(tPORT_CALLBACK)(uint32_t code, uint16_t port_handle);
 * (scn * 2 + 1) dlci.
 *
 ******************************************************************************/
extern int RFCOMM_CreateConnectionWithSecurity(
    uint16_t uuid, uint8_t scn, bool is_server, uint16_t mtu,
    const RawAddress& bd_addr, uint16_t* p_handle, tPORT_CALLBACK* p_mgmt_cb,
    uint8_t service_id, uint16_t sec_mask);

extern int RFCOMM_CreateConnection(uint16_t uuid, uint8_t scn, bool is_server,
                                   uint16_t mtu, const RawAddress& bd_addr,
                                   uint16_t* p_handle,
+18 −0
Original line number Diff line number Diff line
@@ -38,6 +38,9 @@
#include "rfcdefs.h"
#include "sdp_api.h"

#include "btm_sec.h"
#include "stack/include/btm_api_types.h"

#define error(fmt, ...) \
  LOG_ERROR("## ERROR : %s: " fmt "##", __func__, ##__VA_ARGS__)

@@ -70,6 +73,21 @@ static const char* result_code_strings[] = {"Success",
                                            "Invalid SCN",
                                            "Unknown result code"};

int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn,
                                        bool is_server, uint16_t mtu,
                                        const RawAddress& bd_addr,
                                        uint16_t* p_handle,
                                        tPORT_CALLBACK* p_mgmt_cb,
                                        uint8_t service_id, uint16_t sec_mask) {
  if (!BTM_SetSecurityLevel(!is_server, "", service_id, sec_mask, BT_PSM_RFCOMM,
                            BTM_SEC_PROTO_RFCOMM, scn)) {
    return PORT_NO_RESOURCES;
  }

  return RFCOMM_CreateConnection(uuid, scn, is_server, mtu, bd_addr, p_handle,
                                 p_mgmt_cb);
}

/*******************************************************************************
 *
 * Function         RFCOMM_CreateConnection
Loading