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

Commit ca266891 authored by Himanshu Rawat's avatar Himanshu Rawat Committed by Gerrit Code Review
Browse files

Merge changes I39f94b70,If90284e1,Ib31d7dd0,I95f3bd4f,I9d5f2067, ... into main

* changes:
  Retrieve CoD from storage when a new LE device record is created
  Cache CoD during LE pairing
  Expose a BTM interface to get cached class of device
  Expose a btif storage function to read class of device
  Read appearance of new LE devices on connection
  Add GAP interface to read class of device for LE devices
parents b26c7acd 283ea50c
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -666,6 +666,11 @@ static tBTM_STATUS bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda
    return tBTM_STATUS::BTM_NOT_AUTHORIZED;
  }

  DEV_CLASS dev_class = get_btm_client_interface().security.BTM_SecReadDevClass(bda);
  if (!com::android::bluetooth::flags::read_le_appearance()) {
    dev_class = kDevClassEmpty;
  }

  switch (event) {
    case BTM_LE_IO_REQ_EVT:
      ble_io_req(bda, &p_data->io_req.io_cap, &p_data->io_req.oob_data, &p_data->io_req.auth_req,
@@ -678,6 +683,7 @@ static tBTM_STATUS bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda
      sec_event.ble_req.bd_addr = bda;
      bd_name_from_char_pointer(sec_event.ble_req.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.ble_req.dev_class = dev_class;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_CONSENT_REQ_EVT, &sec_event);
      break;

@@ -685,6 +691,7 @@ static tBTM_STATUS bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda
      sec_event.ble_req.bd_addr = bda;
      bd_name_from_char_pointer(sec_event.ble_req.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.ble_req.dev_class = dev_class;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_SEC_REQ_EVT, &sec_event);
      break;

@@ -692,29 +699,38 @@ static tBTM_STATUS bta_dm_ble_smp_cback(tBTM_LE_EVT event, const RawAddress& bda
      sec_event.key_notif.bd_addr = bda;
      bd_name_from_char_pointer(sec_event.key_notif.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.key_notif.dev_class = dev_class;
      sec_event.key_notif.passkey = p_data->key_notif;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_NOTIF_EVT, &sec_event);
      break;

    case BTM_LE_KEY_REQ_EVT:
      sec_event.ble_req.bd_addr = bda;
      sec_event.pin_req.bd_addr = bda;
      bd_name_from_char_pointer(sec_event.pin_req.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.pin_req.dev_class = dev_class;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_PASSKEY_REQ_EVT, &sec_event);
      break;

    case BTM_LE_OOB_REQ_EVT:
      sec_event.ble_req.bd_addr = bda;
      sec_event.rmt_oob.bd_addr = bda;
      bd_name_from_char_pointer(sec_event.rmt_oob.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.rmt_oob.dev_class = dev_class;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_OOB_REQ_EVT, &sec_event);
      break;

    case BTM_LE_NC_REQ_EVT:
      sec_event.key_notif.bd_addr = bda;
      bd_name_clear(sec_event.key_notif.bd_name);
      bd_name_from_char_pointer(sec_event.key_notif.bd_name,
                                get_btm_client_interface().security.BTM_SecReadDevName(bda));
      sec_event.key_notif.dev_class = dev_class;
      sec_event.key_notif.passkey = p_data->key_notif;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_NC_REQ_EVT, &sec_event);
      break;

    case BTM_LE_SC_OOB_REQ_EVT:
      sec_event.ble_req.bd_addr = bda;
      sec_event.rmt_oob.bd_addr = bda;
      bta_dm_sec_cb.p_sec_cback(BTA_DM_BLE_SC_OOB_REQ_EVT, &sec_event);
      break;

+6 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ typedef struct {
  RawAddress bd_addr;  /* BD address peer device. */
  DEV_CLASS dev_class; /* Class of Device */
  BD_NAME bd_name;     /* Name of peer device. */

  bool min_16_digit;   /* true if the pin returned must be at least 16 digits */
} tBTA_DM_PIN_REQ;

@@ -121,7 +122,10 @@ enum class tBTA_DM_BLE_SEC_GRANT {

/* Structure associated with BTA_DM_BLE_SEC_REQ_EVT */
typedef struct {
  /* Note: First 3 data members must be, bd_addr, dev_class, and bd_name in
   * order */
  RawAddress bd_addr; /* peer address */
  DEV_CLASS dev_class;
  BD_NAME bd_name;    /* peer device name */
} tBTA_DM_BLE_SEC_REQ;

@@ -169,6 +173,7 @@ typedef struct {
  RawAddress bd_addr;         /* peer address */
  DEV_CLASS dev_class;        /* peer CoD */
  BD_NAME bd_name;            /* peer device name */

  uint32_t num_val;           /* the numeric value for comparison. If just_works, do not
                                 show this number to UI */
  bool just_works;            /* true, if "Just Works" association model */
@@ -185,6 +190,7 @@ typedef struct {
  RawAddress bd_addr;  /* peer address */
  DEV_CLASS dev_class; /* peer CoD */
  BD_NAME bd_name;     /* peer device name */

  uint32_t passkey;    /* the numeric value for comparison. If just_works, do not
                          show this number to UI */
} tBTA_DM_SP_KEY_NOTIF;
+11 −0
Original line number Diff line number Diff line
@@ -398,6 +398,17 @@ bt_status_t btif_storage_remove_hidd(RawAddress* remote_bd_addr);
// |BD_NAME_LEN|.
bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name);

/*******************************************************************************
 *
 * Function         btif_storage_get_cod
 *
 * Description      Retrieves the stored class of device.
 *
 * Returns          true if successful, otherwise false
 *
 ******************************************************************************/
bool btif_storage_get_cod(const RawAddress& bd_addr, uint32_t* cod);

/*******************************************************************************
 *
 * Function         btif_storage_set_hid_connection_policy
+16 −22
Original line number Diff line number Diff line
@@ -275,7 +275,7 @@ 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 btif_dm_local_key_cb_t ble_local_key_cb;
static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif);
static void btif_dm_ble_passkey_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif);
static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl);
static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ* p_pin_req);
static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req);
@@ -484,18 +484,12 @@ static bool get_cached_remote_name(const RawAddress& bd_addr, uint8_t* p_remote_
}

static uint32_t get_cod(const RawAddress* remote_bdaddr) {
  uint32_t remote_cod;
  bt_property_t prop_name;

  /* check if we already have it in our btif_storage cache */
  BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_CLASS_OF_DEVICE, sizeof(uint32_t),
                             &remote_cod);
  if (btif_storage_get_remote_device_property((RawAddress*)remote_bdaddr, &prop_name) ==
      BT_STATUS_SUCCESS) {
    return remote_cod;
  uint32_t remote_cod = 0;
  if (!btif_storage_get_cod(*remote_bdaddr, &remote_cod)) {
    remote_cod = 0;
  }

  return 0;
  return remote_cod;
}

bool check_cod(const RawAddress* remote_bdaddr, uint32_t cod) {
@@ -2132,7 +2126,7 @@ void btif_dm_sec_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC* p_data) {
      break;
    case BTA_DM_BLE_PASSKEY_NOTIF_EVT:
      log::verbose("BTA_DM_BLE_PASSKEY_NOTIF_EVT");
      btif_dm_ble_key_notif_evt(&p_data->key_notif);
      btif_dm_ble_passkey_notif_evt(&p_data->key_notif);
      break;
    case BTA_DM_BLE_PASSKEY_REQ_EVT:
      log::verbose("BTA_DM_BLE_PASSKEY_REQ_EVT");
@@ -3229,7 +3223,7 @@ bool btif_dm_proc_rmt_oob(const RawAddress& bd_addr, Octet16* p_c, Octet16* p_r)
  return true;
}

static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
static void btif_dm_ble_passkey_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
  RawAddress bd_addr;
  int dev_type;

@@ -3239,8 +3233,8 @@ static void btif_dm_ble_key_notif_evt(tBTA_DM_SP_KEY_NOTIF* p_ssp_key_notif) {
  if (!btif_get_device_type(p_ssp_key_notif->bd_addr, &dev_type)) {
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name, kDevClassEmpty,
                                (tBT_DEVICE_TYPE)dev_type);
  btif_update_remote_properties(p_ssp_key_notif->bd_addr, p_ssp_key_notif->bd_name,
                                p_ssp_key_notif->dev_class, (tBT_DEVICE_TYPE)dev_type);
  bd_addr = p_ssp_key_notif->bd_addr;

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
@@ -3516,7 +3510,7 @@ static void btif_dm_ble_sec_req_evt(tBTA_DM_BLE_SEC_REQ* p_ble_req, bool is_cons
  if (!btif_get_device_type(p_ble_req->bd_addr, &dev_type)) {
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_update_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name, kDevClassEmpty,
  btif_update_remote_properties(p_ble_req->bd_addr, p_ble_req->bd_name, p_ble_req->dev_class,
                                (tBT_DEVICE_TYPE)dev_type);

  RawAddress bd_addr = p_ble_req->bd_addr;
@@ -3552,7 +3546,7 @@ static void btif_dm_ble_passkey_req_evt(tBTA_DM_PIN_REQ* p_pin_req) {
  if (!btif_get_device_type(p_pin_req->bd_addr, &dev_type)) {
    dev_type = BT_DEVICE_TYPE_BLE;
  }
  btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name, kDevClassEmpty,
  btif_update_remote_properties(p_pin_req->bd_addr, p_pin_req->bd_name, p_pin_req->dev_class,
                                (tBT_DEVICE_TYPE)dev_type);

  RawAddress bd_addr = p_pin_req->bd_addr;
@@ -3575,7 +3569,7 @@ static void btif_dm_ble_key_nc_req_evt(tBTA_DM_SP_KEY_NOTIF* p_notif_req) {
  log::verbose("addr:{}", bd_addr);

  /* Remote name update */
  btif_update_remote_properties(p_notif_req->bd_addr, p_notif_req->bd_name, kDevClassEmpty,
  btif_update_remote_properties(p_notif_req->bd_addr, p_notif_req->bd_name, p_notif_req->dev_class,
                                BT_DEVICE_TYPE_BLE);

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
@@ -3609,8 +3603,8 @@ static void btif_dm_ble_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
  }

  /* Remote name update */
  btif_update_remote_properties(req_oob_type->bd_addr, req_oob_type->bd_name, kDevClassEmpty,
                                BT_DEVICE_TYPE_BLE);
  btif_update_remote_properties(req_oob_type->bd_addr, req_oob_type->bd_name,
                                req_oob_type->dev_class, BT_DEVICE_TYPE_BLE);

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  pairing_cb.is_ssp = false;
@@ -3660,8 +3654,8 @@ static void btif_dm_ble_sc_oob_req_evt(tBTA_DM_SP_RMT_OOB* req_oob_type) {
  }

  /* Remote name update */
  btif_update_remote_properties(req_oob_type->bd_addr, oob_data_to_use.device_name, kDevClassEmpty,
                                BT_DEVICE_TYPE_BLE);
  btif_update_remote_properties(req_oob_type->bd_addr, oob_data_to_use.device_name,
                                req_oob_type->dev_class, BT_DEVICE_TYPE_BLE);

  bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
  pairing_cb.is_ssp = false;
+10 −0
Original line number Diff line number Diff line
@@ -1303,6 +1303,16 @@ bool btif_storage_get_stored_remote_name(const RawAddress& bd_addr, char* name)
  return btif_storage_get_remote_device_property(&bd_addr, &property) == BT_STATUS_SUCCESS;
}

// Get the Class of Device.
bool btif_storage_get_cod(const RawAddress& bd_addr, uint32_t* cod) {
  bt_property_t property;
  property.type = BT_PROPERTY_CLASS_OF_DEVICE;
  property.len = sizeof(*cod);
  property.val = cod;

  return btif_storage_get_remote_device_property(&bd_addr, &property) == BT_STATUS_SUCCESS;
}

/** Stores information about GATT Client supported features support */
void btif_storage_set_gatt_cl_supp_feat(const RawAddress& bd_addr, uint8_t feat) {
  do_in_jni_thread(Bind(
Loading