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

Commit fa2d5f5c authored by Rahul Arya's avatar Rahul Arya Committed by Cherrypicker Worker
Browse files

Remove rfcomm_security_records map, store records in tBTA_JV_PCB instead.

The map is globally keyed by SCN, which causes issues when SCNs are
reused (server vs client, or different device connections). tBTA_JV_PCBs
are distinct for every (port, device, server/client) tuple, and so fit
this use-case.

Tag: #stability
Bug: 230553684
Test: Manual (see bug)
Change-Id: Iae24f07fd5d19f66126abfe61052fab96d1b1bdf
(cherry picked from commit 34e42ab4)
Merged-In: Iae24f07fd5d19f66126abfe61052fab96d1b1bdf
parent c042dfe2
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -271,7 +271,6 @@ void bta_ag_del_records(tBTA_AG_SCB* p_scb) {
        bta_ag_cb.profile[i].sdp_handle = 0;
      }
      BTM_FreeSCN(bta_ag_cb.profile[i].scn);
      RFCOMM_ClearSecurityRecord(bta_ag_cb.profile[i].scn);
      bta_sys_remove_uuid(bta_ag_uuid[i]);
    }
  }
+0 −1
Original line number Diff line number Diff line
@@ -204,7 +204,6 @@ void bta_hf_client_del_record(tBTA_HF_CLIENT_CB_ARR* client_cb) {
    SDP_DeleteRecord(client_cb->sdp_handle);
    client_cb->sdp_handle = 0;
    BTM_FreeSCN(client_cb->scn);
    RFCOMM_ClearSecurityRecord(client_cb->scn);
    bta_sys_remove_uuid(UUID_SERVCLASS_HF_HANDSFREE);
  }
}
+11 −10
Original line number Diff line number Diff line
@@ -317,15 +317,11 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB* p_cb,
    p_pcb->handle = 0;
    p_cb->curr_sess--;
    if (p_cb->curr_sess == 0) {
      RFCOMM_ClearSecurityRecord(p_cb->scn);
      p_cb->scn = 0;
      p_cb->p_cback = NULL;
      p_cb->handle = 0;
      p_cb->curr_sess = -1;
    }
    if (remove_server) {
      RFCOMM_ClearSecurityRecord(p_cb->scn);
    }
  }
  return status;
}
@@ -1356,7 +1352,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) {
    RFCOMM_ClearSecurityRecord(remote_scn);
    if (handle) RFCOMM_RemoveConnection(handle);
  }
}
@@ -1532,6 +1527,7 @@ static tBTA_JV_PCB* bta_jv_add_rfc_port(tBTA_JV_RFC_CB* p_cb,
  tPORT_STATE port_state;
  uint32_t event_mask = BTA_JV_RFC_EV_MASK;
  tBTA_JV_PCB* p_pcb = NULL;
  tBTA_SEC sec_mask;
  if (p_cb->max_sess > 1) {
    for (i = 0; i < p_cb->max_sess; i++) {
      if (p_cb->rfc_hdl[i] != 0) {
@@ -1562,10 +1558,16 @@ static tBTA_JV_PCB* bta_jv_add_rfc_port(tBTA_JV_RFC_CB* p_cb,
            << ", si=" << si;
    if (used < p_cb->max_sess && listen == 1 && si) {
      si--;
      if (RFCOMM_CreateConnection(p_cb->sec_id, p_cb->scn, true,
                                  BTA_JV_DEF_RFC_MTU, RawAddress::kAny,
                                  &(p_cb->rfc_hdl[si]),
                                  bta_jv_port_mgmt_sr_cback) == PORT_SUCCESS) {
      if (PORT_GetSecurityMask(p_pcb_open->port_handle, &sec_mask) !=
          PORT_SUCCESS) {
        LOG(ERROR) << __func__
                   << ": RFCOMM_CreateConnection failed: invalid port_handle";
      }

      if (RFCOMM_CreateConnectionWithSecurity(
              p_cb->sec_id, p_cb->scn, true, BTA_JV_DEF_RFC_MTU,
              RawAddress::kAny, &(p_cb->rfc_hdl[si]), bta_jv_port_mgmt_sr_cback,
              sec_mask) == PORT_SUCCESS) {
        p_cb->curr_sess++;
        p_pcb = &bta_jv_cb.port_cb[p_cb->rfc_hdl[si] - 1];
        p_pcb->state = BTA_JV_ST_SR_LISTEN;
@@ -1652,7 +1654,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 {
    RFCOMM_ClearSecurityRecord(local_scn);
    if (handle) RFCOMM_RemoveConnection(handle);
  }
}
+1 −0
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ inline std::string security_mode_text(const tSECURITY_MODE& security_mode) {
  }
}

/* BTM_SEC security masks */
enum : uint16_t {
  /* Nothing required */
  BTM_SEC_NONE = 0x0000,
+11 −7
Original line number Diff line number Diff line
@@ -191,13 +191,6 @@ extern int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn,
                                               tPORT_CALLBACK* p_mgmt_cb,
                                               uint16_t sec_mask);

extern void RFCOMM_ClearSecurityRecord(uint32_t scn);

extern int RFCOMM_CreateConnection(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);

/*******************************************************************************
 *
 * Function         RFCOMM_RemoveConnection
@@ -434,4 +427,15 @@ extern uint8_t PORT_SetTraceLevel(uint8_t new_level);
 ******************************************************************************/
extern const char* PORT_GetResultString(const uint8_t result_code);

/*******************************************************************************
 *
 * Function         PORT_GetSecurityMask
 *
 * Description      This function returns the security bitmask for a port.
 *
 * Returns          the security bitmask.
 *
 ******************************************************************************/
extern int PORT_GetSecurityMask(uint16_t handle, uint16_t* sec_mask);

#endif /* PORT_API_H */
Loading