system/bt
修訂 | e488319d82767ccac6bd628011c934e792ebbc13 (tree) |
---|---|
時間 | 2019-06-05 02:09:40 |
作者 | TreeHugger Robot <treehugger-gerrit@goog...> |
Commiter | Android (Google) Code Review |
Merge "DO NOT MERGE Separate SDP procedure from bonding state (1/2)" into pi-dev
@@ -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 |
@@ -1112,6 +1114,17 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
1112 | 1114 | |
1113 | 1115 | /* Trigger SDP on the device */ |
1114 | 1116 | pairing_cb.sdp_attempts = 1; |
1117 | + | |
1118 | + if (is_crosskey) { | |
1119 | + // If bonding occurred due to cross-key pairing, send bonding callback | |
1120 | + // for static address now | |
1121 | + LOG_INFO(LOG_TAG, | |
1122 | + "%s: send bonding state update for static address %s", | |
1123 | + __func__, bd_addr.ToString().c_str()); | |
1124 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); | |
1125 | + } | |
1126 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1127 | + | |
1115 | 1128 | btif_dm_get_remote_services(bd_addr); |
1116 | 1129 | } |
1117 | 1130 | } |
@@ -1369,9 +1382,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1369 | 1382 | |
1370 | 1383 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__, |
1371 | 1384 | p_data->disc_res.result, p_data->disc_res.services); |
1372 | - if ((p_data->disc_res.result != BTA_SUCCESS) && | |
1373 | - (pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1374 | - (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) { | |
1385 | + if (p_data->disc_res.result != BTA_SUCCESS && | |
1386 | + pairing_cb.state == BT_BOND_STATE_BONDED && | |
1387 | + pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) { | |
1375 | 1388 | if (pairing_cb.sdp_attempts) { |
1376 | 1389 | BTIF_TRACE_WARNING("%s: SDP failed after bonding re-attempting", |
1377 | 1390 | __func__); |
@@ -1398,21 +1411,35 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1398 | 1411 | /* onUuidChanged requires getBondedDevices to be populated. |
1399 | 1412 | ** bond_state_changed needs to be sent prior to remote_device_property |
1400 | 1413 | */ |
1401 | - if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1414 | + if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts && | |
1402 | 1415 | (p_data->disc_res.bd_addr == pairing_cb.bd_addr || |
1403 | - p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) && | |
1404 | - pairing_cb.sdp_attempts > 0) { | |
1405 | - BTIF_TRACE_DEBUG( | |
1406 | - "%s Remote Service SDP done. Call bond_state_changed_cb BONDED", | |
1407 | - __func__); | |
1416 | + p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) { | |
1417 | + LOG_INFO(LOG_TAG, "%s: SDP search done for %s", __func__, | |
1418 | + bd_addr.ToString().c_str()); | |
1408 | 1419 | pairing_cb.sdp_attempts = 0; |
1409 | 1420 | |
1410 | - // If bonding occured due to cross-key pairing, send bonding callback | |
1411 | - // for static address now | |
1412 | - if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) | |
1413 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); | |
1414 | - | |
1415 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1421 | + // Both SDP and bonding are done, clear pairing control block | |
1422 | + pairing_cb = {}; | |
1423 | + | |
1424 | + // Send one empty UUID to Java to unblock pairing intent when SDP failed | |
1425 | + // or no UUID is discovered | |
1426 | + if (p_data->disc_res.result != BTA_SUCCESS || | |
1427 | + p_data->disc_res.num_uuids == 0) { | |
1428 | + LOG_INFO(LOG_TAG, | |
1429 | + "%s: SDP failed, send empty UUID to unblock bonding %s", | |
1430 | + __func__, bd_addr.ToString().c_str()); | |
1431 | + bt_property_t prop; | |
1432 | + Uuid uuid = {}; | |
1433 | + | |
1434 | + prop.type = BT_PROPERTY_UUIDS; | |
1435 | + prop.val = &uuid; | |
1436 | + prop.len = Uuid::kNumBytes128; | |
1437 | + | |
1438 | + /* Send the event to the BTIF */ | |
1439 | + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1440 | + BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1441 | + break; | |
1442 | + } | |
1416 | 1443 | } |
1417 | 1444 | |
1418 | 1445 | if (p_data->disc_res.num_uuids != 0) { |
@@ -1607,7 +1634,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) { | ||
1607 | 1634 | break; |
1608 | 1635 | |
1609 | 1636 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1610 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
1637 | + if (is_bonding_or_sdp()) { | |
1611 | 1638 | bd_addr = pairing_cb.bd_addr; |
1612 | 1639 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
1613 | 1640 | bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result, |
@@ -2250,7 +2277,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) { | ||
2250 | 2277 | ** 1. Restore scan modes |
2251 | 2278 | ** 2. special handling for HID devices |
2252 | 2279 | */ |
2253 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
2280 | + if (is_bonding_or_sdp()) { | |
2254 | 2281 | if (pairing_cb.is_ssp) { |
2255 | 2282 | if (pairing_cb.is_le_only) { |
2256 | 2283 | BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT); |
@@ -2448,7 +2475,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) { | ||
2448 | 2475 | |
2449 | 2476 | /******************************************************************************* |
2450 | 2477 | * |
2451 | - * Function btif_dm_get_remote_services_transport | |
2478 | + * Function btif_dm_get_remote_services_by_transport | |
2452 | 2479 | * |
2453 | 2480 | * Description Start SDP to get remote services by transport |
2454 | 2481 | * |
@@ -2835,6 +2862,10 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
2835 | 2862 | break; |
2836 | 2863 | } |
2837 | 2864 | } |
2865 | + if (state == BT_BOND_STATE_BONDED && bd_addr != pairing_cb.static_bdaddr) { | |
2866 | + // Report RPA bonding state to Java in crosskey paring | |
2867 | + bond_state_changed(status, bd_addr, BT_BOND_STATE_BONDING); | |
2868 | + } | |
2838 | 2869 | bond_state_changed(status, bd_addr, state); |
2839 | 2870 | } |
2840 | 2871 |
@@ -3145,7 +3176,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { | ||
3145 | 3176 | |
3146 | 3177 | void btif_dm_on_disable() { |
3147 | 3178 | /* cancel any pending pairing requests */ |
3148 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
3179 | + if (is_bonding_or_sdp()) { | |
3149 | 3180 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__); |
3150 | 3181 | btif_dm_cancel_bond(&pairing_cb.bd_addr); |
3151 | 3182 | } |