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

Commit 7d58658c authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Remove sec_id related code in RFCOMM

That's for BTM security registration.  RFCOMM is not using it.  So far
only L2cap channel (GAP_ConnOpen) is using dynamic sec_id.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I4c2bc679d7f311bb240179866839a9ca86df0c00
parent ae73a197
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -260,7 +260,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_ag_sec_id[i],
          bta_ag_mgmt_cback_tbl[management_callback_index],
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
      if (status == PORT_SUCCESS) {
        bta_ag_setup_port(p_scb, p_scb->serv_handle[i]);
@@ -335,7 +335,6 @@ void bta_ag_rfc_do_open(tBTA_AG_SCB* p_scb, const tBTA_AG_DATA& data) {
      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_sec_id[p_scb->conn_service],
      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
  APPL_TRACE_DEBUG(
      "%s: p_scb=0x%08x, conn_handle=%d, mgmt_cback_index=%d,"
+2 −3
Original line number Diff line number Diff line
@@ -185,8 +185,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, BTM_SEC_SERVICE_HF_HANDSFREE,
      BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);
      bta_hf_client_mgmt_cback, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT);

  APPL_TRACE_DEBUG("%s: started rfcomm server with handle %d", __func__,
                   bta_hf_client_cb_arr.serv_handle);
@@ -243,7 +242,7 @@ void bta_hf_client_rfc_do_open(tBTA_HF_CLIENT_DATA* p_data) {
  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,
          bta_hf_client_mgmt_cback,
          BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT) == PORT_SUCCESS) {
    bta_hf_client_setup_port(client_cb->conn_handle);
    APPL_TRACE_DEBUG("bta_hf_client_rfc_do_open : conn_handle = %d",
+4 −34
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ static void bta_jv_free_sec_id(uint8_t* p_sec_id) {
  uint8_t sec_id = *p_sec_id;
  *p_sec_id = 0;
  if (sec_id >= BTA_JV_FIRST_SERVICE_ID && sec_id <= BTA_JV_LAST_SERVICE_ID) {
    BTM_SecClrService(sec_id);
    bta_jv_cb.sec_id[sec_id - BTA_JV_FIRST_SERVICE_ID] = 0;
  }
}
@@ -293,14 +294,12 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
    if (p_cb->curr_sess == 0) {
      RFCOMM_ClearSecurityRecord(p_cb->scn);
      p_cb->scn = 0;
      bta_jv_free_sec_id(&p_cb->sec_id);
      p_cb->p_cback = NULL;
      p_cb->handle = 0;
      p_cb->curr_sess = -1;
    }
    if (remove_server) {
      RFCOMM_ClearSecurityRecord(p_cb->scn);
      bta_jv_free_sec_id(&p_cb->sec_id);
    }
  }
  return status;
@@ -1272,22 +1271,13 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
  uint32_t event_mask = BTA_JV_RFC_EV_MASK;
  tPORT_STATE port_state;

  uint8_t sec_id = bta_jv_alloc_sec_id();

  tBTA_JV_RFCOMM_CL_INIT evt_data;
  memset(&evt_data, 0, sizeof(evt_data));
  evt_data.sec_id = sec_id;
  evt_data.status = BTA_JV_SUCCESS;
  if (0 == sec_id) {
    evt_data.status = BTA_JV_FAILURE;
    LOG(ERROR) << __func__ << ": sec_id=" << +sec_id
               << " is zero, remote_scn:" << +remote_scn;
  }

  if (evt_data.status == BTA_JV_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,
          peer_bd_addr, &handle, bta_jv_port_mgmt_cl_cback,
          sec_mask) != PORT_SUCCESS) {
    LOG(ERROR) << __func__ << ": RFCOMM_CreateConnection failed";
    evt_data.status = BTA_JV_FAILURE;
@@ -1297,7 +1287,6 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
    tBTA_JV_RFC_CB* p_cb = bta_jv_alloc_rfc_cb(handle, &p_pcb);
    if (p_cb) {
      p_cb->p_cback = p_cback;
      p_cb->sec_id = sec_id;
      p_cb->scn = 0;
      p_pcb->state = BTA_JV_ST_CL_OPENING;
      p_pcb->rfcomm_slot_id = rfcomm_slot_id;
@@ -1323,7 +1312,6 @@ void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn,
  bta_jv.rfc_cl_init = evt_data;
  p_cback(BTA_JV_RFCOMM_CL_INIT_EVT, &bta_jv, rfcomm_slot_id);
  if (bta_jv.rfc_cl_init.status == BTA_JV_FAILURE) {
    if (sec_id) bta_jv_free_sec_id(&sec_id);
    RFCOMM_ClearSecurityRecord(remote_scn);
    if (handle) RFCOMM_RemoveConnection(handle);
  }
@@ -1366,8 +1354,6 @@ void bta_jv_rfcomm_close(uint32_t handle, uint32_t rfcomm_slot_id) {

  if (!find_rfc_pcb(rfcomm_slot_id, &p_cb, &p_pcb)) return;
  bta_jv_free_rfc_cb(p_cb, p_pcb);
  VLOG(2) << __func__ << ": sec id in use=" << get_sec_id_used()
          << ", rfc_cb in use=" << get_rfc_cb_used();
}

/*******************************************************************************
@@ -1576,28 +1562,17 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
  uint16_t handle = 0;
  uint32_t event_mask = BTA_JV_RFC_EV_MASK;
  tPORT_STATE port_state;
  uint8_t sec_id = 0;
  tBTA_JV_RFC_CB* p_cb = NULL;
  tBTA_JV_PCB* p_pcb;
  tBTA_JV_RFCOMM_START evt_data;

  memset(&evt_data, 0, sizeof(evt_data));
  evt_data.status = BTA_JV_FAILURE;
  VLOG(2) << __func__ << ": sec id in use=" << get_sec_id_used()
          << ", rfc_cb in use=" << get_rfc_cb_used();

  do {
    sec_id = bta_jv_alloc_sec_id();

    if (0 == sec_id) {
      LOG(ERROR) << __func__ << ": run out of sec_id";
      break;
    }

    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) {
            0, local_scn, true, BTA_JV_DEF_RFC_MTU, RawAddress::kAny, &handle,
            bta_jv_port_mgmt_sr_cback, sec_mask) != PORT_SUCCESS) {
      LOG(ERROR) << __func__ << ": RFCOMM_CreateConnection failed";
      break;
    }
@@ -1610,13 +1585,11 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,

    p_cb->max_sess = max_session;
    p_cb->p_cback = p_cback;
    p_cb->sec_id = sec_id;
    p_cb->scn = local_scn;
    p_pcb->state = BTA_JV_ST_SR_LISTEN;
    p_pcb->rfcomm_slot_id = rfcomm_slot_id;
    evt_data.status = BTA_JV_SUCCESS;
    evt_data.handle = p_cb->handle;
    evt_data.sec_id = sec_id;
    evt_data.use_co = true;

    PORT_ClearKeepHandleFlag(handle);
@@ -1635,7 +1608,6 @@ void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn,
  if (bta_jv.rfc_start.status == BTA_JV_SUCCESS) {
    PORT_SetDataCOCallback(handle, bta_jv_port_data_co_cback);
  } else {
    if (sec_id) bta_jv_free_sec_id(&sec_id);
    RFCOMM_ClearSecurityRecord(local_scn);
    if (handle) RFCOMM_RemoveConnection(handle);
  }
@@ -1656,8 +1628,6 @@ void bta_jv_rfcomm_stop_server(uint32_t handle, uint32_t rfcomm_slot_id) {
  VLOG(2) << __func__ << ": p_pcb=" << p_pcb
          << ", p_pcb->port_handle=" << p_pcb->port_handle;
  bta_jv_free_rfc_cb(p_cb, p_pcb);
  VLOG(2) << __func__ << ": sec id in use=" << get_sec_id_used()
          << ", rfc_cb in use=" << get_rfc_cb_used();
}

/* write data to an RFCOMM connection */
+6 −4
Original line number Diff line number Diff line
@@ -181,10 +181,12 @@ 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_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,
                                               uint16_t sec_mask);

extern void RFCOMM_ClearSecurityRecord(uint32_t scn);

+4 −2
Original line number Diff line number Diff line
@@ -78,14 +78,16 @@ int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn,
                                        const RawAddress& bd_addr,
                                        uint16_t* p_handle,
                                        tPORT_CALLBACK* p_mgmt_cb,
                                        uint8_t service_id, uint16_t sec_mask) {
                                        uint16_t sec_mask) {
  rfcomm_security_records[scn] = sec_mask;

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

extern void RFCOMM_ClearSecurityRecord(uint32_t scn) {}
extern void RFCOMM_ClearSecurityRecord(uint32_t scn) {
  rfcomm_security_records.erase(scn);
}

/*******************************************************************************
 *