system/bt
修订版 | ce061b32625f47b12b4a9f54beba93ec9cb9db1d (tree) |
---|---|
时间 | 2019-09-20 01:55:25 |
作者 | Ugo Yu <ugoyu@goog...> |
Commiter | Max Spector |
DO NOT MERGE Separate SDP procedure from bonding state (1/2)
- Do not stay in bonding state if the device is paried but still
- Report BOND_BONDED to Java after authentication for a classic
- Send BONDING event to Java when static identity address is
- Send BONDING event to Java for the initial random address
- Do not send bond event for static identity address when SDP is done.
- Make sure pairing control block always get cleaned up when both SDP
- Send empty UUIDs to Java layer to unblock bonding intent broadcast
Bug: 79703832
Test: runtest bluetooth, regression test
Change-Id: Ic33ca045b996c02a7c98e458f791a1747a8ea6d5
(cherry picked from commit 6628beb969f3f8e58972d2c2eb8b4bc053a11109)
@@ -257,6 +257,11 @@ static bool is_empty_128bit(uint8_t* data) { | ||
257 | 257 | return !memcmp(zero, data, sizeof(zero)); |
258 | 258 | } |
259 | 259 | |
260 | +static bool is_bonding_or_sdp() { | |
261 | + return pairing_cb.state == BT_BOND_STATE_BONDING || | |
262 | + (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts); | |
263 | +} | |
264 | + | |
260 | 265 | static void btif_dm_data_copy(uint16_t event, char* dst, char* src) { |
261 | 266 | tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst; |
262 | 267 | 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, | ||
483 | 488 | bt_bond_state_t state) { |
484 | 489 | btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state); |
485 | 490 | |
486 | - // Send bonding state only once - based on outgoing/incoming we may receive | |
487 | - // duplicates | |
488 | 491 | if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) { |
489 | 492 | // Cross key pairing so send callback for static address |
490 | 493 | if (!pairing_cb.static_bdaddr.IsEmpty()) { |
@@ -502,14 +505,13 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, | ||
502 | 505 | auto tmp = bd_addr; |
503 | 506 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, &tmp, state); |
504 | 507 | |
505 | - if (state == BT_BOND_STATE_BONDING) { | |
508 | + if (state == BT_BOND_STATE_BONDING || | |
509 | + (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { | |
510 | + // Save state for the device is bonding or SDP. | |
506 | 511 | pairing_cb.state = state; |
507 | 512 | pairing_cb.bd_addr = bd_addr; |
508 | 513 | } else { |
509 | - if (!pairing_cb.sdp_attempts) | |
510 | - memset(&pairing_cb, 0, sizeof(pairing_cb)); | |
511 | - else | |
512 | - BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__); | |
514 | + pairing_cb = {}; | |
513 | 515 | } |
514 | 516 | } |
515 | 517 |
@@ -1135,6 +1137,17 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
1135 | 1137 | |
1136 | 1138 | /* Trigger SDP on the device */ |
1137 | 1139 | pairing_cb.sdp_attempts = 1; |
1140 | + | |
1141 | + if (is_crosskey) { | |
1142 | + // If bonding occurred due to cross-key pairing, send bonding callback | |
1143 | + // for static address now | |
1144 | + LOG_INFO(LOG_TAG, | |
1145 | + "%s: send bonding state update for static address %s", | |
1146 | + __func__, bd_addr.ToString().c_str()); | |
1147 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); | |
1148 | + } | |
1149 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1150 | + | |
1138 | 1151 | btif_dm_get_remote_services(bd_addr); |
1139 | 1152 | } |
1140 | 1153 | } |
@@ -1393,7 +1406,7 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1393 | 1406 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__, |
1394 | 1407 | p_data->disc_res.result, p_data->disc_res.services); |
1395 | 1408 | if ((p_data->disc_res.result != BTA_SUCCESS) && |
1396 | - (pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1409 | + (pairing_cb.state == BT_BOND_STATE_BONDED) && | |
1397 | 1410 | (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) { |
1398 | 1411 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", |
1399 | 1412 | __func__); |
@@ -1416,21 +1429,35 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1416 | 1429 | /* onUuidChanged requires getBondedDevices to be populated. |
1417 | 1430 | ** bond_state_changed needs to be sent prior to remote_device_property |
1418 | 1431 | */ |
1419 | - if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1432 | + if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts && | |
1420 | 1433 | (p_data->disc_res.bd_addr == pairing_cb.bd_addr || |
1421 | - p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) && | |
1422 | - pairing_cb.sdp_attempts > 0) { | |
1423 | - BTIF_TRACE_DEBUG( | |
1424 | - "%s Remote Service SDP done. Call bond_state_changed_cb BONDED", | |
1425 | - __func__); | |
1434 | + p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) { | |
1435 | + LOG_INFO(LOG_TAG, "%s: SDP search done for %s", __func__, | |
1436 | + bd_addr.ToString().c_str()); | |
1426 | 1437 | pairing_cb.sdp_attempts = 0; |
1427 | 1438 | |
1428 | - // If bonding occured due to cross-key pairing, send bonding callback | |
1429 | - // for static address now | |
1430 | - if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) | |
1431 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); | |
1432 | - | |
1433 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1439 | + // Both SDP and bonding are done, clear pairing control block | |
1440 | + pairing_cb = {}; | |
1441 | + | |
1442 | + // Send one empty UUID to Java to unblock pairing intent when SDP failed | |
1443 | + // or no UUID is discovered | |
1444 | + if (p_data->disc_res.result != BTA_SUCCESS || | |
1445 | + p_data->disc_res.num_uuids == 0) { | |
1446 | + LOG_INFO(LOG_TAG, | |
1447 | + "%s: SDP failed, send empty UUID to unblock bonding %s", | |
1448 | + __func__, bd_addr.ToString().c_str()); | |
1449 | + bt_property_t prop; | |
1450 | + Uuid uuid = {}; | |
1451 | + | |
1452 | + prop.type = BT_PROPERTY_UUIDS; | |
1453 | + prop.val = &uuid; | |
1454 | + prop.len = Uuid::kNumBytes128; | |
1455 | + | |
1456 | + /* Send the event to the BTIF */ | |
1457 | + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1458 | + BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1459 | + break; | |
1460 | + } | |
1434 | 1461 | } |
1435 | 1462 | |
1436 | 1463 | if (p_data->disc_res.num_uuids != 0) { |
@@ -1625,7 +1652,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) { | ||
1625 | 1652 | break; |
1626 | 1653 | |
1627 | 1654 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1628 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
1655 | + if (is_bonding_or_sdp()) { | |
1629 | 1656 | bd_addr = pairing_cb.bd_addr; |
1630 | 1657 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
1631 | 1658 | bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result, |
@@ -2268,7 +2295,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) { | ||
2268 | 2295 | ** 1. Restore scan modes |
2269 | 2296 | ** 2. special handling for HID devices |
2270 | 2297 | */ |
2271 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
2298 | + if (is_bonding_or_sdp()) { | |
2272 | 2299 | if (pairing_cb.is_ssp) { |
2273 | 2300 | if (pairing_cb.is_le_only) { |
2274 | 2301 | BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT); |
@@ -2466,7 +2493,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) { | ||
2466 | 2493 | |
2467 | 2494 | /******************************************************************************* |
2468 | 2495 | * |
2469 | - * Function btif_dm_get_remote_services_transport | |
2496 | + * Function btif_dm_get_remote_services_by_transport | |
2470 | 2497 | * |
2471 | 2498 | * Description Start SDP to get remote services by transport |
2472 | 2499 | * |
@@ -2853,6 +2880,10 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
2853 | 2880 | break; |
2854 | 2881 | } |
2855 | 2882 | } |
2883 | + if (state == BT_BOND_STATE_BONDED && bd_addr != pairing_cb.static_bdaddr) { | |
2884 | + // Report RPA bonding state to Java in crosskey paring | |
2885 | + bond_state_changed(status, bd_addr, BT_BOND_STATE_BONDING); | |
2886 | + } | |
2856 | 2887 | bond_state_changed(status, bd_addr, state); |
2857 | 2888 | } |
2858 | 2889 |
@@ -3163,7 +3194,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { | ||
3163 | 3194 | |
3164 | 3195 | void btif_dm_on_disable() { |
3165 | 3196 | /* cancel any pending pairing requests */ |
3166 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
3197 | + if (is_bonding_or_sdp()) { | |
3167 | 3198 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__); |
3168 | 3199 | btif_dm_cancel_bond(&pairing_cb.bd_addr); |
3169 | 3200 | } |