From 82bb0ebe0760cd131400de9ececaae682f6c7f97 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski <jpawlowski@google.com> Date: Fri, 27 Jan 2017 08:06:20 -0800 Subject: [PATCH] Propagate BT5 specific scan result properties up the stack (2/3) Bug: 30622771 Test: sl4a FilteringTest Change-Id: Ib9d18ea3a1fc7d95300415a04b551d66767b04d2 --- system/bta/dm/bta_dm_act.cc | 6 +++ system/bta/include/bta_api.h | 5 ++ system/btif/src/btif_ble_scanner.cc | 20 +++++--- system/service/gatt_server_old.cc | 7 ++- .../service/hal/bluetooth_gatt_interface.cc | 5 +- system/stack/btm/btm_ble_gap.cc | 49 ++++++++++++------- system/stack/include/btm_api_types.h | 13 +++++ 7 files changed, 78 insertions(+), 27 deletions(-) diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc index 8972e0c8df9..cf850cc587e 100644 --- a/system/bta/dm/bta_dm_act.cc +++ b/system/bta/dm/bta_dm_act.cc @@ -3942,6 +3942,12 @@ static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir) { result.inq_res.inq_result_type = p_inq->inq_result_type; result.inq_res.device_type = p_inq->device_type; result.inq_res.flag = p_inq->flag; + result.inq_res.ble_evt_type = p_inq->ble_evt_type; + result.inq_res.ble_primary_phy = p_inq->ble_primary_phy; + result.inq_res.ble_secondary_phy = p_inq->ble_secondary_phy; + result.inq_res.ble_advertising_sid = p_inq->ble_advertising_sid; + result.inq_res.ble_tx_power = p_inq->ble_tx_power; + result.inq_res.ble_periodic_adv_int = p_inq->ble_periodic_adv_int; /* application will parse EIR to find out remote device name */ result.inq_res.p_eir = p_eir; diff --git a/system/bta/include/bta_api.h b/system/bta/include/bta_api.h index da1d352640f..0a478982f9e 100644 --- a/system/bta/include/bta_api.h +++ b/system/bta/include/bta_api.h @@ -731,6 +731,11 @@ typedef struct { uint8_t inq_result_type; uint8_t ble_addr_type; uint16_t ble_evt_type; + uint8_t ble_primary_phy; + uint8_t ble_secondary_phy; + uint8_t ble_advertising_sid; + int8_t ble_tx_power; + uint16_t ble_periodic_adv_int; tBT_DEVICE_TYPE device_type; uint8_t flag; } tBTA_DM_INQ_RES; diff --git a/system/btif/src/btif_ble_scanner.cc b/system/btif/src/btif_ble_scanner.cc index 0dddfd73cc2..20984769cb1 100644 --- a/system/btif/src/btif_ble_scanner.cc +++ b/system/btif/src/btif_ble_scanner.cc @@ -217,6 +217,10 @@ void bta_batch_scan_reports_cb(int client_id, tBTA_STATUS status, void bta_scan_results_cb_impl(bt_bdaddr_t bd_addr, tBT_DEVICE_TYPE device_type, int8_t rssi, uint8_t addr_type, + uint16_t ble_evt_type, uint8_t ble_primary_phy, + uint8_t ble_secondary_phy, + uint8_t ble_advertising_sid, int8_t ble_tx_power, + uint16_t ble_periodic_adv_int, vector<uint8_t> value) { uint8_t remote_name_len; const uint8_t* p_eir_remote_name = NULL; @@ -255,8 +259,9 @@ void bta_scan_results_cb_impl(bt_bdaddr_t bd_addr, tBT_DEVICE_TYPE device_type, btif_storage_set_remote_addr_type(&bd_addr, addr_type); - HAL_CBACK(bt_gatt_callbacks, scanner->scan_result_cb, &bd_addr, rssi, - std::move(value)); + HAL_CBACK(bt_gatt_callbacks, scanner->scan_result_cb, ble_evt_type, addr_type, + &bd_addr, ble_primary_phy, ble_secondary_phy, ble_advertising_sid, + ble_tx_power, rssi, ble_periodic_adv_int, std::move(value)); } void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) { @@ -284,11 +289,14 @@ void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) { } } + tBTA_DM_INQ_RES* r = &p_data->inq_res; bt_bdaddr_t bdaddr; - bdcpy(bdaddr.address, p_data->inq_res.bd_addr); - do_in_jni_thread(Bind(bta_scan_results_cb_impl, bdaddr, - p_data->inq_res.device_type, p_data->inq_res.rssi, - p_data->inq_res.ble_addr_type, std::move(value))); + bdcpy(bdaddr.address, r->bd_addr); + do_in_jni_thread(Bind(bta_scan_results_cb_impl, bdaddr, r->device_type, + r->rssi, r->ble_addr_type, r->ble_evt_type, + r->ble_primary_phy, r->ble_secondary_phy, + r->ble_advertising_sid, r->ble_tx_power, + r->ble_periodic_adv_int, std::move(value))); } void bta_track_adv_event_cb(tBTM_BLE_TRACK_ADV_DATA* p_track_adv_data) { diff --git a/system/service/gatt_server_old.cc b/system/service/gatt_server_old.cc index 17eaa8c5437..7dfd2b164ab 100644 --- a/system/service/gatt_server_old.cc +++ b/system/service/gatt_server_old.cc @@ -369,10 +369,13 @@ void ServiceStoppedCallback(int status, int server_if, int srvc_handle) { g_internal->api_synchronize.notify_one(); } -void ScanResultCallback(bt_bdaddr_t* bda, int rssi, +void ScanResultCallback(uint16_t ble_evt_type, uint8_t addr_type, + bt_bdaddr_t* bda, uint8_t ble_primary_phy, + uint8_t ble_secondary_phy, uint8_t ble_advertising_sid, + int8_t ble_tx_power, int8_t rssi, + uint16_t ble_periodic_adv_int, std::vector<uint8_t> adv_data) { std::string addr(BtAddrString(bda)); - (void)adv_data; std::lock_guard<std::mutex> lock(g_internal->lock); g_internal->scan_results[addr] = rssi; } diff --git a/system/service/hal/bluetooth_gatt_interface.cc b/system/service/hal/bluetooth_gatt_interface.cc index f672b3bb1a2..ea72e7b54a0 100644 --- a/system/service/hal/bluetooth_gatt_interface.cc +++ b/system/service/hal/bluetooth_gatt_interface.cc @@ -89,7 +89,10 @@ void RegisterClientCallback(int status, int client_if, bt_uuid_t* app_uuid) { } void ScanResultCallback( - bt_bdaddr_t* bda, int rssi, + uint16_t ble_evt_type, uint8_t addr_type, bt_bdaddr_t* bda, + uint8_t ble_primary_phy, uint8_t ble_secondary_phy, + uint8_t ble_advertising_sid, int8_t ble_tx_power, int8_t rssi, + uint16_t ble_periodic_adv_int, std::vector<uint8_t> adv_data) { // NOLINT(pass-by-value) shared_lock<shared_mutex_impl> lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); diff --git a/system/stack/btm/btm_ble_gap.cc b/system/stack/btm/btm_ble_gap.cc index 09d0cb986fd..e044e60d31a 100644 --- a/system/stack/btm/btm_ble_gap.cc +++ b/system/stack/btm/btm_ble_gap.cc @@ -64,9 +64,10 @@ static tBTM_BLE_CTRL_FEATURES_CBACK* p_ctrl_le_feature_rd_cmpl_cback = NULL; * Local functions ******************************************************************************/ static void btm_ble_update_adv_flag(uint8_t flag); -static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, - uint16_t evt_type, uint8_t data_len, - uint8_t* data, int8_t rssi); +static void btm_ble_process_adv_pkt_cont( + uint16_t evt_type, uint8_t addr_type, BD_ADDR bda, uint8_t primary_phy, + uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, + int8_t rssi, uint16_t periodic_adv_int, uint8_t data_len, uint8_t* data); static uint8_t btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB* p_cb, BD_ADDR_PTR p_peer_addr_ptr, tBLE_ADDR_TYPE* p_peer_addr_type, @@ -1859,8 +1860,11 @@ static void btm_ble_appearance_to_cod(uint16_t appearance, uint8_t* dev_class) { * Update adv packet information into inquiry result. */ bool btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type, - uint16_t evt_type, uint8_t data_len, - uint8_t* data, int8_t rssi) { + uint16_t evt_type, uint8_t primary_phy, + uint8_t secondary_phy, uint8_t advertising_sid, + int8_t tx_power, int8_t rssi, + uint16_t periodic_adv_int, uint8_t data_len, + uint8_t* data) { bool to_report = true; tBTM_INQ_RESULTS* p_cur = &p_i->inq_info.results; uint8_t len; @@ -1881,6 +1885,11 @@ bool btm_ble_update_inq_result(tINQ_DB_ENT* p_i, uint8_t addr_type, p_cur->inq_result_type = BTM_INQ_RESULT_BLE; p_cur->ble_addr_type = addr_type; p_cur->rssi = rssi; + p_cur->ble_primary_phy = primary_phy; + p_cur->ble_secondary_phy = secondary_phy; + p_cur->ble_advertising_sid = advertising_sid; + p_cur->ble_tx_power = tx_power; + p_cur->ble_periodic_adv_int = periodic_adv_int; /* active scan, always wait until get scan_rsp to report the result */ if (btm_cb.ble_ctr_cb.inq_var.scan_type == BTM_BLE_SCAN_MODE_ACTI && @@ -2061,8 +2070,9 @@ void btm_ble_process_ext_adv_pkt(uint8_t data_len, uint8_t* data) { } btm_ble_process_adv_addr(bda, addr_type); - btm_ble_process_adv_pkt_cont(bda, addr_type, event_type, pkt_data_len, - pkt_data, rssi); + btm_ble_process_adv_pkt_cont(event_type, addr_type, bda, primary_phy, + secondary_phy, advertising_sid, tx_power, rssi, + periodic_adv_int, pkt_data_len, pkt_data); } } @@ -2129,8 +2139,10 @@ void btm_ble_process_adv_pkt(uint8_t data_len, uint8_t* data) { return; } - btm_ble_process_adv_pkt_cont(bda, addr_type, event_type, pkt_data_len, - pkt_data, rssi); + btm_ble_process_adv_pkt_cont( + event_type, addr_type, bda, PHY_LE_1M, PHY_LE_NO_PACKET, NO_ADI_PRESENT, + TX_POWER_NOT_PRESENT, rssi, 0x00 /* no periodic adv */, pkt_data_len, + pkt_data); } } @@ -2138,15 +2150,13 @@ void btm_ble_process_adv_pkt(uint8_t data_len, uint8_t* data) { * This function is called after random address resolution is done, and proceed * to process adv packet. */ -static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, - uint16_t evt_type, uint8_t data_len, - uint8_t* data, int8_t rssi) { +static void btm_ble_process_adv_pkt_cont( + uint16_t evt_type, uint8_t addr_type, BD_ADDR bda, uint8_t primary_phy, + uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, + int8_t rssi, uint16_t periodic_adv_int, uint8_t data_len, uint8_t* data) { tINQ_DB_ENT* p_i; tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; - tBTM_INQ_RESULTS_CB* p_inq_results_cb = p_inq->p_inq_results_cb; - tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; bool update = true; - uint8_t result = 0; p_i = btm_inq_db_find(bda); @@ -2178,11 +2188,12 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, p_inq->inq_cmpl_info.num_resp++; } /* update the LE device information in inquiry database */ - if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, data_len, data, - rssi)) + if (!btm_ble_update_inq_result(p_i, addr_type, evt_type, primary_phy, + secondary_phy, advertising_sid, tx_power, rssi, + periodic_adv_int, data_len, data)) return; - result = btm_ble_is_discoverable(bda); + uint8_t result = btm_ble_is_discoverable(bda); if (result == 0) { LOG_WARN(LOG_TAG, "%s device no longer discoverable, discarding advertising packet", @@ -2214,6 +2225,8 @@ static void btm_ble_process_adv_pkt_cont(BD_ADDR bda, uint8_t addr_type, } } + tBTM_BLE_INQ_CB* p_le_inq_cb = &btm_cb.ble_ctr_cb.inq_var; + tBTM_INQ_RESULTS_CB* p_inq_results_cb = p_inq->p_inq_results_cb; if (p_inq_results_cb && (result & BTM_BLE_INQ_RESULT)) { (p_inq_results_cb)((tBTM_INQ_RESULTS*)&p_i->inq_info.results, p_le_inq_cb->adv_data_cache); diff --git a/system/stack/include/btm_api_types.h b/system/stack/include/btm_api_types.h index a2f1a13427f..8abaa0c2153 100644 --- a/system/stack/include/btm_api_types.h +++ b/system/stack/include/btm_api_types.h @@ -621,6 +621,14 @@ constexpr uint8_t BLE_EVT_DIRECTED_BIT = 2; constexpr uint8_t BLE_EVT_SCAN_RESPONSE_BIT = 3; constexpr uint8_t BLE_EVT_LEGACY_BIT = 4; +constexpr uint8_t PHY_LE_NO_PACKET = 0x00; +constexpr uint8_t PHY_LE_1M = 0x01; +constexpr uint8_t PHY_LE_2M = 0x02; +constexpr uint8_t PHY_LE_CODED = 0x03; + +constexpr uint8_t NO_ADI_PRESENT = 0xFF; +constexpr uint8_t TX_POWER_NOT_PRESENT = 0x7F; + /* These are the fields returned in each device's response to the inquiry. It * is returned in the results callback if registered. */ @@ -638,6 +646,11 @@ typedef struct { uint8_t inq_result_type; uint8_t ble_addr_type; uint16_t ble_evt_type; + uint8_t ble_primary_phy; + uint8_t ble_secondary_phy; + uint8_t ble_advertising_sid; + int8_t ble_tx_power; + uint16_t ble_periodic_adv_int; uint8_t flag; } tBTM_INQ_RESULTS; -- GitLab