2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-03 02:49:09 +08:00

Bluetooth: Don't send device found events for duplicate reports

Occasionally, during active scanning we will receive duplicate ADV_IND
reports from the same device before receiving the SCAN_RSP from them. In
order to not wake up user space unnecessarily it's better not to send
these extra events as they do not contain any new information.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
This commit is contained in:
Johan Hedberg 2014-03-25 14:34:59 +02:00 committed by Marcel Holtmann
parent 73cf71d986
commit 474ee066f5

View File

@ -4021,6 +4021,7 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
u8 bdaddr_type, s8 rssi, u8 *data, u8 len) u8 bdaddr_type, s8 rssi, u8 *data, u8 len)
{ {
struct discovery_state *d = &hdev->discovery; struct discovery_state *d = &hdev->discovery;
bool match;
/* Passive scanning shouldn't trigger any device found events */ /* Passive scanning shouldn't trigger any device found events */
if (hdev->le_scan_type == LE_SCAN_PASSIVE) { if (hdev->le_scan_type == LE_SCAN_PASSIVE) {
@ -4048,17 +4049,21 @@ static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr,
return; return;
} }
/* Check if the pending report is for the same device as the new one */
match = (!bacmp(bdaddr, &d->last_adv_addr) &&
bdaddr_type == d->last_adv_addr_type);
/* If the pending data doesn't match this report or this isn't a /* If the pending data doesn't match this report or this isn't a
* scan response (e.g. we got a duplicate ADV_IND) then force * scan response (e.g. we got a duplicate ADV_IND) then force
* sending of the pending data. * sending of the pending data.
*/ */
if (type != LE_ADV_SCAN_RSP || bacmp(bdaddr, &d->last_adv_addr) || if (type != LE_ADV_SCAN_RSP || !match) {
bdaddr_type != d->last_adv_addr_type) { /* Send out whatever is in the cache, but skip duplicates */
/* Send out whatever is in the cache */ if (!match)
mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
d->last_adv_addr_type, NULL, 0, 0, 1, d->last_adv_addr_type, NULL, 0,
d->last_adv_data, d->last_adv_data_len, 0, 1, d->last_adv_data,
NULL, 0); d->last_adv_data_len, NULL, 0);
/* If the new report will trigger a SCAN_REQ store it for /* If the new report will trigger a SCAN_REQ store it for
* later merging. * later merging.