system/bt
Revisão | 5240e718810550289c6cbb78eed44dfd28ef8066 (tree) |
---|---|
Hora | 2019-06-05 11:12:24 |
Autor | Ugo Yu <ugoyu@goog...> |
Commiter | Ugo Yu |
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: I60d8883e6d095b440cce49686a2049c8b5660235
Merged-In: I8a98ba2178039e25c65fc701855066a8788312e6
@@ -184,6 +184,7 @@ typedef struct { | ||
184 | 184 | #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) |
185 | 185 | |
186 | 186 | #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" |
187 | +#define UUID_EMPTY "00000000-0000-0000-0000-000000000000" | |
187 | 188 | |
188 | 189 | #define MAX_BTIF_BOND_EVENT_ENTRIES 15 |
189 | 190 |
@@ -262,6 +263,11 @@ static bool is_empty_128bit(uint8_t* data) { | ||
262 | 263 | return !memcmp(zero, data, sizeof(zero)); |
263 | 264 | } |
264 | 265 | |
266 | +static bool is_bonding_or_sdp() { | |
267 | + return pairing_cb.state == BT_BOND_STATE_BONDING || | |
268 | + (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts); | |
269 | +} | |
270 | + | |
265 | 271 | static void btif_dm_data_copy(uint16_t event, char* dst, char* src) { |
266 | 272 | tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst; |
267 | 273 | tBTA_DM_SEC* src_dm_sec = (tBTA_DM_SEC*)src; |
@@ -491,8 +497,6 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t* bd_addr, | ||
491 | 497 | bt_bond_state_t state) { |
492 | 498 | btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state); |
493 | 499 | |
494 | - // Send bonding state only once - based on outgoing/incoming we may receive | |
495 | - // duplicates | |
496 | 500 | if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) { |
497 | 501 | // Cross key pairing so send callback for static address |
498 | 502 | if (!bdaddr_is_empty(&pairing_cb.static_bdaddr)) { |
@@ -508,14 +512,13 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t* bd_addr, | ||
508 | 512 | |
509 | 513 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); |
510 | 514 | |
511 | - if (state == BT_BOND_STATE_BONDING) { | |
515 | + if (state == BT_BOND_STATE_BONDING || | |
516 | + (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { | |
517 | + // Save state for the device is bonding or SDP. | |
512 | 518 | pairing_cb.state = state; |
513 | 519 | bdcpy(pairing_cb.bd_addr, bd_addr->address); |
514 | 520 | } else { |
515 | - if (!pairing_cb.sdp_attempts) | |
516 | - memset(&pairing_cb, 0, sizeof(pairing_cb)); | |
517 | - else | |
518 | - BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__); | |
521 | + pairing_cb = {}; | |
519 | 522 | } |
520 | 523 | } |
521 | 524 |
@@ -1137,6 +1140,19 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
1137 | 1140 | |
1138 | 1141 | /* Trigger SDP on the device */ |
1139 | 1142 | pairing_cb.sdp_attempts = 1; |
1143 | + | |
1144 | + if (is_crosskey) { | |
1145 | + // If bonding occurred due to cross-key pairing, send bonding callback | |
1146 | + // for static address now | |
1147 | + bdstr_t bdstr; | |
1148 | + LOG_INFO(LOG_TAG, | |
1149 | + "%s: send bonding state update for static address %s", | |
1150 | + __func__, bdaddr_to_string(&bd_addr, bdstr, sizeof(bdstr))); | |
1151 | + bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, | |
1152 | + BT_BOND_STATE_BONDING); | |
1153 | + } | |
1154 | + bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); | |
1155 | + | |
1140 | 1156 | btif_dm_get_remote_services(&bd_addr); |
1141 | 1157 | } |
1142 | 1158 | } |
@@ -1398,9 +1414,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1398 | 1414 | |
1399 | 1415 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__, |
1400 | 1416 | p_data->disc_res.result, p_data->disc_res.services); |
1401 | - if ((p_data->disc_res.result != BTA_SUCCESS) && | |
1402 | - (pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1403 | - (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) { | |
1417 | + if (p_data->disc_res.result != BTA_SUCCESS && | |
1418 | + pairing_cb.state == BT_BOND_STATE_BONDED && | |
1419 | + pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) { | |
1404 | 1420 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", |
1405 | 1421 | __func__); |
1406 | 1422 | pairing_cb.sdp_attempts++; |
@@ -1425,24 +1441,41 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1425 | 1441 | /* onUuidChanged requires getBondedDevices to be populated. |
1426 | 1442 | ** bond_state_changed needs to be sent prior to remote_device_property |
1427 | 1443 | */ |
1428 | - if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1444 | + if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts && | |
1429 | 1445 | ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || |
1430 | 1446 | (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == |
1431 | - 0)) && | |
1432 | - pairing_cb.sdp_attempts > 0) { | |
1433 | - BTIF_TRACE_DEBUG( | |
1434 | - "%s Remote Service SDP done. Call bond_state_changed_cb BONDED", | |
1435 | - __func__); | |
1447 | + 0))) { | |
1448 | + bdstr_t bdstr; | |
1449 | + LOG_INFO(LOG_TAG, "%s: SDP search done for %s", __func__, | |
1450 | + bdaddr_to_string(&bd_addr, bdstr, sizeof(bdstr))); | |
1436 | 1451 | pairing_cb.sdp_attempts = 0; |
1437 | 1452 | |
1438 | - // If bonding occured due to cross-key pairing, send bonding callback | |
1439 | - // for static address now | |
1440 | - if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == | |
1441 | - 0) | |
1442 | - bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, | |
1443 | - BT_BOND_STATE_BONDING); | |
1444 | - | |
1445 | - bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); | |
1453 | + // Both SDP and bonding are done, clear pairing control block | |
1454 | + pairing_cb = {}; | |
1455 | + | |
1456 | + // Send one empty UUID to Java to unblock pairing intent when SDP failed | |
1457 | + // or no UUID is discovered | |
1458 | + if (p_data->disc_res.result != BTA_SUCCESS || | |
1459 | + p_data->disc_res.num_uuids == 0) { | |
1460 | + bdstr_t bdstr; | |
1461 | + LOG_INFO(LOG_TAG, | |
1462 | + "%s: SDP failed, send empty UUID to unblock bonding %s", | |
1463 | + __func__, bdaddr_to_string(&bd_addr, bdstr, sizeof(bdstr))); | |
1464 | + bt_property_t prop; | |
1465 | + bt_uuid_t uuid = {}; | |
1466 | + char uuid_str[128] = UUID_EMPTY; | |
1467 | + | |
1468 | + string_to_uuid(uuid_str, &uuid); | |
1469 | + | |
1470 | + prop.type = BT_PROPERTY_UUIDS; | |
1471 | + prop.val = uuid.uu; | |
1472 | + prop.len = MAX_UUID_SIZE; | |
1473 | + | |
1474 | + /* Send the event to the BTIF */ | |
1475 | + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1476 | + BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1477 | + break; | |
1478 | + } | |
1446 | 1479 | } |
1447 | 1480 | |
1448 | 1481 | if (p_data->disc_res.num_uuids != 0) { |
@@ -1654,7 +1687,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) { | ||
1654 | 1687 | break; |
1655 | 1688 | |
1656 | 1689 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1657 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
1690 | + if (is_bonding_or_sdp()) { | |
1658 | 1691 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
1659 | 1692 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
1660 | 1693 | bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result, |
@@ -2311,7 +2344,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t* bd_addr) { | ||
2311 | 2344 | ** 1. Restore scan modes |
2312 | 2345 | ** 2. special handling for HID devices |
2313 | 2346 | */ |
2314 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
2347 | + if (is_bonding_or_sdp()) { | |
2315 | 2348 | if (pairing_cb.is_ssp) { |
2316 | 2349 | if (pairing_cb.is_le_only) { |
2317 | 2350 | BTA_DmBleSecurityGrant((uint8_t*)bd_addr->address, |
@@ -2513,7 +2546,7 @@ bt_status_t btif_dm_get_remote_services(bt_bdaddr_t* remote_addr) { | ||
2513 | 2546 | |
2514 | 2547 | /******************************************************************************* |
2515 | 2548 | * |
2516 | - * Function btif_dm_get_remote_services_transport | |
2549 | + * Function btif_dm_get_remote_services_by_transport | |
2517 | 2550 | * |
2518 | 2551 | * Description Start SDP to get remote services by transport |
2519 | 2552 | * |
@@ -2931,6 +2964,11 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
2931 | 2964 | break; |
2932 | 2965 | } |
2933 | 2966 | } |
2967 | + if (state == BT_BOND_STATE_BONDED && | |
2968 | + memcmp(&bd_addr, &pairing_cb.static_bdaddr, BD_ADDR_LEN)) { | |
2969 | + // Report RPA bonding state to Java in crosskey paring | |
2970 | + bond_state_changed(status, &bd_addr, BT_BOND_STATE_BONDING); | |
2971 | + } | |
2934 | 2972 | bond_state_changed(status, &bd_addr, state); |
2935 | 2973 | } |
2936 | 2974 |
@@ -3249,7 +3287,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { | ||
3249 | 3287 | |
3250 | 3288 | void btif_dm_on_disable() { |
3251 | 3289 | /* cancel any pending pairing requests */ |
3252 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
3290 | + if (is_bonding_or_sdp()) { | |
3253 | 3291 | bt_bdaddr_t bd_addr; |
3254 | 3292 | |
3255 | 3293 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__); |