summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Himanshu Rawat <rwt@google.com> 2024-08-28 20:43:51 +0000
committer Himanshu Rawat <rwt@google.com> 2024-08-31 02:02:34 +0000
commit48d6eea23afd948e22482ff4ea3221ee34ee6a34 (patch)
tree901ca48c1182be3b4fa4b5ff8665d3da148b26d3
parent27a3bac7fe64762d7a996201d37d88183a95184c (diff)
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
-rw-r--r--system/stack/btm/btm_ble_gap.cc56
-rw-r--r--system/stack/gap/gap_ble.cc21
-rw-r--r--system/stack/include/gap_api.h11
-rw-r--r--system/test/mock/mock_stack_btm_ble_gap.cc4
-rw-r--r--system/test/mock/mock_stack_gap_ble.cc5
5 files changed, 97 insertions, 0 deletions
diff --git a/system/stack/btm/btm_ble_gap.cc b/system/stack/btm/btm_ble_gap.cc
index f73e9bf269..f3f8a4f763 100644
--- a/system/stack/btm/btm_ble_gap.cc
+++ b/system/stack/btm/btm_ble_gap.cc
@@ -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,
@@ -1655,6 +1656,61 @@ tBTM_STATUS btm_ble_read_remote_name(const RawAddress& remote_bda, tBTM_NAME_CMP
/*******************************************************************************
*
+ * 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
*
* Description This function cancel read remote LE device name.
diff --git a/system/stack/gap/gap_ble.cc b/system/stack/gap/gap_ble.cc
index 9f09ce4b44..2a7ccbc61a 100644
--- a/system/stack/gap/gap_ble.cc
+++ b/system/stack/gap/gap_ble.cc
@@ -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;
}
}
@@ -561,6 +569,19 @@ bool GAP_BleReadPeerDevName(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_c
/*******************************************************************************
*
+ * 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
*
* Description Cancel reading a peripheral's device name.
diff --git a/system/stack/include/gap_api.h b/system/stack/include/gap_api.h
index 572ba922c6..a764a1e73d 100644
--- a/system/stack/include/gap_api.h
+++ b/system/stack/include/gap_api.h
@@ -276,6 +276,17 @@ bool GAP_BleReadPeerDevName(const RawAddress& peer_bda, tGAP_BLE_CMPL_CBACK* p_c
/*******************************************************************************
*
+ * 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
*
* Description Cancel reading a peripheral's device name.
diff --git a/system/test/mock/mock_stack_btm_ble_gap.cc b/system/test/mock/mock_stack_btm_ble_gap.cc
index 2e5ccc456f..e717de17c7 100644
--- a/system/test/mock/mock_stack_btm_ble_gap.cc
+++ b/system/test/mock/mock_stack_btm_ble_gap.cc
@@ -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;
diff --git a/system/test/mock/mock_stack_gap_ble.cc b/system/test/mock/mock_stack_gap_ble.cc
index 3cb239e9b8..e07b77b1d3 100644
--- a/system/test/mock/mock_stack_gap_ble.cc
+++ b/system/test/mock/mock_stack_gap_ble.cc
@@ -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;