diff options
Diffstat (limited to 'stack/btm')
-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 |
3 files changed, 55 insertions, 10 deletions
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; /**************************************** |