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

Commit 21282e3b authored by Hansong Zhang's avatar Hansong Zhang
Browse files

Clear RFCOMM security when done

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I8aabfbc439dfc30b75d84c247b898d8d910475c1
parent 0ca6a08e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -273,7 +273,7 @@ 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);
      BTM_SecClrService(bta_ag_sec_id[i]);
      BTM_ClearRfcommSecurity(bta_ag_cb.profile[i].scn);
      bta_sys_remove_uuid(bta_ag_uuid[i]);
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -205,7 +205,7 @@ 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);
    BTM_SecClrService(BTM_SEC_SERVICE_HF_HANDSFREE);
    BTM_ClearRfcommSecurity(client_cb->scn);
    bta_sys_remove_uuid(UUID_SERVCLASS_HF_HANDSFREE);
  }
}
+8 −10
Original line number Diff line number Diff line
@@ -502,17 +502,19 @@ bool BTM_SetSecurityLevel(bool is_originator, const char* p_name,
}

struct RfcommSecurityRecord {
  uint32_t service_id;
  bool need_mitm;
  bool need_16_digit_pin;
};
static std::unordered_map<uint32_t, RfcommSecurityRecord>
    legacy_stack_rfcomm_security_records;

void BTM_SetRfcommSecurity(uint32_t service_id, uint32_t scn, bool need_mitm,
void BTM_SetRfcommSecurity(uint32_t scn, bool need_mitm,
                           bool need_16_digit_pin) {
  legacy_stack_rfcomm_security_records[scn] = {service_id, need_mitm,
                                               need_16_digit_pin};
  legacy_stack_rfcomm_security_records[scn] = {need_mitm, need_16_digit_pin};
}

void BTM_ClearRfcommSecurity(uint32_t scn) {
  legacy_stack_rfcomm_security_records.erase(scn);
}

/*******************************************************************************
@@ -534,12 +536,6 @@ void BTM_SetRfcommSecurity(uint32_t service_id, uint32_t scn, bool need_mitm,
 *
 ******************************************************************************/
uint8_t BTM_SecClrService(uint8_t service_id) {
  for (auto& entry : legacy_stack_rfcomm_security_records) {
    if (entry.second.service_id == service_id) {
      legacy_stack_rfcomm_security_records.erase(entry.first);
    }
  }

  tBTM_SEC_SERV_REC* p_srec = &btm_cb.sec_serv_rec[0];
  uint8_t num_freed = 0;
  int i;
@@ -2167,6 +2163,8 @@ void btm_sec_dev_reset(void) {
    /* add mx service to use no security */
    BTM_SetSecurityLevel(false, "RFC_MUX", BTM_SEC_SERVICE_RFC_MUX,
                         BTM_SEC_NONE, BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, 0);
    BTM_SetSecurityLevel(true, "RFC_MUX", BTM_SEC_SERVICE_RFC_MUX, BTM_SEC_NONE,
                         BT_PSM_RFCOMM, BTM_SEC_PROTO_RFCOMM, 0);
  } else {
    btm_cb.security_mode = BTM_SEC_MODE_SERVICE;
  }
+2 −1
Original line number Diff line number Diff line
@@ -138,8 +138,9 @@ bool BTM_SetSecurityLevel(bool is_originator, const char* p_name,
                          uint32_t mx_proto_id, uint32_t mx_chan_id);

// Set the rfcomm security requirement
void BTM_SetRfcommSecurity(uint32_t service_id, uint32_t scn, bool need_mitm,
void BTM_SetRfcommSecurity(uint32_t scn, bool need_mitm,
                           bool need_16_digit_pin);
void BTM_ClearRfcommSecurity(uint32_t scn);

/*******************************************************************************
 *
+1 −2
Original line number Diff line number Diff line
@@ -79,8 +79,7 @@ int RFCOMM_CreateConnectionWithSecurity(uint16_t uuid, uint8_t scn,
                                        uint16_t* p_handle,
                                        tPORT_CALLBACK* p_mgmt_cb,
                                        uint8_t service_id, uint16_t sec_mask) {
  BTM_SetRfcommSecurity(service_id, scn,
                        sec_mask & (BTM_SEC_OUT_MITM | BTM_SEC_IN_MITM),
  BTM_SetRfcommSecurity(scn, sec_mask & (BTM_SEC_OUT_MITM | BTM_SEC_IN_MITM),
                        sec_mask & BTM_SEC_IN_MIN_16_DIGIT_PIN);

  return RFCOMM_CreateConnection(uuid, scn, is_server, mtu, bd_addr, p_handle,
Loading