diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-12-18 02:09:11 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-12-18 02:09:11 +0000 |
commit | 7dd923d180ac61c2d9d1afbedbceba2c66cad45a (patch) | |
tree | 4d8a79162210d3a83fefacf194d3e264da350394 | |
parent | 78dfd28572173eec985068ece27a5d7b5819a7d0 (diff) | |
parent | 70d7e7d21603bbcab90d6ba1ab14299708811193 (diff) | |
download | bt-7dd923d180ac61c2d9d1afbedbceba2c66cad45a.tar.gz |
Snap for 8012527 from 70d7e7d21603bbcab90d6ba1ab14299708811193 to sc-v2-release
Change-Id: Ieb1a81f8b5f1748d3bb6b058e195c8ca2d3c4981
-rw-r--r-- | bta/dm/bta_dm_act.cc | 7 | ||||
-rw-r--r-- | bta/include/bta_api.h | 1 | ||||
-rw-r--r-- | btif/src/btif_ble_scanner.cc | 6 | ||||
-rw-r--r-- | include/hardware/ble_scanner.h | 2 | ||||
-rw-r--r-- | main/shim/btm.cc | 7 | ||||
-rw-r--r-- | service/gatt_server_old.cc | 2 | ||||
-rw-r--r-- | service/hal/bluetooth_gatt_interface.cc | 2 | ||||
-rw-r--r-- | stack/btm/btm_ble_adv_filter.cc | 43 | ||||
-rw-r--r-- | stack/btm/btm_ble_gap.cc | 20 | ||||
-rw-r--r-- | stack/btm/neighbor_inquiry.h | 2 | ||||
-rw-r--r-- | test/mock/mock_stack_btm_ble_gap.cc | 2 |
11 files changed, 73 insertions, 21 deletions
diff --git a/bta/dm/bta_dm_act.cc b/bta/dm/bta_dm_act.cc index ebdd9594c..569cf3423 100644 --- a/bta/dm/bta_dm_act.cc +++ b/bta/dm/bta_dm_act.cc @@ -1814,6 +1814,10 @@ static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, uint16_t service_class; result.inq_res.bd_addr = p_inq->remote_bd_addr; + + // Pass the original address to GattService#onScanResult + result.inq_res.original_bda = p_inq->original_bda; + memcpy(result.inq_res.dev_class, p_inq->dev_class, DEV_CLASS_LEN); BTM_COD_SERVICE_CLASS(service_class, p_inq->dev_class); result.inq_res.is_limited = @@ -1858,7 +1862,6 @@ static void bta_dm_inq_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, ******************************************************************************/ static void bta_dm_inq_cmpl_cb(void* p_result) { APPL_TRACE_DEBUG("%s", __func__); - bta_dm_inq_cmpl(((tBTM_INQUIRY_CMPL*)p_result)->num_resp); } @@ -3311,8 +3314,8 @@ static void bta_dm_observe_results_cb(tBTM_INQ_RESULTS* p_inq, uint8_t* p_eir, tBTA_DM_SEARCH result; tBTM_INQ_INFO* p_inq_info; APPL_TRACE_DEBUG("bta_dm_observe_results_cb"); - result.inq_res.bd_addr = p_inq->remote_bd_addr; + result.inq_res.original_bda = p_inq->original_bda; result.inq_res.rssi = p_inq->rssi; result.inq_res.ble_addr_type = p_inq->ble_addr_type; result.inq_res.inq_result_type = p_inq->inq_result_type; diff --git a/bta/include/bta_api.h b/bta/include/bta_api.h index 8e3eb8d4f..398f6e5c1 100644 --- a/bta/include/bta_api.h +++ b/bta/include/bta_api.h @@ -427,6 +427,7 @@ typedef struct { uint16_t ble_periodic_adv_int; tBT_DEVICE_TYPE device_type; uint8_t flag; + RawAddress original_bda; /* original address to pass up to GattService#onScanResult */ } tBTA_DM_INQ_RES; /* Structure associated with BTA_DM_INQ_CMPL_EVT */ diff --git a/btif/src/btif_ble_scanner.cc b/btif/src/btif_ble_scanner.cc index badae4ed3..de03de990 100644 --- a/btif/src/btif_ble_scanner.cc +++ b/btif/src/btif_ble_scanner.cc @@ -109,7 +109,7 @@ void bta_scan_results_cb_impl(RawAddress bd_addr, tBT_DEVICE_TYPE device_type, 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) { + vector<uint8_t> value, RawAddress original_bda) { uint8_t remote_name_len; bt_device_type_t dev_type; bt_property_t properties; @@ -155,7 +155,7 @@ void bta_scan_results_cb_impl(RawAddress 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, 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)); + ble_tx_power, rssi, ble_periodic_adv_int, std::move(value), &original_bda); } void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) { @@ -188,7 +188,7 @@ void bta_scan_results_cb(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH* p_data) { 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))); + r->ble_periodic_adv_int, std::move(value), r->original_bda)); } void bta_track_adv_event_cb(tBTM_BLE_TRACK_ADV_DATA* p_track_adv_data) { diff --git a/include/hardware/ble_scanner.h b/include/hardware/ble_scanner.h index 7f4ee855f..9313aca28 100644 --- a/include/hardware/ble_scanner.h +++ b/include/hardware/ble_scanner.h @@ -43,7 +43,7 @@ typedef void (*scan_result_callback)(uint16_t event_type, uint8_t addr_type, uint8_t secondary_phy, uint8_t advertising_sid, int8_t tx_power, int8_t rssi, uint16_t periodic_adv_int, - std::vector<uint8_t> adv_data); + std::vector<uint8_t> adv_data, RawAddress* original_bda); typedef struct { scan_result_callback scan_result_cb; diff --git a/main/shim/btm.cc b/main/shim/btm.cc index b6a213504..40b9afd79 100644 --- a/main/shim/btm.cc +++ b/main/shim/btm.cc @@ -60,7 +60,7 @@ extern void btm_ble_process_adv_pkt_cont( uint16_t event_type, uint8_t address_type, const RawAddress& raw_address, 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); + uint8_t* data, const RawAddress& original_bda); extern void btm_api_process_inquiry_result(const RawAddress& raw_address, uint8_t page_scan_rep_mode, @@ -122,12 +122,15 @@ void Btm::ScanningCallbacks::OnScanResult( btm_ble_process_adv_addr(raw_address, &ble_address_type); } + // Pass up to GattService#onScanResult + RawAddress original_bda = raw_address; btm_ble_process_adv_addr(raw_address, &ble_address_type); btm_ble_process_adv_pkt_cont(extended_event_type, ble_address_type, raw_address, primary_phy, secondary_phy, advertising_sid, tx_power, rssi, periodic_advertising_interval, - advertising_data.size(), &advertising_data[0]); + advertising_data.size(), &advertising_data[0], + original_bda); } void Btm::ScanningCallbacks::OnTrackAdvFoundLost( diff --git a/service/gatt_server_old.cc b/service/gatt_server_old.cc index d72be583c..0719992db 100644 --- a/service/gatt_server_old.cc +++ b/service/gatt_server_old.cc @@ -377,7 +377,7 @@ void ScanResultCallback(uint16_t ble_evt_type, uint8_t addr_type, 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::vector<uint8_t> adv_data, RawAddress* original_bda) { std::string addr(BtAddrString(bda)); std::lock_guard<std::mutex> lock(g_internal->lock); g_internal->scan_results[addr] = rssi; diff --git a/service/hal/bluetooth_gatt_interface.cc b/service/hal/bluetooth_gatt_interface.cc index 505f3fc1e..5ae78e8d8 100644 --- a/service/hal/bluetooth_gatt_interface.cc +++ b/service/hal/bluetooth_gatt_interface.cc @@ -97,7 +97,7 @@ void ScanResultCallback( 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) + std::vector<uint8_t> adv_data, RawAddress* original_bda) { // NOLINT(pass-by-value) shared_lock<shared_mutex_impl> lock(g_instance_lock); VERIFY_INTERFACE_OR_RETURN(); CHECK(bda); diff --git a/stack/btm/btm_ble_adv_filter.cc b/stack/btm/btm_ble_adv_filter.cc index 710cca7e6..c84549ddf 100644 --- a/stack/btm/btm_ble_adv_filter.cc +++ b/stack/btm/btm_ble_adv_filter.cc @@ -479,18 +479,50 @@ static void BTM_LE_PF_addr_filter(tBTM_BLE_SCAN_COND_OP action, UINT8_TO_STREAM(p, filt_index); if (action != BTM_BLE_SCAN_COND_CLEAR) { - if (addr.type == BLE_ADDR_PUBLIC_ID) { + if (addr.type == BLE_ADDR_PUBLIC_ID || addr.type == BLE_ADDR_PUBLIC) { LOG(INFO) << __func__ << " Filter address " << addr.bda << " has type PUBLIC_ID, try to get identity address"; /* If no matching identity address is found for the input address, - * this call will have no effect. */ - btm_random_pseudo_to_identity_addr(&addr.bda, &addr.type); + * this call will have no effect. + * + * This is necessary in the case that the address passed is an RPA. The RPA is then looked + * up and converted to the identity address. + * + * However, we don't want to change the address type because if it is a 2 then the mapping + * function gets confused and defaults to 3. + * + * Using the dummy type we don't change the original type. + * + * This sort of change has been made in AOSP already. aosp/1842714 + */ + uint8_t dummy_addr_type; + btm_random_pseudo_to_identity_addr(&addr.bda, &dummy_addr_type); } LOG(INFO) << __func__ << " Adding scan filter with peer address: " << addr.bda; BDADDR_TO_STREAM(p, addr.bda); + + /* + * DANGER: Thar be dragons! + * + * The vendor command (APCF Filtering 0x0157) takes Public (0) or Random (1) or Any (2). + * + * Advertising results have four types: + *  - Public = 0 + *  - Random = 1 + *  - Public ID = 2 + *  - Random ID = 3 + * + * e.g. specifying PUBLIC (0) will only return results with a public address. + * It will ignore resolved addresses, since they return PUBLIC IDENTITY (2). + * For this, Any (0x02) must be specified. This should also cover if the RPA is + * derived from RANDOM STATIC. + */ + + /* ALWAYS FORCE 2 for this vendor command! */ + addr.type = 0x02; // Really, you will break scanning if you change this. UINT8_TO_STREAM(p, addr.type); } @@ -607,7 +639,7 @@ void BTM_LE_PF_set(tBTM_BLE_PF_FILT_INDEX filt_index, case BTM_BLE_PF_ADDR_FILTER: { tBLE_BD_ADDR target_addr; target_addr.bda = cmd.address; - target_addr.type = (cmd.addr_type & (~BLE_ADDR_TYPE_ID_BIT)); + target_addr.type = cmd.addr_type; BTM_LE_PF_addr_filter(action, filt_index, target_addr, base::DoNothing()); @@ -647,8 +679,7 @@ void BTM_LE_PF_set(tBTM_BLE_PF_FILT_INDEX filt_index, // Set the IRK tBTM_LE_PID_KEYS pid_keys; pid_keys.irk = cmd.irk; - pid_keys.identity_addr_type = - (cmd.addr_type & (~BLE_ADDR_TYPE_ID_BIT)); + pid_keys.identity_addr_type = cmd.addr_type; pid_keys.identity_addr = cmd.address; // Add it to the union to pass to SecAddBleKey tBTM_LE_KEY_VALUE le_key; diff --git a/stack/btm/btm_ble_gap.cc b/stack/btm/btm_ble_gap.cc index 9f8f7b0b7..907d0d85c 100644 --- a/stack/btm/btm_ble_gap.cc +++ b/stack/btm/btm_ble_gap.cc @@ -175,7 +175,8 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type, 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); + uint8_t data_len, uint8_t* data, + const RawAddress& original_bda); static uint8_t btm_set_conn_mode_adv_init_addr(RawAddress& p_peer_addr_ptr, tBLE_ADDR_TYPE* p_peer_addr_type, tBLE_ADDR_TYPE* p_own_addr_type); @@ -1774,13 +1775,17 @@ void btm_ble_process_ext_adv_pkt(uint8_t data_len, uint8_t* data) { rssi); } + // Store this to pass up the callback chain to GattService#onScanResult for the check + // in ScanFilter#matches + RawAddress original_bda = bda; + if (addr_type != BLE_ADDR_ANONYMOUS) { btm_ble_process_adv_addr(bda, &addr_type); } 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); + periodic_adv_int, pkt_data_len, pkt_data, original_bda); } } @@ -1829,6 +1834,9 @@ void btm_ble_process_adv_pkt(uint8_t data_len, uint8_t* data) { pkt_data_len, rssi); } + // Pass up the address to GattService#onScanResult to use in ScanFilter#matches + RawAddress original_bda = bda; + btm_ble_process_adv_addr(bda, &addr_type); uint16_t event_type; @@ -1860,7 +1868,7 @@ void btm_ble_process_adv_pkt(uint8_t data_len, uint8_t* data) { 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); + pkt_data, original_bda); } } @@ -1873,7 +1881,8 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type, 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) { + uint8_t data_len, uint8_t* data, + const RawAddress& original_bda) { tBTM_INQUIRY_VAR_ST* p_inq = &btm_cb.btm_inq_vars; bool update = true; @@ -1974,6 +1983,9 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type, if (!update) result &= ~BTM_BLE_INQ_RESULT; + // Pass address up to GattService#onScanResult + p_i->inq_info.results.original_bda = original_bda; + 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, diff --git a/stack/btm/neighbor_inquiry.h b/stack/btm/neighbor_inquiry.h index 8d1b0d547..eaa9e5dc5 100644 --- a/stack/btm/neighbor_inquiry.h +++ b/stack/btm/neighbor_inquiry.h @@ -116,6 +116,8 @@ typedef struct { int8_t ble_tx_power; uint16_t ble_periodic_adv_int; uint8_t flag; + // Pass original bda up to GattService#onScanResult + RawAddress original_bda; } tBTM_INQ_RESULTS; /**************************************** diff --git a/test/mock/mock_stack_btm_ble_gap.cc b/test/mock/mock_stack_btm_ble_gap.cc index 582a2dc40..a037692ad 100644 --- a/test/mock/mock_stack_btm_ble_gap.cc +++ b/test/mock/mock_stack_btm_ble_gap.cc @@ -154,7 +154,7 @@ void btm_ble_process_adv_pkt_cont(uint16_t evt_type, uint8_t addr_type, 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) { + uint8_t data_len, uint8_t* data, const RawAddress& original_bda) { mock_function_count_map[__func__]++; } void btm_ble_process_adv_pkt_cont_for_inquiry( |