system/bt
Revision | 7f531dbf2ba52e4bfdb130db2166b462b446b6e0 (tree) |
---|---|
Time | 2019-06-05 01:39:19 |
Author | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge changes from topic "am-d2784a9e-cd2f-4414-b4db-f53b523a7b87" into nyc-mr2-dev
* changes:
@@ -191,6 +191,7 @@ typedef struct | ||
191 | 191 | #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) |
192 | 192 | |
193 | 193 | #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" |
194 | +#define UUID_EMPTY "00000000-0000-0000-0000-000000000000" | |
194 | 195 | |
195 | 196 | #define MAX_BTIF_BOND_EVENT_ENTRIES 15 |
196 | 197 |
@@ -270,6 +271,11 @@ static bool is_empty_128bit(uint8_t *data) | ||
270 | 271 | return !memcmp(zero, data, sizeof(zero)); |
271 | 272 | } |
272 | 273 | |
274 | +static bool is_bonding_or_sdp() { | |
275 | + return pairing_cb.state == BT_BOND_STATE_BONDING || | |
276 | + (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts); | |
277 | +} | |
278 | + | |
273 | 279 | static void btif_dm_data_copy(uint16_t event, char *dst, char *src) |
274 | 280 | { |
275 | 281 | tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst; |
@@ -551,15 +557,14 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond | ||
551 | 557 | |
552 | 558 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); |
553 | 559 | |
554 | - if (state == BT_BOND_STATE_BONDING) | |
560 | + if (state == BT_BOND_STATE_BONDING || | |
561 | + (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) | |
555 | 562 | { |
563 | + // Save state for the device is bonding or SDP. | |
556 | 564 | pairing_cb.state = state; |
557 | 565 | bdcpy(pairing_cb.bd_addr, bd_addr->address); |
558 | 566 | } else { |
559 | - if (!pairing_cb.sdp_attempts) | |
560 | - memset(&pairing_cb, 0, sizeof(pairing_cb)); | |
561 | - else | |
562 | - BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__); | |
567 | + memset(&pairing_cb, 0, sizeof(pairing_cb)); | |
563 | 568 | } |
564 | 569 | } |
565 | 570 |
@@ -1187,6 +1192,14 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) | ||
1187 | 1192 | |
1188 | 1193 | // Ensure inquiry is stopped before attempting service discovery |
1189 | 1194 | btif_dm_cancel_discovery(); |
1195 | + if (is_crosskey) { | |
1196 | + // If bonding occurred due to cross-key pairing, send bonding callback | |
1197 | + // for static address now | |
1198 | + LOG_INFO(LOG_TAG, | |
1199 | + "%s: send bonding state update for static address", __func__); | |
1200 | + bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); | |
1201 | + } | |
1202 | + bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); | |
1190 | 1203 | |
1191 | 1204 | /* Trigger SDP on the device */ |
1192 | 1205 | pairing_cb.sdp_attempts = 1; |
@@ -1480,7 +1493,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) | ||
1480 | 1493 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, |
1481 | 1494 | p_data->disc_res.result, p_data->disc_res.services); |
1482 | 1495 | if ((p_data->disc_res.result != BTA_SUCCESS) && |
1483 | - (pairing_cb.state == BT_BOND_STATE_BONDING ) && | |
1496 | + (pairing_cb.state == BT_BOND_STATE_BONDED) && | |
1484 | 1497 | (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) |
1485 | 1498 | { |
1486 | 1499 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); |
@@ -1505,21 +1518,37 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) | ||
1505 | 1518 | /* onUuidChanged requires getBondedDevices to be populated. |
1506 | 1519 | ** bond_state_changed needs to be sent prior to remote_device_property |
1507 | 1520 | */ |
1508 | - if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1521 | + if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) && | |
1509 | 1522 | ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || |
1510 | - (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) && | |
1511 | - pairing_cb.sdp_attempts > 0) | |
1523 | + (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0))) | |
1512 | 1524 | { |
1513 | - BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED", | |
1514 | - __FUNCTION__); | |
1525 | + LOG_INFO(LOG_TAG, "%s Remote Service SDP done.", __FUNCTION__); | |
1515 | 1526 | pairing_cb.sdp_attempts = 0; |
1516 | 1527 | |
1517 | - // If bonding occured due to cross-key pairing, send bonding callback | |
1518 | - // for static address now | |
1519 | - if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0) | |
1520 | - bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); | |
1528 | + // Both SDP and bonding are done, clear pairing control block | |
1529 | + memset(&pairing_cb, 0, sizeof(pairing_cb)); | |
1530 | + | |
1531 | + // Send one empty UUID to Java to unblock pairing intent when SDP failed | |
1532 | + // or no UUID is discovered | |
1533 | + if (p_data->disc_res.result == BTA_SUCCESS || | |
1534 | + p_data->disc_res.num_uuids == 0) { | |
1535 | + LOG_INFO(LOG_TAG, "%s: SDP failed, send empty UUID to unblock bonding", | |
1536 | + __func__); | |
1537 | + bt_property_t prop; | |
1538 | + bt_uuid_t uuid = {}; | |
1539 | + char uuid_str[128] = UUID_EMPTY; | |
1521 | 1540 | |
1522 | - bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); | |
1541 | + string_to_uuid(uuid_str, &uuid); | |
1542 | + | |
1543 | + prop.type = BT_PROPERTY_UUIDS; | |
1544 | + prop.val = uuid.uu; | |
1545 | + prop.len = MAX_UUID_SIZE; | |
1546 | + | |
1547 | + /* Send the event to the BTIF */ | |
1548 | + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1549 | + BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1550 | + break; | |
1551 | + } | |
1523 | 1552 | } |
1524 | 1553 | |
1525 | 1554 | if (p_data->disc_res.num_uuids != 0) |
@@ -1743,7 +1772,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) | ||
1743 | 1772 | break; |
1744 | 1773 | |
1745 | 1774 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1746 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) | |
1775 | + if (is_bonding_or_sdp()) | |
1747 | 1776 | { |
1748 | 1777 | bdcpy(bd_addr.address, pairing_cb.bd_addr); |
1749 | 1778 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
@@ -2410,7 +2439,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) | ||
2410 | 2439 | ** 1. Restore scan modes |
2411 | 2440 | ** 2. special handling for HID devices |
2412 | 2441 | */ |
2413 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) | |
2442 | + if (is_bonding_or_sdp()) | |
2414 | 2443 | { |
2415 | 2444 | |
2416 | 2445 | #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) |
@@ -2472,7 +2501,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) | ||
2472 | 2501 | |
2473 | 2502 | void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) |
2474 | 2503 | { |
2475 | - if (pairing_cb.state == BT_BOND_STATE_BONDING && | |
2504 | + if (is_bonding_or_sdp() && | |
2476 | 2505 | bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) |
2477 | 2506 | { |
2478 | 2507 | bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); |
@@ -3112,6 +3141,11 @@ static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) | ||
3112 | 3141 | break; |
3113 | 3142 | } |
3114 | 3143 | } |
3144 | + if (state == BT_BOND_STATE_BONDED && | |
3145 | + (bdcmp(bd_addr.address, pairing_cb.static_bdaddr.address) != 0)) { | |
3146 | + // Report RPA bonding state to Java in crosskey paring | |
3147 | + bond_state_changed(status, &bd_addr, BT_BOND_STATE_BONDING); | |
3148 | + } | |
3115 | 3149 | bond_state_changed(status, &bd_addr, state); |
3116 | 3150 | } |
3117 | 3151 |
@@ -3462,7 +3496,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len) | ||
3462 | 3496 | void btif_dm_on_disable() |
3463 | 3497 | { |
3464 | 3498 | /* cancel any pending pairing requests */ |
3465 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) | |
3499 | + if (is_bonding_or_sdp()) | |
3466 | 3500 | { |
3467 | 3501 | bt_bdaddr_t bd_addr; |
3468 | 3502 |