system/bt
Revision | 56cdedd92b1bccd35738f832bf97ac57c1dc2169 (tree) |
---|---|
Zeit | 2019-07-16 04:58:39 |
Autor | Arjun Garg <arjgarg@goog...> |
Commiter | Arjun Garg |
Revert "DO NOT MERGE Separate SDP procedure from bonding state (1/2)"
This reverts commit 1df6bcbe986e783b486789d07afe35c47c2658ae.
@@ -183,7 +183,6 @@ typedef struct { | ||
183 | 183 | #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) |
184 | 184 | |
185 | 185 | #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" |
186 | -#define UUID_EMPTY "00000000-0000-0000-0000-000000000000" | |
187 | 186 | |
188 | 187 | #define MAX_BTIF_BOND_EVENT_ENTRIES 15 |
189 | 188 |
@@ -262,11 +261,6 @@ static bool is_empty_128bit(uint8_t* data) { | ||
262 | 261 | return !memcmp(zero, data, sizeof(zero)); |
263 | 262 | } |
264 | 263 | |
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 | - | |
270 | 264 | static void btif_dm_data_copy(uint16_t event, char* dst, char* src) { |
271 | 265 | tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst; |
272 | 266 | tBTA_DM_SEC* src_dm_sec = (tBTA_DM_SEC*)src; |
@@ -493,6 +487,8 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, | ||
493 | 487 | bt_bond_state_t state) { |
494 | 488 | btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state); |
495 | 489 | |
490 | + // Send bonding state only once - based on outgoing/incoming we may receive | |
491 | + // duplicates | |
496 | 492 | if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) { |
497 | 493 | // Cross key pairing so send callback for static address |
498 | 494 | if (!pairing_cb.static_bdaddr.IsEmpty()) { |
@@ -510,13 +506,14 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, | ||
510 | 506 | auto tmp = bd_addr; |
511 | 507 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, &tmp, state); |
512 | 508 | |
513 | - if (state == BT_BOND_STATE_BONDING || | |
514 | - (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { | |
515 | - // Save state for the device is bonding or SDP. | |
509 | + if (state == BT_BOND_STATE_BONDING) { | |
516 | 510 | pairing_cb.state = state; |
517 | 511 | pairing_cb.bd_addr = bd_addr; |
518 | 512 | } else { |
519 | - pairing_cb = {}; | |
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__); | |
520 | 517 | } |
521 | 518 | } |
522 | 519 |
@@ -1124,17 +1121,6 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
1124 | 1121 | |
1125 | 1122 | /* Trigger SDP on the device */ |
1126 | 1123 | pairing_cb.sdp_attempts = 1; |
1127 | - | |
1128 | - if (is_crosskey) { | |
1129 | - // If bonding occurred due to cross-key pairing, send bonding callback | |
1130 | - // for static address now | |
1131 | - LOG_INFO(LOG_TAG, | |
1132 | - "%s: send bonding state update for static address %s", | |
1133 | - __func__, bd_addr.ToString().c_str()); | |
1134 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDING); | |
1135 | - } | |
1136 | - bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1137 | - | |
1138 | 1124 | btif_dm_get_remote_services(bd_addr); |
1139 | 1125 | } |
1140 | 1126 | } |
@@ -1392,9 +1378,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1392 | 1378 | |
1393 | 1379 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__, |
1394 | 1380 | p_data->disc_res.result, p_data->disc_res.services); |
1395 | - if (p_data->disc_res.result != BTA_SUCCESS && | |
1396 | - pairing_cb.state == BT_BOND_STATE_BONDED && | |
1397 | - pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) { | |
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)) { | |
1398 | 1384 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", |
1399 | 1385 | __func__); |
1400 | 1386 | pairing_cb.sdp_attempts++; |
@@ -1419,38 +1405,21 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1419 | 1405 | /* onUuidChanged requires getBondedDevices to be populated. |
1420 | 1406 | ** bond_state_changed needs to be sent prior to remote_device_property |
1421 | 1407 | */ |
1422 | - if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) && | |
1408 | + if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1423 | 1409 | (p_data->disc_res.bd_addr == pairing_cb.bd_addr || |
1424 | - p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) { | |
1425 | - LOG_INFO(LOG_TAG, "%s: SDP search done for %s", __func__, | |
1426 | - bd_addr.ToString().c_str()); | |
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__); | |
1427 | 1415 | pairing_cb.sdp_attempts = 0; |
1428 | 1416 | |
1429 | - // Both SDP and bonding are done, clear pairing control block | |
1430 | - pairing_cb = {}; | |
1431 | - | |
1432 | - // Send one empty UUID to Java to unblock pairing intent when SDP failed | |
1433 | - // or no UUID is discovered | |
1434 | - if (p_data->disc_res.result != BTA_SUCCESS || | |
1435 | - p_data->disc_res.num_uuids == 0) { | |
1436 | - LOG_INFO(LOG_TAG, | |
1437 | - "%s: SDP failed, send empty UUID to unblock bonding %s", | |
1438 | - __func__, bd_addr.ToString().c_str()); | |
1439 | - bt_property_t prop; | |
1440 | - bt_uuid_t uuid = {}; | |
1441 | - char uuid_str[128] = UUID_EMPTY; | |
1442 | - | |
1443 | - string_to_uuid(uuid_str, &uuid); | |
1444 | - | |
1445 | - prop.type = BT_PROPERTY_UUIDS; | |
1446 | - prop.val = uuid.uu; | |
1447 | - prop.len = MAX_UUID_SIZE; | |
1448 | - | |
1449 | - /* Send the event to the BTIF */ | |
1450 | - HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1451 | - BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1452 | - break; | |
1453 | - } | |
1417 | + // If bonding occured due to cross-key pairing, send bonding callback | |
1418 | + // for static address now | |
1419 | + if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) | |
1420 | + 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); | |
1454 | 1423 | } |
1455 | 1424 | |
1456 | 1425 | if (p_data->disc_res.num_uuids != 0) { |
@@ -1660,7 +1629,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) { | ||
1660 | 1629 | break; |
1661 | 1630 | |
1662 | 1631 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1663 | - if (is_bonding_or_sdp()) { | |
1632 | + if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
1664 | 1633 | bd_addr = pairing_cb.bd_addr; |
1665 | 1634 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
1666 | 1635 | bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result, |
@@ -2308,7 +2277,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) { | ||
2308 | 2277 | ** 1. Restore scan modes |
2309 | 2278 | ** 2. special handling for HID devices |
2310 | 2279 | */ |
2311 | - if (is_bonding_or_sdp()) { | |
2280 | + if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
2312 | 2281 | if (pairing_cb.is_ssp) { |
2313 | 2282 | if (pairing_cb.is_le_only) { |
2314 | 2283 | BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT); |
@@ -2500,7 +2469,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) { | ||
2500 | 2469 | |
2501 | 2470 | /******************************************************************************* |
2502 | 2471 | * |
2503 | - * Function btif_dm_get_remote_services_by_transport | |
2472 | + * Function btif_dm_get_remote_services_transport | |
2504 | 2473 | * |
2505 | 2474 | * Description Start SDP to get remote services by transport |
2506 | 2475 | * |
@@ -2892,10 +2861,6 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
2892 | 2861 | break; |
2893 | 2862 | } |
2894 | 2863 | } |
2895 | - if (state == BT_BOND_STATE_BONDED && bd_addr != pairing_cb.static_bdaddr) { | |
2896 | - // Report RPA bonding state to Java in crosskey paring | |
2897 | - bond_state_changed(status, bd_addr, BT_BOND_STATE_BONDING); | |
2898 | - } | |
2899 | 2864 | bond_state_changed(status, bd_addr, state); |
2900 | 2865 | } |
2901 | 2866 |
@@ -3206,7 +3171,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { | ||
3206 | 3171 | |
3207 | 3172 | void btif_dm_on_disable() { |
3208 | 3173 | /* cancel any pending pairing requests */ |
3209 | - if (is_bonding_or_sdp()) { | |
3174 | + if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
3210 | 3175 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__); |
3211 | 3176 | btif_dm_cancel_bond(&pairing_cb.bd_addr); |
3212 | 3177 | } |