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

Commit 3dc36374 authored by Chao Quan's avatar Chao Quan Committed by Jakub Pawlowski
Browse files

Refactor btm_ble_resolving_list_load_dev

Test: compilation
Change-Id: I69fd4d9df63801bcc8b529d95bee74fd06c86249
parent ae682857
Loading
Loading
Loading
Loading
+75 −70
Original line number Diff line number Diff line
@@ -681,29 +681,42 @@ bool btm_ble_disable_resolving_list(uint8_t rl_mask, bool to_resume) {
 *
 ******************************************************************************/
bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) {
  bool rt = false;
  uint8_t rl_mask = btm_cb.ble_ctr_cb.rl_state;

  BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__,
                  btm_cb.ble_ctr_cb.privacy_mode);
  const uint8_t rl_state = btm_cb.ble_ctr_cb.rl_state;

  /* if controller does not support RPA offloading or privacy 1.2, skip */
  if (controller_get_interface()->get_ble_resolving_list_max_size() == 0)
  if (controller_get_interface()->get_ble_resolving_list_max_size() == 0) {
    BTM_TRACE_DEBUG(
        "%s: Controller does not support RPA offloading or privacy 1.2",
        __func__);
    return false;
  }

  BTM_TRACE_DEBUG("%s btm_cb.ble_ctr_cb.privacy_mode = %d", __func__,
  BTM_TRACE_DEBUG("%s: btm_cb.ble_ctr_cb.privacy_mode = %d", __func__,
                  btm_cb.ble_ctr_cb.privacy_mode);

  if (!p_dev_rec) {
    BTM_TRACE_DEBUG("%s: No device security record", __func__);
    return false;
  }

  /* only add RPA enabled device into resolving list */
  if (p_dev_rec != NULL && /* RPA is being used and PID is known */
      ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 ||
       (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0)) {
    if (!(p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
        btm_ble_brcm_find_resolving_pending_entry(
            p_dev_rec->bd_addr, BTM_BLE_META_ADD_IRK_ENTRY) == false) {
      if (btm_cb.ble_ctr_cb.resolving_list_avail_size > 0) {
        if (rl_mask) {
          if (!btm_ble_disable_resolving_list(rl_mask, false)) return false;
  if ((p_dev_rec->ble.key_type & (BTM_LE_KEY_PID | BTM_LE_KEY_LID)) == 0) {
    BTM_TRACE_DEBUG("%s: Device not a RPA enabled device", __func__);
    return false;
  }

  if ((p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) ||
      btm_ble_brcm_find_resolving_pending_entry(p_dev_rec->bd_addr,
                                                BTM_BLE_META_ADD_IRK_ENTRY)) {
    BTM_TRACE_ERROR("%s: Device already in Resolving list", __func__);
    return true;
  }

  if (btm_cb.ble_ctr_cb.resolving_list_avail_size == 0) {
    return false;
  }

  if (rl_state && !btm_ble_disable_resolving_list(rl_state, false)) {
    return false;
  }

  btm_ble_update_resolving_list(p_dev_rec->bd_addr, true);
@@ -716,11 +729,12 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) {
      p_dev_rec->ble.static_addr_type = p_dev_rec->ble.ble_addr_type;
    }

          BTM_TRACE_DEBUG("%s:adding device to controller resolving list",
                          __func__);
    BTM_TRACE_DEBUG("%s: adding device %s to controller resolving list",
                    __func__, p_dev_rec->ble.static_addr.ToString().c_str());

    // use identical IRK for now
          btsnd_hcic_ble_add_device_resolving_list(
              p_dev_rec->ble.static_addr_type, p_dev_rec->ble.static_addr,
    btsnd_hcic_ble_add_device_resolving_list(p_dev_rec->ble.static_addr_type,
                                             p_dev_rec->ble.static_addr,
                                             peer_irk, local_irk);

    if (controller_get_interface()->supports_ble_set_privacy_mode()) {
@@ -737,29 +751,20 @@ bool btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC* p_dev_rec) {
    UINT8_TO_STREAM(p, p_dev_rec->ble.static_addr_type);
    BDADDR_TO_STREAM(p, p_dev_rec->ble.static_addr);

          BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC,
                                    BTM_BLE_META_ADD_IRK_LEN, param,
                                    btm_ble_resolving_list_vsc_op_cmpl);
    BTM_VendorSpecificCommand(HCI_VENDOR_BLE_RPA_VSC, BTM_BLE_META_ADD_IRK_LEN,
                              param, btm_ble_resolving_list_vsc_op_cmpl);
  }

        rt = true;
  btm_ble_enq_resolving_list_pending(p_dev_rec->bd_addr,
                                     BTM_BLE_META_ADD_IRK_ENTRY);

  /* if resolving list has been turned on, re-enable it */
        if (rl_mask)
          btm_ble_enable_resolving_list(rl_mask);
  if (rl_state)
    btm_ble_enable_resolving_list(rl_state);
  else
    btm_ble_enable_resolving_list(BTM_BLE_RL_INIT);
      }
    } else {
      BTM_TRACE_ERROR("Device already in Resolving list");
      rt = true;
    }
  } else {
    BTM_TRACE_DEBUG("Device not a RPA enabled device");
  }
  return rt;

  return true;
}

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