system/bt
Révision | dc44715a83fcb547a74941ce8eb689ba7f08860f (tree) |
---|---|
l'heure | 2019-02-13 06:10:56 |
Auteur | Ugo Yu <ugoyu@goog...> |
Commiter | JP Sugarbroad |
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 is completed.
- Report empty UUID to Java if a classic Bluetooth device SDP
- Hold BOND_BONDED intent util SDP is findished.
- Only accept profile connection for the device is at bonded
Bug: 79703832
Test: runtest bluetooth
Change-Id: I023713e07308bfc0e5bb8d67f386bcc50f6a0f85
(cherry picked from commit 122e115b87fe98ca5e5e65b9765c146f9e52b65e)
(cherry picked from commit f3681c8616af4d052c410ba3e88747541a974bf5)
@@ -183,6 +183,7 @@ 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" | |
186 | 187 | |
187 | 188 | #define MAX_BTIF_BOND_EVENT_ENTRIES 15 |
188 | 189 |
@@ -261,6 +262,11 @@ static bool is_empty_128bit(uint8_t* data) { | ||
261 | 262 | return !memcmp(zero, data, sizeof(zero)); |
262 | 263 | } |
263 | 264 | |
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 | + | |
264 | 270 | static void btif_dm_data_copy(uint16_t event, char* dst, char* src) { |
265 | 271 | tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst; |
266 | 272 | tBTA_DM_SEC* src_dm_sec = (tBTA_DM_SEC*)src; |
@@ -487,8 +493,6 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, | ||
487 | 493 | bt_bond_state_t state) { |
488 | 494 | btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state); |
489 | 495 | |
490 | - // Send bonding state only once - based on outgoing/incoming we may receive | |
491 | - // duplicates | |
492 | 496 | if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) { |
493 | 497 | // Cross key pairing so send callback for static address |
494 | 498 | if (!pairing_cb.static_bdaddr.IsEmpty()) { |
@@ -506,14 +510,18 @@ static void bond_state_changed(bt_status_t status, const RawAddress& bd_addr, | ||
506 | 510 | auto tmp = bd_addr; |
507 | 511 | HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, &tmp, state); |
508 | 512 | |
509 | - if (state == BT_BOND_STATE_BONDING) { | |
513 | + int dev_type; | |
514 | + if (!btif_get_device_type(bd_addr, &dev_type)) { | |
515 | + dev_type = BT_DEVICE_TYPE_BREDR; | |
516 | + } | |
517 | + | |
518 | + if (state == BT_BOND_STATE_BONDING || | |
519 | + (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { | |
520 | + // Save state for the device is bonding or SDP. | |
510 | 521 | pairing_cb.state = state; |
511 | 522 | pairing_cb.bd_addr = bd_addr; |
512 | 523 | } else { |
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__); | |
524 | + pairing_cb = {}; | |
517 | 525 | } |
518 | 526 | } |
519 | 527 |
@@ -1121,6 +1129,10 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) { | ||
1121 | 1129 | |
1122 | 1130 | /* Trigger SDP on the device */ |
1123 | 1131 | pairing_cb.sdp_attempts = 1; |
1132 | + | |
1133 | + // Report bonded to Java before start SDP | |
1134 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1135 | + | |
1124 | 1136 | btif_dm_get_remote_services(bd_addr); |
1125 | 1137 | } |
1126 | 1138 | } |
@@ -1378,9 +1390,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1378 | 1390 | |
1379 | 1391 | BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__, |
1380 | 1392 | p_data->disc_res.result, p_data->disc_res.services); |
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)) { | |
1393 | + if (p_data->disc_res.result != BTA_SUCCESS && | |
1394 | + pairing_cb.state == BT_BOND_STATE_BONDED && | |
1395 | + pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING) { | |
1384 | 1396 | BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", |
1385 | 1397 | __func__); |
1386 | 1398 | pairing_cb.sdp_attempts++; |
@@ -1405,21 +1417,42 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) { | ||
1405 | 1417 | /* onUuidChanged requires getBondedDevices to be populated. |
1406 | 1418 | ** bond_state_changed needs to be sent prior to remote_device_property |
1407 | 1419 | */ |
1408 | - if ((pairing_cb.state == BT_BOND_STATE_BONDING) && | |
1420 | + if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) && | |
1409 | 1421 | (p_data->disc_res.bd_addr == pairing_cb.bd_addr || |
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__); | |
1422 | + p_data->disc_res.bd_addr == pairing_cb.static_bdaddr)) { | |
1423 | + LOG_INFO(LOG_TAG, "%s Remote Service SDP done.", __func__); | |
1415 | 1424 | pairing_cb.sdp_attempts = 0; |
1416 | 1425 | |
1417 | - // If bonding occured due to cross-key pairing, send bonding callback | |
1426 | + // If bond occured due to cross-key pairing, send bond state callback | |
1418 | 1427 | // for static address now |
1419 | - if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) | |
1428 | + if (p_data->disc_res.bd_addr == pairing_cb.static_bdaddr) { | |
1420 | 1429 | 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); | |
1430 | + bond_state_changed(BT_STATUS_SUCCESS, bd_addr, BT_BOND_STATE_BONDED); | |
1431 | + } | |
1432 | + if (pairing_cb.state == BT_BOND_STATE_BONDED) { | |
1433 | + if (p_data->disc_res.result == BTA_SUCCESS) { | |
1434 | + // Device is bonded and SDP completed. Clear the pairing control | |
1435 | + // block. | |
1436 | + pairing_cb = {}; | |
1437 | + } else { | |
1438 | + // Report empty UUID to Java if SDP report negative result while | |
1439 | + // pairing. | |
1440 | + bt_property_t prop; | |
1441 | + bt_uuid_t uuid; | |
1442 | + char uuid_str[128] = UUID_EMPTY; | |
1443 | + | |
1444 | + string_to_uuid(uuid_str, &uuid); | |
1445 | + | |
1446 | + prop.type = BT_PROPERTY_UUIDS; | |
1447 | + prop.val = uuid.uu; | |
1448 | + prop.len = MAX_UUID_SIZE; | |
1449 | + | |
1450 | + /* Send the event to the BTIF */ | |
1451 | + HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, | |
1452 | + BT_STATUS_SUCCESS, &bd_addr, 1, &prop); | |
1453 | + break; | |
1454 | + } | |
1455 | + } | |
1423 | 1456 | } |
1424 | 1457 | |
1425 | 1458 | if (p_data->disc_res.num_uuids != 0) { |
@@ -1629,7 +1662,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) { | ||
1629 | 1662 | break; |
1630 | 1663 | |
1631 | 1664 | case BTA_DM_BOND_CANCEL_CMPL_EVT: |
1632 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
1665 | + if (is_bonding_or_sdp()) { | |
1633 | 1666 | bd_addr = pairing_cb.bd_addr; |
1634 | 1667 | btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); |
1635 | 1668 | bond_state_changed((bt_status_t)p_data->bond_cancel_cmpl.result, |
@@ -2277,7 +2310,7 @@ bt_status_t btif_dm_cancel_bond(const RawAddress* bd_addr) { | ||
2277 | 2310 | ** 1. Restore scan modes |
2278 | 2311 | ** 2. special handling for HID devices |
2279 | 2312 | */ |
2280 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
2313 | + if (is_bonding_or_sdp()) { | |
2281 | 2314 | if (pairing_cb.is_ssp) { |
2282 | 2315 | if (pairing_cb.is_le_only) { |
2283 | 2316 | BTA_DmBleSecurityGrant(*bd_addr, BTA_DM_SEC_PAIR_NOT_SPT); |
@@ -2469,7 +2502,7 @@ bt_status_t btif_dm_get_remote_services(const RawAddress& remote_addr) { | ||
2469 | 2502 | |
2470 | 2503 | /******************************************************************************* |
2471 | 2504 | * |
2472 | - * Function btif_dm_get_remote_services_transport | |
2505 | + * Function btif_dm_get_remote_services_by_transport | |
2473 | 2506 | * |
2474 | 2507 | * Description Start SDP to get remote services by transport |
2475 | 2508 | * |
@@ -3171,7 +3204,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) { | ||
3171 | 3204 | |
3172 | 3205 | void btif_dm_on_disable() { |
3173 | 3206 | /* cancel any pending pairing requests */ |
3174 | - if (pairing_cb.state == BT_BOND_STATE_BONDING) { | |
3207 | + if (is_bonding_or_sdp()) { | |
3175 | 3208 | BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__); |
3176 | 3209 | btif_dm_cancel_bond(&pairing_cb.bd_addr); |
3177 | 3210 | } |