• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/bt


Commit MetaInfo

Revisão5240e718810550289c6cbb78eed44dfd28ef8066 (tree)
Hora2019-06-05 11:12:24
AutorUgo Yu <ugoyu@goog...>
CommiterUgo Yu

Mensagem de Log

DO NOT MERGE Separate SDP procedure from bonding state (1/2)

- Do not stay in bonding state if the device is paried but still

discovering service.

- Report BOND_BONDED to Java after authentication for a classic

Bluetooth device is completed.

- Send BONDING event to Java when static identity address is

first obtained during crosskey pairing

- Send BONDING event to Java for the initial random address

before send BONDED event

- 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

and pairing are done

- Send empty UUIDs to Java layer to unblock bonding intent broadcast

when SDP fails

Bug: 79703832
Test: runtest bluetooth, regression test
Change-Id: I60d8883e6d095b440cce49686a2049c8b5660235
Merged-In: I8a98ba2178039e25c65fc701855066a8788312e6

Mudança Sumário

Diff

--- a/btif/src/btif_dm.cc
+++ b/btif/src/btif_dm.cc
@@ -184,6 +184,7 @@ typedef struct {
184184 #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id))
185185
186186 #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb"
187+#define UUID_EMPTY "00000000-0000-0000-0000-000000000000"
187188
188189 #define MAX_BTIF_BOND_EVENT_ENTRIES 15
189190
@@ -262,6 +263,11 @@ static bool is_empty_128bit(uint8_t* data) {
262263 return !memcmp(zero, data, sizeof(zero));
263264 }
264265
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+
265271 static void btif_dm_data_copy(uint16_t event, char* dst, char* src) {
266272 tBTA_DM_SEC* dst_dm_sec = (tBTA_DM_SEC*)dst;
267273 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,
491497 bt_bond_state_t state) {
492498 btif_stats_add_bond_event(bd_addr, BTIF_DM_FUNC_BOND_STATE_CHANGED, state);
493499
494- // Send bonding state only once - based on outgoing/incoming we may receive
495- // duplicates
496500 if ((pairing_cb.state == state) && (state == BT_BOND_STATE_BONDING)) {
497501 // Cross key pairing so send callback for static address
498502 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,
508512
509513 HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state);
510514
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.
512518 pairing_cb.state = state;
513519 bdcpy(pairing_cb.bd_addr, bd_addr->address);
514520 } 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 = {};
519522 }
520523 }
521524
@@ -1137,6 +1140,19 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
11371140
11381141 /* Trigger SDP on the device */
11391142 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+
11401156 btif_dm_get_remote_services(&bd_addr);
11411157 }
11421158 }
@@ -1398,9 +1414,9 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
13981414
13991415 BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __func__,
14001416 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) {
14041420 BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting",
14051421 __func__);
14061422 pairing_cb.sdp_attempts++;
@@ -1425,24 +1441,41 @@ static void btif_dm_search_services_evt(uint16_t event, char* p_param) {
14251441 /* onUuidChanged requires getBondedDevices to be populated.
14261442 ** bond_state_changed needs to be sent prior to remote_device_property
14271443 */
1428- if ((pairing_cb.state == BT_BOND_STATE_BONDING) &&
1444+ if (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts &&
14291445 ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) ||
14301446 (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)));
14361451 pairing_cb.sdp_attempts = 0;
14371452
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+ }
14461479 }
14471480
14481481 if (p_data->disc_res.num_uuids != 0) {
@@ -1654,7 +1687,7 @@ static void btif_dm_upstreams_evt(uint16_t event, char* p_param) {
16541687 break;
16551688
16561689 case BTA_DM_BOND_CANCEL_CMPL_EVT:
1657- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
1690+ if (is_bonding_or_sdp()) {
16581691 bdcpy(bd_addr.address, pairing_cb.bd_addr);
16591692 btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN);
16601693 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) {
23112344 ** 1. Restore scan modes
23122345 ** 2. special handling for HID devices
23132346 */
2314- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
2347+ if (is_bonding_or_sdp()) {
23152348 if (pairing_cb.is_ssp) {
23162349 if (pairing_cb.is_le_only) {
23172350 BTA_DmBleSecurityGrant((uint8_t*)bd_addr->address,
@@ -2513,7 +2546,7 @@ bt_status_t btif_dm_get_remote_services(bt_bdaddr_t* remote_addr) {
25132546
25142547 /*******************************************************************************
25152548 *
2516- * Function btif_dm_get_remote_services_transport
2549+ * Function btif_dm_get_remote_services_by_transport
25172550 *
25182551 * Description Start SDP to get remote services by transport
25192552 *
@@ -2931,6 +2964,11 @@ static void btif_dm_ble_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
29312964 break;
29322965 }
29332966 }
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+ }
29342972 bond_state_changed(status, &bd_addr, state);
29352973 }
29362974
@@ -3249,7 +3287,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t* buf, uint8_t len) {
32493287
32503288 void btif_dm_on_disable() {
32513289 /* cancel any pending pairing requests */
3252- if (pairing_cb.state == BT_BOND_STATE_BONDING) {
3290+ if (is_bonding_or_sdp()) {
32533291 bt_bdaddr_t bd_addr;
32543292
32553293 BTIF_TRACE_DEBUG("%s: Cancel pending pairing request", __func__);