aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2019-08-13 14:46:21 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-08-13 14:46:21 -0700
commit64a3bb3b93b8b5ff3bec836ebdcb56ef66db14a7 (patch)
tree2f80bdaac62724b7b56884f921ba7f3d9d69272f
parent4b1d4904a6e839752cd789aef46391da4064cd5c (diff)
parent8d4973126b7b0ef05dfb23a64b0654342c8cb9bd (diff)
downloadbt-pie-gsi.tar.gz
Snap for 5674421 from a3c00b27470c47bae945fd6d222b52519375160b to pi-platform-releasepie-gsi
am: 8d4973126b Change-Id: Iea44ade82864f78f05fbc2dd33c09d9e29d087be
-rw-r--r--btif/src/btif_dm.cc83
-rw-r--r--stack/btu/btu_hcif.cc16
2 files changed, 73 insertions, 26 deletions
diff --git a/btif/src/btif_dm.cc b/btif/src/btif_dm.cc
index dd9b8130e..c85a39524 100644
--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -257,6 +257,11 @@ static bool is_empty_128bit(uint8_t* data) {
return !memcmp(zero, data, sizeof(zero));
}
+static bool is_bonding_or_sdp() {
+ return pairing_cb.state == BT_BOND_STATE_BONDING ||
+ (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts);
+}
+
static void btif_dm_data_copy(uint16_t event, char* dst, char* src) {
tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst;
tBTA_DM_SEC* src_dm_sec = (tBTA_DM_SEC*)src;
@@ -483,8 +488,6 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
bt_bond_state_t state) {
btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state);
- // Send bonding state only once - based on outgoing/incoming we may receive
- // duplicates
if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) {
// Cross key pairing so send callback for static address
if (!pairing_cb.static_bdaddr.IsEmpty()) {
@@ -502,14 +505,13 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
auto tmp = bd_addr;
HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, &tmp, state);
- if (state == BT_BOND_STATE_BONDING) {
+ if (state == BT_BOND_STATE_BONDING ||
+ (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) {
+ // Save state for the device is bonding or SDP.
pairing_cb.state = state;
pairing_cb.bd_addr = bd_addr;
} else {
- if (!pairing_cb.sdp_attempts)
- memset(&pairing_cb, 0, sizeof(pairing_cb));
- else
- BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
+ pairing_cb = {};
}
}
@@ -1135,6 +1137,17 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
/* Trigger SDP on the device */
pairing_cb.sdp_attempts = 1;
+
+ if (is_crosskey) {
+ // If bonding occurred due to cross-key pairing, send bonding callback
+ // for static address now
+ LOG_INFO(LOG_TAG,
+ "%s: send bonding state update for static address %s",
+ __func__, bd_addr.ToString().c_str());
+ bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
+ }
+ bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED);
+
btif_dm_get_remote_services(bd_addr);
}
}
@@ -1392,9 +1405,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__,
p_data->disc_res.result, p_data->disc_res.services);
- if ((p_data->disc_res.result != BTA_SUCCESS) &&
- (pairing_cb.state == BT_BOND_STATE_BONDING) &&
- (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) {
+ if (p_data->disc_res.result != BTA_SUCCESS &&
+ pairing_cb.state == BT_BOND_STATE_BONDED &&
+ pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) {
if (pairing_cb.sdp_attempts) {
BTIF_TRACE_WARNING("%s: SDP failed after bonding re-attempting",
__func__);
@@ -1421,21 +1434,35 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
/* onUuidChanged requires getBondedDevices to be populated.
** bond_state_changed needs to be sent prior to remote_device_property
*/
- if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
+ if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts &&
(p_data->disc_res.bd_addr == pairing_cb.bd_addr ||
- p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) &&
- pairing_cb.sdp_attempts > 0) {
- BTIF_TRACE_DEBUG(
- "%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
- __func__);
+ p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) {
+ LOG_INFO(LOG_TAG, "%s: SDP search done for %s", __func__,
+ bd_addr.ToString().c_str());
pairing_cb.sdp_attempts = 0;
- // If bonding occured due to cross-key pairing, send bonding callback
- // for static address now
- if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)
- bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
-
- bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED);
+ // Both SDP and bonding are done, clear pairing control block
+ pairing_cb = {};
+
+ // Send one empty UUID to Java to unblock pairing intent when SDP failed
+ // or no UUID is discovered
+ if (p_data->disc_res.result != BTA_SUCCESS ||
+ p_data->disc_res.num_uuids == 0) {
+ LOG_INFO(LOG_TAG,
+ "%s: SDP failed, send empty UUID to unblock bonding %s",
+ __func__, bd_addr.ToString().c_str());
+ bt_property_t prop;
+ Uuid uuid = {};
+
+ prop.type = BT_PROPERTY_UUIDS;
+ prop.val = &uuid;
+ prop.len = Uuid::kNumBytes128;
+
+ /* Send the event to the BTIF */
+ HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
+ BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
+ break;
+ }
}
if (p_data->disc_res.num_uuids != 0) {
@@ -1630,7 +1657,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
break;
case BTA_DM_BOND_CANCEL_CMPL_EVT:
- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
+ if (is_bonding_or_sdp()) {
bd_addr = pairing_cb.bd_addr;
btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result,
@@ -2273,7 +2300,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) {
** 1. Restore scan modes
** 2. special handling for HID devices
*/
- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
+ if (is_bonding_or_sdp()) {
if (pairing_cb.is_ssp) {
if (pairing_cb.is_le_only) {
BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT);
@@ -2471,7 +2498,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) {
/*******************************************************************************
*
- * Function btif_dm_get_remote_services_transport
+ * Function btif_dm_get_remote_services_by_transport
*
* Description Start SDP to get remote services by transport
*
@@ -2858,6 +2885,10 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
break;
}
}
+ if (state == BT_BOND_STATE_BONDED && bd_addr != pairing_cb.static_bdaddr) {
+ // Report RPA bonding state to Java in crosskey paring
+ bond_state_changed(status, bd_addr, BT_BOND_STATE_BONDING);
+ }
bond_state_changed(status, bd_addr, state);
}
@@ -3168,7 +3199,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) {
void btif_dm_on_disable() {
/* cancel any pending pairing requests */
- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
+ if (is_bonding_or_sdp()) {
BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__);
btif_dm_cancel_bond(&pairing_cb.bd_addr);
}
diff --git a/stack/btu/btu_hcif.cc b/stack/btu/btu_hcif.cc
index fbd769510..b5243cdca 100644
--- a/stack/btu/btu_hcif.cc
+++ b/stack/btu/btu_hcif.cc
@@ -733,6 +733,14 @@ static void read_encryption_key_size_complete_after_encryption_change(
<< std::to_string(key_size);
}
+ if (status == HCI_ERR_INSUFFCIENT_SECURITY) {
+ /* If remote device stop the encryption before we call "Read Encryption Key
+ * Size", we might receive Insufficient Security, which means that link is
+ * no longer encrypted. */
+ LOG(INFO) << __func__ << ": encryption stopped on link: " << loghex(handle);
+ return;
+ }
+
if (status != HCI_SUCCESS) {
LOG(INFO) << __func__ << ": disconnecting, status: " << loghex(status);
btsnd_hcic_disconnect(handle, HCI_ERR_PEER_USER);
@@ -1694,6 +1702,14 @@ static void read_encryption_key_size_complete_after_key_refresh(
<< std::to_string(key_size);
}
+ if (status == HCI_ERR_INSUFFCIENT_SECURITY) {
+ /* If remote device stop the encryption before we call "Read Encryption Key
+ * Size", we might receive Insufficient Security, which means that link is
+ * no longer encrypted. */
+ LOG(INFO) << __func__ << ": encryption stopped on link: " << loghex(handle);
+ return;
+ }
+
if (status != HCI_SUCCESS) {
LOG(INFO) << __func__ << ": disconnecting, status: " << loghex(status);
btsnd_hcic_disconnect(handle, HCI_ERR_PEER_USER);