Loading system/btif/src/btif_dm.c +54 −20 Original line number Original line Diff line number Diff line Loading @@ -191,6 +191,7 @@ typedef struct #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" #define UUID_EMPTY "00000000-0000-0000-0000-000000000000" #define MAX_BTIF_BOND_EVENT_ENTRIES 15 #define MAX_BTIF_BOND_EVENT_ENTRIES 15 Loading Loading @@ -269,6 +270,11 @@ static bool is_empty_128bit(uint8_t *data) return !memcmp(zero, data, sizeof(zero)); return !memcmp(zero, data, sizeof(zero)); } } static bool is_bonding_or_sdp() { return pairing_cb.state == BT_BOND_STATE_BONDING || (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts); } static void btif_dm_data_copy(uint16_t event, char *dst, char *src) static void btif_dm_data_copy(uint16_t event, char *dst, char *src) { { tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst; tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst; Loading Loading @@ -550,15 +556,14 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); if (state == BT_BOND_STATE_BONDING) if (state == BT_BOND_STATE_BONDING || (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { { // Save state for the device is bonding or SDP. pairing_cb.state = state; pairing_cb.state = state; bdcpy(pairing_cb.bd_addr, bd_addr->address); bdcpy(pairing_cb.bd_addr, bd_addr->address); } else { } else { if (!pairing_cb.sdp_attempts) memset(&pairing_cb, 0, sizeof(pairing_cb)); memset(&pairing_cb, 0, sizeof(pairing_cb)); else BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__); } } } } Loading Loading @@ -1203,6 +1208,14 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) // Ensure inquiry is stopped before attempting service discovery // Ensure inquiry is stopped before attempting service discovery btif_dm_cancel_discovery(); btif_dm_cancel_discovery(); if (is_crosskey) { // If bonding occurred due to cross-key pairing, send bonding callback // for static address now LOG_INFO(LOG_TAG, "%s: send bonding state update for static address", __func__); bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); /* Trigger SDP on the device */ /* Trigger SDP on the device */ pairing_cb.sdp_attempts = 1; pairing_cb.sdp_attempts = 1; Loading Loading @@ -1496,7 +1509,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, p_data->disc_res.result, p_data->disc_res.services); p_data->disc_res.result, p_data->disc_res.services); if ((p_data->disc_res.result != BTA_SUCCESS) && if ((p_data->disc_res.result != BTA_SUCCESS) && (pairing_cb.state == BT_BOND_STATE_BONDING ) && (pairing_cb.state == BT_BOND_STATE_BONDED) && (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) { { BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); Loading @@ -1521,21 +1534,37 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) /* onUuidChanged requires getBondedDevices to be populated. /* onUuidChanged requires getBondedDevices to be populated. ** bond_state_changed needs to be sent prior to remote_device_property ** bond_state_changed needs to be sent prior to remote_device_property */ */ if ((pairing_cb.state == BT_BOND_STATE_BONDING) && if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) && ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) && (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0))) pairing_cb.sdp_attempts > 0) { { BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED", LOG_INFO(LOG_TAG, "%s Remote Service SDP done.", __FUNCTION__); __FUNCTION__); pairing_cb.sdp_attempts = 0; pairing_cb.sdp_attempts = 0; // If bonding occured due to cross-key pairing, send bonding callback // Both SDP and bonding are done, clear pairing control block // for static address now memset(&pairing_cb, 0, sizeof(pairing_cb)); if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0) bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); // Send one empty UUID to Java to unblock pairing intent when SDP failed // or no UUID is discovered if (p_data->disc_res.result == BTA_SUCCESS || p_data->disc_res.num_uuids == 0) { LOG_INFO(LOG_TAG, "%s: SDP failed, send empty UUID to unblock bonding", __func__); bt_property_t prop; bt_uuid_t uuid = {}; char uuid_str[128] = UUID_EMPTY; string_to_uuid(uuid_str, &uuid); prop.type = BT_PROPERTY_UUIDS; prop.val = uuid.uu; prop.len = MAX_UUID_SIZE; /* Send the event to the BTIF */ HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, BT_STATUS_SUCCESS, &bd_addr, 1, &prop); break; } } } if (p_data->disc_res.num_uuids != 0) if (p_data->disc_res.num_uuids != 0) Loading Loading @@ -1755,7 +1784,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) break; break; case BTA_DM_BOND_CANCEL_CMPL_EVT: case BTA_DM_BOND_CANCEL_CMPL_EVT: if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { bdcpy(bd_addr.address, pairing_cb.bd_addr); bdcpy(bd_addr.address, pairing_cb.bd_addr); btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); Loading Loading @@ -2405,7 +2434,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) ** 1. Restore scan modes ** 1. Restore scan modes ** 2. special handling for HID devices ** 2. special handling for HID devices */ */ if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) Loading Loading @@ -2467,7 +2496,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) { { if (pairing_cb.state == BT_BOND_STATE_BONDING && if (is_bonding_or_sdp() && bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) { { bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); Loading Loading @@ -3100,6 +3129,11 @@ static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) break; break; } } } } if (state == BT_BOND_STATE_BONDED && (bdcmp(bd_addr.address, pairing_cb.static_bdaddr.address) != 0)) { // Report RPA bonding state to Java in crosskey paring bond_state_changed(status, &bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(status, &bd_addr, state); bond_state_changed(status, &bd_addr, state); } } Loading Loading @@ -3413,7 +3447,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len) void btif_dm_on_disable() void btif_dm_on_disable() { { /* cancel any pending pairing requests */ /* cancel any pending pairing requests */ if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { bt_bdaddr_t bd_addr; bt_bdaddr_t bd_addr; Loading Loading
system/btif/src/btif_dm.c +54 −20 Original line number Original line Diff line number Diff line Loading @@ -191,6 +191,7 @@ typedef struct #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) #define BTA_SERVICE_ID_TO_SERVICE_MASK(id) (1 << (id)) #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" #define UUID_HUMAN_INTERFACE_DEVICE "00001124-0000-1000-8000-00805f9b34fb" #define UUID_EMPTY "00000000-0000-0000-0000-000000000000" #define MAX_BTIF_BOND_EVENT_ENTRIES 15 #define MAX_BTIF_BOND_EVENT_ENTRIES 15 Loading Loading @@ -269,6 +270,11 @@ static bool is_empty_128bit(uint8_t *data) return !memcmp(zero, data, sizeof(zero)); return !memcmp(zero, data, sizeof(zero)); } } static bool is_bonding_or_sdp() { return pairing_cb.state == BT_BOND_STATE_BONDING || (pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts); } static void btif_dm_data_copy(uint16_t event, char *dst, char *src) static void btif_dm_data_copy(uint16_t event, char *dst, char *src) { { tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst; tBTA_DM_SEC *dst_dm_sec = (tBTA_DM_SEC*)dst; Loading Loading @@ -550,15 +556,14 @@ static void bond_state_changed(bt_status_t status, bt_bdaddr_t *bd_addr, bt_bond HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); HAL_CBACK(bt_hal_cbacks, bond_state_changed_cb, status, bd_addr, state); if (state == BT_BOND_STATE_BONDING) if (state == BT_BOND_STATE_BONDING || (state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts > 0)) { { // Save state for the device is bonding or SDP. pairing_cb.state = state; pairing_cb.state = state; bdcpy(pairing_cb.bd_addr, bd_addr->address); bdcpy(pairing_cb.bd_addr, bd_addr->address); } else { } else { if (!pairing_cb.sdp_attempts) memset(&pairing_cb, 0, sizeof(pairing_cb)); memset(&pairing_cb, 0, sizeof(pairing_cb)); else BTIF_TRACE_DEBUG("%s: BR-EDR service discovery active", __func__); } } } } Loading Loading @@ -1203,6 +1208,14 @@ static void btif_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) // Ensure inquiry is stopped before attempting service discovery // Ensure inquiry is stopped before attempting service discovery btif_dm_cancel_discovery(); btif_dm_cancel_discovery(); if (is_crosskey) { // If bonding occurred due to cross-key pairing, send bonding callback // for static address now LOG_INFO(LOG_TAG, "%s: send bonding state update for static address", __func__); bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); /* Trigger SDP on the device */ /* Trigger SDP on the device */ pairing_cb.sdp_attempts = 1; pairing_cb.sdp_attempts = 1; Loading Loading @@ -1496,7 +1509,7 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, BTIF_TRACE_DEBUG("%s:(result=0x%x, services 0x%x)", __FUNCTION__, p_data->disc_res.result, p_data->disc_res.services); p_data->disc_res.result, p_data->disc_res.services); if ((p_data->disc_res.result != BTA_SUCCESS) && if ((p_data->disc_res.result != BTA_SUCCESS) && (pairing_cb.state == BT_BOND_STATE_BONDING ) && (pairing_cb.state == BT_BOND_STATE_BONDED) && (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) (pairing_cb.sdp_attempts < BTIF_DM_MAX_SDP_ATTEMPTS_AFTER_PAIRING)) { { BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); BTIF_TRACE_WARNING("%s:SDP failed after bonding re-attempting", __FUNCTION__); Loading @@ -1521,21 +1534,37 @@ static void btif_dm_search_services_evt(UINT16 event, char *p_param) /* onUuidChanged requires getBondedDevices to be populated. /* onUuidChanged requires getBondedDevices to be populated. ** bond_state_changed needs to be sent prior to remote_device_property ** bond_state_changed needs to be sent prior to remote_device_property */ */ if ((pairing_cb.state == BT_BOND_STATE_BONDING) && if ((pairing_cb.state == BT_BOND_STATE_BONDED && pairing_cb.sdp_attempts) && ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || ((bdcmp(p_data->disc_res.bd_addr, pairing_cb.bd_addr) == 0) || (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0)) && (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0))) pairing_cb.sdp_attempts > 0) { { BTIF_TRACE_DEBUG("%s Remote Service SDP done. Call bond_state_changed_cb BONDED", LOG_INFO(LOG_TAG, "%s Remote Service SDP done.", __FUNCTION__); __FUNCTION__); pairing_cb.sdp_attempts = 0; pairing_cb.sdp_attempts = 0; // If bonding occured due to cross-key pairing, send bonding callback // Both SDP and bonding are done, clear pairing control block // for static address now memset(&pairing_cb, 0, sizeof(pairing_cb)); if (bdcmp(p_data->disc_res.bd_addr, pairing_cb.static_bdaddr.address) == 0) bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDING); bond_state_changed(BT_STATUS_SUCCESS, &bd_addr, BT_BOND_STATE_BONDED); // Send one empty UUID to Java to unblock pairing intent when SDP failed // or no UUID is discovered if (p_data->disc_res.result == BTA_SUCCESS || p_data->disc_res.num_uuids == 0) { LOG_INFO(LOG_TAG, "%s: SDP failed, send empty UUID to unblock bonding", __func__); bt_property_t prop; bt_uuid_t uuid = {}; char uuid_str[128] = UUID_EMPTY; string_to_uuid(uuid_str, &uuid); prop.type = BT_PROPERTY_UUIDS; prop.val = uuid.uu; prop.len = MAX_UUID_SIZE; /* Send the event to the BTIF */ HAL_CBACK(bt_hal_cbacks, remote_device_properties_cb, BT_STATUS_SUCCESS, &bd_addr, 1, &prop); break; } } } if (p_data->disc_res.num_uuids != 0) if (p_data->disc_res.num_uuids != 0) Loading Loading @@ -1755,7 +1784,7 @@ static void btif_dm_upstreams_evt(UINT16 event, char* p_param) break; break; case BTA_DM_BOND_CANCEL_CMPL_EVT: case BTA_DM_BOND_CANCEL_CMPL_EVT: if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { bdcpy(bd_addr.address, pairing_cb.bd_addr); bdcpy(bd_addr.address, pairing_cb.bd_addr); btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); btm_set_bond_type_dev(pairing_cb.bd_addr, BOND_TYPE_UNKNOWN); Loading Loading @@ -2405,7 +2434,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) ** 1. Restore scan modes ** 1. Restore scan modes ** 2. special handling for HID devices ** 2. special handling for HID devices */ */ if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) #if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE)) Loading Loading @@ -2467,7 +2496,7 @@ bt_status_t btif_dm_cancel_bond(const bt_bdaddr_t *bd_addr) void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) void btif_dm_hh_open_failed(bt_bdaddr_t *bdaddr) { { if (pairing_cb.state == BT_BOND_STATE_BONDING && if (is_bonding_or_sdp() && bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) bdcmp(bdaddr->address, pairing_cb.bd_addr) == 0) { { bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); bond_state_changed(BT_STATUS_FAIL, bdaddr, BT_BOND_STATE_NONE); Loading Loading @@ -3100,6 +3129,11 @@ static void btif_dm_ble_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl) break; break; } } } } if (state == BT_BOND_STATE_BONDED && (bdcmp(bd_addr.address, pairing_cb.static_bdaddr.address) != 0)) { // Report RPA bonding state to Java in crosskey paring bond_state_changed(status, &bd_addr, BT_BOND_STATE_BONDING); } bond_state_changed(status, &bd_addr, state); bond_state_changed(status, &bd_addr, state); } } Loading Loading @@ -3413,7 +3447,7 @@ bt_status_t btif_le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t len) void btif_dm_on_disable() void btif_dm_on_disable() { { /* cancel any pending pairing requests */ /* cancel any pending pairing requests */ if (pairing_cb.state == BT_BOND_STATE_BONDING) if (is_bonding_or_sdp()) { { bt_bdaddr_t bd_addr; bt_bdaddr_t bd_addr; Loading