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

Commit 2d9e1d50 authored by Rongxuan Liu's avatar Rongxuan Liu
Browse files

Add support to create le bond with address type (2/2)

Bug: 265341075
Tag: #feature
Test: atest BluetoothInstrumentationTests
      manual e2e test with LE device

Change-Id: I84dd1ea8b14a9374971feeb5b05870452ceaabda
parent d366b5e2
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ namespace android {
#define TRANSPORT_BREDR 1
#define TRANSPORT_LE 2

#define BLE_ADDR_PUBLIC 0x00
#define BLE_ADDR_RANDOM 0x01

const jint INVALID_FD = -1;

static jmethodID method_oobDataReceivedCallback;
@@ -1131,7 +1134,13 @@ static jboolean createBondNative(JNIEnv* env, jobject obj, jbyteArray address,
    return JNI_FALSE;
  }

  int ret = sBluetoothInterface->create_bond((RawAddress*)addr, transport);
  uint8_t addr_type = (uint8_t)addrType;
  int ret = BT_STATUS_SUCCESS;
  if (addr_type == BLE_ADDR_RANDOM) {
    ret = sBluetoothInterface->create_bond_le((RawAddress*)addr, addr_type);
  } else {
    ret = sBluetoothInterface->create_bond((RawAddress*)addr, transport);
  }
  env->ReleaseByteArrayElements(address, addr, 0);
  return (ret == BT_STATUS_SUCCESS) ? JNI_TRUE : JNI_FALSE;
}
+9 −0
Original line number Diff line number Diff line
@@ -224,6 +224,15 @@ bool btif_dm_pairing_is_busy();
 ******************************************************************************/
void btif_dm_create_bond(const RawAddress bd_addr, int transport);

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_le
 *
 * Description      Initiate bonding with the specified device over le transport
 *
 ******************************************************************************/
void btif_dm_create_bond_le(const RawAddress bd_addr, uint8_t addr_type);

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_out_of_band
+10 −0
Original line number Diff line number Diff line
@@ -587,6 +587,15 @@ static int create_bond(const RawAddress* bd_addr, int transport) {
  return BT_STATUS_SUCCESS;
}

static int create_bond_le(const RawAddress* bd_addr, uint8_t addr_type) {
  if (!interface_ready()) return BT_STATUS_NOT_READY;
  if (btif_dm_pairing_is_busy()) return BT_STATUS_BUSY;

  do_in_main_thread(
      FROM_HERE, base::BindOnce(btif_dm_create_bond_le, *bd_addr, addr_type));
  return BT_STATUS_SUCCESS;
}

