Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-bt: Commit

system/bt


Commit MetaInfo

Revisión1f0f244beef4deb9c58058a1523b8158c222734b (tree)
Tiempo2019-02-20 07:39:40
AutorUgo Yu <ugoyu@goog...>
Commiterandroid-build-team Robot

Log Message

DO NOT MERGE Separate SDP procedure from bonding state (1/2)

- Do not stay in bonding state if the device is paried but still

discovering service.

- Report BOND_BONDED to Java after authentication is completed.
- Report empty UUID to Java if a classic Bluetooth device SDP

failed while pairing.

- Hold BOND_BONDED intent util SDP is findished.
- Only accept profile connection for the device is at bonded

  1. Any attempt to connect while bonding would potentially
    lead to an unauthorized connection.

Bug: 79703832
Test: runtest bluetooth
Change-Id: I023713e07308bfc0e5bb8d67f386bcc50f6a0f85
(cherry picked from commit 122e115b87fe98ca5e5e65b9765c146f9e52b65e)
(cherry picked from commit f3681c8616af4d052c410ba3e88747541a974bf5)

Cambiar Resumen

Diferencia incremental

--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -183,6 +183,7 @@ typedef struct {
183183 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
184184
185185 #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb"
186+#define UUID_EMPTY "00000000-0000-0000-0000-000000000000"
186187
187188 #define MAX_BTIF_BOND_EVENT_ENTRIES 15
188189
@@ -261,6 +262,11 @@ static bool is_empty_128bit(uint8_t* data) {
261262 return !memcmp(zero, data, sizeof(zero));
262263 }
263264
265+static bool is_bonding_or_sdp() {
266+ return pairing_cb.state == BT_BOND_STATE_BONDING ||
267+ (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts);
268+}
269+
264270 static void btif_dm_data_copy(uint16_t event, char* dst, char* src) {
265271 tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst;
266272 tBTA_DM_SEC* src_dm_sec = (tBTA_DM_SEC*)src;
@@ -487,8 +493,6 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
487493 bt_bond_state_t state) {
488494 btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state);
489495
490- // Send bonding state only once - based on outgoing/incoming we may receive
491- // duplicates
492496 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) {
493497 // Cross key pairing so send callback for static address
494498 if (!pairing_cb.static_bdaddr.IsEmpty()) {
@@ -506,14 +510,18 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr,
506510 auto tmp = bd_addr;
507511 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, &tmp, state);
508512
509- if (state == BT_BOND_STATE_BONDING) {
513+ int dev_type;
514+ if (!btif_get_device_type(bd_addr, &dev_type)) {
515+ dev_type = BT_DEVICE_TYPE_BREDR;
516+ }
517+
518+ if (state == BT_BOND_STATE_BONDING ||
519+ (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) {
520+ // Save state for the device is bonding or SDP.
510521 pairing_cb.state = state;
511522 pairing_cb.bd_addr = bd_addr;
512523 } else {
513- if (!pairing_cb.sdp_attempts)
514- memset(&pairing_cb, 0, sizeof(pairing_cb));
515- else
516- BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__);
524+ pairing_cb = {};
517525 }
518526 }
519527
@@ -1121,6 +1129,10 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
11211129
11221130 /* Trigger SDP on the device */
11231131 pairing_cb.sdp_attempts = 1;
1132+
1133+ // Report bonded to Java before start SDP
1134+ bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED);
1135+
11241136 btif_dm_get_remote_services(bd_addr);
11251137 }
11261138 }
@@ -1378,9 +1390,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
13781390
13791391 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__,
13801392 p_data->disc_res.result, p_data->disc_res.services);
1381- if ((p_data->disc_res.result != BTA_SUCCESS) &&
1382- (pairing_cb.state == BT_BOND_STATE_BONDING) &&
1383- (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) {
1393+ if (p_data->disc_res.result != BTA_SUCCESS &&
1394+ pairing_cb.state == BT_BOND_STATE_BONDED &&
1395+ pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) {
13841396 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting",
13851397 __func__);
13861398 pairing_cb.sdp_attempts++;
@@ -1405,21 +1417,42 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
14051417 /* onUuidChanged requires getBondedDevices to be populated.
14061418 ** bond_state_changed needs to be sent prior to remote_device_property
14071419 */
1408- if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1420+ if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) &&
14091421 (p_data->disc_res.bd_addr == pairing_cb.bd_addr ||
1410- p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) &&
1411- pairing_cb.sdp_attempts > 0) {
1412- BTIF_TRACE_DEBUG(
1413- "%s Remote Service SDP done. Call bond_state_changed_cb BONDED",
1414- __func__);
1422+ p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) {
1423+ LOG_INFO(LOG_TAG, "%s Remote Service SDP done.", __func__);
14151424 pairing_cb.sdp_attempts = 0;
14161425
1417- // If bonding occured due to cross-key pairing, send bonding callback
1426+ // If bond occured due to cross-key pairing, send bond state callback
14181427 // for static address now
1419- if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)
1428+ if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) {
14201429 bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING);
1421-
1422- bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED);
1430+ bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED);
1431+ }
1432+ if (pairing_cb.state == BT_BOND_STATE_BONDED) {
1433+ if (p_data->disc_res.result == BTA_SUCCESS) {
1434+ // Device is bonded and SDP completed. Clear the pairing control
1435+ // block.
1436+ pairing_cb = {};
1437+ } else {
1438+ // Report empty UUID to Java if SDP report negative result while
1439+ // pairing.
1440+ bt_property_t prop;
1441+ bt_uuid_t uuid;
1442+ char uuid_str[128] = UUID_EMPTY;
1443+
1444+ string_to_uuid(uuid_str, &uuid);
1445+
1446+ prop.type = BT_PROPERTY_UUIDS;
1447+ prop.val = uuid.uu;
1448+ prop.len = MAX_UUID_SIZE;
1449+
1450+ /* Send the event to the BTIF */
1451+ HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb,
1452+ BT_STATUS_SUCCESS, &bd_addr, 1, &prop);
1453+ break;
1454+ }
1455+ }
14231456 }
14241457
14251458 if (p_data->disc_res.num_uuids != 0) {
@@ -1629,7 +1662,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
16291662 break;
16301663
16311664 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1632- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
1665+ if (is_bonding_or_sdp()) {
16331666 bd_addr = pairing_cb.bd_addr;
16341667 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
16351668 bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result,
@@ -2277,7 +2310,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) {
22772310 ** 1. Restore scan modes
22782311 ** 2. special handling for HID devices
22792312 */
2280- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
2313+ if (is_bonding_or_sdp()) {
22812314 if (pairing_cb.is_ssp) {
22822315 if (pairing_cb.is_le_only) {
22832316 BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT);
@@ -2469,7 +2502,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) {
24692502
24702503 /*******************************************************************************
24712504 *
2472- * Function btif_dm_get_remote_services_transport
2505+ * Function btif_dm_get_remote_services_by_transport
24732506 *
24742507 * Description Start SDP to get remote services by transport
24752508 *
@@ -3171,7 +3204,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) {
31713204
31723205 void btif_dm_on_disable() {
31733206 /* cancel any pending pairing requests */
3174- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
3207+ if (is_bonding_or_sdp()) {
31753208 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__);
31763209 btif_dm_cancel_bond(&pairing_cb.bd_addr);
31773210 }
Show on old repository browser