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

Commit 48d6eea2 authored by Himanshu Rawat's avatar Himanshu Rawat
Browse files

Add GAP interface to read class of device for LE devices

Test: mmm packages/modules/Bluetooth
Flag: EXEMPT no logical change
Bug: 286334644
Change-Id: I522a2c0d62b596e89afee20ed5a6a55fd2e96bd5
parent 27a3bac7
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -288,6 +288,7 @@ static void btm_ble_start_slow_adv(void);
static void btm_ble_inquiry_timer_gap_limited_discovery_timeout(void* data);
static void btm_ble_inquiry_timer_timeout(void* data);
static void btm_ble_observer_timer_timeout(void* data);
static DEV_CLASS btm_ble_appearance_to_cod(uint16_t appearance);

enum : uint8_t {
  BTM_BLE_NOT_SCANNING = 0x00,
@@ -1653,6 +1654,61 @@ tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda, tBTM_NAME_CMP
  return tBTM_STATUS::BTM_CMD_STARTED;
}

/*******************************************************************************
 *
 * Function         btm_ble_read_remote_appearance_cmpl
 *
 * Description      This function is called when peer's appearance value is received.
 *
 * Returns          void
 *
 ******************************************************************************/
static void btm_ble_read_remote_appearance_cmpl(bool status, const RawAddress& bda, uint16_t length,
                                                char* data) {
  if (!status) {
    log::error("Failed to read appearance of {}", bda);
    return;
  }
  if (length != 2 || data == nullptr) {
    log::error("Invalid appearance value size {} for {}", length, bda);
    return;
  }

  uint16_t appearance = data[0] + (data[1] << 8);
  DEV_CLASS cod = btm_ble_appearance_to_cod(appearance);
  log::info("Appearance 0x{:04x}, Class of Device {} found for {}", appearance, dev_class_text(cod),
            bda);

  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bda);
  if (p_dev_rec != nullptr) {
    p_dev_rec->dev_class = cod;
  }
}

/*******************************************************************************
 *
 * Function         btm_ble_read_remote_cod
 *
 * Description      Finds Class of Device by reading GATT appearance characteristic
 *
 * Parameters:      Device address
 *
 * Returns          void
 *
 ******************************************************************************/
tBTM_STATUS btm_ble_read_remote_cod(const RawAddress& remote_bda) {
  if (!bluetooth::shim::GetController()->SupportsBle()) {
    return tBTM_STATUS::BTM_ERR_PROCESSING;
  }

  if (!GAP_BleReadPeerAppearance(remote_bda, btm_ble_read_remote_appearance_cmpl)) {
    return tBTM_STATUS::BTM_BUSY;
  }

  log::verbose("Reading appearance characteristic {}", remote_bda);
  return tBTM_STATUS::BTM_CMD_STARTED;
}

/*******************************************************************************
 *
 * Function         btm_ble_cancel_remote_name
+21 −0
Original line number Diff line number Diff line
@@ -382,6 +382,14 @@ void client_cmpl_cback(uint16_t conn_id, tGATTC_OPTYPE op, tGATT_STATUS status,
    case GATT_UUID_GAP_CENTRAL_ADDR_RESOL:
      cl_op_cmpl(*p_clcb, true, 1, pp);
      break;

    case GATT_UUID_GAP_ICON:
      cl_op_cmpl(*p_clcb, true, p_data->att_value.len, pp);
      break;

    default:
      log::error("Unexpected operation {}", op);
      break;
  }
}

@@ -559,6 +567,19 @@ bool GAP_BleReadPeerDevName(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_c
  return accept_client_operation(peer_bda, GATT_UUID_GAP_DEVICE_NAME, p_cback);
}

/*******************************************************************************
 *
 * Function         GAP_BleReadPeerAppearance
 *
 * Description      Start a process to read a connected peripheral's appearance.
 *
 * Returns          true if request accepted
 *
 ******************************************************************************/
bool GAP_BleReadPeerAppearance(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_cback) {
  return accept_client_operation(peer_bda, GATT_UUID_GAP_ICON, p_cback);
}

/*******************************************************************************
 *
 * Function         GAP_BleCancelReadPeerDevName
+11 −0
Original line number Diff line number Diff line
@@ -274,6 +274,17 @@ bool GAP_BleReadPeerPrefConnParams(const RawAddress& peer_bda);
 ******************************************************************************/
bool GAP_BleReadPeerDevName(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_cback);

/*******************************************************************************
 *
 * Function         GAP_BleReadPeerAppearance
 *
 * Description      Start a process to read a connected peripheral's appearance.
 *
 * Returns          true if request accepted
 *
 ******************************************************************************/
bool GAP_BleReadPeerAppearance(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_cback);

/*******************************************************************************
 *
 * Function         GAP_BleCancelReadPeerDevName
+4 −0
Original line number Diff line number Diff line
@@ -53,6 +53,10 @@ bool BTM_BleLocalPrivacyEnabled(void) {
  inc_func_call_count(__func__);
  return false;
}
bool btm_ble_read_remote_cod(const RawAddress& /* remote_bda */) {
  inc_func_call_count(__func__);
  return false;
}
bool btm_ble_cancel_remote_name(const RawAddress& /* remote_bda */) {
  inc_func_call_count(__func__);
  return false;
+5 −0
Original line number Diff line number Diff line
@@ -33,6 +33,11 @@ bool GAP_BleReadPeerDevName(const RawAddress& /* peer_bda */, tGAP_BLE_CMPL_CBAC
  inc_func_call_count(__func__);
  return false;
}
bool GAP_BleReadPeerAppearance(const RawAddress& /* peer_bda */,
                               tGAP_BLE_CMPL_CBACK* /* p_cback */) {
  inc_func_call_count(__func__);
  return false;
}
bool GAP_BleReadPeerPrefConnParams(const RawAddress& /* peer_bda */) {
  inc_func_call_count(__func__);
  return false;