static int create_bond_out_of_band(const RawAddress* bd_addr, int transport,
                                   const bt_oob_data_t* p192_data,
                                   const bt_oob_data_t* p256_data) {
@@ -984,6 +993,7 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
    .start_discovery = start_discovery,
    .cancel_discovery = cancel_discovery,
    .create_bond = create_bond,
    .create_bond_le = create_bond_le,
    .create_bond_out_of_band = create_bond_out_of_band,
    .remove_bond = remove_bond,
    .cancel_bond = cancel_bond,
+51 −2
Original line number Diff line number Diff line
@@ -258,6 +258,8 @@ static btif_dm_oob_cb_t oob_cb;
static btif_dm_metadata_cb_t metadata_cb{.le_audio_cache{40}};
static void btif_dm_cb_create_bond(const RawAddress bd_addr,
                                   tBT_TRANSPORT transport);
static void btif_dm_cb_create_bond_le(const RawAddress bd_addr,
                                      tBLE_ADDR_TYPE addr_type);
static void btif_update_remote_properties(const RawAddress& bd_addr,
                                          BD_NAME bd_name, DEV_CLASS dev_class,
                                          tBT_DEVICE_TYPE dev_type);
@@ -745,6 +747,26 @@ static void btif_dm_cb_create_bond(const RawAddress bd_addr,
  pairing_cb.is_local_initiated = true;
}

/*******************************************************************************
 *
 * Function         btif_dm_cb_create_bond_le
 *
 * Description      Create bond initiated with le device from the BTIF thread
 *                  context
 *
 * Returns          void
 *
 ******************************************************************************/
static void btif_dm_cb_create_bond_le(const RawAddress bd_addr,
                                      tBLE_ADDR_TYPE addr_type) {
  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  /* Handle only LE create bond with random address case */
  BTA_DmAddBleDevice(bd_addr, addr_type, BT_DEVICE_TYPE_BLE);
  BTA_DmBond(bd_addr, addr_type, BT_TRANSPORT_LE, BT_DEVICE_TYPE_BLE);
  /*  Track  originator of bond creation  */
  pairing_cb.is_local_initiated = true;
}

/*******************************************************************************
 *
 * Function         btif_dm_get_connection_state
@@ -1016,6 +1038,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
  pairing_cb.fail_reason = p_auth_cmpl->fail_reason;

  RawAddress bd_addr = p_auth_cmpl->bd_addr;
  tBLE_ADDR_TYPE addr_type = p_auth_cmpl->addr_type;
  if (!bluetooth::shim::is_gd_security_enabled()) {
    if ((p_auth_cmpl->success) && (p_auth_cmpl->key_present)) {
      if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
@@ -1164,7 +1187,11 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
          BTIF_TRACE_WARNING("%s() - Pairing timeout; retrying (%d) ...",
                             __func__, pairing_cb.timeout_retries);
          --pairing_cb.timeout_retries;
          if (addr_type == BLE_ADDR_RANDOM) {
            btif_dm_cb_create_bond_le(bd_addr, addr_type);
          } else {
            btif_dm_cb_create_bond(bd_addr, BT_TRANSPORT_AUTO);
          }
          return;
        }
        FALLTHROUGH_INTENDED; /* FALLTHROUGH */
@@ -1195,7 +1222,11 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
          /* Create the Bond once again */
          BTIF_TRACE_WARNING("%s() auto pair failed. Reinitiate Bond",
                             __func__);
          if (addr_type == BLE_ADDR_RANDOM) {
            btif_dm_cb_create_bond_le(bd_addr, addr_type);
          } else {
            btif_dm_cb_create_bond(bd_addr, BT_TRANSPORT_AUTO);
          }
          return;
        } else {
          /* if autopair attempts are more than 1, or not attempted */
@@ -2235,6 +2266,24 @@ void btif_dm_create_bond(const RawAddress bd_addr, int transport) {
  btif_dm_cb_create_bond(bd_addr, transport);
}

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_le
 *
 * Description      Initiate bonding with the specified device over le transport
 *
 ******************************************************************************/
void btif_dm_create_bond_le(const RawAddress bd_addr,
                            tBLE_ADDR_TYPE addr_type) {
  BTIF_TRACE_EVENT("%s: bd_addr=%s, addr_type=%d, transport=%d", __func__,
                   ADDRESS_TO_LOGGABLE_CSTR(bd_addr), addr_type);
  btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_CREATE_BOND,
                            pairing_cb.state);

  pairing_cb.timeout_retries = NUM_TIMEOUT_RETRIES;
  btif_dm_cb_create_bond_le(bd_addr, addr_type);
}

/*******************************************************************************
 *
 * Function         btif_dm_create_bond_out_of_band
+3 −0
Original line number Diff line number Diff line
@@ -679,6 +679,9 @@ typedef struct {
  /** Create Bluetooth Bonding */
  int (*create_bond)(const RawAddress* bd_addr, int transport);

  /** Create Bluetooth Bonding over le transport */
  int (*create_bond_le)(const RawAddress* bd_addr, uint8_t addr_type);

  /** Create Bluetooth Bond using out of band data */
  int (*create_bond_out_of_band)(const RawAddress* bd_addr, int transport,
                                 const bt_oob_data_t* p192_data,
Loading