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

Commit a2ac1bd1 authored by Chris Manton's avatar Chris Manton
Browse files

Factor out btm_ble_conn_complete::maybe_resolve_address

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working

Change-Id: I910bb35b9eecfd543a4d0b132eef638bdf86040b
parent 5dfaf87a
Loading
Loading
Loading
Loading
+47 −40
Original line number Diff line number Diff line
@@ -90,37 +90,9 @@ void btm_ble_create_ll_conn_complete(uint8_t status) {
  }
}

/** LE connection complete. */
void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
                           bool enhanced) {
  uint8_t peer_addr_type;
  RawAddress local_rpa, peer_rpa;
  uint8_t role, status, bda_type;
  uint16_t handle;
  RawAddress bda;
  uint16_t conn_interval, conn_latency, conn_timeout;
static bool maybe_resolve_address(RawAddress bda, tBLE_ADDR_TYPE bda_type) {
  bool match = false;

  STREAM_TO_UINT8(status, p);
  STREAM_TO_UINT16(handle, p);
  STREAM_TO_UINT8(role, p);
  STREAM_TO_UINT8(bda_type, p);
  STREAM_TO_BDADDR(bda, p);
  if (enhanced) {
    STREAM_TO_BDADDR(local_rpa, p);
    STREAM_TO_BDADDR(peer_rpa, p);
  }
  STREAM_TO_UINT16(conn_interval, p);
  STREAM_TO_UINT16(conn_latency, p);
  STREAM_TO_UINT16(conn_timeout, p);
  handle = HCID_GET_HANDLE(handle);

  uint32_t hci_ble_event =
      enhanced ? android::bluetooth::hci::BLE_EVT_ENHANCED_CONN_COMPLETE_EVT
               : android::bluetooth::hci::BLE_EVT_CONN_COMPLETE_EVT;

  if (status == HCI_SUCCESS) {
    peer_addr_type = bda_type;
  tBLE_ADDR_TYPE peer_addr_type = bda_type;
  bool addr_is_rpa =
      (peer_addr_type == BLE_ADDR_RANDOM && BTM_BLE_IS_RESOLVE_BDA(bda));

@@ -153,6 +125,41 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
      LOG(INFO) << __func__ << ": unable to match and resolve random address";
    }
  }
  return match;
}

/** LE connection complete. */
void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
                           bool enhanced) {
  RawAddress local_rpa, peer_rpa;
  uint8_t role, status;
  tBLE_ADDR_TYPE bda_type;
  uint16_t handle;
  RawAddress bda;
  uint16_t conn_interval, conn_latency, conn_timeout;

  STREAM_TO_UINT8(status, p);
  STREAM_TO_UINT16(handle, p);
  STREAM_TO_UINT8(role, p);
  STREAM_TO_UINT8(bda_type, p);
  STREAM_TO_BDADDR(bda, p);
  if (enhanced) {
    STREAM_TO_BDADDR(local_rpa, p);
    STREAM_TO_BDADDR(peer_rpa, p);
  }
  STREAM_TO_UINT16(conn_interval, p);
  STREAM_TO_UINT16(conn_latency, p);
  STREAM_TO_UINT16(conn_timeout, p);
  handle = HCID_GET_HANDLE(handle);

  uint32_t hci_ble_event =
      enhanced ? android::bluetooth::hci::BLE_EVT_ENHANCED_CONN_COMPLETE_EVT
               : android::bluetooth::hci::BLE_EVT_CONN_COMPLETE_EVT;

  if (status == HCI_SUCCESS) {
    tBLE_ADDR_TYPE peer_addr_type = bda_type;
    bool match = maybe_resolve_address(bda, bda_type);

    // Log for the HCI success case after resolving Bluetooth address
    bluetooth::common::LogLinkLayerConnectionEvent(
        &bda, handle, android::bluetooth::DIRECTION_UNKNOWN,
@@ -179,6 +186,10 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
        btm_ble_refresh_peer_resolvable_private_addr(
            bda, peer_rpa, tBTM_SEC_BLE::BTM_BLE_ADDR_RRA);
    }
    btm_ble_update_mode_operation(role, &bda, status);

    if (role == HCI_ROLE_SLAVE)
      btm_ble_advertiser_notify_terminated_legacy(status, handle);
  } else {
    // Log for non HCI success case
    bluetooth::common::LogLinkLayerConnectionEvent(
@@ -196,12 +207,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
      btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE;
      btm_ble_disable_resolving_list(BTM_BLE_RL_ADV, true);
    }
  }

    btm_ble_update_mode_operation(role, &bda, status);

  if (role == HCI_ROLE_SLAVE)
    btm_ble_advertiser_notify_terminated_legacy(status, handle);
  }
}

void btm_ble_create_conn_cancel() {